├── .gitignore ├── .gitmodules ├── GNUmakefile ├── README.md ├── demo.html ├── flashblocknotifier.js └── flashblocknotifier.min.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "yuicompressor"] 2 | path = yuicompressor 3 | url = git://github.com/yui/yuicompressor.git 4 | -------------------------------------------------------------------------------- /GNUmakefile: -------------------------------------------------------------------------------- 1 | all: 2 | java -jar yuicompressor/build/yuicompressor-2.4.6.jar --type js --charset 'utf8' -o flashblocknotifier.min.js FlashBlockNotifier.js 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #FlashBlockNotifier 2 | This is a wrapper for swfobject that detects FlashBlock in browser. 3 | 4 | Script requires SWFObject (http://code.google.com/p/swfobject/). 5 | 6 | Also this wrapper can remove blocked swf and let you downgrade to other options. 7 | 8 | Feel free to contact me via email. 9 | 10 | Thanks to flashblockdetector project (http://code.google.com/p/flashblockdetector) 11 | 12 | © 2011-2012, Alexey Androsov 13 | 14 | Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) or GPL Version 3 (http://www.gnu.org/licenses/gpl.html) licenses. 15 | 16 | ##FlashBlockNotifier detects: 17 | - Chrome 18 | - FlashBlock (https://chrome.google.com/webstore/detail/cdngiadmnkhgemkimkhiilgffbjijcie) 19 | - FlashBlock (https://chrome.google.com/webstore/detail/gofhjkjmkpinhpoiabjplobcaignabnl) 20 | - FlashFree (https://chrome.google.com/webstore/detail/ebmieckllmmifjjbipnppinpiohpfahm) 21 | - Firefox Flashblock (https://addons.mozilla.org/ru/firefox/addon/flashblock/) 22 | - Opera >= 11.5 "Enable plugins on demand" setting 23 | - Safari ClickToFlash Extension (http://hoyois.github.com/safariextensions/clicktoplugin/) 24 | - Safari ClickToFlash Plugin (for Safari < 5.0.6) (http://rentzsch.github.com/clicktoflash/) 25 | 26 | ##Tested on: 27 | - Chrome 12 28 | - FlashBlock by Lex1 1.2.11.12 29 | - FlashBlock by josorek 0.9.31 30 | - FlashFree 1.1.3 31 | - Firefox 5.0.1 + Flashblock 1.5.15.1 32 | - Opera 11.5 33 | - Safari 5.1 + ClickToFlash (2.3.2) 34 | - Safari 5.1 + ClickToFlash (2.6) 35 | 36 | ##API Reference: 37 | FlashBlockNotifier.embedSWF(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn, removeBlockedSWF) 38 | 39 | Syntax is identical to [swfobject.emdebSWF](http://code.google.com/p/swfobject/wiki/api#swfobject.embedSWF(swfUrlStr,_replaceElemIdStr,_widthStr,_height). 40 | 41 | Last param "removeBlockedSWF" (default is true) tells FlashBlockNotifier to remove or not to remove blocked swf object from DOM. 42 | 43 | Event object in callbackFn has new property "__fbn" which means "swf can't load because of flashblock". 44 | -------------------------------------------------------------------------------- /demo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | FlashBlockNotifier demo page 6 | 7 | 8 | 9 | 10 |

This is demo page for FlashBlockNotifier project.

11 |

FlashBlockNotifier is a wrapper for swfobject that detects FlashBlock extensions in browsers (Chrome, Firefox, Opera, Safari).

12 |

This page source code.

13 |
14 |

15 | 16 | Result: 17 | 18 | 19 |

