From e2455a0609e2409ed7103e17af7f98f3d5c031f5 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford Date: Wed, 4 Jan 2017 13:56:12 -0800 Subject: [PATCH] Fix GH-103: Create SWF regardless of platform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Port LLK/scratchr2#4168 for ScratchX. Original description from that change: > This fixes #4112 by creating the swf regardless of OS and browser. > Calling `embedSWF` would first check for the existence of the plugin > before creating, causing browsers that don’t allow the flash plugin by > default to not be able to show their “allow” message. This tries to > create the swf no matter what, allowing browsers to detect flash > themselves. > > Logic is as follows: > 1. check if `userAgent` returns a mobile/tablet OS. Display error > message if so > 2. check if on windows and using ie – check for an express install if > so (like in `embedSWF`) > 3. load the swf in all other cases, let browsers handle it. > > Test Cases: > - Test how project pages load in Android and iOS devices, on tablets > and on phones, and on multiple desktop OS's for correct loading > behavior. This resolves LLK/scratchx#103 --- index.html | 1 + js/scratchx.js | 29 +++++++++++++++++++++++++---- libs/bowser.min.js | 6 ++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 libs/bowser.min.js diff --git a/index.html b/index.html index 9119fa2..6007329 100644 --- a/index.html +++ b/index.html @@ -689,6 +689,7 @@

Open an Extension Project

