Andrew Poulos
7/21/2014 4:11:00 AM
On 21/07/2014 4:07 AM, danca wrote:
> Il 20/07/2014 12:42, Thomas 'PointedEars' Lahn ha scritto:
>> Andrew Poulos wrote:
>>
>>> How about changing the code to something like:
>>>
>>> var AcrobatInfo = (function() {
>>
>> Not a constructor; by convention, the name should start lowercase.
>> Preferably, you would put it in a private namespace, like
>> â??ap.acrobatInfoâ?. Creating a user-defined object that would retrieve
>> the information about all plugins, and then would allow to retrieve
>> information for a specific plugin, is indicated.
>>
>>> var isInstalled = false, vern = null;
>>>
>>> function findPlugin(nme) { var p; for (key in navigator.plugins) {
>>
>> Do not use the for-in statement with host objects and array-like
>> objects; their properties may not be enumerable, not in a defined
>> order or have enumerable properties that you do not want to iterate
>> over (like â??refreshâ?); use the â??forâ? statement instead. Exception:
>> Array instances known to encapsulate a sparse array; in that case
>> for-in is more efficient, and you can filter and sort the properties
>> later, if necessary.
>>
>> You have not declared â??keyâ?; this code will throw a ReferenceError
>> exception in strict mode.
>>
>>> [â?¦] (function() { var plugin;
>>>
>>> if (typeof window.ActiveXObject != "undefined") {
>>
>> Check the â??ActiveXObjectâ? property of the global object instead.
>>
>>> // AcroPDF.PDF is used by version 7 and later // PDF.PdfCtrl is
>>> used by version 6 and earlier
>>
>> You should use multi-line comments for documentation instead, in
>> order to be able to tell them apart from deactivating comments
>> easily.
>>
>>> try { plugin = new ActiveXObject("AcroPDF.PDF"); isInstalled =
>>> true; } catch(e) {} try { plugin = new
>>> ActiveXObject("PDF.PdfCtrl"); isInstalled = true; } catch(e) {}
>>
>> You should nest those try-catch blocks, leaving at most one empty
>> â??catchâ? block.
>>
>> â??isInstalledâ? is superfluous because you can test against the value
>> of â??pluginâ? instead, which would be either not â??nullâ? or not
>> â??undefinedâ? if successful, depending on how you initialize it.
>>
>>> })(); [â?¦] })();
>>
>> I suggest you always use the same indentation for opening and
>> closing delimiters.
>>
>> And â??}())â? instead in order to make clear what makes up the
>> right-hand side expression. This will also become handy in editors
>> like Vim or Eclipse JSDT with Vrapper plugin, where, which I
>> discovered yesterday, you can type â??vi)â? to select everything between
>> the outer parentheses, for refactoring.
>>
>>
> Uhm... something like this?
> getInfo={}
> getInfo.acrobatInfo = (function() { var vern = null;
> function findPlugin(nme) { var p;
> for (var key=0; key<navigator.plugins.length; ++key) {
> p = navigator.plugins[key];
> if (p.name == nme) return p; }
> return null; }
> (function() { var plugin;
> if (typeof ActiveXObject != "undefined") { /* AcroPDF.PDF is used by
> version 7 and later - PDF.PdfCtrl is used by version 6 and earlier*/
> try { plugin = new ActiveXObject("AcroPDF.PDF")}
> catch(e) { try { plugin = new ActiveXObject("PDF.PdfCtrl")}
> catch(e) {}
> }
> if (plugin) { vern = plugin.GetVersions().split(',')[0].split('=')[1]; }
> } else { plugin = findPlugin('Adobe Acrobat') || findPlugin('Chrome PDF
> Viewer') || findPlugin('WebKit built-in PDF');
> if (plugin && plugin.version) vern = plugin.version; }
> plugin = null; })();
> return { installed: vern!=null, version: vern }; })();
>
> Usage
>
> var a = "Acrobat is " + (getInfo.acrobatInfo.installed?"":"not") +
> "installed. " + getInfo.acrobatInfo.version||"";
>
> Many thanks.
> I tested in FF, Konqueror and IE 8/9 and it seems to work, (ok I don't
> have Acrobat plugin installed in Konqueror so it's unclear). In IE 8 it
> truncates the version number, and in Opera 12.16 and Safari 5.1.7 the
> plugin is not detected.
It truncates the version in Chrome as well.
It works for me in Opera 22 and Safari 5 (under Windows) but to get the
version in Safari 5 I parsed plugin.description as plugin.version didn't
seem to exist.
Andrew Poulos