PageRenderTime 60ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/1.2.1/j/swfuploadr52_0002/swfupload.js

http://kfm.googlecode.com/
JavaScript | 660 lines | 468 code | 91 blank | 101 comment | 81 complexity | 0747879c91037b1600ac9bb6c05c1c98 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, Apache-2.0
  1. /**
  2. * SWFUpload 0.8.3 Revision 5.2 by Jacob Roberts, April 2007, linebyline.blogspot.com
  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.moveName] !== 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 += 'bgcolor="' + this.getSetting("flash_color") + '" quality="high" menu="false" flashvars="';
  133. html += this.getFlashVars();
  134. html += '" />';
  135. // Create IE Object HTML
  136. } else {
  137. // Build the basic Object tag
  138. html = '<object id="' + this.movieName + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.getSetting("flash_width") + '" height="' + this.getSetting("flash_height") + '">';
  139. html += '<param name="movie" value="' + this.getSetting("flash_url") + '">';
  140. html += '<param name="bgcolor" value="' + this.getSetting("flash_color") + '" />';
  141. html += '<param name="quality" value="high" />';
  142. html += '<param name="menu" value="false" />';
  143. html += '<param name="flashvars" value="';
  144. html += this.getFlashVars();
  145. html += '" /></object>';
  146. }
  147. return html;
  148. };
  149. // This private method builds the parameter string that will be passed
  150. // to flash.
  151. SWFUpload.prototype.getFlashVars = function () {
  152. // Add the cookies to the backend string
  153. var upload_target_url = this.getSetting("upload_target_url");
  154. var query_string = this.buildQueryString();
  155. // Build the parameter string
  156. var html = "";
  157. html += "controlID=" + encodeURIComponent(this.getSetting("control_id"));
  158. html += "&uploadTargetURL=" + encodeURIComponent(upload_target_url);
  159. html += "&uploadQueryString=" + encodeURIComponent(query_string);
  160. html += "&beginUploadOnQueue=" + encodeURIComponent(this.getSetting("begin_upload_on_queue"));
  161. html += "&fileTypes=" + encodeURIComponent(this.getSetting("file_types"));
  162. html += "&fileTypesDescription=" + encodeURIComponent(this.getSetting("file_types_description"));
  163. html += "&fileSizeLimit=" + encodeURIComponent(this.getSetting("file_size_limit"));
  164. html += "&fileUploadLimit=" + encodeURIComponent(this.getSetting("file_upload_limit"));
  165. html += "&fileQueueLimit=" + encodeURIComponent(this.getSetting("file_queue_limit"));
  166. html += "&debugEnabled=" + encodeURIComponent(this.getSetting("debug_enabled"));
  167. return html;
  168. };
  169. SWFUpload.prototype.buildQueryString = function () {
  170. var upload_cookies = this.getSetting("upload_cookies");
  171. var upload_params = this.getSetting("upload_params");
  172. var query_string_pairs = [];
  173. var i, value, name;
  174. // Retrieve the cookies
  175. if (typeof(upload_cookies) === "object" && typeof(upload_cookies.length) === "number") {
  176. for (i = 0; i < upload_cookies.length; i++) {
  177. if (typeof(upload_cookies[i]) === "string" && upload_cookies[i] !== "") {
  178. value = this.getCookie(upload_cookies[i]);
  179. if (value !== "") {
  180. query_string_pairs.push(encodeURIComponent(upload_cookies[i]) + "=" + encodeURIComponent(value));
  181. }
  182. }
  183. }
  184. }
  185. // Retrieve the user defined parameters
  186. if (typeof(upload_params) === "object") {
  187. for (name in upload_params) {
  188. if (upload_params.hasOwnProperty(name)) {
  189. if (typeof(upload_params[name]) === "string" /*&& upload_params[name] != ""*/) {
  190. query_string_pairs.push(encodeURIComponent(name) + "=" + encodeURIComponent(upload_params[name]));
  191. }
  192. }
  193. }
  194. }
  195. return query_string_pairs.join("&");
  196. };
  197. // This private method "loads" the UI. If a target was specified then it is assumed that "display: none" was set and
  198. // it does a "display: block" so the UI is shown. Then if a degraded_target is specified it hides it by setting "display: none"
  199. // If you want SWFUpload to do something else then provide a "ui_function" setting and that will be called instead.
  200. SWFUpload.prototype.showUI = function () {
  201. var ui_container_id, ui_target, degraded_container_id, degraded_target;
  202. try {
  203. ui_container_id = this.getSetting("ui_container_id");
  204. if (ui_container_id !== "") {
  205. ui_target = document.getElementById(ui_container_id);
  206. if (ui_target !== null) {
  207. ui_target.style.display = "block";
  208. // Now that the UI has been taken care of hide the degraded UI
  209. degraded_container_id = this.getSetting("degraded_container_id");
  210. if (degraded_container_id !== "") {
  211. degraded_target = document.getElementById(degraded_container_id);
  212. if (degraded_target !== null) {
  213. degraded_target.style.display = "none";
  214. }
  215. }
  216. }
  217. }
  218. } catch (ex) {
  219. this.debugMessage(ex);
  220. }
  221. };
  222. // Saves a setting. If the value given is undefined or null then the default_value is used.
  223. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  224. if (typeof(value) === "undefined" || value === null) {
  225. this.settings[name] = default_value;
  226. } else {
  227. this.settings[name] = value;
  228. }
  229. return this.settings[name];
  230. };
  231. // Gets a setting. Returns null if it wasn't found.
  232. SWFUpload.prototype.getSetting = function (name) {
  233. if (typeof(this.settings[name]) === "undefined") {
  234. return "";
  235. } else {
  236. return this.settings[name];
  237. }
  238. };
  239. // Gets a setting, if the setting is undefined then return the default value
  240. // This does not affect or use the interal setting object.
  241. SWFUpload.prototype.retrieveSetting = function (value, default_value) {
  242. if (typeof(value) === "undefined" || value === null) {
  243. return default_value;
  244. } else {
  245. return value;
  246. }
  247. };
  248. // This method is used when debugging is enabled.
  249. // It loops through all the settings and displays
  250. // them in the debug Console.
  251. SWFUpload.prototype.displayDebugInfo = function () {
  252. var key, debug_message = "";
  253. debug_message += "----- DEBUG OUTPUT ----\nID: " + this.movieElement.id + "\n";
  254. // It's bad to use the for..in with an associative array, but oh well
  255. for (key in this.settings) {
  256. if (this.settings.hasOwnProperty(key)) {
  257. debug_message += key + ": " + this.settings[key] + "\n";
  258. }
  259. }
  260. debug_message += "----- DEBUG OUTPUT END ----\n";
  261. debug_message += "\n";
  262. this.debugMessage(debug_message);
  263. };
  264. // Sets the UploadTargetURL. To commit the change you must call UpdateUploadStrings.
  265. SWFUpload.prototype.setUploadTargetURL = function (url) {
  266. if (typeof(url) === "string") {
  267. return this.addSetting("upload_target_url", url, "");
  268. } else {
  269. return false;
  270. }
  271. };
  272. // Sets the upload_cookies array. To commit the change you must call UpdateUploadStrings.
  273. SWFUpload.prototype.setUploadCookies = function (cookie_name_array) {
  274. if (typeof(cookie_name_array) === "object" && typeof(cookie_name_array.length) === "number") {
  275. return this.addSetting("upload_cookies", cookie_name_array, []);
  276. } else {
  277. return false;
  278. }
  279. };
  280. // Sets the upload params object. To commit the change you must call UpdateUploadStrings.
  281. SWFUpload.prototype.setUploadParams = function (param_object) {
  282. if (typeof(param_object) === "object") {
  283. return this.addSetting("upload_params", param_object, []);
  284. } else {
  285. return false;
  286. }
  287. };
  288. /* *****************************
  289. -- Flash control methods --
  290. Your UI should use these
  291. to operate SWFUpload
  292. ***************************** */
  293. SWFUpload.prototype.browse = function () {
  294. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.Browse) === "function") {
  295. try {
  296. this.movieElement.Browse();
  297. }
  298. catch (ex) {
  299. this.debugMessage("Could not call browse: " + ex);
  300. }
  301. } else {
  302. this.debugMessage("Could not find Flash element");
  303. }
  304. };
  305. // Begins the uploads (if begin_upload_on_queue is disabled)
  306. // The file_id is optional. If specified only that file will be uploaded. If not specified SWFUpload will
  307. // begin to process the queue.
  308. SWFUpload.prototype.startUpload = function (file_id) {
  309. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.StartUpload) === "function") {
  310. try {
  311. this.movieElement.StartUpload(file_id);
  312. }
  313. catch (ex) {
  314. this.debugMessage("Could not call StartUpload: " + ex);
  315. }
  316. } else {
  317. this.debugMessage("Could not find Flash element");
  318. }
  319. };
  320. // Cancels the current uploading item. If no item is uploading then nothing happens.
  321. SWFUpload.prototype.cancelUpload = function (file_id) {
  322. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.CancelUpload) === "function") {
  323. try {
  324. this.movieElement.CancelUpload(file_id);
  325. }
  326. catch (ex) {
  327. this.debugMessage("Could not call CancelUpload");
  328. }
  329. } else {
  330. this.debugMessage("Could not find Flash element");
  331. }
  332. };
  333. // Cancels all the files in the queue. Including any current uploads.
  334. SWFUpload.prototype.cancelQueue = function () {
  335. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.CancelQueue) === "function") {
  336. try {
  337. this.movieElement.CancelQueue();
  338. }
  339. catch (ex) {
  340. this.debugMessage("Could not call CancelQueue");
  341. }
  342. } else {
  343. this.debugMessage("Could not find Flash element");
  344. }
  345. };
  346. // Stops the current upload. The file is re-queued. If nothing is currently uploading then nothing happens.
  347. SWFUpload.prototype.stopUpload = function () {
  348. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.StopUpload) === "function") {
  349. try {
  350. this.movieElement.StopUpload();
  351. }
  352. catch (ex) {
  353. this.debugMessage("Could not call StopUpload");
  354. }
  355. } else {
  356. this.debugMessage("Could not find Flash element");
  357. }
  358. };
  359. // Updates the upload url strings in the Flash Movie
  360. // This must be called in order for calls to SetUploadTargetURL, SetUploadCookies, and SetUploadQueryString to take effect.
  361. SWFUpload.prototype.updateUploadStrings = function () {
  362. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.SetUploadStrings) === "function") {
  363. try {
  364. this.movieElement.SetUploadStrings(this.getSetting("upload_target_url"), this.buildQueryString());
  365. }
  366. catch (ex) {
  367. this.debugMessage("Could not call SetUploadStrings");
  368. }
  369. } else {
  370. this.debugMessage("Could not find Flash element");
  371. }
  372. };
  373. SWFUpload.prototype.addFileParam = function (file_id, name, value) {
  374. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.AddFileParam) === "function") {
  375. try {
  376. return this.movieElement.AddFileParam(file_id, encodeURIComponent(name), encodeURIComponent(value));
  377. }
  378. catch (ex) {
  379. this.debugMessage("Could not call addFileParam");
  380. }
  381. } else {
  382. this.debugMessage("Could not find Flash element");
  383. }
  384. };
  385. SWFUpload.prototype.removeFileParam = function (file_id, name) {
  386. if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.RemoveFileParam) === "function") {
  387. try {
  388. return this.movieElement.RemoveFileParam(file_id, encodeURIComponent(name));
  389. }
  390. catch (ex) {
  391. this.debugMessage("Could not call addFileParam");
  392. }
  393. } else {
  394. this.debugMessage("Could not find Flash element");
  395. }
  396. };
  397. /* *******************************
  398. Default Event Handlers
  399. ******************************* */
  400. // This is the callback method that the Flash movie will call when it has been loaded and is ready to go.
  401. // Calling this or showUI "manually" bypass the Flash Detection built in to SWFUpload.
  402. // FlashReady should not generally be overwritten. Use a ui_function setting if you want to control the UI loading after the flash has loaded.
  403. SWFUpload.prototype.flashReady = function () {
  404. var ui_function;
  405. try {
  406. this.debugMessage("Flash called back and is ready.");
  407. ui_function = this.getSetting("ui_function");
  408. if (typeof(ui_function) === "function") {
  409. ui_function.apply(this);
  410. } else {
  411. this.showUI();
  412. }
  413. } catch (ex) {
  414. this.debugMessage(ex);
  415. }
  416. };
  417. // Called when the user cancels the File browser window.
  418. SWFUpload.prototype.dialogCancelled = function () {
  419. this.debugMessage("browse Dialog Cancelled.");
  420. };
  421. // Called once for file the user selects
  422. SWFUpload.prototype.fileQueued = function (file) {
  423. this.debugMessage("File Queued: " + file.id);
  424. };
  425. // Called during upload as the file progresses
  426. SWFUpload.prototype.fileProgress = function (file, bytes_complete) {
  427. this.debugMessage("File Progress: " + file.id + ", Bytes: " + bytes_complete);
  428. };
  429. // Called after a file is cancelled
  430. SWFUpload.prototype.fileCancelled = function (file) {
  431. this.debugMessage("File Cancelled: " + file.id);
  432. };
  433. // Called when a file upload has completed
  434. SWFUpload.prototype.fileComplete = function (file) {
  435. this.debugMessage("File Complete: " + file.id);
  436. };
  437. // Called when at least 1 file has been uploaded and there are no files remaining in the queue.
  438. SWFUpload.prototype.queueComplete = function (file_upload_count) {
  439. this.debugMessage("Queue Complete. Files Uploaded:" + file_upload_count);
  440. };
  441. // Called when the upload is stopped.
  442. SWFUpload.prototype.queueStopped = function (file) {
  443. this.debugMessage("Queue Stopped. File Stopped:" + file.id);
  444. };
  445. // Called by SWFUpload JavaScript and Flash flash functions when debug is enabled
  446. SWFUpload.prototype.debug = function (message) {
  447. this.debugMessage(message);
  448. };
  449. // Called when an error occurs. Use errcode to determine which error occurred.
  450. SWFUpload.prototype.error = function (errcode, file, msg) {
  451. try {
  452. switch (errcode) {
  453. case SWFUpload.ERROR_CODE_HTTP_ERROR:
  454. this.debugMessage("Error Code: HTTP Error, File name: " + file.name + ", Message: " + msg);
  455. break;
  456. case SWFUpload.ERROR_CODE_MISSING_UPLOAD_TARGET:
  457. this.debugMessage("Error Code: No backend file, File name: " + file.name + ", Message: " + msg);
  458. break;
  459. case SWFUpload.ERROR_CODE_IO_ERROR:
  460. this.debugMessage("Error Code: IO Error, File name: " + file.name + ", Message: " + msg);
  461. break;
  462. case SWFUpload.ERROR_CODE_SECURITY_ERROR:
  463. this.debugMessage("Error Code: Security Error, File name: " + file.name + ", Message: " + msg);
  464. break;
  465. case SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT:
  466. this.debugMessage("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
  467. break;
  468. case SWFUpload.ERROR_CODE_ZERO_BYTE_FILE:
  469. this.debugMessage("Error Code: Zero Byte File, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
  470. break;
  471. case SWFUpload.ERROR_CODE_UPLOAD_LIMIT_EXCEEDED:
  472. this.debugMessage("Error Code: Upload limit reached, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
  473. break;
  474. case SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED:
  475. this.debugMessage("Error Code: Upload limit reached, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
  476. break;
  477. case SWFUpload.ERROR_CODE_UPLOAD_FAILED:
  478. this.debugMessage("Error Code: Upload Initialization exception, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg);
  479. break;
  480. case SWFUpload.ERROR_CODE_SPECIFIED_FILE_NOT_FOUND:
  481. this.debugMessage("Error Code: File ID specified for upload was not found, Message: " + msg);
  482. break;
  483. default:
  484. this.debugMessage("Error Code: Unhandled error occured. Errorcode: " + errcode);
  485. }
  486. } catch (ex) {
  487. this.debugMessage(ex);
  488. }
  489. };
  490. /* **********************************
  491. Utility Functions
  492. ********************************** */
  493. // Gets a cookie (http://www.w3schools.com/js/js_cookies.asp)
  494. SWFUpload.prototype.getCookie = function (cookie_name) {
  495. var cookie_start, cookie_end;
  496. try {
  497. if (document.cookie.length > 0 && cookie_name !== "")
  498. {
  499. cookie_start = document.cookie.indexOf(cookie_name + "=");
  500. if (cookie_start !== -1)
  501. {
  502. cookie_start = cookie_start + cookie_name.length + 1;
  503. cookie_end = document.cookie.indexOf(";", cookie_start);
  504. if (cookie_end === -1) {
  505. cookie_end = document.cookie.length;
  506. }
  507. return unescape(document.cookie.substring(cookie_start, cookie_end));
  508. }
  509. }
  510. } catch (ex) {
  511. this.debugMessage(ex);
  512. }
  513. return "";
  514. };
  515. /* **********************************
  516. Debug Console
  517. The debug console is a self contained, in page location
  518. for debug message to be sent. The Debug Console adds
  519. itself to the body if necessary.
  520. The console is automatically scrolled as messages appear.
  521. ********************************** */
  522. SWFUpload.prototype.debugMessage = function (message) {
  523. var exception_message, exception_values;
  524. if (this.debug_enabled) {
  525. if (typeof(message) === "object" && typeof(message.name) === "string" && typeof(message.message) === "string") {
  526. exception_message = "";
  527. exception_values = [];
  528. for (var key in message) {
  529. exception_values.push(key + ": " + message[key]);
  530. }
  531. exception_message = exception_values.join("\n");
  532. exception_values = exception_message.split("\n");
  533. exception_message = "EXCEPTION: " + exception_values.join("\nEXCEPTION: ");
  534. SWFUpload.Console.writeLine(exception_message);
  535. } else {
  536. SWFUpload.Console.writeLine(message);
  537. }
  538. }
  539. };
  540. SWFUpload.Console = {};
  541. SWFUpload.Console.writeLine = function (message) {
  542. var console, documentForm;
  543. try {
  544. console = document.getElementById("SWFUpload_Console");
  545. if (!console) {
  546. documentForm = document.createElement("form");
  547. document.getElementsByTagName("body")[0].appendChild(documentForm);
  548. console = document.createElement("textarea");
  549. console.id = "SWFUpload_Console";
  550. console.style.fontFamily = "monospace";
  551. console.setAttribute("wrap", "off");
  552. console.wrap = "off";
  553. console.style.overflow = "auto";
  554. console.style.width = "700px";
  555. console.style.height = "350px";
  556. console.style.margin = "5px";
  557. documentForm.appendChild(console);
  558. }
  559. console.value += message + "\n";
  560. console.scrollTop = console.scrollHeight - console.clientHeight;
  561. } catch (ex) {
  562. alert("Exception: " + ex.name + " Message: " + ex.message);
  563. }
  564. };