PageRenderTime 74ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/themes/forum/swfupload/swf.all.js

https://github.com/paranoidxc/iwebhost
JavaScript | 1697 lines | 1161 code | 271 blank | 265 comment | 130 complexity | d35774931eb7cfc107b4c4722f4a3926 MD5 | raw file
  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. /* ******************* */
  14. /* Constructor & Init */
  15. /* ******************* */
  16. /*start of swfupload.js */
  17. var SWFUpload;
  18. if (SWFUpload == undefined) {
  19. SWFUpload = function (settings) {
  20. this.initSWFUpload(settings);
  21. };
  22. }
  23. SWFUpload.prototype.initSWFUpload = function (settings) {
  24. try {
  25. this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
  26. this.settings = settings;
  27. this.eventQueue = [];
  28. this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
  29. this.movieElement = null;
  30. // Setup global control tracking
  31. SWFUpload.instances[this.movieName] = this;
  32. // Load the settings. Load the Flash movie.
  33. this.initSettings();
  34. this.loadFlash();
  35. this.displayDebugInfo();
  36. } catch (ex) {
  37. delete SWFUpload.instances[this.movieName];
  38. throw ex;
  39. }
  40. };
  41. /* *************** */
  42. /* Static Members */
  43. /* *************** */
  44. SWFUpload.instances = {};
  45. SWFUpload.movieCount = 0;
  46. SWFUpload.version = "2.2.0 2009-03-25";
  47. SWFUpload.QUEUE_ERROR = {
  48. QUEUE_LIMIT_EXCEEDED : -100,
  49. FILE_EXCEEDS_SIZE_LIMIT : -110,
  50. ZERO_BYTE_FILE : -120,
  51. INVALID_FILETYPE : -130
  52. };
  53. SWFUpload.UPLOAD_ERROR = {
  54. HTTP_ERROR : -200,
  55. MISSING_UPLOAD_URL : -210,
  56. IO_ERROR : -220,
  57. SECURITY_ERROR : -230,
  58. UPLOAD_LIMIT_EXCEEDED : -240,
  59. UPLOAD_FAILED : -250,
  60. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  61. FILE_VALIDATION_FAILED : -270,
  62. FILE_CANCELLED : -280,
  63. UPLOAD_STOPPED : -290
  64. };
  65. SWFUpload.FILE_STATUS = {
  66. QUEUED : -1,
  67. IN_PROGRESS : -2,
  68. ERROR : -3,
  69. COMPLETE : -4,
  70. CANCELLED : -5
  71. };
  72. SWFUpload.BUTTON_ACTION = {
  73. SELECT_FILE : -100,
  74. SELECT_FILES : -110,
  75. START_UPLOAD : -120
  76. };
  77. SWFUpload.CURSOR = {
  78. ARROW : -1,
  79. HAND : -2
  80. };
  81. SWFUpload.WINDOW_MODE = {
  82. WINDOW : "window",
  83. TRANSPARENT : "transparent",
  84. OPAQUE : "opaque"
  85. };
  86. // Private: takes a URL, determines if it is relative and converts to an absolute URL
  87. // using the current site. Only processes the URL if it can, otherwise returns the URL untouched
  88. SWFUpload.completeURL = function(url) {
  89. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  90. return url;
  91. }
  92. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  93. var indexSlash = window.location.pathname.lastIndexOf("/");
  94. if (indexSlash <= 0) {
  95. path = "/";
  96. } else {
  97. path = window.location.pathname.substr(0, indexSlash) + "/";
  98. }
  99. return /*currentURL +*/ path + url;
  100. };
  101. /* ******************** */
  102. /* Instance Members */
  103. /* ******************** */
  104. // Private: initSettings ensures that all the
  105. // settings are set, getting a default value if one was not assigned.
  106. SWFUpload.prototype.initSettings = function () {
  107. this.ensureDefault = function (settingName, defaultValue) {
  108. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  109. };
  110. // Upload backend settings
  111. this.ensureDefault("upload_url", "");
  112. this.ensureDefault("preserve_relative_urls", false);
  113. this.ensureDefault("file_post_name", "Filedata");
  114. this.ensureDefault("post_params", {});
  115. this.ensureDefault("use_query_string", false);
  116. this.ensureDefault("requeue_on_error", false);
  117. this.ensureDefault("http_success", []);
  118. this.ensureDefault("assume_success_timeout", 0);
  119. // File Settings
  120. this.ensureDefault("file_types", "*.*");
  121. this.ensureDefault("file_types_description", "All Files");
  122. this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
  123. this.ensureDefault("file_upload_limit", 0);
  124. this.ensureDefault("file_queue_limit", 0);
  125. // Flash Settings
  126. this.ensureDefault("flash_url", "swfupload.swf");
  127. this.ensureDefault("prevent_swf_caching", true);
  128. // Button Settings
  129. this.ensureDefault("button_image_url", "");
  130. this.ensureDefault("button_width", 1);
  131. this.ensureDefault("button_height", 1);
  132. this.ensureDefault("button_text", "");
  133. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  134. this.ensureDefault("button_text_top_padding", 0);
  135. this.ensureDefault("button_text_left_padding", 0);
  136. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  137. this.ensureDefault("button_disabled", false);
  138. this.ensureDefault("button_placeholder_id", "");
  139. this.ensureDefault("button_placeholder", null);
  140. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  141. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  142. // Debug Settings
  143. this.ensureDefault("debug", false);
  144. this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
  145. // Event Handlers
  146. this.settings.return_upload_start_handler = this.returnUploadStart;
  147. this.ensureDefault("swfupload_loaded_handler", null);
  148. this.ensureDefault("file_dialog_start_handler", null);
  149. this.ensureDefault("file_queued_handler", null);
  150. this.ensureDefault("file_queue_error_handler", null);
  151. this.ensureDefault("file_dialog_complete_handler", null);
  152. this.ensureDefault("upload_start_handler", null);
  153. this.ensureDefault("upload_progress_handler", null);
  154. this.ensureDefault("upload_error_handler", null);
  155. this.ensureDefault("upload_success_handler", null);
  156. this.ensureDefault("upload_complete_handler", null);
  157. this.ensureDefault("debug_handler", this.debugMessage);
  158. this.ensureDefault("custom_settings", {});
  159. // Other settings
  160. this.customSettings = this.settings.custom_settings;
  161. // Update the flash url if needed
  162. if (!!this.settings.prevent_swf_caching) {
  163. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  164. }
  165. if (!this.settings.preserve_relative_urls) {
  166. //this.settings.flash_url = SWFUpload.completeURL(this.settings.flash_url); // Don't need to do this one since flash doesn't look at it
  167. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  168. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  169. }
  170. delete this.ensureDefault;
  171. };
  172. // Private: loadFlash replaces the button_placeholder element with the flash movie.
  173. SWFUpload.prototype.loadFlash = function () {
  174. var targetElement, tempParent;
  175. // Make sure an element with the ID we are going to use doesn't already exist
  176. if (document.getElementById(this.movieName) !== null) {
  177. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  178. }
  179. // Get the element where we will be placing the flash movie
  180. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  181. if (targetElement == undefined) {
  182. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  183. }
  184. // Append the container and load the flash
  185. tempParent = document.createElement("div");
  186. tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
  187. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  188. // Fix IE Flash/Form bug
  189. if (window[this.movieName] == undefined) {
  190. window[this.movieName] = this.getMovieElement();
  191. }
  192. };
  193. // Private: getFlashHTML generates the object tag needed to embed the flash in to the document
  194. SWFUpload.prototype.getFlashHTML = function () {
  195. // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
  196. 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">',
  197. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  198. '<param name="movie" value="', this.settings.flash_url, '" />',
  199. '<param name="quality" value="high" />',
  200. '<param name="menu" value="false" />',
  201. '<param name="allowScriptAccess" value="always" />',
  202. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  203. '</object>'].join("");
  204. };
  205. // Private: getFlashVars builds the parameter string that will be passed
  206. // to flash in the flashvars param.
  207. SWFUpload.prototype.getFlashVars = function () {
  208. // Build a string from the post param object
  209. var paramString = this.buildParamString();
  210. var httpSuccessString = this.settings.http_success.join(",");
  211. // Build the parameter string
  212. return ["movieName=", encodeURIComponent(this.movieName),
  213. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  214. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  215. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  216. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  217. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  218. "&amp;params=", encodeURIComponent(paramString),
  219. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  220. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  221. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  222. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  223. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  224. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  225. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  226. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  227. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  228. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  229. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  230. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  231. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  232. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  233. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  234. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  235. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  236. ].join("");
  237. };
  238. // Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
  239. // The element is cached after the first lookup
  240. SWFUpload.prototype.getMovieElement = function () {
  241. if (this.movieElement == undefined) {
  242. this.movieElement = document.getElementById(this.movieName);
  243. }
  244. if (this.movieElement === null) {
  245. throw "Could not find Flash element";
  246. }
  247. return this.movieElement;
  248. };
  249. // Private: buildParamString takes the name/value pairs in the post_params setting object
  250. // and joins them up in to a string formatted "name=value&amp;name=value"
  251. SWFUpload.prototype.buildParamString = function () {
  252. var postParams = this.settings.post_params;
  253. var paramStringPairs = [];
  254. if (typeof(postParams) === "object") {
  255. for (var name in postParams) {
  256. if (postParams.hasOwnProperty(name)) {
  257. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  258. }
  259. }
  260. }
  261. return paramStringPairs.join("&amp;");
  262. };
  263. // Public: Used to remove a SWFUpload instance from the page. This method strives to remove
  264. // all references to the SWF, and other objects so memory is properly freed.
  265. // Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
  266. // Credits: Major improvements provided by steffen
  267. SWFUpload.prototype.destroy = function () {
  268. try {
  269. // Make sure Flash is done before we try to remove it
  270. this.cancelUpload(null, false);
  271. // Remove the SWFUpload DOM nodes
  272. var movieElement = null;
  273. movieElement = this.getMovieElement();
  274. if (movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  275. // Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround)
  276. for (var i in movieElement) {
  277. try {
  278. if (typeof(movieElement[i]) === "function") {
  279. movieElement[i] = null;
  280. }
  281. } catch (ex1) {}
  282. }
  283. // Remove the Movie Element from the page
  284. try {
  285. movieElement.parentNode.removeChild(movieElement);
  286. } catch (ex) {}
  287. }
  288. // Remove IE form fix reference
  289. window[this.movieName] = null;
  290. // Destroy other references
  291. SWFUpload.instances[this.movieName] = null;
  292. delete SWFUpload.instances[this.movieName];
  293. this.movieElement = null;
  294. this.settings = null;
  295. this.customSettings = null;
  296. this.eventQueue = null;
  297. this.movieName = null;
  298. return true;
  299. } catch (ex2) {
  300. return false;
  301. }
  302. };
  303. // Public: displayDebugInfo prints out settings and configuration
  304. // information about this SWFUpload instance.
  305. // This function (and any references to it) can be deleted when placing
  306. // SWFUpload in production.
  307. SWFUpload.prototype.displayDebugInfo = function () {
  308. this.debug(
  309. [
  310. "---SWFUpload Instance Info---\n",
  311. "Version: ", SWFUpload.version, "\n",
  312. "Movie Name: ", this.movieName, "\n",
  313. "Settings:\n",
  314. "\t", "upload_url: ", this.settings.upload_url, "\n",
  315. "\t", "flash_url: ", this.settings.flash_url, "\n",
  316. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  317. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  318. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  319. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  320. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  321. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  322. "\t", "file_types: ", this.settings.file_types, "\n",
  323. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  324. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  325. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  326. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  327. "\t", "debug: ", this.settings.debug.toString(), "\n",
  328. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  329. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  330. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  331. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  332. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  333. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  334. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  335. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  336. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  337. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  338. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  339. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  340. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  341. "Event Handlers:\n",
  342. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  343. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  344. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  345. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  346. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  347. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  348. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  349. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  350. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  351. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  352. ].join("")
  353. );
  354. };
  355. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  356. the maintain v2 API compatibility
  357. */
  358. // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
  359. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  360. if (value == undefined) {
  361. return (this.settings[name] = default_value);
  362. } else {
  363. return (this.settings[name] = value);
  364. }
  365. };
  366. // Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
  367. SWFUpload.prototype.getSetting = function (name) {
  368. if (this.settings[name] != undefined) {
  369. return this.settings[name];
  370. }
  371. return "";
  372. };
  373. // Private: callFlash handles function calls made to the Flash element.
  374. // Calls are made with a setTimeout for some functions to work around
  375. // bugs in the ExternalInterface library.
  376. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  377. argumentArray = argumentArray || [];
  378. var movieElement = this.getMovieElement();
  379. var returnValue, returnString;
  380. // Flash's method if calling ExternalInterface methods (code adapted from MooTools).
  381. try {
  382. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  383. returnValue = eval(returnString);
  384. } catch (ex) {
  385. throw "Call to " + functionName + " failed";
  386. }
  387. // Unescape file post param values
  388. if (returnValue != undefined && typeof returnValue.post === "object") {
  389. returnValue = this.unescapeFilePostParams(returnValue);
  390. }
  391. return returnValue;
  392. };
  393. /* *****************************
  394. -- Flash control methods --
  395. Your UI should use these
  396. to operate SWFUpload
  397. ***************************** */
  398. // WARNING: this function does not work in Flash Player 10
  399. // Public: selectFile causes a File Selection Dialog window to appear. This
  400. // dialog only allows 1 file to be selected.
  401. SWFUpload.prototype.selectFile = function () {
  402. this.callFlash("SelectFile");
  403. };
  404. // WARNING: this function does not work in Flash Player 10
  405. // Public: selectFiles causes a File Selection Dialog window to appear/ This
  406. // dialog allows the user to select any number of files
  407. // Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
  408. // If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
  409. // for this bug.
  410. SWFUpload.prototype.selectFiles = function () {
  411. this.callFlash("SelectFiles");
  412. };
  413. // Public: startUpload starts uploading the first file in the queue unless
  414. // the optional parameter 'fileID' specifies the ID
  415. SWFUpload.prototype.startUpload = function (fileID) {
  416. this.callFlash("StartUpload", [fileID]);
  417. };
  418. // Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
  419. // If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
  420. // If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
  421. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  422. if (triggerErrorEvent !== false) {
  423. triggerErrorEvent = true;
  424. }
  425. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  426. };
  427. // Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
  428. // If nothing is currently uploading then nothing happens.
  429. SWFUpload.prototype.stopUpload = function () {
  430. this.callFlash("StopUpload");
  431. };
  432. /* ************************
  433. * Settings methods
  434. * These methods change the SWFUpload settings.
  435. * SWFUpload settings should not be changed directly on the settings object
  436. * since many of the settings need to be passed to Flash in order to take
  437. * effect.
  438. * *********************** */
  439. // Public: getStats gets the file statistics object.
  440. SWFUpload.prototype.getStats = function () {
  441. return this.callFlash("GetStats");
  442. };
  443. // Public: setStats changes the SWFUpload statistics. You shouldn't need to
  444. // change the statistics but you can. Changing the statistics does not
  445. // affect SWFUpload accept for the successful_uploads count which is used
  446. // by the upload_limit setting to determine how many files the user may upload.
  447. SWFUpload.prototype.setStats = function (statsObject) {
  448. this.callFlash("SetStats", [statsObject]);
  449. };
  450. // Public: getFile retrieves a File object by ID or Index. If the file is
  451. // not found then 'null' is returned.
  452. SWFUpload.prototype.getFile = function (fileID) {
  453. if (typeof(fileID) === "number") {
  454. return this.callFlash("GetFileByIndex", [fileID]);
  455. } else {
  456. return this.callFlash("GetFile", [fileID]);
  457. }
  458. };
  459. // Public: addFileParam sets a name/value pair that will be posted with the
  460. // file specified by the Files ID. If the name already exists then the
  461. // exiting value will be overwritten.
  462. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  463. return this.callFlash("AddFileParam", [fileID, name, value]);
  464. };
  465. // Public: removeFileParam removes a previously set (by addFileParam) name/value
  466. // pair from the specified file.
  467. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  468. this.callFlash("RemoveFileParam", [fileID, name]);
  469. };
  470. // Public: setUploadUrl changes the upload_url setting.
  471. SWFUpload.prototype.setUploadURL = function (url) {
  472. this.settings.upload_url = url.toString();
  473. this.callFlash("SetUploadURL", [url]);
  474. };
  475. // Public: setPostParams changes the post_params setting
  476. SWFUpload.prototype.setPostParams = function (paramsObject) {
  477. this.settings.post_params = paramsObject;
  478. this.callFlash("SetPostParams", [paramsObject]);
  479. };
  480. // Public: addPostParam adds post name/value pair. Each name can have only one value.
  481. SWFUpload.prototype.addPostParam = function (name, value) {
  482. this.settings.post_params[name] = value;
  483. this.callFlash("SetPostParams", [this.settings.post_params]);
  484. };
  485. // Public: removePostParam deletes post name/value pair.
  486. SWFUpload.prototype.removePostParam = function (name) {
  487. delete this.settings.post_params[name];
  488. this.callFlash("SetPostParams", [this.settings.post_params]);
  489. };
  490. // Public: setFileTypes changes the file_types setting and the file_types_description setting
  491. SWFUpload.prototype.setFileTypes = function (types, description) {
  492. this.settings.file_types = types;
  493. this.settings.file_types_description = description;
  494. this.callFlash("SetFileTypes", [types, description]);
  495. };
  496. // Public: setFileSizeLimit changes the file_size_limit setting
  497. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  498. this.settings.file_size_limit = fileSizeLimit;
  499. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  500. };
  501. // Public: setFileUploadLimit changes the file_upload_limit setting
  502. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  503. this.settings.file_upload_limit = fileUploadLimit;
  504. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  505. };
  506. // Public: setFileQueueLimit changes the file_queue_limit setting
  507. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  508. this.settings.file_queue_limit = fileQueueLimit;
  509. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  510. };
  511. // Public: setFilePostName changes the file_post_name setting
  512. SWFUpload.prototype.setFilePostName = function (filePostName) {
  513. this.settings.file_post_name = filePostName;
  514. this.callFlash("SetFilePostName", [filePostName]);
  515. };
  516. // Public: setUseQueryString changes the use_query_string setting
  517. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  518. this.settings.use_query_string = useQueryString;
  519. this.callFlash("SetUseQueryString", [useQueryString]);
  520. };
  521. // Public: setRequeueOnError changes the requeue_on_error setting
  522. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  523. this.settings.requeue_on_error = requeueOnError;
  524. this.callFlash("SetRequeueOnError", [requeueOnError]);
  525. };
  526. // Public: setHTTPSuccess changes the http_success setting
  527. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  528. if (typeof http_status_codes === "string") {
  529. http_status_codes = http_status_codes.replace(" ", "").split(",");
  530. }
  531. this.settings.http_success = http_status_codes;
  532. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  533. };
  534. // Public: setHTTPSuccess changes the http_success setting
  535. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  536. this.settings.assume_success_timeout = timeout_seconds;
  537. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  538. };
  539. // Public: setDebugEnabled changes the debug_enabled setting
  540. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  541. this.settings.debug_enabled = debugEnabled;
  542. this.callFlash("SetDebugEnabled", [debugEnabled]);
  543. };
  544. // Public: setButtonImageURL loads a button image sprite
  545. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  546. if (buttonImageURL == undefined) {
  547. buttonImageURL = "";
  548. }
  549. this.settings.button_image_url = buttonImageURL;
  550. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  551. };
  552. // Public: setButtonDimensions resizes the Flash Movie and button
  553. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  554. this.settings.button_width = width;
  555. this.settings.button_height = height;
  556. var movie = this.getMovieElement();
  557. if (movie != undefined) {
  558. movie.style.width = width + "px";
  559. movie.style.height = height + "px";
  560. }
  561. this.callFlash("SetButtonDimensions", [width, height]);
  562. };
  563. // Public: setButtonText Changes the text overlaid on the button
  564. SWFUpload.prototype.setButtonText = function (html) {
  565. this.settings.button_text = html;
  566. this.callFlash("SetButtonText", [html]);
  567. };
  568. // Public: setButtonTextPadding changes the top and left padding of the text overlay
  569. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  570. this.settings.button_text_top_padding = top;
  571. this.settings.button_text_left_padding = left;
  572. this.callFlash("SetButtonTextPadding", [left, top]);
  573. };
  574. // Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
  575. SWFUpload.prototype.setButtonTextStyle = function (css) {
  576. this.settings.button_text_style = css;
  577. this.callFlash("SetButtonTextStyle", [css]);
  578. };
  579. // Public: setButtonDisabled disables/enables the button
  580. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  581. this.settings.button_disabled = isDisabled;
  582. this.callFlash("SetButtonDisabled", [isDisabled]);
  583. };
  584. // Public: setButtonAction sets the action that occurs when the button is clicked
  585. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  586. this.settings.button_action = buttonAction;
  587. this.callFlash("SetButtonAction", [buttonAction]);
  588. };
  589. // Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
  590. SWFUpload.prototype.setButtonCursor = function (cursor) {
  591. this.settings.button_cursor = cursor;
  592. this.callFlash("SetButtonCursor", [cursor]);
  593. };
  594. /* *******************************
  595. Flash Event Interfaces
  596. These functions are used by Flash to trigger the various
  597. events.
  598. All these functions a Private.
  599. Because the ExternalInterface library is buggy the event calls
  600. are added to a queue and the queue then executed by a setTimeout.
  601. This ensures that events are executed in a determinate order and that
  602. the ExternalInterface bugs are avoided.
  603. ******************************* */
  604. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  605. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  606. if (argumentArray == undefined) {
  607. argumentArray = [];
  608. } else if (!(argumentArray instanceof Array)) {
  609. argumentArray = [argumentArray];
  610. }
  611. var self = this;
  612. if (typeof this.settings[handlerName] === "function") {
  613. // Queue the event
  614. this.eventQueue.push(function () {
  615. this.settings[handlerName].apply(this, argumentArray);
  616. });
  617. // Execute the next queued event
  618. setTimeout(function () {
  619. self.executeNextEvent();
  620. }, 0);
  621. } else if (this.settings[handlerName] !== null) {
  622. throw "Event handler " + handlerName + " is unknown or is not a function";
  623. }
  624. };
  625. // Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
  626. // we must queue them in order to garentee that they are executed in order.
  627. SWFUpload.prototype.executeNextEvent = function () {
  628. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  629. var f = this.eventQueue ? this.eventQueue.shift() : null;
  630. if (typeof(f) === "function") {
  631. f.apply(this);
  632. }
  633. };
  634. // Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
  635. // properties that contain characters that are not valid for JavaScript identifiers. To work around this
  636. // the Flash Component escapes the parameter names and we must unescape again before passing them along.
  637. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  638. var reg = /[$]([0-9a-f]{4})/i;
  639. var unescapedPost = {};
  640. var uk;
  641. if (file != undefined) {
  642. for (var k in file.post) {
  643. if (file.post.hasOwnProperty(k)) {
  644. uk = k;
  645. var match;
  646. while ((match = reg.exec(uk)) !== null) {
  647. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  648. }
  649. unescapedPost[uk] = file.post[k];
  650. }
  651. }
  652. file.post = unescapedPost;
  653. }
  654. return file;
  655. };
  656. // Private: Called by Flash to see if JS can call in to Flash (test if External Interface is working)
  657. SWFUpload.prototype.testExternalInterface = function () {
  658. try {
  659. return this.callFlash("TestExternalInterface");
  660. } catch (ex) {
  661. return false;
  662. }
  663. };
  664. // Private: This event is called by Flash when it has finished loading. Don't modify this.
  665. // Use the swfupload_loaded_handler event setting to execute custom code when SWFUpload has loaded.
  666. SWFUpload.prototype.flashReady = function () {
  667. // Check that the movie element is loaded correctly with its ExternalInterface methods defined
  668. var movieElement = this.getMovieElement();
  669. if (!movieElement) {
  670. this.debug("Flash called back ready but the flash movie can't be found.");
  671. return;
  672. }
  673. this.cleanUp(movieElement);
  674. this.queueEvent("swfupload_loaded_handler");
  675. };
  676. // Private: removes Flash added fuctions to the DOM node to prevent memory leaks in IE.
  677. // This function is called by Flash each time the ExternalInterface functions are created.
  678. SWFUpload.prototype.cleanUp = function (movieElement) {
  679. // Pro-actively unhook all the Flash functions
  680. try {
  681. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  682. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  683. for (var key in movieElement) {
  684. try {
  685. if (typeof(movieElement[key]) === "function") {
  686. movieElement[key] = null;
  687. }
  688. } catch (ex) {
  689. }
  690. }
  691. }
  692. } catch (ex1) {
  693. }
  694. // Fix Flashes own cleanup code so if the SWFMovie was removed from the page
  695. // it doesn't display errors.
  696. window["__flash__removeCallback"] = function (instance, name) {
  697. try {
  698. if (instance) {
  699. instance[name] = null;
  700. }
  701. } catch (flashEx) {
  702. }
  703. };
  704. };
  705. /* This is a chance to do something before the browse window opens */
  706. SWFUpload.prototype.fileDialogStart = function () {
  707. this.queueEvent("file_dialog_start_handler");
  708. };
  709. /* Called when a file is successfully added to the queue. */
  710. SWFUpload.prototype.fileQueued = function (file) {
  711. file = this.unescapeFilePostParams(file);
  712. this.queueEvent("file_queued_handler", file);
  713. };
  714. /* Handle errors that occur when an attempt to queue a file fails. */
  715. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  716. file = this.unescapeFilePostParams(file);
  717. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  718. };
  719. /* Called after the file dialog has closed and the selected files have been queued.
  720. You could call startUpload here if you want the queued files to begin uploading immediately. */
  721. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  722. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  723. };
  724. SWFUpload.prototype.uploadStart = function (file) {
  725. file = this.unescapeFilePostParams(file);
  726. this.queueEvent("return_upload_start_handler", file);
  727. };
  728. SWFUpload.prototype.returnUploadStart = function (file) {
  729. var returnValue;
  730. if (typeof this.settings.upload_start_handler === "function") {
  731. file = this.unescapeFilePostParams(file);
  732. returnValue = this.settings.upload_start_handler.call(this, file);
  733. } else if (this.settings.upload_start_handler != undefined) {
  734. throw "upload_start_handler must be a function";
  735. }
  736. // Convert undefined to true so if nothing is returned from the upload_start_handler it is
  737. // interpretted as 'true'.
  738. if (returnValue === undefined) {
  739. returnValue = true;
  740. }
  741. returnValue = !!returnValue;
  742. this.callFlash("ReturnUploadStart", [returnValue]);
  743. };
  744. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  745. file = this.unescapeFilePostParams(file);
  746. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  747. };
  748. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  749. file = this.unescapeFilePostParams(file);
  750. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  751. };
  752. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  753. file = this.unescapeFilePostParams(file);
  754. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  755. };
  756. SWFUpload.prototype.uploadComplete = function (file) {
  757. file = this.unescapeFilePostParams(file);
  758. this.queueEvent("upload_complete_handler", file);
  759. };
  760. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  761. internal debug console. You can override this event and have messages written where you want. */
  762. SWFUpload.prototype.debug = function (message) {
  763. this.queueEvent("debug_handler", message);
  764. };
  765. /* **********************************
  766. Debug Console
  767. The debug console is a self contained, in page location
  768. for debug message to be sent. The Debug Console adds
  769. itself to the body if necessary.
  770. The console is automatically scrolled as messages appear.
  771. If you are using your own debug handler or when you deploy to production and
  772. have debug disabled you can remove these functions to reduce the file size
  773. and complexity.
  774. ********************************** */
  775. // Private: debugMessage is the default debug_handler. If you want to print debug messages
  776. // call the debug() function. When overriding the function your own function should
  777. // check to see if the debug setting is true before outputting debug information.
  778. SWFUpload.prototype.debugMessage = function (message) {
  779. if (this.settings.debug) {
  780. var exceptionMessage, exceptionValues = [];
  781. // Check for an exception object and print it nicely
  782. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  783. for (var key in message) {
  784. if (message.hasOwnProperty(key)) {
  785. exceptionValues.push(key + ": " + message[key]);
  786. }
  787. }
  788. exceptionMessage = exceptionValues.join("\n") || "";
  789. exceptionValues = exceptionMessage.split("\n");
  790. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  791. SWFUpload.Console.writeLine(exceptionMessage);
  792. } else {
  793. SWFUpload.Console.writeLine(message);
  794. }
  795. }
  796. };
  797. SWFUpload.Console = {};
  798. SWFUpload.Console.writeLine = function (message) {
  799. var console, documentForm;
  800. try {
  801. console = document.getElementById("SWFUpload_Console");
  802. if (!console) {
  803. documentForm = document.createElement("form");
  804. document.getElementsByTagName("body")[0].appendChild(documentForm);
  805. console = document.createElement("textarea");
  806. console.id = "SWFUpload_Console";
  807. console.style.fontFamily = "monospace";
  808. console.setAttribute("wrap", "off");
  809. console.wrap = "off";
  810. console.style.overflow = "auto";
  811. console.style.width = "700px";
  812. console.style.height = "350px";
  813. console.style.margin = "5px";
  814. documentForm.appendChild(console);
  815. }
  816. console.value += message + "\n";
  817. console.scrollTop = console.scrollHeight - console.clientHeight;
  818. } catch (ex) {
  819. alert("Exception: " + ex.name + " Message: " + ex.message);
  820. }
  821. };
  822. /* end of swfupload.js */
  823. /* start of swfupload.queuejs */
  824. /*
  825. Queue Plug-in
  826. Features:
  827. *Adds a cancelQueue() method for cancelling the entire queue.
  828. *All queued files are uploaded when startUpload() is called.
  829. *If false is returned from uploadComplete then the queue upload is stopped.
  830. If false is not returned (strict comparison) then the queue upload is continued.
  831. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  832. Set the event handler with the queue_complete_handler setting.
  833. */
  834. var SWFUpload;
  835. if (typeof(SWFUpload) === "function") {
  836. SWFUpload.queue = {};
  837. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  838. return function () {
  839. if (typeof(oldInitSettings) === "function") {
  840. oldInitSettings.call(this);
  841. }
  842. this.queueSettings = {};
  843. this.queueSettings.queue_cancelled_flag = false;
  844. this.queueSettings.queue_upload_count = 0;
  845. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  846. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  847. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  848. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  849. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  850. };
  851. })(SWFUpload.prototype.initSettings);
  852. SWFUpload.prototype.startUpload = function (fileID) {
  853. this.queueSettings.queue_cancelled_flag = false;
  854. this.callFlash("StartUpload", [fileID]);
  855. };
  856. SWFUpload.prototype.cancelQueue = function () {
  857. this.queueSettings.queue_cancelled_flag = true;
  858. this.stopUpload();
  859. var stats = this.getStats();
  860. while (stats.files_queued > 0) {
  861. this.cancelUpload();
  862. stats = this.getStats();
  863. }
  864. };
  865. SWFUpload.queue.uploadStartHandler = function (file) {
  866. var returnValue;
  867. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  868. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  869. }
  870. // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
  871. returnValue = (returnValue === false) ? false : true;
  872. this.queueSettings.queue_cancelled_flag = !returnValue;
  873. return returnValue;
  874. };
  875. SWFUpload.queue.uploadCompleteHandler = function (file) {
  876. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  877. var continueUpload;
  878. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  879. this.queueSettings.queue_upload_count++;
  880. }
  881. if (typeof(user_upload_complete_handler) === "function") {
  882. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  883. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  884. // If the file was stopped and re-queued don't restart the upload
  885. continueUpload = false;
  886. } else {
  887. continueUpload = true;
  888. }
  889. if (continueUpload) {
  890. var stats = this.getStats();
  891. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  892. this.startUpload();
  893. } else if (this.queueSettings.queue_cancelled_flag === false) {
  894. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  895. this.queueSettings.queue_upload_count = 0;
  896. } else {
  897. this.queueSettings.queue_cancelled_flag = false;
  898. this.queueSettings.queue_upload_count = 0;
  899. }
  900. }
  901. };
  902. }
  903. /* end of swfupload.queuejs */
  904. /* start of fileprogress.js */
  905. /*
  906. A simple class for displaying file information and progress
  907. Note: This is a demonstration only and not part of SWFUpload.
  908. Note: Some have had problems adapting this class in IE7. It may not be suitable for your application.
  909. */
  910. // Constructor
  911. // file is a SWFUpload file object
  912. // targetID is the HTML element id attribute that the FileProgress HTML structure will be added to.
  913. // Instantiating a new FileProgress object with an existing file will reuse/update the existing DOM elements
  914. function FileProgress(file, targetID) {
  915. this.fileProgressID = file.id;
  916. this.opacity = 100;
  917. this.height = 0;
  918. this.fileProgressWrapper = document.getElementById(this.fileProgressID);
  919. if (!this.fileProgressWrapper) {
  920. this.fileProgressWrapper = document.createElement("div");
  921. this.fileProgressWrapper.className = "progressWrapper";
  922. this.fileProgressWrapper.id = this.fileProgressID;
  923. this.fileProgressElement = document.createElement("div");
  924. this.fileProgressElement.className = "progressContainer";
  925. var progressCancel = document.createElement("a");
  926. progressCancel.className = "progressCancel";
  927. progressCancel.href = "#";
  928. progressCancel.style.visibility = "hidden";
  929. progressCancel.appendChild(document.createTextNode(" "));
  930. var progressText = document.createElement("div");
  931. progressText.className = "progressName";
  932. progressText.appendChild(document.createTextNode(file.name));
  933. var progressBar = document.createElement("div");
  934. progressBar.className = "progressBarInProgress";
  935. var progressStatus = document.createElement("div");
  936. progressStatus.className = "progressBarStatus";
  937. progressStatus.innerHTML = "&nbsp;";
  938. this.fileProgressElement.appendChild(progressCancel);
  939. this.fileProgressElement.appendChild(progressText);
  940. this.fileProgressElement.appendChild(progressStatus);
  941. this.fileProgressElement.appendChild(progressBar);
  942. this.fileProgressWrapper.appendChild(this.fileProgressElement);
  943. document.getElementById(targetID).appendChild(this.fileProgressWrapper);
  944. } else {
  945. this.fileProgressElement = this.fileProgressWrapper.firstChild;
  946. this.reset();
  947. }
  948. this.height = this.fileProgressWrapper.offsetHeight;
  949. this.setTimer(null);
  950. }
  951. FileProgress.prototype.setTimer = function (timer) {
  952. this.fileProgressElement["FP_TIMER"] = timer;
  953. };
  954. FileProgress.prototype.getTimer = function (timer) {
  955. return this.fileProgressElement["FP_TIMER"] || null;
  956. };
  957. FileProgress.prototype.reset = function () {
  958. this.fileProgressElement.className = "progressContainer";
  959. this.fileProgressElement.childNodes[2].innerHTML = "&nbsp;";
  960. this.fileProgressElement.childNodes[2].className = "progressBarStatus";
  961. this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
  962. this.fileProgressElement.childNodes[3].style.width = "0%";
  963. this.appear();
  964. };
  965. FileProgress.prototype.setProgress = function (percentage) {
  966. this.fileProgressElement.className = "progressContainer green";
  967. this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
  968. this.fileProgressElement.childNodes[3].style.width = percentage + "%";
  969. this.appear();
  970. };
  971. FileProgress.prototype.setComplete = function () {
  972. this.fileProgressElement.className = "progressContainer blue";
  973. this.fileProgressElement.childNodes[3].className = "progressBarComplete";
  974. this.fileProgressElement.childNodes[3].style.width = "";
  975. var oSelf = this;
  976. this.setTimer(setTimeout(function () {
  977. oSelf.disappear();
  978. }, 10000));
  979. };
  980. FileProgress.prototype.setError = function () {
  981. this.fileProgressElement.className = "progressContainer red";
  982. this.fileProgressElement.childNodes[3].className = "progressBarError";
  983. this.fileProgressElement.childNodes[3].style.width = "";
  984. var oSelf = this;
  985. this.setTimer(setTimeout(function () {
  986. oSelf.disappear();
  987. }, 5000));
  988. };
  989. FileProgress.prototype.setCancelled = function () {
  990. this.fileProgressElement.className = "progressContainer";
  991. this.fileProgressElement.childNodes[3].className = "progressBarError";
  992. this.fileProgressElement.childNodes[3].style.width = "";
  993. var oSelf = this;
  994. this.setTimer(setTimeout(function () {
  995. oSelf.disappear();
  996. }, 2000));
  997. };
  998. FileProgress.prototype.setStatus = function (status) {
  999. this.fileProgressElement.childNodes[2].innerHTML = status;
  1000. };
  1001. // Show/Hide the cancel button
  1002. FileProgress.prototype.toggleCancel = function (show, swfUploadInstance) {
  1003. this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
  1004. if (swfUploadInstance) {
  1005. var fileID = this.fileProgressID;
  1006. this.fileProgressElement.childNodes[0].onclick = function () {
  1007. swfUploadInstance.cancelUpload(fileID);
  1008. return false;
  1009. };
  1010. }
  1011. };
  1012. FileProgress.prototype.appear = function () {
  1013. if (this.getTimer() !== null) {
  1014. clearTimeout(this.getTimer());
  1015. this.setTimer(null);
  1016. }
  1017. if (this.fileProgressWrapper.filters) {
  1018. try {
  1019. this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 100;
  1020. } catch (e) {
  1021. // If it is not set initially, the browser will throw an error. This will set it if it is not set yet.
  1022. this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
  1023. }
  1024. } else {
  1025. this.fileProgressWrapper.style.opacity = 1;
  1026. }
  1027. this.fileProgressWrapper.style.height = "";
  1028. this.height = this.fileProgressWrapper.offsetHeight;
  1029. this.opacity = 100;
  1030. this.fileProgressWrapper.style.display = "";
  1031. };
  1032. // Fades out and clips away the FileProgress box.
  1033. FileProgress.prototype.disappear = function () {
  1034. var reduceOpacityBy = 15;
  1035. var reduceHeightBy = 4;
  1036. var rate = 30; // 15 fps
  1037. if (this.opacity > 0) {
  1038. this.opacity -= reduceOpacityBy;
  1039. if (this.opacity < 0) {
  1040. this.opacity = 0;
  1041. }
  1042. if (this.fileProgressWrapper.filters) {
  1043. try {
  1044. this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = this.opacity;
  1045. } catch (e) {
  1046. // If it is not set initially, the browser will throw an error. This will set it if it is not set yet.
  1047. this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + this.opacity + ")";
  1048. }
  1049. } else {
  1050. this.fileProgressWrapper.style.opacity = this.opacity / 100;
  1051. }
  1052. }
  1053. if (this.height > 0) {
  1054. this.height -= reduceHeightBy;
  1055. if (this.height < 0) {
  1056. this.height = 0;
  1057. }
  1058. this.fileProgressWrapper.style.height = this.height + "px";
  1059. }
  1060. if (this.height > 0 || this.opacity > 0) {
  1061. var oSelf = this;
  1062. this.setTimer(setTimeout(function () {
  1063. oSelf.disappear();
  1064. }, rate));
  1065. } else {
  1066. this.fileProgressWrapper.style.display = "none";
  1067. this.setTimer(null);
  1068. }
  1069. };
  1070. /* end of fileprogress.js */
  1071. /* start of fileprogress.js */
  1072. /*
  1073. A simple class for displaying file information and progress
  1074. Note: This is a demonstration only and not part of SWFUpload.
  1075. Note: Some have had problems adapting this class in IE7. It may not be suitable for your application.
  1076. */
  1077. // Constructor
  1078. // file is a SWFUpload file object
  1079. // targetID is the HTML element id attribute that the FileProgress HTML structure will be added to.
  1080. // Instantiating a new FileProgress object with an existing file will reuse/update the existing DOM elements
  1081. function FileProgress(file, targetID) {
  1082. this.fileProgressID = file.id;
  1083. this.opacity = 100;
  1084. this.height = 0;
  1085. this.fileProgressWrapper = document.getElementById(this.fileProgressID);
  1086. if (!this.fileProgressWrapper) {
  1087. this.fileProgressWrapper = document.createElement("div");
  1088. this.fileProgressWrapper.className = "progressWrapper";
  1089. this.fileProgressWrapper.id = this.fileProgressID;
  1090. this.fileProgressElement = document.createElement("div");
  1091. this.fileProgressElement.className = "progressContainer";
  1092. var progressCancel = document.createElement("a");
  1093. progressCancel.className = "progressCancel";
  1094. progressCancel.href = "#";
  1095. progressCancel.style.visibility = "hidden";
  1096. progressCancel.appendChild(document.createTextNode(" "));
  1097. var progressText = document.createElement("div");
  1098. progressText.className = "progressName";
  1099. progressText.appendChild(document.createTextNode(file.name));
  1100. var progressBar = document.createElement("div");
  1101. progressBar.className = "progressBarInProgress";
  1102. var progressStatus = document.createElement("div");
  1103. progressStatus.className = "progressBarStatus";
  1104. progressStatus.innerHTML = "&nbsp;";
  1105. this.fileProgressElement.appendChild(progressCancel);
  1106. this.fileProgressElement.appendChild(progressText);
  1107. this.fileProgressElement.appendChild(progressStatus);
  1108. this.fileProgressElement.appendChild(progressBar);
  1109. this.fileProgressWrapper.appendChild(this.fileProgressElement);
  1110. document.getElementById(targetID).appendChild(this.fileProgressWrapper);
  1111. } else {
  1112. this.fileProgressElement = this.fileProgressWrapper.firstChild;
  1113. this.reset();
  1114. }
  1115. this.height = this.fileProgressWrapper.offsetHeight;
  1116. this.setTimer(null);
  1117. }
  1118. FileProgress.prototype.setTimer = function (timer) {
  1119. this.fileProgressElement["FP_TIMER"] = timer;
  1120. };
  1121. FileProgress.prototype.getTimer = function (timer) {
  1122. return this.fileProgressElement["FP_TIMER"] || null;
  1123. };
  1124. FileProgress.prototype.reset = function () {
  1125. this.fileProgressElement.className = "progressContainer";
  1126. this.fileProgressElement.childNodes[2].innerHTML = "&nbsp;";
  1127. this.fileProgressElement.childNodes[2].className = "progressBarStatus";
  1128. this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
  1129. this.fileProgressElement.childNodes[3].style.width = "0%";
  1130. this.appear();
  1131. };
  1132. FileProgress.prototype.setProgress = function (percentage) {
  1133. this.fileProgressElement.className = "progressContainer green";
  1134. this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
  1135. this.fileProgressElement.childNodes[3].style.width = percentage + "%";
  1136. this.appear();
  1137. };
  1138. FileProgress.prototype.setComplete = function () {
  1139. this.fileProgressElement.className = "progressContainer blue";
  1140. this.fileProgressElement.childNodes[3].className = "progressBarComplete";
  1141. this.fileProgressElement.childNodes[3].style.width = "";
  1142. var oSelf = this;
  1143. this.setTimer(setTimeout(function () {
  1144. oSelf.disappear();
  1145. }, 10000));
  1146. };
  1147. FileProgress.prototype.setError = function () {
  1148. this.fileProgressElement.className = "progressContainer red";
  1149. this.fileProgressElement.childNodes[3].className = "progressBarError";
  1150. this.fileProgressElement.childNodes[3].style.width = "";
  1151. var oSelf = this;
  1152. this.setTimer(setTimeout(function () {
  1153. oSelf.disappear();
  1154. }, 5000));
  1155. };
  1156. FileProgress.prototype.setCancelled = function () {
  1157. this.fileProgressElement.className = "progressContainer";
  1158. this.fileProgressElement.childNodes[3].className = "progressBarError";
  1159. this.fileProgressElement.childNodes[3].style.width = "";
  1160. var oSelf = this;
  1161. this.setTimer(setTimeout(function () {
  1162. oSelf.disappear();
  1163. }, 2000));
  1164. };
  1165. FileProgress.prototype.setStatus = function (status) {
  1166. this.fileProgressElement.childNodes[2].innerHTML = status;
  1167. };
  1168. // Show/Hide the cancel button
  1169. FileProgress.prototype.toggleCancel = function (show, swfUploadInstance) {
  1170. this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
  1171. if (swfUploadInstance) {
  1172. var fileID = this.fileProgressID;
  1173. this.fileProgressElement.childNodes[0].onclick = function () {
  1174. swfUploadInstance.cancelUpload(fileID);
  1175. return false;
  1176. };
  1177. }
  1178. };
  1179. FileProgress.prototype.appear = function () {
  1180. if (this.getTimer() !== null) {
  1181. clearTimeout(this.getTimer());
  1182. this.setTimer(null);
  1183. }
  1184. if (this.fileProgressWrapper.filters) {
  1185. try {
  1186. this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 100;
  1187. } catch (e) {
  1188. // If it is not set initially, the browser will throw an error. This will set it if it is not set yet.
  1189. this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
  1190. }
  1191. } else {
  1192. this.fileProgressWrapper.style.opacity = 1;
  1193. }
  1194. this.fileProgressWrapper.style.height = "";
  1195. this.height = this.fileProgressWrapper.offsetHeight;
  1196. this.opacity = 100;
  1197. this.fileProgressWrapper.style.display = "";
  1198. };
  1199. // Fades out and clips away the FileProgress box.
  1200. FileProgress.prototype.disappear = function () {
  1201. var reduceOpacityBy = 15;
  1202. var reduceHeightBy = 4;
  1203. var rate = 30; // 15 fps
  1204. if (this.opacity > 0) {
  1205. this.opacity -= reduceOpacityBy;
  1206. if (this.opacity < 0) {
  1207. this.opacity = 0;
  1208. }
  1209. if (this.fileProgressWrapper.filters) {
  1210. try {
  1211. this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = this.opacity;
  1212. } catch (e) {
  1213. // If it is not set initially, the browser will throw an error. This will set it if it is not set yet.
  1214. this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + this.opacity + ")";
  1215. }
  1216. } else {
  1217. this.fileProgressWrapper.style.opacity = this.opacity / 100;
  1218. }
  1219. }
  1220. if (this.height > 0) {
  1221. this.height -= reduceHeightBy;
  1222. if (this.height < 0) {
  1223. this.height = 0;
  1224. }
  1225. this.fileProgressWrapper.style.height = this.height + "px";
  1226. }
  1227. if (this.height > 0 || this.opacity > 0) {
  1228. var oSelf = this;
  1229. this.setTimer(setTimeout(function () {
  1230. oSelf.disappear();
  1231. }, rate));
  1232. } else {
  1233. this.fileProgressWrapper.style.display = "none";
  1234. this.setTimer(null);
  1235. }
  1236. };
  1237. /* end of fileprogress.js */
  1238. /* start of handlers.js */
  1239. /* Demo Note: This demo uses a FileProgress class that handles the UI for displaying the file name and percent complete.
  1240. The FileProgress class is not part of SWFUpload.
  1241. */
  1242. /* **********************
  1243. Event Handlers
  1244. These are my custom event handlers to make my
  1245. web application behave the way I went when SWFUpload
  1246. completes different tasks. These aren't part of the SWFUpload
  1247. package. They are part of my application. Without these none
  1248. of the actions SWFUpload makes will show up in my application.
  1249. ********************** */
  1250. function fileQueued(file) {
  1251. try {
  1252. var progress = new FileProgress(file, this.customSettings.progressTarget);
  1253. progress.setStatus("Pending...");
  1254. progress.toggleCancel(true, this);
  1255. } catch (ex) {
  1256. this.debug(ex);
  1257. }
  1258. }
  1259. function fileQueueError(file, errorCode, message) {
  1260. try {
  1261. if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
  1262. alert("You have attempted to queue too many files.\n" + (message === 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file.")));
  1263. return;
  1264. }
  1265. var progress = new FileProgress(file, this.customSettings.progressTarget);
  1266. progress.setError();
  1267. progress.toggleCancel(false);
  1268. switch (errorCode) {
  1269. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  1270. progress.setStatus("File is too big.");
  1271. this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  1272. break;
  1273. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  1274. progress.setStatus("Cannot upload Zero Byte files.");
  1275. this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  1276. break;
  1277. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  1278. progress.setStatus("Invalid File Type.");
  1279. this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  1280. break;
  1281. default:
  1282. if (file !== null) {
  1283. progress.setStatus("Unhandled Error");
  1284. }
  1285. this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  1286. break;
  1287. }
  1288. } catch (ex) {
  1289. this.debug(ex);
  1290. }
  1291. }
  1292. function fileDialogComplete(numFilesSelected, numFilesQueued) {
  1293. try {
  1294. if (numFilesSelected > 0) {
  1295. document.getElementById(this.customSettings.cancelButtonId).disabled = false;
  1296. }
  1297. /* I want auto start the upload and I can do that here */
  1298. this.startUpload();
  1299. } catch (ex) {
  1300. this.debug(ex);
  1301. }
  1302. }
  1303. function pickatt_uploadStart(file){
  1304. // $('.swfloadstatus').show();
  1305. }
  1306. function uploadStart(file) {
  1307. try {
  1308. /* I don't want to do any file validation or anything, I'll just update the UI and
  1309. return true to indicate that the upload should start.
  1310. It's important to update the UI here because in Linux no uploadProgress events are called. The best
  1311. we can do is say we are uploading.
  1312. */
  1313. $('.swfloadstatus').show();
  1314. $('.swfloadstatus').show();
  1315. $('#fsUploadProgress').show();
  1316. var progress = new FileProgress(file, this.customSettings.progressTarget);
  1317. progress.setStatus("Uploading...");
  1318. progress.toggleCancel(true, this);
  1319. }
  1320. catch (ex) {}
  1321. return true;
  1322. }
  1323. function uploadProgress(file, bytesLoaded, bytesTotal) {
  1324. try {
  1325. var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
  1326. var progress = new FileProgress(file, this.customSettings.progressTarget);
  1327. progress.setProgress(percent);
  1328. progress.setStatus("Uploading...");
  1329. } catch (ex) {
  1330. this.debug(ex);
  1331. }
  1332. }
  1333. function pickatt_uploadSuccess(file, serverData) {
  1334. try {
  1335. var progress = new FileProgress(file, this.customSettings.progressTarget);
  1336. progress.setComplete();
  1337. progress.setStatus("Complete.");
  1338. progress.toggleCancel(false);
  1339. // $('.swfloadstatus').hide();
  1340. //alert( $('.progressWrapper:last').find('.progressName').html() );
  1341. // uploadTips($('.progressWrapper:last'), $('.progressWrapper:last').find('.progressName').html() );
  1342. } catch (ex) {
  1343. this.debug(ex);
  1344. }
  1345. }
  1346. function uploadSuccess(file, serverData) {
  1347. try {
  1348. var progress = new FileProgress(file, this.customSettings.progressTarget);
  1349. progress.setComplete();
  1350. progress.setStatus("Complete.");
  1351. progress.toggleCancel(false);
  1352. } catch (ex) {
  1353. this.debug(ex);
  1354. }
  1355. }
  1356. function uploadError(file, errorCode, message) {
  1357. try {
  1358. var progress = new FileProgress(file, this.customSettings.progressTarget);
  1359. progress.setError();
  1360. progress.toggleCancel(false);
  1361. switch (errorCode) {
  1362. case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
  1363. progress.setStatus("Upload Error: " + message);
  1364. this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message);
  1365. break;
  1366. case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
  1367. progress.setStatus("Upload Failed.");
  1368. this.debug("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  1369. break;
  1370. case SWFUpload.UPLOAD_ERROR.IO_ERROR:
  1371. progress.setStatus("Server (IO) Error");
  1372. this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + message);
  1373. break;
  1374. case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
  1375. progress.setStatus("Security Error");
  1376. this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + message);
  1377. break;
  1378. case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
  1379. progress.setStatus("Upload limit exceeded.");
  1380. this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  1381. break;
  1382. case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
  1383. progress.setStatus("Failed Validation. Upload skipped.");
  1384. this.debug("Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  1385. break;
  1386. case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
  1387. // If there aren't any files left (they were all cancelled) disable the cancel button
  1388. if (this.getStats().files_queued === 0) {
  1389. document.getElementById(this.customSettings.cancelButtonId).disabled = true;
  1390. }
  1391. progress.setStatus("Cancelled");
  1392. progress.setCancelled();
  1393. break;
  1394. case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
  1395. progress.setStatus("Stopped");
  1396. break;
  1397. default:
  1398. progress.setStatus("Unhandled Error: " + errorCode);
  1399. this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
  1400. break;
  1401. }
  1402. } catch (ex) {
  1403. this.debug(ex);
  1404. }
  1405. }
  1406. function uploadComplete(file) {
  1407. if (this.getStats().files_queued === 0) {
  1408. document.getElementById(this.customSettings.cancelButtonId).disabled = true;
  1409. $('.swfloadstatus').hide();
  1410. $('.swfloadstatus').hide();
  1411. $('#fsUploadProgress').hide();
  1412. member_photo_reload();
  1413. }
  1414. }
  1415. // This event comes from the Queue Plugin
  1416. function queueComplete(numFilesUploaded) {
  1417. var status = document.getElementById("divStatus");
  1418. status.innerHTML = numFilesUploaded + " file" + (numFilesUploaded === 1 ? "" : "s") + " uploaded.";
  1419. }
  1420. /* end of hadlers.js */