Skip to content

Commit

Permalink
flash: Creating gubeds & fixing IE edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Archibald committed Jun 29, 2010
1 parent c9df509 commit 08f6aec
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
50 changes: 40 additions & 10 deletions src/flash/flash.js
Expand Up @@ -68,20 +68,24 @@ Glow.provide(function(glow) {
flashInstance = flashPluginInstalled() ? glow(nonIeFlashHtml).prependTo(document.body)[0] : {};
}

if (flashInstance.GetVariable && (versionString = flashInstance.GetVariable('$version')) ) {
cachedVersionString = versionString.split(' ')[1].replace(/,/g, '.');
cachedVersionDetails = cachedVersionString.split('.');
// using try/catch as IE may throw an error accessing flashInstance.GetVariable, even though it's happy to call it as a function
try {
if ( versionString = flashInstance.GetVariable('$version') ) {
cachedVersionString = versionString.split(' ')[1].replace(/,/g, '.');
cachedVersionDetails = cachedVersionString.split('.');

// convert parts to numbers
i = cachedVersionDetails.length;
// convert parts to numbers
i = cachedVersionDetails.length;

while (i--) {
cachedVersionDetails[i] = cachedVersionDetails[i] - 0;
}
while (i--) {
cachedVersionDetails[i] = cachedVersionDetails[i] - 0;
}

// remove it from the document if we added it
flashInstance.parentNode && glow(flashInstance).destroy();
// remove it from the document if we added it
flashInstance.parentNode && glow(flashInstance).destroy();
}
}
catch (e) {}

return cachedVersionDetails;
}
Expand Down Expand Up @@ -214,11 +218,37 @@ Glow.provide(function(glow) {
}).appendTo('#movieContainer');
*/
function create(swfUrl, minVer, opts) {
/*!debug*/
if (arguments.length > 3 || arguments.length < 2) {
glow.debug.warn('[wrong count] glow.flash.create expects 2 or 3 arguments, not '+arguments.length+'.');
}
if (typeof swfUrl != 'string') {
glow.debug.warn('[wrong type] glow.flash.create "swfUrl" param expected string, got ' + typeof swfUrl + '.');
}
if ( !/^(string|number)$/.test(typeof minVer) ) {
glow.debug.warn('[wrong type] glow.flash.create "minVer" param expected string or number, got ' + typeof minVer + '.');
}
// format of minVer checked in installed()
if (opts && typeof opts != 'object') {
glow.debug.warn('[wrong type] glow.flash.create "opts" param expected object, got ' + typeof opts + '.');
}
/*gubed!*/

opts = apply({
flashVars: '',
alt: 'You need to install the latest version of Flash to play this content. <a href="http://get.adobe.com/flashplayer/">Download the Flash player now.</a>.'
}, opts);

/*!debug*/
// format of minVer checked in installed()
if ( !/^(string|object)$/.test(typeof opts.flashVars) ) {
glow.debug.warn('[wrong type] glow.flash.create "opts.flashVars" param expected object or string, got ' + typeof opts.flashVars + '.');
}
if ( opts.params && typeof opts.params != 'object' ) {
glow.debug.warn('[wrong type] glow.flash.create "opts.params" param expected object, got ' + typeof opts.params + '.');
}
/*gubed!*/

var flashNodeList,
flashVars = opts.flashVars,
alt = opts.alt,
Expand Down
2 changes: 1 addition & 1 deletion test/manual/glow/flash/flash.html
Expand Up @@ -67,7 +67,7 @@ <h2>glow.flash.create</h2>
If you have flash installed, you should see a smiley face below
</p>

<div id="flash1" style="width: 100px; height: 100px"></div>
<div id="flash1" style="height: 100px"></div>

<script type="text/javascript">
glow.flash.create('../../data/smile.swf', 6).appendTo('#flash1');
Expand Down

0 comments on commit 08f6aec

Please sign in to comment.