20 |
21 | 52 |
53 | 54 | -------------------------------------------------------------------------------- /flashblocknotifier.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a wrapper for swfobject that detects FlashBlock in browser. 3 | * 4 | * Wrapper detects: 5 | * - Chrome 6 | * - FlashBlock (https://chrome.google.com/webstore/detail/cdngiadmnkhgemkimkhiilgffbjijcie) 7 | * - FlashBlock (https://chrome.google.com/webstore/detail/gofhjkjmkpinhpoiabjplobcaignabnl) 8 | * - FlashFree (https://chrome.google.com/webstore/detail/ebmieckllmmifjjbipnppinpiohpfahm) 9 | * - Firefox Flashblock (https://addons.mozilla.org/ru/firefox/addon/flashblock/) 10 | * - Opera >= 11.5 "Enable plugins on demand" setting 11 | * - Safari ClickToFlash Extension (http://hoyois.github.com/safariextensions/clicktoplugin/) 12 | * - Safari ClickToFlash Plugin (for Safari < 5.0.6) (http://rentzsch.github.com/clicktoflash/) 13 | * 14 | * Tested on: 15 | * - Chrome 12 16 | * - FlashBlock by Lex1 1.2.11.12 17 | * - FlashBlock by josorek 0.9.31 18 | * - FlashFree 1.1.3 19 | * - Firefox 5.0.1 + Flashblock 1.5.15.1 20 | * - Opera 11.5 21 | * - Safari 5.1 + ClickToFlash (2.3.2) 22 | * - Safari 5.1 + ClickToFlash (2.6) 23 | * 24 | * Also this wrapper can remove blocked swf and let you downgrade to other options. 25 | * 26 | * Feel free to contact me via email. 27 | * 28 | * Copyright 2011, Alexey Androsov 29 | * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) or GPL Version 3 (http://www.gnu.org/licenses/gpl.html) licenses. 30 | * 31 | * @requires swfobject 32 | * @author Alexey Androsov 33 | * @version 1.0.2 34 | * 35 | * Thanks to flashblockdetector project (http://code.google.com/p/flashblockdetector) 36 | */ 37 | (function(/**document*/document, /**window*/window) { 38 | 39 | function remove(node) { 40 | var parent = node.parentNode; 41 | parent && parent.removeChild(node); 42 | } 43 | 44 | /** 45 | * FlashBlockNotifier is a wrapper for swfobject that detects FlashBlock in browser. 46 | */ 47 | var FlashBlockNotifier = window['FlashBlockNotifier'] = { 48 | 49 | /** 50 | * CSS-class for swf wrapper. 51 | * @protected 52 | * @default fbn-swf-wrapper 53 | * @type String 54 | */ 55 | __SWF_WRAPPER_CLASS: 'fbn-swf-wrapper', 56 | 57 | /** 58 | * Timeout for flash block detect 59 | * @default 500 60 | * @protected 61 | * @type Number 62 | */ 63 | __TIMEOUT: 500, 64 | 65 | __TESTS: [ 66 | // Chrome notification "The flash plug-in was blocked because it is out of date" 67 | //TODO: this test is very unstable, try to find another one 68 | function(swfNode) { 69 | return swfNode.getAttribute('title') === 'Flash'; 70 | }, 71 | // Chome FlashBlock extension (https://chrome.google.com/webstore/detail/cdngiadmnkhgemkimkhiilgffbjijcie) 72 | // Chome FlashBlock extension (https://chrome.google.com/webstore/detail/gofhjkjmkpinhpoiabjplobcaignabnl) 73 | function(swfNode, wrapperNode) { 74 | // we expect that swf is the only child of wrapper 75 | return wrapperNode.childNodes.length > 1 76 | }, 77 | // older Safari ClickToFlash (http://rentzsch.github.com/clicktoflash/) 78 | function(swfNode) { 79 | // IE has no swfNode.type 80 | return swfNode.type && swfNode.type != 'application/x-shockwave-flash' 81 | }, 82 | // FlashBlock for Firefox (https://addons.mozilla.org/ru/firefox/addon/flashblock/) 83 | // Chrome FlashFree (https://chrome.google.com/webstore/detail/ebmieckllmmifjjbipnppinpiohpfahm) 84 | function(swfNode) { 85 | // swf have been detached from DOM 86 | return !swfNode.parentNode; 87 | }, 88 | // Safari ClickToFlash Extension (http://hoyois.github.com/safariextensions/clicktoplugin/) 89 | function(swfNode) { 90 | var parentNode = swfNode.parentNode; 91 | 92 | if (parentNode) { 93 | if (parentNode.className.indexOf('CTFnodisplay') > -1) { 94 | return true; 95 | } 96 | 97 | try { 98 | // safe parentNode chain :) 99 | if (parentNode.parentNode.parentNode.id.indexOf('CTP') > -1) { 100 | //CTF Version >= 2.6 101 | return true; 102 | } 103 | } catch (e) { 104 | } 105 | 106 | } 107 | return false; 108 | } 109 | ], 110 | 111 | /** 112 | * Embed SWF info page. This function has same options as swfobject.embedSWF except last param removeBlockedSWF. 113 | * @see http://code.google.com/p/swfobject/wiki/api 114 | * @param swfUrlStr 115 | * @param replaceElemIdStr 116 | * @param widthStr 117 | * @param heightStr 118 | * @param swfVersionStr 119 | * @param xiSwfUrlStr 120 | * @param flashvarsObj 121 | * @param parObj 122 | * @param attObj 123 | * @param callbackFn 124 | * @param {Boolean} [removeBlockedSWF=true] Remove swf if blocked 125 | */ 126 | embedSWF: function(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn, removeBlockedSWF) { 127 | var swfobject = window['swfobject']; 128 | 129 | if (!swfobject) { 130 | return; 131 | } 132 | 133 | swfobject.addDomLoadEvent(function() { 134 | var replaceElement = document.getElementById(replaceElemIdStr); 135 | if (!replaceElement) { 136 | return; 137 | } 138 | 139 | // We need to create div-wrapper because some flash block plugins replace swf with another content. 140 | // Also some flash requires wrapper to work properly. 141 | var wrapper = document.createElement('div'); 142 | wrapper.className = FlashBlockNotifier.__SWF_WRAPPER_CLASS; 143 | 144 | replaceElement.parentNode.replaceChild(wrapper, replaceElement); 145 | wrapper.appendChild(replaceElement); 146 | 147 | swfobject.embedSWF(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj, function(e) { 148 | // e.success === false means that browser don't have flash or flash is too old 149 | // @see http://code.google.com/p/swfobject/wiki/api 150 | if (!e || e.success === false) { 151 | callbackFn(e); 152 | 153 | } else { 154 | var swfElement = e['ref'], 155 | getSVGDocument = false; 156 | 157 | try { 158 | //IE9 has this method, but crash on execute 159 | getSVGDocument = swfElement && swfElement['getSVGDocument'] && swfElement['getSVGDocument'](); 160 | } catch (e) { 161 | getSVGDocument = false; 162 | } 163 | 164 | if (getSVGDocument) { 165 | // Opera 11.5 and above replaces flash with SVG button 166 | onFailure(e); 167 | 168 | } else { 169 | //set timeout to let FlashBlock plugin detect swf and replace it some contents 170 | window.setTimeout(function() { 171 | var TESTS = FlashBlockNotifier.__TESTS; 172 | for (var i = 0, j = TESTS.length; i < j; i++) { 173 | if (TESTS[i](swfElement, wrapper)) { 174 | onFailure(e); 175 | return; 176 | } 177 | } 178 | callbackFn(e); 179 | }, FlashBlockNotifier.__TIMEOUT); 180 | } 181 | } 182 | 183 | function onFailure(e) { 184 | if (removeBlockedSWF !== false) { 185 | //remove swf 186 | swfobject.removeSWF(replaceElemIdStr); 187 | //remove wrapper 188 | remove(wrapper); 189 | 190 | //remove extension artefacts 191 | 192 | //ClickToFlash artefacts 193 | var ctf = document.getElementById('CTFstack'); 194 | if (ctf) { 195 | remove(ctf); 196 | } 197 | 198 | //Chrome FlashBlock artefact 199 | var lastBodyChild = document.body.lastChild; 200 | if (lastBodyChild && lastBodyChild.className == 'ujs_flashblock_placeholder') { 201 | remove(lastBodyChild); 202 | } 203 | } 204 | e.success = false; 205 | e.__fbn = true; 206 | callbackFn(e); 207 | } 208 | }); 209 | }); 210 | } 211 | }; 212 | 213 | })(document, window); 214 | -------------------------------------------------------------------------------- /flashblocknotifier.min.js: -------------------------------------------------------------------------------- 1 | (function(b,d){function a(f){var e=f.parentNode;e&&e.removeChild(f)}var c=d.FlashBlockNotifier={__SWF_WRAPPER_CLASS:"fbn-swf-wrapper",__TIMEOUT:500,__TESTS:[function(e){return e.getAttribute("title")==="Flash"},function(f,e){return e.childNodes.length>1},function(e){return e.type&&e.type!="application/x-shockwave-flash"},function(e){return !e.parentNode},function(h){var f=h.parentNode;if(f){if(f.className.indexOf("CTFnodisplay")>-1){return true}try{if(f.parentNode.parentNode.id.indexOf("CTP")>-1){return true}}catch(g){}}return false}],embedSWF:function(j,p,m,o,f,i,h,l,n,k,e){var g=d.swfobject;if(!g){return}g.addDomLoadEvent(function(){var q=b.getElementById(p);if(!q){return}var r=b.createElement("div");r.className=c.__SWF_WRAPPER_CLASS;q.parentNode.replaceChild(r,q);r.appendChild(q);g.embedSWF(j,p,m,o,f,i,h,l,n,function(u){if(!u||u.success===false){k(u)}else{var v=u.ref,s=false;try{s=v&&v.getSVGDocument&&v.getSVGDocument()}catch(u){s=false}if(s){t(u)}else{d.setTimeout(function(){var y=c.__TESTS;for(var x=0,w=y.length;x