Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 76e8342cb91496d740397a098b7df6d276183c18
Merge: c5fc164 c108a1b
Author: Stu Cox <stuart.cox@gmail.com>
Date:   Tue Nov 26 18:09:11 2013 +0000

    Merge branch 'flash-detect' of https://github.com/patrickkettner/Modernizr into patrickkettner-flash-detect

    Conflicts:
    	lib/polyfills.json

commit c108a1b
Author: Patrick Kettner <patrickkettner@gmail.com>
Date:   Tue Oct 22 00:35:37 2013 -0400

    add flash detect
  • Loading branch information
stucox committed Nov 26, 2013
1 parent c5fc164 commit 28c4021
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
82 changes: 82 additions & 0 deletions feature-detects/flash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*!
{
"name": "Flash",
"property": "flash",
"tags": ["flash"],
"polyfills": ["shumway"]
}
!*/
/* DOC
Detects support flash, as well as flash blocking plugins
*/
define(['Modernizr', 'createElement', 'docElement', 'addTest'], function( Modernizr, createElement, docElement, addTest ) {
Modernizr.addAsyncTest(function() {
/* jshint -W053 */
var runTest = function(result, embed) {
var bool = !!result;
if (bool) {
bool = new Boolean(bool);
bool.blocked = (result === 'blocked');
}
addTest('flash', function() { return bool; });
if (embed) {
docElement.removeChild(embed);
}
};
var easy_detect;
var activex;
// we wrap activex in a try/catch becuase when flash is disabled through
// ActiveX controls, it throws an error.
try {
// Pan is an API that exists for flash objects.
activex = "Pan" in new window.ActiveXObject("ShockwaveFlash.ShockwaveFlash");
} catch(e) {}

easy_detect = !( ( "plugins" in navigator && "Shockwave Flash" in navigator.plugins ) || activex );

if (easy_detect) {
runTest(false);
}
else {
// flash seems to be installed, but it might be blocked. We have to
// actually create an element to see what happens to it.
var embed = createElement('embed');
var inline_style;

embed.type = 'application/x-shockwave-flash';

docElement.appendChild(embed);

// Pan doesn't exist in the embed if its IE (its on the ActiveXObjeect)
// so this check is for all other browsers.
if (!("Pan" in embed) && !activex) {
runTest('blocked', embed);
return;
}

// If we have got this far, there is still a chance a userland plugin
// is blocking us (either changing the styles, or automatically removing
// the element). Both of these require us to take a step back for a moment
// to allow for them to get time of the thread, hence a setTimeout.
setTimeout(function() {
if (!docElement.contains(embed)) {
runTest('blocked');
return;
}

inline_style = embed.style.cssText;
if (inline_style !== '') {
// the style of the element has changed automatically. This is a
// really poor heuristic, but for lower end flash blocks, it the
// only change they can make.
runTest('blocked', embed);
return;
}

runTest(true, embed);
}, 10);
}
});
});
1 change: 1 addition & 0 deletions lib/config-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"test/exif-orientation",
"test/file/api",
"test/file/filesystem",
"test/flash",
"test/forms/fileinput",
"test/forms/formattribute",
"test/forms/inputnumber-l10n",
Expand Down
6 changes: 6 additions & 0 deletions lib/polyfills.json
Original file line number Diff line number Diff line change
Expand Up @@ -681,5 +681,11 @@
"authors": ["web-animations"],
"href": "https://github.com/web-animations/web-animations-js",
"licenses": ["Apache2"]
},
"shumway": {
"name": "JavaScript Flash VM",
"authors": ["Mozilla Foundation"],
"href": "https://github.com/mozilla/shumway",
"licenses": ["Apache2"]
}
}

0 comments on commit 28c4021

Please sign in to comment.