/** * flash (http://jquery.lukelutman.com/plugins/flash) * a jquery plugin for embedding flash movies. * * version 1.0 * november 9th, 2006 * * copyright (c) 2006 luke lutman (http://www.lukelutman.com) * dual licensed under the mit and gpl licenses. * http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/gpl-license.php * * inspired by: * swfobject (http://blog.deconcept.com/swfobject/) * ufo (http://www.bobbyvandersluis.com/ufo/) * sifr (http://www.mikeindustries.com/sifr/) * * important: * the packed version of jquery breaks activex control * activation in internet explorer. use jsmin to minifiy * jquery (see: http://jquery.lukelutman.com/plugins/flash#activex). * **/ ;(function(){ var $$; /** * * @desc replace matching elements with a flash movie. * @author luke lutman * @version 1.0.1 * * @name flash * @param hash htmloptions options for the embed/object tag. * @param hash pluginoptions options for detecting/updating the flash plugin (optional). * @param function replace custom block called for each matched element if flash is installed (optional). * @param function update custom block called for each matched if flash isn't installed (optional). * @type jquery * * @cat plugins/flash * * @example $('#hello').flash({ src: 'hello.swf' }); * @desc embed a flash movie. * * @example $('#hello').flash({ src: 'hello.swf' }, { version: 8 }); * @desc embed a flash 8 movie. * * @example $('#hello').flash({ src: 'hello.swf' }, { expressinstall: true }); * @desc embed a flash movie using express install if flash isn't installed. * * @example $('#hello').flash({ src: 'hello.swf' }, { update: false }); * @desc embed a flash movie, don't show an update message if flash isn't installed. * **/ $$ = jquery.fn.flash = function(htmloptions, pluginoptions, replace, update) { // set the default block. var block = replace || $$.replace; // merge the default and passed plugin options. pluginoptions = $$.copy($$.pluginoptions, pluginoptions); // detect flash. if(!$$.hasflash(pluginoptions.version)) { // use express install (if specified and flash plugin 6,0,65 or higher is installed). if(pluginoptions.expressinstall && $$.hasflash(6,0,65)) { // add the necessary flashvars (merged later). var expressinstalloptions = { flashvars: { mmredirecturl: location, mmplayertype: 'plugin', mmdoctitle: jquery('title').text() } }; // ask the user to update (if specified). } else if (pluginoptions.update) { // change the block to insert the update message instead of the flash movie. block = update || $$.update; // fail } else { // the required version of flash isn't installed. // express install is turned off, or flash 6,0,65 isn't installed. // update is turned off. // return without doing anything. return this; } } // merge the default, express install and passed html options. htmloptions = $$.copy($$.htmloptions, expressinstalloptions, htmloptions); // invoke $block (with a copy of the merged html options) for each element. return this.each(function(){ block.call(this, $$.copy(htmloptions)); }); }; /** * * @name flash.copy * @desc copy an arbitrary number of objects into a new object. * @type object * * @example $$.copy({ foo: 1 }, { bar: 2 }); * @result { foo: 1, bar: 2 }; * **/ $$.copy = function() { var options = {}, flashvars = {}; for(var i = 0; i < arguments.length; i++) { var arg = arguments[i]; if(arg == undefined) continue; jquery.extend(options, arg); // don't clobber one flash vars object with another // merge them instead if(arg.flashvars == undefined) continue; jquery.extend(flashvars, arg.flashvars); } options.flashvars = flashvars; return options; }; /* * @name flash.hasflash * @desc check if a specific version of the flash plugin is installed * @type boolean * **/ $$.hasflash = function() { // look for a flag in the query string to bypass flash detection if(/hasflash\=true/.test(location)) return true; if(/hasflash\=false/.test(location)) return false; var pv = $$.hasflash.playerversion().match(/\d+/g); var rv = string([arguments[0], arguments[1], arguments[2]]).match(/\d+/g) || string($$.pluginoptions.version).match(/\d+/g); for(var i = 0; i < 3; i++) { pv[i] = parseint(pv[i] || 0); rv[i] = parseint(rv[i] || 0); // player is less than required if(pv[i] < rv[i]) return false; // player is greater than required if(pv[i] > rv[i]) return true; } // major version, minor version and revision match exactly return true; }; /** * * @name flash.hasflash.playerversion * @desc get the version of the installed flash plugin. * @type string * **/ $$.hasflash.playerversion = function() { // ie try { try { // avoid fp6 minor version lookup issues // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ var axo = new activexobject('shockwaveflash.shockwaveflash.6'); try { axo.allowscriptaccess = 'always'; } catch(e) { return '6,0,0'; } } catch(e) {} return new activexobject('shockwaveflash.shockwaveflash').getvariable('$version').replace(/\d+/g, ',').match(/^,?(.+),?$/)[1]; // other browsers } catch(e) { try { if(navigator.mimetypes["application/x-shockwave-flash"].enabledplugin){ return (navigator.plugins["shockwave flash 2.0"] || navigator.plugins["shockwave flash"]).description.replace(/\d+/g, ",").match(/^,?(.+),?$/)[1]; } } catch(e) {} } return '0,0,0'; }; /** * * @name flash.htmloptions * @desc the default set of options for the object or embed tag. * **/ $$.htmloptions = { height: 245, flashvars: {}, pluginspage: 'http://www.adobe.com/go/getflashplayer', src: '#', type: 'application/x-shockwave-flash', width: 980, wmode:'transparent' }; /** * * @name flash.pluginoptions * @desc the default set of options for checking/updating the flash plugin. * **/ $$.pluginoptions = { expressinstall: false, update: true, version: '6.0.65' }; /** * * @name flash.replace * @desc the default method for replacing an element with a flash movie. * **/ $$.replace = function(htmloptions) { this.innerhtml = '
this content requires the flash player. download flash player. already have flash player? click here.
'; this.innerhtml = ''+this.innerhtml+''; jquery(this) .addclass('flash-update') .prepend(msg); }; /** * * @desc convert a hash of html options to a string of attributes, using function.apply(). * @example toattributestring.apply(htmloptions) * @result foo="bar" foo="bar" * **/ function toattributestring() { var s = ''; for(var key in this) if(typeof this[key] != 'function') s += key+'="'+this[key]+'" '; return s; }; /** * * @desc convert a hash of flashvars to a url-encoded string, using function.apply(). * @example toflashvarsstring.apply(flashvarsobject) * @result foo=bar&foo=bar * **/ function toflashvarsstring() { var s = ''; for(var key in this) if(typeof this[key] != 'function') s += key+'='+encodeuricomponent(this[key])+'&'; return s.replace(/&$/, ''); }; /** * * @name flash.transform * @desc transform a set of html options into an embed tag. * @type string * * @example $$.transform(htmloptions) * @result * * note: the embed tag is not standards-compliant, but it * works in all current browsers. flash.transform can be * overwritten with a custom function to generate more * standards-compliant markup. * **/ $$.transform = function(htmloptions) { htmloptions.tostring = toattributestring; if(htmloptions.flashvars) htmloptions.flashvars.tostring = toflashvarsstring; return ''; }; /** * * flash player 9 fix (http://blog.deconcept.com/2006/07/28/swfobject-143-released/) * **/ if (window.attachevent) { window.attachevent("onbeforeunload", function(){ __flash_unloadhandler = function() {}; __flash_savedunloadhandler = function() {}; }); } })();