ga('send', 'pageview', 'home'); + diff --git a/js/scratchx.js b/js/scratchx.js index 4593c56..fe45a9d 100644 --- a/js/scratchx.js +++ b/js/scratchx.js @@ -109,14 +109,35 @@ var params = { }; $.each(flashVars, function (prop, val) { - if ($.isPlainObject(val)) - flashVars[prop] = encodeURIComponent(JSON.stringify(val)); + if ($.isPlainObject(val)) { + val = encodeURIComponent(JSON.stringify(val)); + } + if (typeof params.flashvars !== 'undefined') { + params.flashvars += '&' + prop + '=' + val; + } else { + params.flashvars = prop + '=' + val; + } }); swfobject.switchOffAutoHideShow(); -swfobject.embedSWF('Scratch.swf', 'scratch', '100%', '100%', '11.7.0', 'libs/expressInstall.swf', - flashVars, params, null, handleEmbedStatus); +var swfAttributes = { + data: 'Scratch.swf', + width: '100%', + height: '100%' +}; + +swfobject.addDomLoadEvent(function() { + // check if mobile/tablet browser user bowser + if(bowser.mobile || bowser.tablet) { + // if on mobile, show error screen + handleEmbedStatus({success: false}); + } else { + // if not on ie, let browser try to handle flash loading + var swf = swfobject.createSWF(swfAttributes, params, "scratch"); + handleEmbedStatus({success: true, ref: swf}); + } +}); /* File uploads */ diff --git a/libs/bowser.min.js b/libs/bowser.min.js new file mode 100644 index 0000000..affb143 --- /dev/null +++ b/libs/bowser.min.js @@ -0,0 +1,6 @@ +/*! + * Bowser - a browser detector + * https://github.com/ded/bowser + * MIT License | (c) Dustin Diaz 2014 + */ +!function(e,t){typeof module!="undefined"&&module.exports?module.exports.browser=t():typeof define=="function"&&define.amd?define(t):this[e]=t()}("bowser",function(){function t(t){function n(e){var n=t.match(e);return n&&n.length>1&&n[1]||""}var r=n(/(ipod|iphone|ipad)/i).toLowerCase(),i=/like android/i.test(t),s=!i&&/android/i.test(t),o=n(/version\/(\d+(\.\d+)?)/i),u=/tablet/i.test(t),a=!u&&/[^-]mobi/i.test(t),f;/opera|opr/i.test(t)?f={name:"Opera",opera:e,version:o||n(/(?:opera|opr)[\s\/](\d+(\.\d+)?)/i)}:/windows phone/i.test(t)?f={name:"Windows Phone",windowsphone:e,msie:e,version:n(/iemobile\/(\d+(\.\d+)?)/i)}:/msie|trident/i.test(t)?f={name:"Internet Explorer",msie:e,version:n(/(?:msie |rv:)(\d+(\.\d+)?)/i)}:/chrome|crios|crmo/i.test(t)?f={name:"Chrome",chrome:e,version:n(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i)}:r?(f={name:r=="iphone"?"iPhone":r=="ipad"?"iPad":"iPod"},o&&(f.version=o)):/sailfish/i.test(t)?f={name:"Sailfish",sailfish:e,version:n(/sailfish\s?browser\/(\d+(\.\d+)?)/i)}:/seamonkey\//i.test(t)?f={name:"SeaMonkey",seamonkey:e,version:n(/seamonkey\/(\d+(\.\d+)?)/i)}:/firefox|iceweasel/i.test(t)?(f={name:"Firefox",firefox:e,version:n(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i)},/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(t)&&(f.firefoxos=e)):/silk/i.test(t)?f={name:"Amazon Silk",silk:e,version:n(/silk\/(\d+(\.\d+)?)/i)}:s?f={name:"Android",version:o}:/phantom/i.test(t)?f={name:"PhantomJS",phantom:e,version:n(/phantomjs\/(\d+(\.\d+)?)/i)}:/blackberry|\bbb\d+/i.test(t)||/rim\stablet/i.test(t)?f={name:"BlackBerry",blackberry:e,version:o||n(/blackberry[\d]+\/(\d+(\.\d+)?)/i)}:/(web|hpw)os/i.test(t)?(f={name:"WebOS",webos:e,version:o||n(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i)},/touchpad\//i.test(t)&&(f.touchpad=e)):/bada/i.test(t)?f={name:"Bada",bada:e,version:n(/dolfin\/(\d+(\.\d+)?)/i)}:/tizen/i.test(t)?f={name:"Tizen",tizen:e,version:n(/(?:tizen\s?)?browser\/(\d+(\.\d+)?)/i)||o}:/safari/i.test(t)?f={name:"Safari",safari:e,version:o}:f={},/(apple)?webkit/i.test(t)?(f.name=f.name||"Webkit",f.webkit=e,!f.version&&o&&(f.version=o)):!f.opera&&/gecko\//i.test(t)&&(f.name=f.name||"Gecko",f.gecko=e,f.version=f.version||n(/gecko\/(\d+(\.\d+)?)/i)),s||f.silk?f.android=e:r&&(f[r]=e,f.ios=e);var l="";r?(l=n(/os (\d+([_\s]\d+)*) like mac os x/i),l=l.replace(/[_\s]/g,".")):s?l=n(/android[ \/-](\d+(\.\d+)*)/i):f.windowsphone?l=n(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i):f.webos?l=n(/(?:web|hpw)os\/(\d+(\.\d+)*)/i):f.blackberry?l=n(/rim\stablet\sos\s(\d+(\.\d+)*)/i):f.bada?l=n(/bada\/(\d+(\.\d+)*)/i):f.tizen&&(l=n(/tizen[\/\s](\d+(\.\d+)*)/i)),l&&(f.osversion=l);var c=l.split(".")[0];if(u||r=="ipad"||s&&(c==3||c==4&&!a)||f.silk)f.tablet=e;else if(a||r=="iphone"||r=="ipod"||s||f.blackberry||f.webos||f.bada)f.mobile=e;return f.msie&&f.version>=10||f.chrome&&f.version>=20||f.firefox&&f.version>=20||f.safari&&f.version>=6||f.opera&&f.version>=10||f.ios&&f.osversion&&f.osversion.split(".")[0]>=6||f.blackberry&&f.version>=10.1?f.a=e:f.msie&&f.version<10||f.chrome&&f.version<20||f.firefox&&f.version<20||f.safari&&f.version<6||f.opera&&f.version<10||f.ios&&f.osversion&&f.osversion.split(".")[0]<6?f.c=e:f.x=e,f}var e=!0,n=t(typeof navigator!="undefined"?navigator.userAgent:"");return n._detect=t,n}) \ No newline at end of file