mmSWFUpload.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /**
  2. * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/
  3. *
  4. * SWFUpload is (c) 2006 Lars Huring and Mammon Media and is released under the MIT License:
  5. * http://www.opensource.org/licenses/mit-license.php
  6. *
  7. */
  8. mmSWFUpload = {
  9. init: function(settings) {
  10. this.settings = settings;
  11. // Remove background flicker in IE
  12. try {
  13. document.execCommand('BackgroundImageCache', false, true);
  14. } catch(e) {}
  15. // Create SWFObject
  16. var so = new SWFObject("global/js/SWFUpload/upload.swf", "_mmSWFUploadField", this.addSetting("width", "76px"), this.addSetting("height", "21px"), this.addSetting("flash_version", "8"), "#000000");
  17. if(deconcept.SWFObjectUtil.getPlayerVersion(so.getAttribute("version")).major >= 8) {
  18. so.addParam("wmode", "transparent");
  19. so.addParam("menu", "false");
  20. // Add all settings to flash
  21. so.addVariable("uploadBackend", this.addSetting("upload_backend", ""));
  22. so.addVariable("uploadStartCallback", this.addSetting("upload_start_callback", ""));
  23. so.addVariable("uploadProgressCallback", this.addSetting("upload_progress_callback", ""));
  24. so.addVariable("uploadCompleteCallback", this.addSetting("upload_complete_callback", ""));
  25. so.addVariable("uploadCancelCallback", this.addSetting("upload_cancel_callback", ""));
  26. so.addVariable("uploadErrorCallback", this.addSetting("upload_error_callback", "mmSWFUpload.handleErrors"));
  27. so.addVariable("allowedFiletypes", this.addSetting("allowed_filetypes", "*.gif;*.jpg;*.png"));
  28. // Set up button and styles
  29. var btn = document.getElementById(this.addSetting("target", "flashUpload"))
  30. btn.style.overflow = "hidden";
  31. btn.style.width = this.addSetting("width", "76px");
  32. btn.style.height = this.addSetting("height", "21px");
  33. // Preload images
  34. buttonImage = new Image();
  35. buttonImage.src = this.addSetting("button_image", "jscripts/SWFObject/images/btn_upload.png");
  36. btn.style.backgroundImage = "url(" + this.settings["button_image"] + ")";
  37. if(this.settings["button_mouseover_image"]) {
  38. var buttonOverImage = new Image();
  39. buttonOverImage.src = this.addSetting("button_mouseover_image", "jscripts/SWFObject/images/btn_upload_over.png");
  40. btn.onmouseover = function() {
  41. btn.style.backgroundImage = "url(" + mmSWFUpload.settings["button_mouseover_image"] + ")";
  42. }
  43. btn.onmouseout = function() {
  44. btn.style.backgroundImage = "url(" + mmSWFUpload.settings["button_image"] + ")";
  45. }
  46. }
  47. // Output the flash
  48. so.write(this.addSetting("target", "flashUpload"));
  49. }
  50. if(this.settings["debug"] == true) {
  51. document.write("<strong>Target:</strong> " + this.settings["target"] + "<br />");
  52. document.write("<strong>Width:</strong> " + this.settings["width"] + "<br />");
  53. document.write("<strong>Height:</strong> " + this.settings["height"] + "<br />");
  54. document.write("<strong>Button image:</strong> " + this.settings["button_image"] + "<br />");
  55. document.write("<strong>Upload start callback:</strong> " + this.settings["upload_start_callback"] + "<br />");
  56. document.write("<strong>Upload progress callback:</strong> " + this.settings["upload_progress_callback"] + "<br />");
  57. document.write("<strong>Upload complete callback:</strong> " + this.settings["upload_complete_callback"] + "<br />");
  58. document.write("<strong>Upload filetypes:</strong> " + this.settings["allowed_filetypes"] + "<br />");
  59. document.write("<strong>Upload backend file:</strong> " + this.settings["upload_backend"] + "<br />");
  60. document.write("<strong>Upload error callback:</strong> " + this.settings["upload_error_callback"] + "<br />");
  61. document.write("<strong>Upload cancel callback:</strong> " + this.settings["upload_cancel_callback"] + "<br />");
  62. }
  63. },
  64. // Make sure that we get a few default values
  65. addSetting: function(setting, defval) {
  66. if(!this.settings[setting]) {
  67. this.settings[setting] = defval;
  68. }
  69. return this.settings[setting];
  70. },
  71. // Default error handling.
  72. handleErrors: function(errcode, file, msg) {
  73. switch(errcode) {
  74. case -10: // HTTP error
  75. // alert(errcode + ", " + file + ", " + msg);
  76. break;
  77. case -20: // No backend file specified
  78. alert(errcode + ", " + file + ", " + msg);
  79. break;
  80. case -30: // IOError
  81. alert(errcode + ", " + file + ", " + msg);
  82. break;
  83. case -40: // Security error
  84. alert(errcode + ", " + file + ", " + msg);
  85. break;
  86. }
  87. }
  88. }
  89. /**
  90. * SWFObject v1.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
  91. *
  92. * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
  93. * http://www.opensource.org/licenses/mit-license.php
  94. *
  95. * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
  96. * legal reasons.
  97. */
  98. if(typeof deconcept=="undefined"){var deconcept=new Object();}
  99. if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}
  100. if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}
  101. deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){
  102. if(!document.createElement||!document.getElementById){return;}
  103. this.DETECT_KEY=_b?_b:"detectflash";
  104. this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);
  105. this.params=new Object();
  106. this.variables=new Object();
  107. this.attributes=new Array();
  108. if(_1){this.setAttribute("swf",_1);}
  109. if(id){this.setAttribute("id",id);}
  110. if(w){this.setAttribute("width",w);}
  111. if(h){this.setAttribute("height",h);}
  112. if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}
  113. this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion(this.getAttribute("version"),_7);
  114. if(c){this.addParam("bgcolor",c);}
  115. var q=_8?_8:"high";
  116. this.addParam("quality",q);
  117. this.setAttribute("useExpressInstall",_7);
  118. this.setAttribute("doExpressInstall",false);
  119. var _d=(_9)?_9:window.location;
  120. this.setAttribute("xiRedirectUrl",_d);
  121. this.setAttribute("redirectUrl","");
  122. if(_a){this.setAttribute("redirectUrl",_a);}};
  123. deconcept.SWFObject.prototype={setAttribute:function(_e,_f){
  124. this.attributes[_e]=_f;
  125. },getAttribute:function(_10){
  126. return this.attributes[_10];
  127. },addParam:function(_11,_12){
  128. this.params[_11]=_12;
  129. },getParams:function(){
  130. return this.params;
  131. },addVariable:function(_13,_14){
  132. this.variables[_13]=_14;
  133. },getVariable:function(_15){
  134. return this.variables[_15];
  135. },getVariables:function(){
  136. return this.variables;
  137. },getVariablePairs:function(){
  138. var _16=new Array();
  139. var key;
  140. var _18=this.getVariables();
  141. for(key in _18){
  142. _16.push(key+"="+_18[key]);}
  143. return _16;
  144. },getSWFHTML:function(){
  145. var _19="";
  146. if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){
  147. if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");}
  148. _19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";
  149. _19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";
  150. var _1a=this.getParams();
  151. for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}
  152. var _1c=this.getVariablePairs().join("&");
  153. if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}
  154. _19+="/>";
  155. }else{
  156. if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}
  157. _19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";
  158. _19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";
  159. var _1d=this.getParams();
  160. for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}
  161. var _1f=this.getVariablePairs().join("&");
  162. if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}
  163. _19+="</object>";}
  164. return _19;
  165. },write:function(_20){
  166. if(this.getAttribute("useExpressInstall")){
  167. var _21=new deconcept.PlayerVersion([6,0,65]);
  168. if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){
  169. this.setAttribute("doExpressInstall",true);
  170. this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));
  171. document.title=document.title.slice(0,47)+" - Flash Player Installation";
  172. this.addVariable("MMdoctitle",document.title);}}
  173. if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){
  174. var n=(typeof _20=="string")?document.getElementById(_20):_20;
  175. n.innerHTML=this.getSWFHTML();
  176. return true;
  177. }else{
  178. if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}
  179. return false;}};
  180. deconcept.SWFObjectUtil.getPlayerVersion=function(_23,_24){
  181. var _25=new deconcept.PlayerVersion([0,0,0]);
  182. if(navigator.plugins&&navigator.mimeTypes.length){
  183. var x=navigator.plugins["Shockwave Flash"];
  184. if(x&&x.description){_25=new deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
  185. }else{try{
  186. var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
  187. for(var i=3;axo!=null;i++){
  188. axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
  189. _25=new deconcept.PlayerVersion([i,0,0]);}}
  190. catch(e){}
  191. if(_23&&_25.major>_23.major){return _25;}
  192. if(!_23||((_23.minor!=0||_23.rev!=0)&&_25.major==_23.major)||_25.major!=6||_24){
  193. try{_25=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}
  194. catch(e){}}}
  195. return _25;};
  196. deconcept.PlayerVersion=function(_29){
  197. this.major=parseInt(_29[0])!=null?parseInt(_29[0]):0;
  198. this.minor=parseInt(_29[1])||0;
  199. this.rev=parseInt(_29[2])||0;};
  200. deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
  201. if(this.major<fv.major){return false;}
  202. if(this.major>fv.major){return true;}
  203. if(this.minor<fv.minor){return false;}
  204. if(this.minor>fv.minor){return true;}
  205. if(this.rev<fv.rev){return false;}return true;};
  206. deconcept.util={getRequestParameter:function(_2b){
  207. var q=document.location.search||document.location.hash;
  208. if(q){
  209. var _2d=q.indexOf(_2b+"=");
  210. var _2e=(q.indexOf("&",_2d)>-1)?q.indexOf("&",_2d):q.length;
  211. if(q.length>1&&_2d>-1){
  212. return q.substring(q.indexOf("=",_2d)+1,_2e);
  213. }}return "";}};
  214. if(Array.prototype.push==null){
  215. Array.prototype.push=function(_2f){
  216. this[this.length]=_2f;
  217. return this.length;};}
  218. var getQueryParamValue=deconcept.util.getRequestParameter;
  219. var FlashObject=deconcept.SWFObject; // for backwards compatibility
  220. var SWFObject=deconcept.SWFObject;