Advertisement
Kimarite

SWFUpload

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