swfupload.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /**
  2. * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
  3. *
  4. * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
  5. *
  6. * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz閚 and Mammon Media and is released under the MIT License:
  7. * http://www.opensource.org/licenses/mit-license.php
  8. *
  9. * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
  10. * http://www.opensource.org/licenses/mit-license.php
  11. *
  12. */
  13. +(function($){
  14. window.SWFUpload = function(a) {
  15. this.initSWFUpload(a);
  16. }
  17. SWFUpload.prototype.initSWFUpload = function(b) {
  18. try {
  19. this.customSettings = {};
  20. this.settings = b;
  21. this.eventQueue = [];
  22. this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
  23. this.movieElement = null;
  24. SWFUpload.instances[this.movieName] = this;
  25. this.initSettings();
  26. this.loadFlash();
  27. this.displayDebugInfo();
  28. } catch (a) {
  29. delete SWFUpload.instances[this.movieName];
  30. throw a;
  31. }
  32. };
  33. SWFUpload.instances = {};
  34. SWFUpload.movieCount = 0;
  35. SWFUpload.version = "2.2.0 2009-03-25";
  36. SWFUpload.QUEUE_ERROR = {
  37. QUEUE_LIMIT_EXCEEDED:-100,
  38. FILE_EXCEEDS_SIZE_LIMIT:-110,
  39. ZERO_BYTE_FILE:-120,
  40. INVALID_FILETYPE:-130
  41. };
  42. SWFUpload.UPLOAD_ERROR = {
  43. HTTP_ERROR:-200,
  44. MISSING_UPLOAD_URL:-210,
  45. IO_ERROR:-220,
  46. SECURITY_ERROR:-230,
  47. UPLOAD_LIMIT_EXCEEDED:-240,
  48. UPLOAD_FAILED:-250,
  49. SPECIFIED_FILE_ID_NOT_FOUND:-260,
  50. FILE_VALIDATION_FAILED:-270,
  51. FILE_CANCELLED:-280,
  52. UPLOAD_STOPPED:-290
  53. };
  54. SWFUpload.FILE_STATUS = {
  55. QUEUED:-1,
  56. IN_PROGRESS:-2,
  57. ERROR:-3,
  58. COMPLETE:-4,
  59. CANCELLED:-5
  60. };
  61. SWFUpload.BUTTON_ACTION = {
  62. SELECT_FILE:-100,
  63. SELECT_FILES:-110,
  64. START_UPLOAD:-120
  65. };
  66. SWFUpload.CURSOR = {
  67. ARROW:-1,
  68. HAND:-2
  69. };
  70. SWFUpload.WINDOW_MODE = {
  71. WINDOW:"window",
  72. TRANSPARENT:"transparent",
  73. OPAQUE:"opaque"
  74. };
  75. SWFUpload.completeURL = function(a) {
  76. if (typeof a !== "string" || a.match(/^https?:\/\//i) || a.match(/^\//)) {
  77. return a;
  78. }
  79. var c = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port :"");
  80. var b = window.location.pathname.lastIndexOf("/");
  81. if (b <= 0) {
  82. path = "/";
  83. } else {
  84. path = window.location.pathname.substr(0, b) + "/";
  85. }
  86. return path + a;
  87. };
  88. SWFUpload.prototype.initSettings = function() {
  89. this.ensureDefault = function(b, a) {
  90. this.settings[b] = this.settings[b] == undefined ? a :this.settings[b];
  91. };
  92. this.ensureDefault("upload_url", "");
  93. this.ensureDefault("preserve_relative_urls", false);
  94. this.ensureDefault("file_post_name", "Filedata");
  95. this.ensureDefault("post_params", {});
  96. this.ensureDefault("use_query_string", false);
  97. this.ensureDefault("requeue_on_error", false);
  98. this.ensureDefault("http_success", []);
  99. this.ensureDefault("assume_success_timeout", 0);
  100. this.ensureDefault("file_types", "*.*");
  101. this.ensureDefault("file_types_description", "All Files");
  102. this.ensureDefault("file_size_limit", 0);
  103. this.ensureDefault("file_upload_limit", 0);
  104. this.ensureDefault("file_queue_limit", 0);
  105. this.ensureDefault("flash_url", "swfupload.swf");
  106. this.ensureDefault("prevent_swf_caching", true);
  107. this.ensureDefault("button_image_url", "");
  108. this.ensureDefault("button_width", 1);
  109. this.ensureDefault("button_height", 1);
  110. this.ensureDefault("button_text", "");
  111. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  112. this.ensureDefault("button_text_top_padding", 0);
  113. this.ensureDefault("button_text_left_padding", 0);
  114. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  115. this.ensureDefault("button_disabled", false);
  116. this.ensureDefault("button_placeholder_id", "");
  117. this.ensureDefault("button_placeholder", null);
  118. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  119. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  120. this.ensureDefault("debug", false);
  121. this.settings.debug_enabled = this.settings.debug;
  122. this.settings.return_upload_start_handler = this.returnUploadStart;
  123. this.ensureDefault("swfupload_loaded_handler", null);
  124. this.ensureDefault("file_dialog_start_handler", null);
  125. this.ensureDefault("file_queued_handler", null);
  126. this.ensureDefault("file_queue_error_handler", null);
  127. this.ensureDefault("file_dialog_complete_handler", null);
  128. this.ensureDefault("upload_start_handler", null);
  129. this.ensureDefault("upload_progress_handler", null);
  130. this.ensureDefault("upload_error_handler", null);
  131. this.ensureDefault("upload_success_handler", null);
  132. this.ensureDefault("upload_complete_handler", null);
  133. this.ensureDefault("debug_handler", this.debugMessage);
  134. this.ensureDefault("custom_settings", {});
  135. this.customSettings = this.settings.custom_settings;
  136. if (!!this.settings.prevent_swf_caching) {
  137. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" :"&") + "preventswfcaching=" + new Date().getTime();
  138. }
  139. if (!this.settings.preserve_relative_urls) {
  140. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  141. this.settings.button_image_url = this.settings.button_image_url ? SWFUpload.completeURL(this.settings.button_image_url) :this.settings.button_image_url;
  142. }
  143. delete this.ensureDefault;
  144. };
  145. SWFUpload.prototype.loadFlash = function() {
  146. var a, b;
  147. if (document.getElementById(this.movieName) !== null) {
  148. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  149. }
  150. a = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  151. if (a == undefined) {
  152. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  153. }
  154. b = document.createElement("div");
  155. b.innerHTML = this.getFlashHTML();
  156. a.parentNode.replaceChild(b.firstChild, a);
  157. if (window[this.movieName] == undefined) {
  158. window[this.movieName] = this.getMovieElement();
  159. }
  160. };
  161. SWFUpload.prototype.getFlashHTML = function() {
  162. return [ '<object id="', this.movieName, '" type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">', '<param name="wmode" value="', this.settings.button_window_mode, '" />', '<param name="movie" value="', this.settings.flash_url, '" />', '<param name="quality" value="high" />', '<param name="menu" value="false" />', '<param name="allowScriptAccess" value="always" />', '<param name="flashvars" value="' + this.getFlashVars() + '" />', "</object>" ].join("");
  163. };
  164. SWFUpload.prototype.getFlashVars = function() {
  165. var b = this.buildParamString();
  166. var a = this.settings.http_success.join(",");
  167. return [ "movieName=", encodeURIComponent(this.movieName), "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url), "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string), "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error), "&amp;httpSuccess=", encodeURIComponent(a), "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout), "&amp;params=", encodeURIComponent(b), "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name), "&amp;fileTypes=", encodeURIComponent(this.settings.file_types), "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description), "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit), "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit), "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit), "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled), "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url), "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width), "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height), "&amp;buttonText=", encodeURIComponent(this.settings.button_text), "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding), "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding), "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style), "&amp;buttonAction=", encodeURIComponent(this.settings.button_action), "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled), "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor) ].join("");
  168. };
  169. SWFUpload.prototype.getMovieElement = function() {
  170. if (this.movieElement == undefined) {
  171. this.movieElement = document.getElementById(this.movieName);
  172. }
  173. if (this.movieElement === null) {
  174. throw "Could not find Flash element";
  175. }
  176. return this.movieElement;
  177. };
  178. SWFUpload.prototype.buildParamString = function() {
  179. var c = this.settings.post_params;
  180. var b = [];
  181. if (typeof c === "object") {
  182. for (var a in c) {
  183. if (c.hasOwnProperty(a)) {
  184. b.push(encodeURIComponent(a.toString()) + "=" + encodeURIComponent(c[a].toString()));
  185. }
  186. }
  187. }
  188. return b.join("&amp;");
  189. };
  190. SWFUpload.prototype.destroy = function() {
  191. try {
  192. this.cancelUpload(null, false);
  193. var a = null;
  194. a = this.getMovieElement();
  195. if (a && typeof a.CallFunction === "unknown") {
  196. for (var c in a) {
  197. try {
  198. if (typeof a[c] === "function") {
  199. a[c] = null;
  200. }
  201. } catch (e) {}
  202. }
  203. try {
  204. a.parentNode.removeChild(a);
  205. } catch (b) {}
  206. }
  207. window[this.movieName] = null;
  208. SWFUpload.instances[this.movieName] = null;
  209. delete SWFUpload.instances[this.movieName];
  210. this.movieElement = null;
  211. this.settings = null;
  212. this.customSettings = null;
  213. this.eventQueue = null;
  214. this.movieName = null;
  215. return true;
  216. } catch (d) {
  217. return false;
  218. }
  219. };
  220. SWFUpload.prototype.displayDebugInfo = function() {
  221. this.debug([ "---SWFUpload Instance Info---\n", "Version: ", SWFUpload.version, "\n", "Movie Name: ", this.movieName, "\n", "Settings:\n", " ", "upload_url: ", this.settings.upload_url, "\n", " ", "flash_url: ", this.settings.flash_url, "\n", " ", "use_query_string: ", this.settings.use_query_string.toString(), "\n", " ", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n", " ", "http_success: ", this.settings.http_success.join(", "), "\n", " ", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n", " ", "file_post_name: ", this.settings.file_post_name, "\n", " ", "post_params: ", this.settings.post_params.toString(), "\n", " ", "file_types: ", this.settings.file_types, "\n", " ", "file_types_description: ", this.settings.file_types_description, "\n", " ", "file_size_limit: ", this.settings.file_size_limit, "\n", " ", "file_upload_limit: ", this.settings.file_upload_limit, "\n", " ", "file_queue_limit: ", this.settings.file_queue_limit, "\n", " ", "debug: ", this.settings.debug.toString(), "\n", " ", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n", " ", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n", " ", "button_placeholder: ", this.settings.button_placeholder ? "Set" :"Not Set", "\n", " ", "button_image_url: ", this.settings.button_image_url.toString(), "\n", " ", "button_width: ", this.settings.button_width.toString(), "\n", " ", "button_height: ", this.settings.button_height.toString(), "\n", " ", "button_text: ", this.settings.button_text.toString(), "\n", " ", "button_text_style: ", this.settings.button_text_style.toString(), "\n", " ", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n", " ", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n", " ", "button_action: ", this.settings.button_action.toString(), "\n", " ", "button_disabled: ", this.settings.button_disabled.toString(), "\n", " ", "custom_settings: ", this.settings.custom_settings.toString(), "\n", "Event Handlers:\n", " ", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n", " ", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n", " ", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n", " ", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n", " ", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n", " ", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n", " ", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n", " ", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n", " ", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n", " ", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n" ].join(""));
  222. };
  223. SWFUpload.prototype.addSetting = function(b, c, a) {
  224. if (c == undefined) {
  225. return this.settings[b] = a;
  226. } else {
  227. return this.settings[b] = c;
  228. }
  229. };
  230. SWFUpload.prototype.getSetting = function(a) {
  231. if (this.settings[a] != undefined) {
  232. return this.settings[a];
  233. }
  234. return "";
  235. };
  236. SWFUpload.prototype.callFlash = function(functionName, argumentArray) {
  237. argumentArray = argumentArray || [];
  238. var movieElement = this.getMovieElement();
  239. var returnValue, returnString;
  240. try {
  241. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + "</invoke>");
  242. returnValue = eval(returnString);
  243. } catch (ex) {
  244. throw "Call to " + functionName + " failed";
  245. }
  246. if (returnValue != undefined && typeof returnValue.post === "object") {
  247. returnValue = this.unescapeFilePostParams(returnValue);
  248. }
  249. return returnValue;
  250. };
  251. SWFUpload.prototype.selectFile = function() {
  252. this.callFlash("SelectFile");
  253. };
  254. SWFUpload.prototype.selectFiles = function() {
  255. this.callFlash("SelectFiles");
  256. };
  257. SWFUpload.prototype.startUpload = function(a) {
  258. this.callFlash("StartUpload", [ a ]);
  259. };
  260. SWFUpload.prototype.cancelUpload = function(a, b) {
  261. if (b !== false) {
  262. b = true;
  263. }
  264. this.callFlash("CancelUpload", [ a, b ]);
  265. };
  266. SWFUpload.prototype.stopUpload = function() {
  267. this.callFlash("StopUpload");
  268. };
  269. SWFUpload.prototype.getStats = function() {
  270. return this.callFlash("GetStats");
  271. };
  272. SWFUpload.prototype.setStats = function(a) {
  273. this.callFlash("SetStats", [ a ]);
  274. };
  275. SWFUpload.prototype.getFile = function(a) {
  276. if (typeof a === "number") {
  277. return this.callFlash("GetFileByIndex", [ a ]);
  278. } else {
  279. return this.callFlash("GetFile", [ a ]);
  280. }
  281. };
  282. SWFUpload.prototype.addFileParam = function(a, b, c) {
  283. return this.callFlash("AddFileParam", [ a, b, c ]);
  284. };
  285. SWFUpload.prototype.removeFileParam = function(a, b) {
  286. this.callFlash("RemoveFileParam", [ a, b ]);
  287. };
  288. SWFUpload.prototype.setUploadURL = function(a) {
  289. this.settings.upload_url = a.toString();
  290. this.callFlash("SetUploadURL", [ a ]);
  291. };
  292. SWFUpload.prototype.setPostParams = function(a) {
  293. this.settings.post_params = a;
  294. this.callFlash("SetPostParams", [ a ]);
  295. };
  296. SWFUpload.prototype.addPostParam = function(a, b) {
  297. this.settings.post_params[a] = b;
  298. this.callFlash("SetPostParams", [ this.settings.post_params ]);
  299. };
  300. SWFUpload.prototype.removePostParam = function(a) {
  301. delete this.settings.post_params[a];
  302. this.callFlash("SetPostParams", [ this.settings.post_params ]);
  303. };
  304. SWFUpload.prototype.setFileTypes = function(a, b) {
  305. this.settings.file_types = a;
  306. this.settings.file_types_description = b;
  307. this.callFlash("SetFileTypes", [ a, b ]);
  308. };
  309. SWFUpload.prototype.setFileSizeLimit = function(a) {
  310. this.settings.file_size_limit = a;
  311. this.callFlash("SetFileSizeLimit", [ a ]);
  312. };
  313. SWFUpload.prototype.setFileUploadLimit = function(a) {
  314. this.settings.file_upload_limit = a;
  315. this.callFlash("SetFileUploadLimit", [ a ]);
  316. };
  317. SWFUpload.prototype.setFileQueueLimit = function(a) {
  318. this.settings.file_queue_limit = a;
  319. this.callFlash("SetFileQueueLimit", [ a ]);
  320. };
  321. SWFUpload.prototype.setFilePostName = function(a) {
  322. this.settings.file_post_name = a;
  323. this.callFlash("SetFilePostName", [ a ]);
  324. };
  325. SWFUpload.prototype.setUseQueryString = function(a) {
  326. this.settings.use_query_string = a;
  327. this.callFlash("SetUseQueryString", [ a ]);
  328. };
  329. SWFUpload.prototype.setRequeueOnError = function(a) {
  330. this.settings.requeue_on_error = a;
  331. this.callFlash("SetRequeueOnError", [ a ]);
  332. };
  333. SWFUpload.prototype.setHTTPSuccess = function(a) {
  334. if (typeof a === "string") {
  335. a = a.replace(" ", "").split(",");
  336. }
  337. this.settings.http_success = a;
  338. this.callFlash("SetHTTPSuccess", [ a ]);
  339. };
  340. SWFUpload.prototype.setAssumeSuccessTimeout = function(a) {
  341. this.settings.assume_success_timeout = a;
  342. this.callFlash("SetAssumeSuccessTimeout", [ a ]);
  343. };
  344. SWFUpload.prototype.setDebugEnabled = function(a) {
  345. this.settings.debug_enabled = a;
  346. this.callFlash("SetDebugEnabled", [ a ]);
  347. };
  348. SWFUpload.prototype.setButtonImageURL = function(a) {
  349. if (a == undefined) {
  350. a = "";
  351. }
  352. this.settings.button_image_url = a;
  353. this.callFlash("SetButtonImageURL", [ a ]);
  354. };
  355. SWFUpload.prototype.setButtonDimensions = function(c, a) {
  356. this.settings.button_width = c;
  357. this.settings.button_height = a;
  358. var b = this.getMovieElement();
  359. if (b != undefined) {
  360. b.style.width = c + "px";
  361. b.style.height = a + "px";
  362. }
  363. this.callFlash("SetButtonDimensions", [ c, a ]);
  364. };
  365. SWFUpload.prototype.setButtonText = function(a) {
  366. this.settings.button_text = a;
  367. this.callFlash("SetButtonText", [ a ]);
  368. };
  369. SWFUpload.prototype.setButtonTextPadding = function(b, a) {
  370. this.settings.button_text_top_padding = a;
  371. this.settings.button_text_left_padding = b;
  372. this.callFlash("SetButtonTextPadding", [ b, a ]);
  373. };
  374. SWFUpload.prototype.setButtonTextStyle = function(a) {
  375. this.settings.button_text_style = a;
  376. this.callFlash("SetButtonTextStyle", [ a ]);
  377. };
  378. SWFUpload.prototype.setButtonDisabled = function(a) {
  379. this.settings.button_disabled = a;
  380. this.callFlash("SetButtonDisabled", [ a ]);
  381. };
  382. SWFUpload.prototype.setButtonAction = function(a) {
  383. this.settings.button_action = a;
  384. this.callFlash("SetButtonAction", [ a ]);
  385. };
  386. SWFUpload.prototype.setButtonCursor = function(a) {
  387. this.settings.button_cursor = a;
  388. this.callFlash("SetButtonCursor", [ a ]);
  389. };
  390. SWFUpload.prototype.queueEvent = function(b, c) {
  391. if (c == undefined) {
  392. c = [];
  393. } else {
  394. if (!(c instanceof Array)) {
  395. c = [ c ];
  396. }
  397. }
  398. var a = this;
  399. if (typeof this.settings[b] === "function") {
  400. this.eventQueue.push(function() {
  401. this.settings[b].apply(this, c);
  402. });
  403. setTimeout(function() {
  404. a.executeNextEvent();
  405. }, 0);
  406. } else {
  407. if (this.settings[b] !== null) {
  408. throw "Event handler " + b + " is unknown or is not a function";
  409. }
  410. }
  411. };
  412. SWFUpload.prototype.executeNextEvent = function() {
  413. var a = this.eventQueue ? this.eventQueue.shift() :null;
  414. if (typeof a === "function") {
  415. a.apply(this);
  416. }
  417. };
  418. SWFUpload.prototype.unescapeFilePostParams = function(c) {
  419. var e = /[$]([0-9a-f]{4})/i;
  420. var f = {};
  421. var d;
  422. if (c != undefined) {
  423. for (var a in c.post) {
  424. if (c.post.hasOwnProperty(a)) {
  425. d = a;
  426. var b;
  427. while ((b = e.exec(d)) !== null) {
  428. d = d.replace(b[0], String.fromCharCode(parseInt("0x" + b[1], 16)));
  429. }
  430. f[d] = c.post[a];
  431. }
  432. }
  433. c.post = f;
  434. }
  435. return c;
  436. };
  437. SWFUpload.prototype.testExternalInterface = function() {
  438. try {
  439. return this.callFlash("TestExternalInterface");
  440. } catch (a) {
  441. return false;
  442. }
  443. };
  444. SWFUpload.prototype.flashReady = function() {
  445. var a = this.getMovieElement();
  446. if (!a) {
  447. this.debug("Flash called back ready but the flash movie can't be found.");
  448. return;
  449. }
  450. this.cleanUp(a);
  451. this.queueEvent("swfupload_loaded_handler");
  452. };
  453. SWFUpload.prototype.cleanUp = function(a) {
  454. try {
  455. if (this.movieElement && typeof a.CallFunction === "unknown") {
  456. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  457. for (var c in a) {
  458. try {
  459. if (typeof a[c] === "function") {
  460. a[c] = null;
  461. }
  462. } catch (b) {}
  463. }
  464. }
  465. } catch (d) {}
  466. window.__flash__removeCallback = function(e, f) {
  467. try {
  468. if (e) {
  469. e[f] = null;
  470. }
  471. } catch (g) {}
  472. };
  473. };
  474. SWFUpload.prototype.fileDialogStart = function() {
  475. this.queueEvent("file_dialog_start_handler");
  476. };
  477. SWFUpload.prototype.fileQueued = function(a) {
  478. a = this.unescapeFilePostParams(a);
  479. this.queueEvent("file_queued_handler", a);
  480. };
  481. SWFUpload.prototype.fileQueueError = function(a, c, b) {
  482. a = this.unescapeFilePostParams(a);
  483. this.queueEvent("file_queue_error_handler", [ a, c, b ]);
  484. };
  485. SWFUpload.prototype.fileDialogComplete = function(b, c, a) {
  486. this.queueEvent("file_dialog_complete_handler", [ b, c, a ]);
  487. };
  488. SWFUpload.prototype.uploadStart = function(a) {
  489. a = this.unescapeFilePostParams(a);
  490. this.queueEvent("return_upload_start_handler", a);
  491. };
  492. SWFUpload.prototype.returnUploadStart = function(a) {
  493. var b;
  494. if (typeof this.settings.upload_start_handler === "function") {
  495. a = this.unescapeFilePostParams(a);
  496. b = this.settings.upload_start_handler.call(this, a);
  497. } else {
  498. if (this.settings.upload_start_handler != undefined) {
  499. throw "upload_start_handler must be a function";
  500. }
  501. }
  502. if (b === undefined) {
  503. b = true;
  504. }
  505. b = !!b;
  506. this.callFlash("ReturnUploadStart", [ b ]);
  507. };
  508. SWFUpload.prototype.uploadProgress = function(a, c, b) {
  509. a = this.unescapeFilePostParams(a);
  510. this.queueEvent("upload_progress_handler", [ a, c, b ]);
  511. };
  512. SWFUpload.prototype.uploadError = function(a, c, b) {
  513. a = this.unescapeFilePostParams(a);
  514. this.queueEvent("upload_error_handler", [ a, c, b ]);
  515. };
  516. SWFUpload.prototype.uploadSuccess = function(b, a, c) {
  517. b = this.unescapeFilePostParams(b);
  518. this.queueEvent("upload_success_handler", [ b, a, c ]);
  519. };
  520. SWFUpload.prototype.uploadComplete = function(a) {
  521. a = this.unescapeFilePostParams(a);
  522. this.queueEvent("upload_complete_handler", a);
  523. };
  524. SWFUpload.prototype.debug = function(a) {
  525. this.queueEvent("debug_handler", a);
  526. };
  527. SWFUpload.prototype.debugMessage = function(c) {
  528. if (this.settings.debug) {
  529. var a, d = [];
  530. if (typeof c === "object" && typeof c.name === "string" && typeof c.message === "string") {
  531. for (var b in c) {
  532. if (c.hasOwnProperty(b)) {
  533. d.push(b + ": " + c[b]);
  534. }
  535. }
  536. a = d.join("\n") || "";
  537. d = a.split("\n");
  538. a = "EXCEPTION: " + d.join("\nEXCEPTION: ");
  539. SWFUpload.Console.writeLine(a);
  540. } else {
  541. SWFUpload.Console.writeLine(c);
  542. }
  543. }
  544. };
  545. SWFUpload.Console = {};
  546. SWFUpload.Console.writeLine = function(d) {
  547. var b, a;
  548. try {
  549. b = document.getElementById("SWFUpload_Console");
  550. if (!b) {
  551. a = document.createElement("form");
  552. document.getElementsByTagName("body")[0].appendChild(a);
  553. b = document.createElement("textarea");
  554. b.id = "SWFUpload_Console";
  555. b.style.fontFamily = "monospace";
  556. b.setAttribute("wrap", "off");
  557. b.wrap = "off";
  558. b.style.overflow = "auto";
  559. b.style.width = "700px";
  560. b.style.height = "350px";
  561. b.style.margin = "5px";
  562. a.appendChild(b);
  563. }
  564. b.value += d + "\n";
  565. b.scrollTop = b.scrollHeight - b.clientHeight;
  566. } catch (c) {
  567. alert("Exception: " + c.name + " Message: " + c.message);
  568. }
  569. };
  570. })(jQuery);