-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters