web/wp-includes/js/swfupload/plugins/swfupload.swfobject.js
branchwordpress
changeset 109 03b0d1493584
child 132 4d4862461b8d
equal deleted inserted replaced
-1:000000000000 109:03b0d1493584
       
     1 /*
       
     2 	SWFUpload.SWFObject Plugin
       
     3 
       
     4 	Summary:
       
     5 		This plugin uses SWFObject to embed SWFUpload dynamically in the page.  SWFObject provides accurate Flash Player detection and DOM Ready loading.
       
     6 		This plugin replaces the Graceful Degradation plugin.
       
     7 
       
     8 	Features:
       
     9 		* swfupload_load_failed_hander event
       
    10 		* swfupload_pre_load_handler event
       
    11 		* minimum_flash_version setting (default: "9.0.28")
       
    12 		* SWFUpload.onload event for early loading
       
    13 
       
    14 	Usage:
       
    15 		Provide handlers and settings as needed.  When using the SWFUpload.SWFObject plugin you should initialize SWFUploading
       
    16 		in SWFUpload.onload rather than in window.onload.  When initialized this way SWFUpload can load earlier preventing the UI flicker
       
    17 		that was seen using the Graceful Degradation plugin.
       
    18 
       
    19 		<script type="text/javascript">
       
    20 			var swfu;
       
    21 			SWFUpload.onload = function () {
       
    22 				swfu = new SWFUpload({
       
    23 					minimum_flash_version: "9.0.28",
       
    24 					swfupload_pre_load_handler: swfuploadPreLoad,
       
    25 					swfupload_load_failed_handler: swfuploadLoadFailed
       
    26 				});
       
    27 			};
       
    28 		</script>
       
    29 		
       
    30 	Notes:
       
    31 		You must provide set minimum_flash_version setting to "8" if you are using SWFUpload for Flash Player 8.
       
    32 		The swfuploadLoadFailed event is only fired if the minimum version of Flash Player is not met.  Other issues such as missing SWF files, browser bugs
       
    33 		 or corrupt Flash Player installations will not trigger this event.
       
    34 		The swfuploadPreLoad event is fired as soon as the minimum version of Flash Player is found.  It does not wait for SWFUpload to load and can
       
    35 		 be used to prepare the SWFUploadUI and hide alternate content.
       
    36 		swfobject's onDomReady event is cross-browser safe but will default to the window.onload event when DOMReady is not supported by the browser.
       
    37 		 Early DOM Loading is supported in major modern browsers but cannot be guaranteed for every browser ever made.
       
    38 */
       
    39 
       
    40 
       
    41 // SWFObject v2.1 must be loaded
       
    42 	
       
    43 var SWFUpload;
       
    44 if (typeof(SWFUpload) === "function") {
       
    45 	SWFUpload.onload = function () {};
       
    46 	
       
    47 	swfobject.addDomLoadEvent(function () {
       
    48 		if (typeof(SWFUpload.onload) === "function") {
       
    49 			SWFUpload.onload.call(window);
       
    50 		}
       
    51 	});
       
    52 	
       
    53 	SWFUpload.prototype.initSettings = (function (oldInitSettings) {
       
    54 		return function () {
       
    55 			if (typeof(oldInitSettings) === "function") {
       
    56 				oldInitSettings.call(this);
       
    57 			}
       
    58 
       
    59 			this.ensureDefault = function (settingName, defaultValue) {
       
    60 				this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
       
    61 			};
       
    62 
       
    63 			this.ensureDefault("minimum_flash_version", "9.0.28");
       
    64 			this.ensureDefault("swfupload_pre_load_handler", null);
       
    65 			this.ensureDefault("swfupload_load_failed_handler", null);
       
    66 
       
    67 			delete this.ensureDefault;
       
    68 
       
    69 		};
       
    70 	})(SWFUpload.prototype.initSettings);
       
    71 
       
    72 
       
    73 	SWFUpload.prototype.loadFlash = function (oldLoadFlash) {
       
    74 		return function () {
       
    75 			var hasFlash = swfobject.hasFlashPlayerVersion(this.settings.minimum_flash_version);
       
    76 			
       
    77 			if (hasFlash) {
       
    78 				this.queueEvent("swfupload_pre_load_handler");
       
    79 				if (typeof(oldLoadFlash) === "function") {
       
    80 					oldLoadFlash.call(this);
       
    81 				}
       
    82 			} else {
       
    83 				this.queueEvent("swfupload_load_failed_handler");
       
    84 			}
       
    85 		};
       
    86 		
       
    87 	}(SWFUpload.prototype.loadFlash);
       
    88 			
       
    89 	SWFUpload.prototype.displayDebugInfo = function (oldDisplayDebugInfo) {
       
    90 		return function () {
       
    91 			if (typeof(oldDisplayDebugInfo) === "function") {
       
    92 				oldDisplayDebugInfo.call(this);
       
    93 			}
       
    94 			
       
    95 			this.debug(
       
    96 				[
       
    97 					"SWFUpload.SWFObject Plugin settings:", "\n",
       
    98 					"\t", "minimum_flash_version:                      ", this.settings.minimum_flash_version, "\n",
       
    99 					"\t", "swfupload_pre_load_handler assigned:     ", (typeof(this.settings.swfupload_pre_load_handler) === "function").toString(), "\n",
       
   100 					"\t", "swfupload_load_failed_handler assigned:     ", (typeof(this.settings.swfupload_load_failed_handler) === "function").toString(), "\n",
       
   101 				].join("")
       
   102 			);
       
   103 		};	
       
   104 	}(SWFUpload.prototype.displayDebugInfo);
       
   105 }