PageRenderTime 55ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/src/main/webapp/kindeditor/plugins/multiimage/multiimage.js

https://github.com/fairyhawk/imageUpload
JavaScript | 1384 lines | 969 code | 194 blank | 221 comment | 106 complexity | 57e5854cbf4ec22cf285bbdab7fd1f02 MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2011 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @site http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. *******************************************************************************/
  9. (function(K) {
  10. function KSWFUpload(options) {
  11. this.init(options);
  12. }
  13. K.extend(KSWFUpload, {
  14. init : function(options) {
  15. var self = this;
  16. options.afterError = options.afterError || function(str) {
  17. alert(str);
  18. };
  19. self.options = options;
  20. self.progressbars = {};
  21. // template
  22. self.div = K(options.container).html([
  23. '<div class="ke-swfupload">',
  24. '<div class="ke-swfupload-top">',
  25. '<div class="ke-inline-block ke-swfupload-button">',
  26. '<input type="button" value="Browse" />',
  27. '</div>',
  28. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  29. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  30. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  31. '</span>',
  32. '</div>',
  33. '<div class="ke-swfupload-body"></div>',
  34. '</div>'
  35. ].join(''));
  36. self.bodyDiv = K('.ke-swfupload-body', self.div);
  37. function showError(itemDiv, msg) {
  38. K('.ke-status > div', itemDiv).hide();
  39. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  40. }
  41. var settings = {
  42. debug : false,
  43. upload_url : options.uploadUrl,
  44. flash_url : options.flashUrl,
  45. file_post_name : options.filePostName,
  46. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  47. button_image_url: options.buttonImageUrl,
  48. button_width: options.buttonWidth,
  49. button_height: options.buttonHeight,
  50. button_cursor : SWFUpload.CURSOR.HAND,
  51. file_types : options.fileTypes,
  52. file_types_description : options.fileTypesDesc,
  53. file_upload_limit : options.fileUploadLimit,
  54. file_size_limit : options.fileSizeLimit,
  55. post_params : options.postParams,
  56. file_queued_handler : function(file) {
  57. file.url = self.options.fileIconUrl;
  58. self.appendFile(file);
  59. },
  60. file_queue_error_handler : function(file, errorCode, message) {
  61. var errorName = '';
  62. switch (errorCode) {
  63. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  64. errorName = options.queueLimitExceeded;
  65. break;
  66. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  67. errorName = options.fileExceedsSizeLimit;
  68. break;
  69. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  70. errorName = options.zeroByteFile;
  71. break;
  72. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  73. errorName = options.invalidFiletype;
  74. break;
  75. default:
  76. errorName = options.unknownError;
  77. break;
  78. }
  79. K.DEBUG && alert(errorName);
  80. },
  81. upload_start_handler : function(file) {
  82. var self = this;
  83. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  84. K('.ke-status > div', itemDiv).hide();
  85. K('.ke-progressbar', itemDiv).show();
  86. },
  87. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  88. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  89. var progressbar = self.progressbars[file.id];
  90. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  91. progressbar.percent.html(percent + '%');
  92. },
  93. upload_error_handler : function(file, errorCode, message) {
  94. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  95. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  96. showError(itemDiv, self.options.errorMessage);
  97. }
  98. },
  99. upload_success_handler : function(file, serverData) {
  100. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  101. var data = {};
  102. try {
  103. data = K.json(serverData);
  104. } catch (e) {
  105. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  106. }
  107. if (data.error !== 0) {
  108. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  109. return;
  110. }
  111. file.url = data.url;
  112. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  113. K('.ke-status > div', itemDiv).hide();
  114. }
  115. };
  116. self.swfu = new SWFUpload(settings);
  117. K('.ke-swfupload-startupload input', self.div).click(function() {
  118. self.swfu.startUpload();
  119. });
  120. },
  121. getUrlList : function() {
  122. var list = [];
  123. K('.ke-img', self.bodyDiv).each(function() {
  124. var img = K(this);
  125. var status = img.attr('data-status');
  126. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  127. list.push(img.data('data'));
  128. }
  129. });
  130. return list;
  131. },
  132. removeFile : function(fileId) {
  133. var self = this;
  134. self.swfu.cancelUpload(fileId);
  135. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  136. K('.ke-photo', itemDiv).unbind();
  137. K('.ke-delete', itemDiv).unbind();
  138. itemDiv.remove();
  139. },
  140. removeFiles : function() {
  141. var self = this;
  142. K('.ke-item', self.bodyDiv).each(function() {
  143. self.removeFile(K(this).attr('data-id'));
  144. });
  145. },
  146. appendFile : function(file) {
  147. var self = this;
  148. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  149. self.bodyDiv.append(itemDiv);
  150. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  151. .mouseover(function(e) {
  152. K(this).addClass('ke-on');
  153. })
  154. .mouseout(function(e) {
  155. K(this).removeClass('ke-on');
  156. });
  157. itemDiv.append(photoDiv);
  158. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  159. photoDiv.append(img);
  160. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  161. self.removeFile(file.id);
  162. });
  163. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  164. // progressbar
  165. K(['<div class="ke-progressbar">',
  166. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  167. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  168. // message
  169. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  170. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  171. self.progressbars[file.id] = {
  172. bar : K('.ke-progressbar-bar-inner', photoDiv),
  173. percent : K('.ke-progressbar-percent', photoDiv)
  174. };
  175. },
  176. remove : function() {
  177. this.removeFiles();
  178. this.swfu.destroy();
  179. this.div.html('');
  180. }
  181. });
  182. K.swfupload = function(element, options) {
  183. return new KSWFUpload(element, options);
  184. };
  185. })(KindEditor);
  186. KindEditor.plugin('multiimage', function(K) {
  187. var self = this, name = 'multiimage',
  188. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  189. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  190. imgPath = self.pluginsPath + 'multiimage/images/',
  191. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  192. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  193. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  194. filePostName = K.undef(self.filePostName, 'imgFile'),
  195. lang = self.lang(name + '.');
  196. self.plugin.multiImageDialog = function(options) {
  197. var clickFn = options.clickFn,
  198. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  199. var html = [
  200. '<div style="padding:20px;">',
  201. '<div class="swfupload">',
  202. '</div>',
  203. '</div>'
  204. ].join('');
  205. var dialog = self.createDialog({
  206. name : name,
  207. width : 650,
  208. height : 510,
  209. title : self.lang(name),
  210. body : html,
  211. previewBtn : {
  212. name : lang.insertAll,
  213. click : function(e) {
  214. clickFn.call(self, swfupload.getUrlList());
  215. }
  216. },
  217. yesBtn : {
  218. name : lang.clearAll,
  219. click : function(e) {
  220. swfupload.removeFiles();
  221. }
  222. },
  223. beforeRemove : function() {
  224. // IE9 bugfix: https://github.com/kindsoft/kindeditor/issues/72
  225. if (!K.IE || K.V <= 8) {
  226. swfupload.remove();
  227. }
  228. }
  229. }),
  230. div = dialog.div;
  231. var swfupload = K.swfupload({
  232. container : K('.swfupload', div),
  233. buttonImageUrl : imgPath + (self.langType == 'zh_CN' ? 'select-files-zh_CN.png' : 'select-files-en.png'),
  234. buttonWidth : self.langType == 'zh_CN' ? 72 : 88,
  235. buttonHeight : 23,
  236. fileIconUrl : imgPath + 'image.png',
  237. uploadDesc : uploadDesc,
  238. startButtonValue : lang.startUpload,
  239. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  240. flashUrl : imgPath + 'swfupload.swf',
  241. filePostName : filePostName,
  242. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  243. fileTypesDesc : 'Image Files',
  244. fileUploadLimit : imageUploadLimit,
  245. fileSizeLimit : imageSizeLimit,
  246. postParams : K.undef(self.extraFileUploadParams, {}),
  247. queueLimitExceeded : lang.queueLimitExceeded,
  248. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  249. zeroByteFile : lang.zeroByteFile,
  250. invalidFiletype : lang.invalidFiletype,
  251. unknownError : lang.unknownError,
  252. pendingMessage : lang.pending,
  253. errorMessage : lang.uploadError,
  254. afterError : function(html) {
  255. self.errorDialog(html);
  256. }
  257. });
  258. return dialog;
  259. };
  260. self.clickToolbar(name, function() {
  261. self.plugin.multiImageDialog({
  262. clickFn : function (urlList) {
  263. if (urlList.length === 0) {
  264. return;
  265. }
  266. K.each(urlList, function(i, data) {
  267. if (self.afterUpload) {
  268. self.afterUpload.call(self, data.url, data, 'multiimage');
  269. }
  270. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  271. });
  272. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  273. setTimeout(function() {
  274. self.hideDialog().focus();
  275. }, 0);
  276. }
  277. });
  278. });
  279. });
  280. /**
  281. * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
  282. *
  283. * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
  284. *
  285. * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz閚 and Mammon Media and is released under the MIT License:
  286. * http://www.opensource.org/licenses/mit-license.php
  287. *
  288. * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
  289. * http://www.opensource.org/licenses/mit-license.php
  290. *
  291. */
  292. /* ******************* */
  293. /* Constructor & Init */
  294. /* ******************* */
  295. (function() {
  296. window.SWFUpload = function (settings) {
  297. this.initSWFUpload(settings);
  298. };
  299. SWFUpload.prototype.initSWFUpload = function (settings) {
  300. try {
  301. this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
  302. this.settings = settings;
  303. this.eventQueue = [];
  304. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  305. this.movieElement = null;
  306. // Setup global control tracking
  307. SWFUpload.instances[this.movieName] = this;
  308. // Load the settings. Load the Flash movie.
  309. this.initSettings();
  310. this.loadFlash();
  311. this.displayDebugInfo();
  312. } catch (ex) {
  313. delete SWFUpload.instances[this.movieName];
  314. throw ex;
  315. }
  316. };
  317. /* *************** */
  318. /* Static Members */
  319. /* *************** */
  320. SWFUpload.instances = {};
  321. SWFUpload.movieCount = 0;
  322. SWFUpload.version = "2.2.0 2009-03-25";
  323. SWFUpload.QUEUE_ERROR = {
  324. QUEUE_LIMIT_EXCEEDED : -100,
  325. FILE_EXCEEDS_SIZE_LIMIT : -110,
  326. ZERO_BYTE_FILE : -120,
  327. INVALID_FILETYPE : -130
  328. };
  329. SWFUpload.UPLOAD_ERROR = {
  330. HTTP_ERROR : -200,
  331. MISSING_UPLOAD_URL : -210,
  332. IO_ERROR : -220,
  333. SECURITY_ERROR : -230,
  334. UPLOAD_LIMIT_EXCEEDED : -240,
  335. UPLOAD_FAILED : -250,
  336. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  337. FILE_VALIDATION_FAILED : -270,
  338. FILE_CANCELLED : -280,
  339. UPLOAD_STOPPED : -290
  340. };
  341. SWFUpload.FILE_STATUS = {
  342. QUEUED : -1,
  343. IN_PROGRESS : -2,
  344. ERROR : -3,
  345. COMPLETE : -4,
  346. CANCELLED : -5
  347. };
  348. SWFUpload.BUTTON_ACTION = {
  349. SELECT_FILE : -100,
  350. SELECT_FILES : -110,
  351. START_UPLOAD : -120
  352. };
  353. SWFUpload.CURSOR = {
  354. ARROW : -1,
  355. HAND : -2
  356. };
  357. SWFUpload.WINDOW_MODE = {
  358. WINDOW : "window",
  359. TRANSPARENT : "transparent",
  360. OPAQUE : "opaque"
  361. };
  362. // Private: takes a URL, determines if it is relative and converts to an absolute URL
  363. // using the current site. Only processes the URL if it can, otherwise returns the URL untouched
  364. SWFUpload.completeURL = function(url) {
  365. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  366. return url;
  367. }
  368. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  369. var indexSlash = window.location.pathname.lastIndexOf("/");
  370. if (indexSlash <= 0) {
  371. path = "/";
  372. } else {
  373. path = window.location.pathname.substr(0, indexSlash) + "/";
  374. }
  375. return /*currentURL +*/ path + url;
  376. };
  377. /* ******************** */
  378. /* Instance Members */
  379. /* ******************** */
  380. // Private: initSettings ensures that all the
  381. // settings are set, getting a default value if one was not assigned.
  382. SWFUpload.prototype.initSettings = function () {
  383. this.ensureDefault = function (settingName, defaultValue) {
  384. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  385. };
  386. // Upload backend settings
  387. this.ensureDefault("upload_url", "");
  388. this.ensureDefault("preserve_relative_urls", false);
  389. this.ensureDefault("file_post_name", "Filedata");
  390. this.ensureDefault("post_params", {});
  391. this.ensureDefault("use_query_string", false);
  392. this.ensureDefault("requeue_on_error", false);
  393. this.ensureDefault("http_success", []);
  394. this.ensureDefault("assume_success_timeout", 0);
  395. // File Settings
  396. this.ensureDefault("file_types", "*.*");
  397. this.ensureDefault("file_types_description", "All Files");
  398. this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
  399. this.ensureDefault("file_upload_limit", 0);
  400. this.ensureDefault("file_queue_limit", 0);
  401. // Flash Settings
  402. this.ensureDefault("flash_url", "swfupload.swf");
  403. this.ensureDefault("prevent_swf_caching", true);
  404. // Button Settings
  405. this.ensureDefault("button_image_url", "");
  406. this.ensureDefault("button_width", 1);
  407. this.ensureDefault("button_height", 1);
  408. this.ensureDefault("button_text", "");
  409. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  410. this.ensureDefault("button_text_top_padding", 0);
  411. this.ensureDefault("button_text_left_padding", 0);
  412. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  413. this.ensureDefault("button_disabled", false);
  414. this.ensureDefault("button_placeholder_id", "");
  415. this.ensureDefault("button_placeholder", null);
  416. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  417. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  418. // Debug Settings
  419. this.ensureDefault("debug", false);
  420. this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
  421. // Event Handlers
  422. this.settings.return_upload_start_handler = this.returnUploadStart;
  423. this.ensureDefault("swfupload_loaded_handler", null);
  424. this.ensureDefault("file_dialog_start_handler", null);
  425. this.ensureDefault("file_queued_handler", null);
  426. this.ensureDefault("file_queue_error_handler", null);
  427. this.ensureDefault("file_dialog_complete_handler", null);
  428. this.ensureDefault("upload_start_handler", null);
  429. this.ensureDefault("upload_progress_handler", null);
  430. this.ensureDefault("upload_error_handler", null);
  431. this.ensureDefault("upload_success_handler", null);
  432. this.ensureDefault("upload_complete_handler", null);
  433. this.ensureDefault("debug_handler", this.debugMessage);
  434. this.ensureDefault("custom_settings", {});
  435. // Other settings
  436. this.customSettings = this.settings.custom_settings;
  437. // Update the flash url if needed
  438. if (!!this.settings.prevent_swf_caching) {
  439. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  440. }
  441. if (!this.settings.preserve_relative_urls) {
  442. //this.settings.flash_url = SWFUpload.completeURL(this.settings.flash_url); // Don't need to do this one since flash doesn't look at it
  443. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  444. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  445. }
  446. delete this.ensureDefault;
  447. };
  448. // Private: loadFlash replaces the button_placeholder element with the flash movie.
  449. SWFUpload.prototype.loadFlash = function () {
  450. var targetElement, tempParent;
  451. // Make sure an element with the ID we are going to use doesn't already exist
  452. if (document.getElementById(this.movieName) !== null) {
  453. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  454. }
  455. // Get the element where we will be placing the flash movie
  456. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  457. if (targetElement == undefined) {
  458. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  459. }
  460. // Append the container and load the flash
  461. tempParent = document.createElement("div");
  462. tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
  463. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  464. // Fix IE Flash/Form bug
  465. if (window[this.movieName] == undefined) {
  466. window[this.movieName] = this.getMovieElement();
  467. }
  468. };
  469. // Private: getFlashHTML generates the object tag needed to embed the flash in to the document
  470. SWFUpload.prototype.getFlashHTML = function () {
  471. // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
  472. // Fix bug for IE9
  473. // http://www.kindsoft.net/view.php?bbsid=7&postid=5825&pagenum=1
  474. var classid = '';
  475. if (KindEditor.IE && KindEditor.V > 8) {
  476. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  477. }
  478. return ['<object id="', this.movieName, '"' + classid + ' type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">',
  479. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  480. '<param name="movie" value="', this.settings.flash_url, '" />',
  481. '<param name="quality" value="high" />',
  482. '<param name="menu" value="false" />',
  483. '<param name="allowScriptAccess" value="always" />',
  484. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  485. '</object>'].join("");
  486. };
  487. // Private: getFlashVars builds the parameter string that will be passed
  488. // to flash in the flashvars param.
  489. SWFUpload.prototype.getFlashVars = function () {
  490. // Build a string from the post param object
  491. var paramString = this.buildParamString();
  492. var httpSuccessString = this.settings.http_success.join(",");
  493. // Build the parameter string
  494. return ["movieName=", encodeURIComponent(this.movieName),
  495. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  496. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  497. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  498. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  499. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  500. "&amp;params=", encodeURIComponent(paramString),
  501. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  502. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  503. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  504. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  505. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  506. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  507. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  508. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  509. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  510. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  511. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  512. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  513. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  514. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  515. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  516. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  517. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  518. ].join("");
  519. };
  520. // Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
  521. // The element is cached after the first lookup
  522. SWFUpload.prototype.getMovieElement = function () {
  523. if (this.movieElement == undefined) {
  524. this.movieElement = document.getElementById(this.movieName);
  525. }
  526. if (this.movieElement === null) {
  527. throw "Could not find Flash element";
  528. }
  529. return this.movieElement;
  530. };
  531. // Private: buildParamString takes the name/value pairs in the post_params setting object
  532. // and joins them up in to a string formatted "name=value&amp;name=value"
  533. SWFUpload.prototype.buildParamString = function () {
  534. var postParams = this.settings.post_params;
  535. var paramStringPairs = [];
  536. if (typeof(postParams) === "object") {
  537. for (var name in postParams) {
  538. if (postParams.hasOwnProperty(name)) {
  539. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  540. }
  541. }
  542. }
  543. return paramStringPairs.join("&amp;");
  544. };
  545. // Public: Used to remove a SWFUpload instance from the page. This method strives to remove
  546. // all references to the SWF, and other objects so memory is properly freed.
  547. // Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
  548. // Credits: Major improvements provided by steffen
  549. SWFUpload.prototype.destroy = function () {
  550. try {
  551. // Make sure Flash is done before we try to remove it
  552. this.cancelUpload(null, false);
  553. // Remove the SWFUpload DOM nodes
  554. var movieElement = null;
  555. movieElement = this.getMovieElement();
  556. if (movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  557. // Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround)
  558. for (var i in movieElement) {
  559. try {
  560. if (typeof(movieElement[i]) === "function") {
  561. movieElement[i] = null;
  562. }
  563. } catch (ex1) {}
  564. }
  565. // Remove the Movie Element from the page
  566. try {
  567. movieElement.parentNode.removeChild(movieElement);
  568. } catch (ex) {}
  569. }
  570. // Remove IE form fix reference
  571. window[this.movieName] = null;
  572. // Destroy other references
  573. SWFUpload.instances[this.movieName] = null;
  574. delete SWFUpload.instances[this.movieName];
  575. this.movieElement = null;
  576. this.settings = null;
  577. this.customSettings = null;
  578. this.eventQueue = null;
  579. this.movieName = null;
  580. return true;
  581. } catch (ex2) {
  582. return false;
  583. }
  584. };
  585. // Public: displayDebugInfo prints out settings and configuration
  586. // information about this SWFUpload instance.
  587. // This function (and any references to it) can be deleted when placing
  588. // SWFUpload in production.
  589. SWFUpload.prototype.displayDebugInfo = function () {
  590. this.debug(
  591. [
  592. "---SWFUpload Instance Info---\n",
  593. "Version: ", SWFUpload.version, "\n",
  594. "Movie Name: ", this.movieName, "\n",
  595. "Settings:\n",
  596. "\t", "upload_url: ", this.settings.upload_url, "\n",
  597. "\t", "flash_url: ", this.settings.flash_url, "\n",
  598. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  599. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  600. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  601. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  602. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  603. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  604. "\t", "file_types: ", this.settings.file_types, "\n",
  605. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  606. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  607. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  608. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  609. "\t", "debug: ", this.settings.debug.toString(), "\n",
  610. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  611. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  612. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  613. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  614. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  615. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  616. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  617. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  618. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  619. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  620. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  621. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  622. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  623. "Event Handlers:\n",
  624. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  625. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  626. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  627. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  628. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  629. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  630. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  631. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  632. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  633. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  634. ].join("")
  635. );
  636. };
  637. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  638. the maintain v2 API compatibility
  639. */
  640. // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
  641. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  642. if (value == undefined) {
  643. return (this.settings[name] = default_value);
  644. } else {
  645. return (this.settings[name] = value);
  646. }
  647. };
  648. // Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
  649. SWFUpload.prototype.getSetting = function (name) {
  650. if (this.settings[name] != undefined) {
  651. return this.settings[name];
  652. }
  653. return "";
  654. };
  655. // Private: callFlash handles function calls made to the Flash element.
  656. // Calls are made with a setTimeout for some functions to work around
  657. // bugs in the ExternalInterface library.
  658. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  659. argumentArray = argumentArray || [];
  660. var movieElement = this.getMovieElement();
  661. var returnValue, returnString;
  662. // Flash's method if calling ExternalInterface methods (code adapted from MooTools).
  663. try {
  664. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  665. returnValue = eval(returnString);
  666. } catch (ex) {
  667. throw "Call to " + functionName + " failed";
  668. }
  669. // Unescape file post param values
  670. if (returnValue != undefined && typeof returnValue.post === "object") {
  671. returnValue = this.unescapeFilePostParams(returnValue);
  672. }
  673. return returnValue;
  674. };
  675. /* *****************************
  676. -- Flash control methods --
  677. Your UI should use these
  678. to operate SWFUpload
  679. ***************************** */
  680. // WARNING: this function does not work in Flash Player 10
  681. // Public: selectFile causes a File Selection Dialog window to appear. This
  682. // dialog only allows 1 file to be selected.
  683. SWFUpload.prototype.selectFile = function () {
  684. this.callFlash("SelectFile");
  685. };
  686. // WARNING: this function does not work in Flash Player 10
  687. // Public: selectFiles causes a File Selection Dialog window to appear/ This
  688. // dialog allows the user to select any number of files
  689. // Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
  690. // If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
  691. // for this bug.
  692. SWFUpload.prototype.selectFiles = function () {
  693. this.callFlash("SelectFiles");
  694. };
  695. // Public: startUpload starts uploading the first file in the queue unless
  696. // the optional parameter 'fileID' specifies the ID
  697. SWFUpload.prototype.startUpload = function (fileID) {
  698. this.callFlash("StartUpload", [fileID]);
  699. };
  700. // Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
  701. // If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
  702. // If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
  703. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  704. if (triggerErrorEvent !== false) {
  705. triggerErrorEvent = true;
  706. }
  707. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  708. };
  709. // Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
  710. // If nothing is currently uploading then nothing happens.
  711. SWFUpload.prototype.stopUpload = function () {
  712. this.callFlash("StopUpload");
  713. };
  714. /* ************************
  715. * Settings methods
  716. * These methods change the SWFUpload settings.
  717. * SWFUpload settings should not be changed directly on the settings object
  718. * since many of the settings need to be passed to Flash in order to take
  719. * effect.
  720. * *********************** */
  721. // Public: getStats gets the file statistics object.
  722. SWFUpload.prototype.getStats = function () {
  723. return this.callFlash("GetStats");
  724. };
  725. // Public: setStats changes the SWFUpload statistics. You shouldn't need to
  726. // change the statistics but you can. Changing the statistics does not
  727. // affect SWFUpload accept for the successful_uploads count which is used
  728. // by the upload_limit setting to determine how many files the user may upload.
  729. SWFUpload.prototype.setStats = function (statsObject) {
  730. this.callFlash("SetStats", [statsObject]);
  731. };
  732. // Public: getFile retrieves a File object by ID or Index. If the file is
  733. // not found then 'null' is returned.
  734. SWFUpload.prototype.getFile = function (fileID) {
  735. if (typeof(fileID) === "number") {
  736. return this.callFlash("GetFileByIndex", [fileID]);
  737. } else {
  738. return this.callFlash("GetFile", [fileID]);
  739. }
  740. };
  741. // Public: addFileParam sets a name/value pair that will be posted with the
  742. // file specified by the Files ID. If the name already exists then the
  743. // exiting value will be overwritten.
  744. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  745. return this.callFlash("AddFileParam", [fileID, name, value]);
  746. };
  747. // Public: removeFileParam removes a previously set (by addFileParam) name/value
  748. // pair from the specified file.
  749. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  750. this.callFlash("RemoveFileParam", [fileID, name]);
  751. };
  752. // Public: setUploadUrl changes the upload_url setting.
  753. SWFUpload.prototype.setUploadURL = function (url) {
  754. this.settings.upload_url = url.toString();
  755. this.callFlash("SetUploadURL", [url]);
  756. };
  757. // Public: setPostParams changes the post_params setting
  758. SWFUpload.prototype.setPostParams = function (paramsObject) {
  759. this.settings.post_params = paramsObject;
  760. this.callFlash("SetPostParams", [paramsObject]);
  761. };
  762. // Public: addPostParam adds post name/value pair. Each name can have only one value.
  763. SWFUpload.prototype.addPostParam = function (name, value) {
  764. this.settings.post_params[name] = value;
  765. this.callFlash("SetPostParams", [this.settings.post_params]);
  766. };
  767. // Public: removePostParam deletes post name/value pair.
  768. SWFUpload.prototype.removePostParam = function (name) {
  769. delete this.settings.post_params[name];
  770. this.callFlash("SetPostParams", [this.settings.post_params]);
  771. };
  772. // Public: setFileTypes changes the file_types setting and the file_types_description setting
  773. SWFUpload.prototype.setFileTypes = function (types, description) {
  774. this.settings.file_types = types;
  775. this.settings.file_types_description = description;
  776. this.callFlash("SetFileTypes", [types, description]);
  777. };
  778. // Public: setFileSizeLimit changes the file_size_limit setting
  779. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  780. this.settings.file_size_limit = fileSizeLimit;
  781. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  782. };
  783. // Public: setFileUploadLimit changes the file_upload_limit setting
  784. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  785. this.settings.file_upload_limit = fileUploadLimit;
  786. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  787. };
  788. // Public: setFileQueueLimit changes the file_queue_limit setting
  789. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  790. this.settings.file_queue_limit = fileQueueLimit;
  791. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  792. };
  793. // Public: setFilePostName changes the file_post_name setting
  794. SWFUpload.prototype.setFilePostName = function (filePostName) {
  795. this.settings.file_post_name = filePostName;
  796. this.callFlash("SetFilePostName", [filePostName]);
  797. };
  798. // Public: setUseQueryString changes the use_query_string setting
  799. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  800. this.settings.use_query_string = useQueryString;
  801. this.callFlash("SetUseQueryString", [useQueryString]);
  802. };
  803. // Public: setRequeueOnError changes the requeue_on_error setting
  804. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  805. this.settings.requeue_on_error = requeueOnError;
  806. this.callFlash("SetRequeueOnError", [requeueOnError]);
  807. };
  808. // Public: setHTTPSuccess changes the http_success setting
  809. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  810. if (typeof http_status_codes === "string") {
  811. http_status_codes = http_status_codes.replace(" ", "").split(",");
  812. }
  813. this.settings.http_success = http_status_codes;
  814. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  815. };
  816. // Public: setHTTPSuccess changes the http_success setting
  817. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  818. this.settings.assume_success_timeout = timeout_seconds;
  819. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  820. };
  821. // Public: setDebugEnabled changes the debug_enabled setting
  822. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  823. this.settings.debug_enabled = debugEnabled;
  824. this.callFlash("SetDebugEnabled", [debugEnabled]);
  825. };
  826. // Public: setButtonImageURL loads a button image sprite
  827. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  828. if (buttonImageURL == undefined) {
  829. buttonImageURL = "";
  830. }
  831. this.settings.button_image_url = buttonImageURL;
  832. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  833. };
  834. // Public: setButtonDimensions resizes the Flash Movie and button
  835. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  836. this.settings.button_width = width;
  837. this.settings.button_height = height;
  838. var movie = this.getMovieElement();
  839. if (movie != undefined) {
  840. movie.style.width = width + "px";
  841. movie.style.height = height + "px";
  842. }
  843. this.callFlash("SetButtonDimensions", [width, height]);
  844. };
  845. // Public: setButtonText Changes the text overlaid on the button
  846. SWFUpload.prototype.setButtonText = function (html) {
  847. this.settings.button_text = html;
  848. this.callFlash("SetButtonText", [html]);
  849. };
  850. // Public: setButtonTextPadding changes the top and left padding of the text overlay
  851. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  852. this.settings.button_text_top_padding = top;
  853. this.settings.button_text_left_padding = left;
  854. this.callFlash("SetButtonTextPadding", [left, top]);
  855. };
  856. // Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
  857. SWFUpload.prototype.setButtonTextStyle = function (css) {
  858. this.settings.button_text_style = css;
  859. this.callFlash("SetButtonTextStyle", [css]);
  860. };
  861. // Public: setButtonDisabled disables/enables the button
  862. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  863. this.settings.button_disabled = isDisabled;
  864. this.callFlash("SetButtonDisabled", [isDisabled]);
  865. };
  866. // Public: setButtonAction sets the action that occurs when the button is clicked
  867. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  868. this.settings.button_action = buttonAction;
  869. this.callFlash("SetButtonAction", [buttonAction]);
  870. };
  871. // Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
  872. SWFUpload.prototype.setButtonCursor = function (cursor) {
  873. this.settings.button_cursor = cursor;
  874. this.callFlash("SetButtonCursor", [cursor]);
  875. };
  876. /* *******************************
  877. Flash Event Interfaces
  878. These functions are used by Flash to trigger the various
  879. events.
  880. All these functions a Private.
  881. Because the ExternalInterface library is buggy the event calls
  882. are added to a queue and the queue then executed by a setTimeout.
  883. This ensures that events are executed in a determinate order and that
  884. the ExternalInterface bugs are avoided.
  885. ******************************* */
  886. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  887. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  888. if (argumentArray == undefined) {
  889. argumentArray = [];
  890. } else if (!(argumentArray instanceof Array)) {
  891. argumentArray = [argumentArray];
  892. }
  893. var self = this;
  894. if (typeof this.settings[handlerName] === "function") {
  895. // Queue the event
  896. this.eventQueue.push(function () {
  897. this.settings[handlerName].apply(this, argumentArray);
  898. });
  899. // Execute the next queued event
  900. setTimeout(function () {
  901. self.executeNextEvent();
  902. }, 0);
  903. } else if (this.settings[handlerName] !== null) {
  904. throw "Event handler " + handlerName + " is unknown or is not a function";
  905. }
  906. };
  907. // Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
  908. // we must queue them in order to garentee that they are executed in order.
  909. SWFUpload.prototype.executeNextEvent = function () {
  910. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  911. var f = this.eventQueue ? this.eventQueue.shift() : null;
  912. if (typeof(f) === "function") {
  913. f.apply(this);
  914. }
  915. };
  916. // Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
  917. // properties that contain characters that are not valid for JavaScript identifiers. To work around this
  918. // the Flash Component escapes the parameter names and we must unescape again before passing them along.
  919. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  920. var reg = /[$]([0-9a-f]{4})/i;
  921. var unescapedPost = {};
  922. var uk;
  923. if (file != undefined) {
  924. for (var k in file.post) {
  925. if (file.post.hasOwnProperty(k)) {
  926. uk = k;
  927. var match;
  928. while ((match = reg.exec(uk)) !== null) {
  929. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  930. }
  931. unescapedPost[uk] = file.post[k];
  932. }
  933. }
  934. file.post = unescapedPost;
  935. }
  936. return file;
  937. };
  938. // Private: Called by Flash to see if JS can call in to Flash (test if External Interface is working)
  939. SWFUpload.prototype.testExternalInterface = function () {
  940. try {
  941. return this.callFlash("TestExternalInterface");
  942. } catch (ex) {
  943. return false;
  944. }
  945. };
  946. // Private: This event is called by Flash when it has finished loading. Don't modify this.
  947. // Use the swfupload_loaded_handler event setting to execute custom code when SWFUpload has loaded.
  948. SWFUpload.prototype.flashReady = function () {
  949. // Check that the movie element is loaded correctly with its ExternalInterface methods defined
  950. var movieElement = this.getMovieElement();
  951. if (!movieElement) {
  952. this.debug("Flash called back ready but the flash movie can't be found.");
  953. return;
  954. }
  955. this.cleanUp(movieElement);
  956. this.queueEvent("swfupload_loaded_handler");
  957. };
  958. // Private: removes Flash added fuctions to the DOM node to prevent memory leaks in IE.
  959. // This function is called by Flash each time the ExternalInterface functions are created.
  960. SWFUpload.prototype.cleanUp = function (movieElement) {
  961. // Pro-actively unhook all the Flash functions
  962. try {
  963. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
  964. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  965. for (var key in movieElement) {
  966. try {
  967. if (typeof(movieElement[key]) === "function") {
  968. movieElement[key] = null;
  969. }
  970. } catch (ex) {
  971. }
  972. }
  973. }
  974. } catch (ex1) {
  975. }
  976. // Fix Flashes own cleanup code so if the SWFMovie was removed from the page
  977. // it doesn't display errors.
  978. window["__flash__removeCallback"] = function (instance, name) {
  979. try {
  980. if (instance) {
  981. instance[name] = null;
  982. }
  983. } catch (flashEx) {
  984. }
  985. };
  986. };
  987. /* This is a chance to do something before the browse window opens */
  988. SWFUpload.prototype.fileDialogStart = function () {
  989. this.queueEvent("file_dialog_start_handler");
  990. };
  991. /* Called when a file is successfully added to the queue. */
  992. SWFUpload.prototype.fileQueued = function (file) {
  993. file = this.unescapeFilePostParams(file);
  994. this.queueEvent("file_queued_handler", file);
  995. };
  996. /* Handle errors that occur when an attempt to queue a file fails. */
  997. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  998. file = this.unescapeFilePostParams(file);
  999. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  1000. };
  1001. /* Called after the file dialog has closed and the selected files have been queued.
  1002. You could call startUpload here if you want the queued files to begin uploading immediately. */
  1003. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  1004. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  1005. };
  1006. SWFUpload.prototype.uploadStart = function (file) {
  1007. file = this.unescapeFilePostParams(file);
  1008. this.queueEvent("return_upload_start_handler", file);
  1009. };
  1010. SWFUpload.prototype.returnUploadStart = function (file) {
  1011. var returnValue;
  1012. if (typeof this.settings.upload_start_handler === "function") {
  1013. file = this.unescapeFilePostParams(file);
  1014. returnValue = this.settings.upload_start_handler.call(this, file);
  1015. } else if (this.settings.upload_start_handler != undefined) {
  1016. throw "upload_start_handler must be a function";
  1017. }
  1018. // Convert undefined to true so if nothing is returned from the upload_start_handler it is
  1019. // interpretted as 'true'.
  1020. if (returnValue === undefined) {
  1021. returnValue = true;
  1022. }
  1023. returnValue = !!returnValue;
  1024. this.callFlash("ReturnUploadStart", [returnValue]);
  1025. };
  1026. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  1027. file = this.unescapeFilePostParams(file);
  1028. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  1029. };
  1030. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  1031. file = this.unescapeFilePostParams(file);
  1032. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  1033. };
  1034. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  1035. file = this.unescapeFilePostParams(file);
  1036. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  1037. };
  1038. SWFUpload.prototype.uploadComplete = function (file) {
  1039. file = this.unescapeFilePostParams(file);
  1040. this.queueEvent("upload_complete_handler", file);
  1041. };
  1042. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  1043. internal debug console. You can override this event and have messages written where you want. */
  1044. SWFUpload.prototype.debug = function (message) {
  1045. this.queueEvent("debug_handler", message);
  1046. };
  1047. /* **********************************
  1048. Debug Console
  1049. The debug console is a self contained, in page location
  1050. for debug message to be sent. The Debug Console adds
  1051. itself to the body if necessary.
  1052. The console is automatically scrolled as messages appear.
  1053. If you are using your own debug handler or when you deploy to production and
  1054. have debug disabled you can remove these functions to reduce the file size
  1055. and complexity.
  1056. ********************************** */
  1057. // Private: debugMessage is the default debug_handler. If you want to print debug messages
  1058. // call the debug() function. When overriding the function your own function should
  1059. // check to see if the debug setting is true before outputting debug information.
  1060. SWFUpload.prototype.debugMessage = function (message) {
  1061. if (this.settings.debug) {
  1062. var exceptionMessage, exceptionValues = [];
  1063. // Check for an exception object and print it nicely
  1064. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  1065. for (var key in message) {
  1066. if (message.hasOwnProperty(key)) {
  1067. exceptionValues.push(key + ": " + message[key]);
  1068. }
  1069. }
  1070. exceptionMessage = exceptionValues.join("\n") || "";
  1071. exceptionValues = exceptionMessage.split("\n");
  1072. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  1073. SWFUpload.Console.writeLine(exceptionMessage);
  1074. } else {
  1075. SWFUpload.Console.writeLine(message);
  1076. }
  1077. }
  1078. };
  1079. SWFUpload.Console = {};
  1080. SWFUpload.Console.writeLine = function (message) {
  1081. var console, documentForm;
  1082. try {
  1083. console = document.getElementById("SWFUpload_Console");
  1084. if (!console) {
  1085. documentForm = document.createElement("form");
  1086. document.getElementsByTagName("body")[0].appendChild(documentForm);
  1087. console = document.createElement("textarea");
  1088. console.id = "SWFUpload_Console";
  1089. console.style.fontFamily = "monospace";
  1090. console.setAttribute("wrap", "off");
  1091. console.wrap = "off";
  1092. console.style.overflow = "auto";
  1093. console.style.width = "700px";
  1094. console.style.height = "350px";
  1095. console.style.margin = "5px";
  1096. documentForm.appendChild(console);
  1097. }
  1098. console.value += message + "\n";
  1099. console.scrollTop = console.scrollHeight - console.clientHeight;
  1100. } catch (ex) {
  1101. alert("Exception: " + ex.name + " Message: " + ex.message);
  1102. }
  1103. };
  1104. })();
  1105. (function() {
  1106. /*
  1107. Queue Plug-in
  1108. Features:
  1109. *Adds a cancelQueue() method for cancelling the entire queue.
  1110. *All queued files are uploaded when startUpload() is called.
  1111. *If false is returned from uploadComplete then the queue upload is stopped.
  1112. If false is not returned (strict comparison) then the queue upload is continued.
  1113. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  1114. Set the event handler with the queue_complete_handler setting.
  1115. */
  1116. if (typeof(SWFUpload) === "function") {
  1117. SWFUpload.queue = {};
  1118. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  1119. return function () {
  1120. if (typeof(oldInitSettings) === "function") {
  1121. oldInitSettings.call(this);
  1122. }
  1123. this.queueSettings = {};
  1124. this.queueSettings.queue_cancelled_flag = false;
  1125. this.queueSettings.queue_upload_count = 0;
  1126. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  1127. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  1128. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  1129. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  1130. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  1131. };
  1132. })(SWFUpload.prototype.initSettings);
  1133. SWFUpload.prototype.startUpload = function (fileID) {
  1134. this.queueSettings.queue_cancelled_flag = false;
  1135. this.callFlash("StartUpload", [fileID]);
  1136. };
  1137. SWFUpload.prototype.cancelQueue = function () {
  1138. this.queueSettings.queue_cancelled_flag = true;
  1139. this.stopUpload();
  1140. var stats = this.getStats();
  1141. while (stats.files_queued > 0) {
  1142. this.cancelUpload();
  1143. stats = this.getStats();
  1144. }
  1145. };
  1146. SWFUpload.queue.uploadStartHandler = function (file) {
  1147. var returnValue;
  1148. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  1149. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  1150. }
  1151. // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
  1152. returnValue = (returnValue === false) ? false : true;
  1153. this.queueSettings.queue_cancelled_flag = !returnValue;
  1154. return returnValue;
  1155. };
  1156. SWFUpload.queue.uploadCompleteHandler = function (file) {
  1157. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  1158. var continueUpload;
  1159. if (file.filestatus === SWFUpload.FILE

Large files files are truncated, but you can click here to view the full file