PageRenderTime 49ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/flash/src/SWFUpload/FlashDevelop/swfupload.js

#
JavaScript | 662 lines | 470 code | 90 blank | 102 comment | 81 complexity | a9e43e7312458c071178d4cab43cd0fc MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * SWFUpload 0.8.3 Revision 5.2 by Jacob Roberts, April 2007, linebyline.blogspot.com http://code.google.com/p/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. * See Changelog.txt for version history
  8. */
  9. /* *********** */
  10. /* Constructor */
  11. /* *********** */
  12. var SWFUpload = function (init_settings) {
  13. // Remove background flicker in IE (read this: http://misterpixel.blogspot.com/2006/09/forensic-analysis-of-ie6.html)
  14. // This doesn't have anything to do with SWFUpload but can help your UI behave better
  15. try {
  16. document.execCommand('BackgroundImageCache', false, true);
  17. } catch (ex) {
  18. this.debugMessage(ex);
  19. }
  20. try {
  21. this.settings = {};
  22. this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
  23. this.movieElement = null;
  24. // Setup global control tracking
  25. SWFUpload.instances[this.movieName] = this;
  26. // Load the settings. Load the Flash movie.
  27. this.initSettings(init_settings);
  28. this.loadFlash();
  29. if (this.debug_enabled) {
  30. this.displayDebugInfo();
  31. }
  32. } catch (ex) {
  33. this.debugMessage(ex);
  34. }
  35. };
  36. /* *************** */
  37. /* Static thingies */
  38. /* *************** */
  39. SWFUpload.instances = {};
  40. SWFUpload.movieCount = 0;
  41. SWFUpload.ERROR_CODE_HTTP_ERROR = -10;
  42. SWFUpload.ERROR_CODE_MISSING_UPLOAD_TARGET = -20;
  43. SWFUpload.ERROR_CODE_IO_ERROR = -30;
  44. SWFUpload.ERROR_CODE_SECURITY_ERROR = -40;
  45. SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT = -50;
  46. SWFUpload.ERROR_CODE_ZERO_BYTE_FILE = -60;
  47. SWFUpload.ERROR_CODE_UPLOAD_LIMIT_EXCEEDED = -70;
  48. SWFUpload.ERROR_CODE_UPLOAD_FAILED = -80;
  49. SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED = -90;
  50. SWFUpload.ERROR_CODE_SPECIFIED_FILE_NOT_FOUND = -100;
  51. /* ***************** */
  52. /* Instance Thingies */
  53. /* ***************** */
  54. // init is a private method that ensures that all the object settings are set, getting a default value if one was not assigned.
  55. SWFUpload.prototype.initSettings = function (init_settings) {
  56. this.addSetting("control_id", this.movieName, "");
  57. // UI setting
  58. this.addSetting("ui_function", init_settings.ui_function, null);
  59. this.addSetting("ui_container_id", init_settings.ui_container_id, "");
  60. this.addSetting("degraded_container_id", init_settings.degraded_container_id, "");
  61. // Upload backend settings
  62. this.addSetting("upload_target_url", init_settings.upload_target_url, "");
  63. this.addSetting("upload_cookies", init_settings.upload_cookies, []);
  64. this.addSetting("upload_params", init_settings.upload_params, {});
  65. // Upload settings
  66. this.addSetting("begin_upload_on_queue", init_settings.begin_upload_on_queue, true);
  67. this.addSetting("file_types", init_settings.file_types, "*.gif;*.jpg;*.png");
  68. this.addSetting("file_types_description", init_settings.file_types_description, "Common Web Image Formats (gif, jpg, png)");
  69. this.addSetting("file_size_limit", init_settings.file_size_limit, "1024");
  70. this.addSetting("file_upload_limit", init_settings.file_upload_limit, "0");
  71. this.addSetting("file_queue_limit", init_settings.file_queue_limit, "0");
  72. // Flash Settings
  73. this.addSetting("flash_url", init_settings.flash_url, "swfupload.swf");
  74. this.addSetting("flash_container_id", init_settings.flash_container_id, "");
  75. this.addSetting("flash_width", init_settings.flash_width, "1px");
  76. this.addSetting("flash_height", init_settings.flash_height, "1px");
  77. this.addSetting("flash_color", init_settings.flash_color, "#FFFFFF");
  78. // Debug Settings
  79. this.addSetting("debug_enabled", init_settings.debug, false);
  80. this.debug_enabled = this.getSetting("debug_enabled");
  81. // Event Handlers
  82. this.flashReady = this.retrieveSetting(init_settings.flash_ready_handler, this.flashReady);
  83. this.dialogCancelled = this.retrieveSetting(init_settings.dialog_cancelled_handler, this.dialogCancelled);
  84. this.fileQueued = this.retrieveSetting(init_settings.file_queued_handler, this.fileQueued);
  85. this.fileProgress = this.retrieveSetting(init_settings.file_progress_handler, this.fileProgress);
  86. this.fileCancelled = this.retrieveSetting(init_settings.file_cancelled_handler, this.fileCancelled);
  87. this.fileComplete = this.retrieveSetting(init_settings.file_complete_handler, this.fileComplete);
  88. this.queueStopped = this.retrieveSetting(init_settings.queue_stopped_handler, this.queueStopped);
  89. this.queueComplete = this.retrieveSetting(init_settings.queue_complete_handler, this.queueComplete);
  90. this.error = this.retrieveSetting(init_settings.error_handler, this.error);
  91. this.debug = this.retrieveSetting(init_settings.debug_handler, this.debug);
  92. };
  93. // loadFlash is a private method that generates the HTML tag for the Flash
  94. // It then adds the flash to the "target" or to the body and stores a
  95. // reference to the flash element in "movieElement".
  96. SWFUpload.prototype.loadFlash = function () {
  97. var html, container, target_element, flash_container_id;
  98. html = this.getFlashHTML();
  99. // Build the DOM nodes to hold the flash;
  100. container = document.createElement("div");
  101. container.style.width = this.getSetting("flash_width");
  102. container.style.height = this.getSetting("flash_height");
  103. flash_container_id = this.getSetting("flash_container_id");
  104. if (flash_container_id !== "") {
  105. target_element = document.getElementById(flash_container_id);
  106. }
  107. // If the target wasn't found use the "BODY" element
  108. if (typeof(target_element) === "undefined" || target_element === null) {
  109. target_element = document.getElementsByTagName("body")[0];
  110. }
  111. // If all else fails then give up
  112. if (typeof(target_element) === "undefined" || target_element === null) {
  113. this.debugMessage("Could not find an element to add the Flash too. Failed to find element for \"flash_container_id\" or the BODY element.");
  114. return false;
  115. }
  116. target_element.appendChild(container);
  117. container.innerHTML = html;
  118. this.movieElement = document.getElementById(this.movieName); // Save a reference to the flash node so we can make calls to it.
  119. // Fix IEs "Flash can't callback when in a form" issue (http://www.extremefx.com.ar/blog/fixing-flash-external-interface-inside-form-on-internet-explorer)
  120. if (typeof(window[this.movieName]) === "undefined" || window[this.movieName] !== this.movieElement) {
  121. window[this.movieName] = this.movieElement;
  122. }
  123. };
  124. // Generates the embed/object tags needed to embed the flash in to the document
  125. SWFUpload.prototype.getFlashHTML = function () {
  126. var html = "";
  127. // Create Mozilla Embed HTML
  128. if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
  129. // Build the basic embed html
  130. html = '<embed type="application/x-shockwave-flash" src="' + this.getSetting("flash_url") + '" width="' + this.getSetting("flash_width") + '" height="' + this.getSetting("flash_height") + '"';
  131. html += ' id="' + this.movieName + '" name="' + this.movieName + '" ';
  132. html += ' allowScriptAccess="always" '; // So that the SWF can be on a CDN
  133. // html += ' wmode="transparent" ';
  134. html += 'bgcolor="' + this.getSetting("flash_color") + '" quality="high" menu="false" flashvars="';
  135. html += this.getFlashVars();
  136. html += '" />';
  137. // Create IE Object HTML
  138. } else {
  139. // Build the basic Object tag
  140. html = '<object id="' + this.movieName + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.getSetting("flash_width") + '" height="' + this.getSetting("flash_height") + '">';
  141. html += '<param name="movie" value="' + this.getSetting("flash_url") + '">';
  142. html += '<param name="bgcolor" value="' + this.getSetting("flash_color") + '" />';
  143. html += '<param name="quality" value="high" />';
  144. html += '<param name="menu" value="false" />';
  145. html += '<param name="wmode" value="transparent" />';
  146. html += '<param name="allowScriptAccess" value="always" />'; // So that the SWF can be on a CDN
  147. html += '<param name="flashvars" value="';
  148. html += this.getFlashVars();
  149. html += '" /></object>';
  150. }
  151. return html;
  152. };
  153. // This private method builds the parameter string that will be passed
  154. // to flash.
  155. SWFUpload.prototype.getFlashVars = function () {
  156. // Add the cookies to the backend string
  157. var upload_target_url = this.getSetting("upload_target_url");
  158. var query_string = this.buildQueryString();
  159. // Build the parameter string
  160. var html = "";
  161. html += "controlID=" + encodeURIComponent(this.getSetting("control_id"));
  162. html += "&uploadTargetURL=" + encodeURIComponent(upload_target_url);
  163. html += "&uploadQueryString=" + encodeURIComponent(query_string);
  164. html += "&beginUploadOnQueue=" + encodeURIComponent(this.getSetting("begin_upload_on_queue"));
  165. html += "&fileTypes=" + encodeURIComponent(this.getSetting("file_types"));
  166. html += "&fileTypesDescription=" + encodeURIComponent(this.getSetting("file_types_description"));
  167. html += "&fileSizeLimit=" + encodeURIComponent(this.getSetting("file_size_limit"));
  168. html += "&fileUploadLimit=" + encodeURIComponent(this.getSetting("file_upload_limit"));
  169. html += "&fileQueueLimit=" + encodeURIComponent(this.getSetting("file_queue_limit"));
  170. html += "&debugEnabled=" + encodeURIComponent(this.getSetting("debug_enabled"));
  171. return html;
  172. };
  173. SWFUpload.prototype.buildQueryString = function () {
  174. var upload_cookies = this.getSetting("upload_cookies");
  175. var upload_params = this.getSetting("upload_params");
  176. var query_string_pairs = [];
  177. var i, value, name;
  178. // Retrieve the cookies
  179. if (typeof(upload_cookies) === "object" && typeof(upload_cookies.length) === "number") {
  180. for (i = 0; i < upload_cookies.length; i++) {
  181. if (typeof(upload_cookies[i]) === "string" && upload_cookies[i] !== "") {
  182. value = this.getCookie(upload_cookies[i]);
  183. if (value !== "") {
  184. query_string_pairs.push(encodeURIComponent(upload_cookies[i]) + "=" + encodeURIComponent(value));
  185. }
  186. }
  187. }
  188. }
  189. // Retrieve the user defined parameters
  190. if (typeof(upload_params) === "object") {
  191. for (name in upload_params) {
  192. if (upload_params.hasOwnProperty(name)) {
  193. if (typeof(upload_params[name]) === "string" /*&& upload_params[name] != ""*/) {
  194. query_string_pairs.push(encodeURIComponent(name) + "=" + encodeURIComponent(upload_params[name]));
  195. }
  196. }
  197. }
  198. }
  199. return query_string_pairs.join("&");
  200. };
  201. // This private method "loads" the UI. If a target was specified then it is assumed that "display: none" was set and
  202. // it does a "display: block" so the UI is shown. Then if a degraded_target is specified it hides it by setting "display: none"
  203. // If you want SWFUpload to do something else then provide a "ui_function" setting and that will be called instead.
  204. SWFUpload.prototype.showUI = function () {
  205. var ui_container_id, ui_target, degraded_container_id, degraded_target;
  206. try {
  207. ui_container_id = this.getSetting("ui_container_id");
  208. if (ui_container_id !== "") {
  209. ui_target = document.getElementById(ui_container_id);
  210. if (ui_target !== null) {
  211. ui_target.style.display = "block";
  212. // Now that the UI has been taken care of hide the degraded UI
  213. degraded_container_id = this.getSetting("degraded_container_id");
  214. if (degraded_container_id !== "") {
  215. degraded_target = document.getElementById(degraded_container_id);
  216. if (degraded_target !== null) {
  217. degraded_target.style.display = "none";
  218. }
  219. }
  220. }
  221. }
  222. } catch (ex) {
  223. this.debugMessage(ex);
  224. }
  225. };
  226. // Saves a setting. If the value given is undefined or null then the default_value is used.
  227. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  228. if (typeof(value) === "undefined" || value === null) {
  229. this.settings[name] = default_value;
  230. } else {
  231. this.settings[name] = value;
  232. }
  233. return this.settings[name];
  234. };
  235. // Gets a setting. Returns null if it wasn't found.
  236. SWFUpload.prototype.getSetting = function (name) {
  237. if (typeof(this.settings[name]) === "undefined") {
  238. return "";
  239. } else {
  240. return this.settings[name];
  241. }
  242. };
  243. // Gets a setting, if the setting is undefined then return the default value
  244. // This does not affect or use the interal setting object.
  245. SWFUpload.prototype.retrieveSetting = function (value, default_value) {
  246. if (typeof(value) === "undefined" || value === null) {
  247. return default_value;
  248. } else {
  249. return value;
  250. }
  251. };
  252. // This method is used when debugging is enabled.
  253. // It loops through all the settings and displays
  254. // them in the debug Console.
  255. SWFUpload.prototype.displayDebugInfo = function () {
  256. var key, debug_message = "";
  257. debug_message += "----- DEBUG OUTPUT ----\nID: " + this.movieElement.id + "\n";
  258. // It's bad to use the for..in with an associative array, but oh well
  259. for (key in this.settings) {
  260. if (this.settings.hasOwnProperty(key)) {
  261. debug_message += key + ": " + this.settings[key] + "\n";
  262. }
  263. }
  264. debug_message += "----- DEBUG OUTPUT END ----\n";
  265. debug_message += "\n";
  266. this.debugMessage(debug_message);
  267. };
  268. // Sets the UploadTargetURL. To commit the change you must call UpdateUploadStrings.
  269. SWFUpload.prototype.setUploadTargetURL = function (url) {
  270. if (typeof(url) === "string") {
  271. return this.addSetting("upload_target_url", url, "");
  272. } else {
  273. return false;
  274. }
  275. };
  276. // Sets the upload_cookies array. To commit the change you must call UpdateUploadStrings.
  277. SWFUpload.prototype.setUploadCookies = function (cookie_name_array) {
  278. if (typeof(cookie_name_array) === "object" && typeof(cookie_name_array.length) === "number") {
  279. return this.addSetting("upload_cookies", cookie_name_array, []);
  280. } else {
  281. return false;
  282. }
  283. };
  284. // Sets the upload params object. To commit the change you must call UpdateUploadStrings.
  285. SWFUpload.prototype.setUploadParams = function (param_object) {
  286. if (typeof(param_object) === "object") {
  287. return this.addSetting("upload_params", param_object, []);
  288. } else {
  289. return false;
  290. }
  291. };
  292. /* *****************************
  293. -- Flash control methods --
  294. Your UI should use these
  295. to operate SWFUpload
  296. ***************************** */
  297. SWFUpload.prototype.browse = function () {
  298. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.Browse) === "function") {
  299. try {
  300. this.movieElement.Browse();
  301. }
  302. catch (ex) {
  303. this.debugMessage("Could not call browse: " + ex);
  304. }
  305. } else {
  306. this.debugMessage("Could not find Flash element");
  307. }
  308. };
  309. // Begins the uploads (if begin_upload_on_queue is disabled)
  310. // The file_id is optional. If specified only that file will be uploaded. If not specified SWFUpload will
  311. // begin to process the queue.
  312. SWFUpload.prototype.startUpload = function (file_id) {
  313. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.StartUpload) === "function") {
  314. try {
  315. this.movieElement.StartUpload(file_id);
  316. }
  317. catch (ex) {
  318. this.debugMessage("Could not call StartUpload: " + ex);
  319. }
  320. } else {
  321. this.debugMessage("Could not find Flash element");
  322. }
  323. };
  324. // Cancels the current uploading item. If no item is uploading then nothing happens.
  325. SWFUpload.prototype.cancelUpload = function (file_id) {
  326. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.CancelUpload) === "function") {
  327. try {
  328. this.movieElement.CancelUpload(file_id);
  329. }
  330. catch (ex) {
  331. this.debugMessage("Could not call CancelUpload");
  332. }
  333. } else {
  334. this.debugMessage("Could not find Flash element");
  335. }
  336. };
  337. // Cancels all the files in the queue. Including any current uploads.
  338. SWFUpload.prototype.cancelQueue = function () {
  339. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.CancelQueue) === "function") {
  340. try {
  341. this.movieElement.CancelQueue();
  342. }
  343. catch (ex) {
  344. this.debugMessage("Could not call CancelQueue");
  345. }
  346. } else {
  347. this.debugMessage("Could not find Flash element");
  348. }
  349. };
  350. // Stops the current upload. The file is re-queued. If nothing is currently uploading then nothing happens.
  351. SWFUpload.prototype.stopUpload = function () {
  352. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.StopUpload) === "function") {
  353. try {
  354. this.movieElement.StopUpload();
  355. }
  356. catch (ex) {
  357. this.debugMessage("Could not call StopUpload");
  358. }
  359. } else {
  360. this.debugMessage("Could not find Flash element");
  361. }
  362. };
  363. // Updates the upload url strings in the Flash Movie
  364. // This must be called in order for calls to SetUploadTargetURL, SetUploadCookies, and SetUploadQueryString to take effect.
  365. SWFUpload.prototype.updateUploadStrings = function () {
  366. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.SetUploadStrings) === "function") {
  367. try {
  368. this.movieElement.SetUploadStrings(this.getSetting("upload_target_url"), this.buildQueryString());
  369. }
  370. catch (ex) {
  371. this.debugMessage("Could not call SetUploadStrings");
  372. }
  373. } else {
  374. this.debugMessage("Could not find Flash element");
  375. }
  376. };
  377. SWFUpload.prototype.addFileParam = function (file_id, name, value) {
  378. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.AddFileParam) === "function") {
  379. try {
  380. return this.movieElement.AddFileParam(file_id, encodeURIComponent(name), encodeURIComponent(value));
  381. }
  382. catch (ex) {
  383. this.debugMessage("Could not call addFileParam");
  384. }
  385. } else {
  386. this.debugMessage("Could not find Flash element");
  387. }
  388. };
  389. SWFUpload.prototype.removeFileParam = function (file_id, name) {
  390. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.RemoveFileParam) === "function") {
  391. try {
  392. return this.movieElement.RemoveFileParam(file_id, encodeURIComponent(name));
  393. }
  394. catch (ex) {
  395. this.debugMessage("Could not call addFileParam");
  396. }
  397. } else {
  398. this.debugMessage("Could not find Flash element");
  399. }
  400. };
  401. /* *******************************
  402. Default Event Handlers
  403. ******************************* */
  404. // This is the callback method that the Flash movie will call when it has been loaded and is ready to go.
  405. // Calling this or showUI "manually" bypass the Flash Detection built in to SWFUpload.
  406. // FlashReady should not generally be overwritten. Use a ui_function setting if you want to control the UI loading after the flash has loaded.
  407. SWFUpload.prototype.flashReady = function () {
  408. var ui_function;
  409. try {
  410. this.debugMessage("Flash called back and is ready.");
  411. ui_function = this.getSetting("ui_function");
  412. if (typeof(ui_function) === "function") {
  413. ui_function.apply(this);
  414. } else {
  415. this.showUI();
  416. }
  417. } catch (ex) {
  418. this.debugMessage(ex);
  419. }
  420. };
  421. // Called when the user cancels the File browser window.
  422. SWFUpload.prototype.dialogCancelled = function () {
  423. this.debugMessage("browse Dialog Cancelled.");
  424. };
  425. // Called once for file the user selects
  426. SWFUpload.prototype.fileQueued = function (file) {
  427. this.debugMessage("File Queued: " + file.id);
  428. };
  429. // Called during upload as the file progresses
  430. SWFUpload.prototype.fileProgress = function (file, bytes_complete) {
  431. this.debugMessage("File Progress: " + file.id + ", Bytes: " + bytes_complete);
  432. };
  433. // Called after a file is cancelled
  434. SWFUpload.prototype.fileCancelled = function (file) {
  435. this.debugMessage("File Cancelled: " + file.id);
  436. };
  437. // Called when a file upload has completed
  438. SWFUpload.prototype.fileComplete = function (file) {
  439. this.debugMessage("File Complete: " + file.id);
  440. };
  441. // Called when at least 1 file has been uploaded and there are no files remaining in the queue.
  442. SWFUpload.prototype.queueComplete = function (file_upload_count) {
  443. this.debugMessage("Queue Complete. Files Uploaded:" + file_upload_count);
  444. };
  445. // Called when the upload is stopped.
  446. SWFUpload.prototype.queueStopped = function (file) {
  447. this.debugMessage("Queue Stopped. File Stopped:" + file.id);
  448. };
  449. // Called by SWFUpload JavaScript and Flash flash functions when debug is enabled
  450. SWFUpload.prototype.debug = function (message) {
  451. this.debugMessage(message);
  452. };
  453. // Called when an error occurs. Use errcode to determine which error occurred.
  454. SWFUpload.prototype.error = function (errcode, file, msg) {
  455. try {
  456. switch (errcode) {
  457. case SWFUpload.ERROR_CODE_HTTP_ERROR:
  458. this.debugMessage("Error Code: HTTP Error, File name: " + file.name + ", Message: " + msg);
  459. break;
  460. case SWFUpload.ERROR_CODE_MISSING_UPLOAD_TARGET:
  461. this.debugMessage("Error Code: No backend file, File name: " + file.name + ", Message: " + msg);
  462. break;
  463. case SWFUpload.ERROR_CODE_IO_ERROR:
  464. this.debugMessage("Error Code: IO Error, File name: " + file.name + ", Message: " + msg);
  465. break;
  466. case SWFUpload.ERROR_CODE_SECURITY_ERROR:
  467. this.debugMessage("Error Code: Security Error, File name: " + file.name + ", Message: " + msg);
  468. break;
  469. case SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT:
  470. this.debugMessage("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
  471. break;
  472. case SWFUpload.ERROR_CODE_ZERO_BYTE_FILE:
  473. this.debugMessage("Error Code: Zero Byte File, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
  474. break;
  475. case SWFUpload.ERROR_CODE_UPLOAD_LIMIT_EXCEEDED:
  476. this.debugMessage("Error Code: Upload limit reached, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
  477. break;
  478. case SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED:
  479. this.debugMessage("Error Code: Upload limit reached, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
  480. break;
  481. case SWFUpload.ERROR_CODE_UPLOAD_FAILED:
  482. this.debugMessage("Error Code: Upload Initialization exception, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
  483. break;
  484. case SWFUpload.ERROR_CODE_SPECIFIED_FILE_NOT_FOUND:
  485. this.debugMessage("Error Code: File ID specified for upload was not found, Message: " + msg);
  486. break;
  487. default:
  488. this.debugMessage("Error Code: Unhandled error occured. Errorcode: " + errcode);
  489. }
  490. } catch (ex) {
  491. this.debugMessage(ex);
  492. }
  493. };
  494. /* **********************************
  495. Utility Functions
  496. ********************************** */
  497. // Gets a cookie (http://www.w3schools.com/js/js_cookies.asp)
  498. SWFUpload.prototype.getCookie = function (cookie_name) {
  499. var cookie_start, cookie_end;
  500. try {
  501. if (document.cookie.length > 0 && cookie_name !== "")
  502. {
  503. cookie_start = document.cookie.indexOf(cookie_name + "=");
  504. if (cookie_start !== -1)
  505. {
  506. cookie_start = cookie_start + cookie_name.length + 1;
  507. cookie_end = document.cookie.indexOf(";", cookie_start);
  508. if (cookie_end === -1) {
  509. cookie_end = document.cookie.length;
  510. }
  511. return unescape(document.cookie.substring(cookie_start, cookie_end));
  512. }
  513. }
  514. } catch (ex) {
  515. this.debugMessage(ex);
  516. }
  517. return "";
  518. };
  519. /* **********************************
  520. Debug Console
  521. The debug console is a self contained, in page location
  522. for debug message to be sent. The Debug Console adds
  523. itself to the body if necessary.
  524. The console is automatically scrolled as messages appear.
  525. ********************************** */
  526. SWFUpload.prototype.debugMessage = function (message) {
  527. var exception_message, exception_values;
  528. if (this.debug_enabled) {
  529. if (typeof(message) === "object" && typeof(message.name) === "string" && typeof(message.message) === "string") {
  530. exception_message = "";
  531. exception_values = [];
  532. for (var key in message) {
  533. exception_values.push(key + ": " + message[key]);
  534. }
  535. exception_message = exception_values.join("\n");
  536. exception_values = exception_message.split("\n");
  537. exception_message = "EXCEPTION: " + exception_values.join("\nEXCEPTION: ");
  538. SWFUpload.Console.writeLine(exception_message);
  539. } else {
  540. SWFUpload.Console.writeLine(message);
  541. }
  542. }
  543. };
  544. SWFUpload.Console = {};
  545. SWFUpload.Console.writeLine = function (message) {
  546. var console, documentForm;
  547. try {
  548. console = document.getElementById("SWFUpload_Console");
  549. if (!console) {
  550. documentForm = document.createElement("form");
  551. document.getElementsByTagName("body")[0].appendChild(documentForm);
  552. console = document.createElement("textarea");
  553. console.id = "SWFUpload_Console";
  554. console.style.fontFamily = "monospace";
  555. console.setAttribute("wrap", "off");
  556. console.wrap = "off";
  557. console.style.overflow = "auto";
  558. console.style.width = "700px";
  559. console.style.height = "350px";
  560. console.style.margin = "5px";
  561. documentForm.appendChild(console);
  562. }
  563. console.value += message + "\n";
  564. console.scrollTop = console.scrollHeight - console.clientHeight;
  565. } catch (ex) {
  566. alert("Exception: " + ex.name + " Message: " + ex.message);
  567. }
  568. };