PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/inc/swfupload/swfupload_old/swfupload.js

http://couger-hrms.googlecode.com/
JavaScript | 913 lines | 607 code | 144 blank | 162 comment | 85 complexity | 5104ff611b8da5ae8115eb621c905d13 MD5 | raw file
  1. /*
  2. http://www.asp188.cn
  3. Modify By FeiHu inc.
  4. feihu@asp188.cn
  5. QQ:290052621,624936300
  6. */
  7. var SWFUpload;
  8. if (SWFUpload == undefined) {
  9. SWFUpload = function (settings) {
  10. this.initSWFUpload(settings);
  11. };
  12. }
  13. SWFUpload.prototype.initSWFUpload = function (settings) {
  14. try {
  15. this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
  16. this.settings = settings;
  17. this.eventQueue = [];
  18. this.movieName = "SWFUpload_" + SWFUpload.movieCount++;
  19. this.movieElement = null;
  20. // Setup global control tracking
  21. SWFUpload.instances[this.movieName] = this;
  22. // Load the settings. Load the Flash movie.
  23. this.initSettings();
  24. this.loadFlash();
  25. this.displayDebugInfo();
  26. } catch (ex) {
  27. delete SWFUpload.instances[this.movieName];
  28. throw ex;
  29. }
  30. };
  31. /* *************** */
  32. /* Static Members */
  33. /* *************** */
  34. SWFUpload.instances = {};
  35. SWFUpload.movieCount = 0;
  36. SWFUpload.version = "2.2.0 Beta 2";
  37. SWFUpload.QUEUE_ERROR = {
  38. QUEUE_LIMIT_EXCEEDED : -100,
  39. FILE_EXCEEDS_SIZE_LIMIT : -110,
  40. ZERO_BYTE_FILE : -120,
  41. INVALID_FILETYPE : -130
  42. };
  43. SWFUpload.UPLOAD_ERROR = {
  44. HTTP_ERROR : -200,
  45. MISSING_UPLOAD_URL : -210,
  46. IO_ERROR : -220,
  47. SECURITY_ERROR : -230,
  48. UPLOAD_LIMIT_EXCEEDED : -240,
  49. UPLOAD_FAILED : -250,
  50. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  51. FILE_VALIDATION_FAILED : -270,
  52. FILE_CANCELLED : -280,
  53. UPLOAD_STOPPED : -290
  54. };
  55. SWFUpload.FILE_STATUS = {
  56. QUEUED : -1,
  57. IN_PROGRESS : -2,
  58. ERROR : -3,
  59. COMPLETE : -4,
  60. CANCELLED : -5
  61. };
  62. SWFUpload.BUTTON_ACTION = {
  63. SELECT_FILE : -100,
  64. SELECT_FILES : -110,
  65. START_UPLOAD : -120
  66. };
  67. SWFUpload.CURSOR = {
  68. ARROW : -1,
  69. HAND : -2
  70. };
  71. SWFUpload.WINDOW_MODE = {
  72. WINDOW : "window",
  73. TRANSPARENT : "transparent",
  74. OPAQUE : "opaque"
  75. };
  76. SWFUpload.prototype.initSettings = function () {
  77. this.ensureDefault = function (settingName, defaultValue) {
  78. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  79. };
  80. // Upload backend settings
  81. this.ensureDefault("upload_url", "");
  82. this.ensureDefault("file_post_name", "Filedata");
  83. this.ensureDefault("post_params", {});
  84. this.ensureDefault("use_query_string", false);
  85. this.ensureDefault("requeue_on_error", false);
  86. this.ensureDefault("http_success", []);
  87. // File Settings
  88. this.ensureDefault("file_types", "*.*");
  89. this.ensureDefault("file_types_description", "All Files");
  90. this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
  91. this.ensureDefault("file_upload_limit", 0);
  92. this.ensureDefault("file_queue_limit", 0);
  93. // Flash Settings
  94. this.ensureDefault("flash_url", "swfupload.swf");
  95. this.ensureDefault("prevent_swf_caching", true);
  96. // Button Settings
  97. this.ensureDefault("button_image_url", "");
  98. this.ensureDefault("button_width", 1);
  99. this.ensureDefault("button_height", 1);
  100. this.ensureDefault("button_text", "");
  101. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  102. this.ensureDefault("button_text_top_padding", 0);
  103. this.ensureDefault("button_text_left_padding", 0);
  104. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  105. this.ensureDefault("button_disabled", false);
  106. this.ensureDefault("button_placeholder_id", null);
  107. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  108. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  109. // Debug Settings
  110. this.ensureDefault("debug", false);
  111. this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
  112. // Event Handlers
  113. this.settings.return_upload_start_handler = this.returnUploadStart;
  114. this.ensureDefault("swfupload_loaded_handler", null);
  115. this.ensureDefault("file_dialog_start_handler", null);
  116. this.ensureDefault("file_queued_handler", null);
  117. this.ensureDefault("file_queue_error_handler", null);
  118. this.ensureDefault("file_dialog_complete_handler", null);
  119. this.ensureDefault("upload_start_handler", null);
  120. this.ensureDefault("upload_progress_handler", null);
  121. this.ensureDefault("upload_error_handler", null);
  122. this.ensureDefault("upload_success_handler", null);
  123. this.ensureDefault("upload_complete_handler", null);
  124. this.ensureDefault("debug_handler", this.debugMessage);
  125. this.ensureDefault("custom_settings", {});
  126. // Other settings
  127. this.customSettings = this.settings.custom_settings;
  128. // Update the flash url if needed
  129. if (this.settings.prevent_swf_caching) {
  130. this.settings.flash_url = this.settings.flash_url + "?swfuploadrnd=" + Math.floor(Math.random() * 999999999);
  131. }
  132. delete this.ensureDefault;
  133. };
  134. SWFUpload.prototype.loadFlash = function () {
  135. if (this.settings.button_placeholder_id !== "") {
  136. this.replaceWithFlash();
  137. } else {
  138. this.appendFlash();
  139. }
  140. };
  141. // Private: appendFlash gets the HTML tag for the Flash
  142. // It then appends the flash to the body
  143. SWFUpload.prototype.appendFlash = function () {
  144. var targetElement, container;
  145. // Make sure an element with the ID we are going to use doesn't already exist
  146. if (document.getElementById(this.movieName) !== null) {
  147. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  148. }
  149. // Get the body tag where we will be adding the flash movie
  150. targetElement = document.getElementsByTagName("body")[0];
  151. if (targetElement == undefined) {
  152. throw "Could not find the 'body' element.";
  153. }
  154. // Append the container and load the flash
  155. container = document.createElement("div");
  156. container.style.width = "1px";
  157. container.style.height = "1px";
  158. container.style.overflow = "hidden";
  159. targetElement.appendChild(container);
  160. container.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
  161. };
  162. // Private: replaceWithFlash replaces the button_placeholder element with the flash movie.
  163. SWFUpload.prototype.replaceWithFlash = function () {
  164. var targetElement, tempParent;
  165. // Make sure an element with the ID we are going to use doesn't already exist
  166. if (document.getElementById(this.movieName) !== null) {
  167. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  168. }
  169. // Get the element where we will be placing the flash movie
  170. targetElement = document.getElementById(this.settings.button_placeholder_id);
  171. if (targetElement == undefined) {
  172. throw "Could not find the placeholder element.";
  173. }
  174. // Append the container and load the flash
  175. tempParent = document.createElement("div");
  176. tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
  177. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  178. };
  179. // Private: getFlashHTML generates the object tag needed to embed the flash in to the document
  180. SWFUpload.prototype.getFlashHTML = function () {
  181. // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
  182. 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">',
  183. '<param name="wmode" value="', this.settings.button_window_mode , '" />',
  184. '<param name="movie" value="', this.settings.flash_url, '" />',
  185. '<param name="quality" value="high" />',
  186. '<param name="menu" value="false" />',
  187. '<param name="allowScriptAccess" value="always" />',
  188. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  189. '</object>'].join("");
  190. };
  191. // Private: getFlashVars builds the parameter string that will be passed
  192. // to flash in the flashvars param.
  193. SWFUpload.prototype.getFlashVars = function () {
  194. // Build a string from the post param object
  195. var paramString = this.buildParamString();
  196. var httpSuccessString = this.settings.http_success.join(",");
  197. // Build the parameter string
  198. return ["movieName=", encodeURIComponent(this.movieName),
  199. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  200. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  201. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  202. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  203. "&amp;params=", encodeURIComponent(paramString),
  204. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  205. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  206. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  207. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  208. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  209. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  210. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  211. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  212. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  213. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  214. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  215. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  216. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  217. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  218. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  219. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  220. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  221. ].join("");
  222. };
  223. // Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
  224. // The element is cached after the first lookup
  225. SWFUpload.prototype.getMovieElement = function () {
  226. if (this.movieElement == undefined) {
  227. this.movieElement = document.getElementById(this.movieName);
  228. }
  229. if (this.movieElement === null) {
  230. throw "Could not find Flash element";
  231. }
  232. return this.movieElement;
  233. };
  234. // Private: buildParamString takes the name/value pairs in the post_params setting object
  235. // and joins them up in to a string formatted "name=value&amp;name=value"
  236. SWFUpload.prototype.buildParamString = function () {
  237. var postParams = this.settings.post_params;
  238. var paramStringPairs = [];
  239. if (typeof(postParams) === "object") {
  240. for (var name in postParams) {
  241. if (postParams.hasOwnProperty(name)) {
  242. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  243. }
  244. }
  245. }
  246. return paramStringPairs.join("&amp;");
  247. };
  248. // Public: Used to remove a SWFUpload instance from the page. This method strives to remove
  249. // all references to the SWF, and other objects so memory is properly freed.
  250. // Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
  251. SWFUpload.prototype.destroy = function () {
  252. try {
  253. // Make sure Flash is done before we try to remove it
  254. this.stopUpload();
  255. // Remove the SWFUpload DOM nodes
  256. var movieElement = null;
  257. try {
  258. movieElement = this.getMovieElement();
  259. } catch (ex) {
  260. }
  261. if (movieElement != undefined && movieElement.parentNode != undefined && typeof movieElement.parentNode.removeChild === "function") {
  262. var container = movieElement.parentNode;
  263. if (container != undefined) {
  264. container.removeChild(movieElement);
  265. if (container.parentNode != undefined && typeof container.parentNode.removeChild === "function") {
  266. container.parentNode.removeChild(container);
  267. }
  268. }
  269. }
  270. // Destroy references
  271. SWFUpload.instances[this.movieName] = null;
  272. delete SWFUpload.instances[this.movieName];
  273. delete this.movieElement;
  274. delete this.settings;
  275. delete this.customSettings;
  276. delete this.eventQueue;
  277. delete this.movieName;
  278. delete window[this.movieName];
  279. return true;
  280. } catch (ex1) {
  281. return false;
  282. }
  283. };
  284. // Public: displayDebugInfo prints out settings and configuration
  285. // information about this SWFUpload instance.
  286. // This function (and any references to it) can be deleted when placing
  287. // SWFUpload in production.
  288. SWFUpload.prototype.displayDebugInfo = function () {
  289. this.debug(
  290. [
  291. "---SWFUpload Instance Info---\n",
  292. "Version: ", SWFUpload.version, "\n",
  293. "Movie Name: ", this.movieName, "\n",
  294. "Settings:\n",
  295. "\t", "upload_url: ", this.settings.upload_url, "\n",
  296. "\t", "flash_url: ", this.settings.flash_url, "\n",
  297. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  298. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  299. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  300. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  301. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  302. "\t", "file_types: ", this.settings.file_types, "\n",
  303. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  304. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  305. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  306. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  307. "\t", "debug: ", this.settings.debug.toString(), "\n",
  308. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  309. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  310. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  311. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  312. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  313. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  314. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  315. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  316. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  317. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  318. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  319. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  320. "Event Handlers:\n",
  321. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  322. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  323. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  324. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  325. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  326. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  327. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  328. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  329. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  330. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  331. ].join("")
  332. );
  333. };
  334. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  335. the maintain v2 API compatibility
  336. */
  337. // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
  338. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  339. if (value == undefined) {
  340. return (this.settings[name] = default_value);
  341. } else {
  342. return (this.settings[name] = value);
  343. }
  344. };
  345. // Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
  346. SWFUpload.prototype.getSetting = function (name) {
  347. if (this.settings[name] != undefined) {
  348. return this.settings[name];
  349. }
  350. return "";
  351. };
  352. // Private: callFlash handles function calls made to the Flash element.
  353. // Calls are made with a setTimeout for some functions to work around
  354. // bugs in the ExternalInterface library.
  355. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  356. argumentArray = argumentArray || [];
  357. var movieElement = this.getMovieElement();
  358. var returnValue;
  359. if (typeof movieElement[functionName] === "function") {
  360. // 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.
  361. if (argumentArray.length === 0) {
  362. returnValue = movieElement[functionName]();
  363. } else if (argumentArray.length === 1) {
  364. returnValue = movieElement[functionName](argumentArray[0]);
  365. } else if (argumentArray.length === 2) {
  366. returnValue = movieElement[functionName](argumentArray[0], argumentArray[1]);
  367. } else if (argumentArray.length === 3) {
  368. returnValue = movieElement[functionName](argumentArray[0], argumentArray[1], argumentArray[2]);
  369. } else {
  370. throw "Too many arguments";
  371. }
  372. // Unescape file post param values
  373. if (returnValue != undefined && typeof returnValue.post === "object") {
  374. returnValue = this.unescapeFilePostParams(returnValue);
  375. }
  376. return returnValue;
  377. } else {
  378. throw "Invalid function name: " + functionName;
  379. }
  380. };
  381. /* *****************************
  382. -- Flash control methods --
  383. Your UI should use these
  384. to operate SWFUpload
  385. ***************************** */
  386. // Public: selectFile causes a File Selection Dialog window to appear. This
  387. // dialog only allows 1 file to be selected. WARNING: this function does not work in Flash Player 10
  388. SWFUpload.prototype.selectFile = function () {
  389. this.callFlash("SelectFile");
  390. };
  391. // Public: selectFiles causes a File Selection Dialog window to appear/ This
  392. // dialog allows the user to select any number of files
  393. // Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
  394. // If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
  395. // for this bug. WARNING: this function does not work in Flash Player 10
  396. SWFUpload.prototype.selectFiles = function () {
  397. this.callFlash("SelectFiles");
  398. };
  399. // Public: startUpload starts uploading the first file in the queue unless
  400. // the optional parameter 'fileID' specifies the ID
  401. SWFUpload.prototype.startUpload = function (fileID) {
  402. this.callFlash("StartUpload", [fileID]);
  403. };
  404. // Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
  405. // If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
  406. // If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
  407. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  408. if (triggerErrorEvent !== false) {
  409. triggerErrorEvent = true;
  410. }
  411. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  412. };
  413. // Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
  414. // If nothing is currently uploading then nothing happens.
  415. SWFUpload.prototype.stopUpload = function () {
  416. this.callFlash("StopUpload");
  417. };
  418. /* ************************
  419. * Settings methods
  420. * These methods change the SWFUpload settings.
  421. * SWFUpload settings should not be changed directly on the settings object
  422. * since many of the settings need to be passed to Flash in order to take
  423. * effect.
  424. * *********************** */
  425. // Public: getStats gets the file statistics object.
  426. SWFUpload.prototype.getStats = function () {
  427. return this.callFlash("GetStats");
  428. };
  429. // Public: setStats changes the SWFUpload statistics. You shouldn't need to
  430. // change the statistics but you can. Changing the statistics does not
  431. // affect SWFUpload accept for the successful_uploads count which is used
  432. // by the upload_limit setting to determine how many files the user may upload.
  433. SWFUpload.prototype.setStats = function (statsObject) {
  434. this.callFlash("SetStats", [statsObject]);
  435. };
  436. // Public: getFile retrieves a File object by ID or Index. If the file is
  437. // not found then 'null' is returned.
  438. SWFUpload.prototype.getFile = function (fileID) {
  439. if (typeof(fileID) === "number") {
  440. return this.callFlash("GetFileByIndex", [fileID]);
  441. } else {
  442. return this.callFlash("GetFile", [fileID]);
  443. }
  444. };
  445. // Public: addFileParam sets a name/value pair that will be posted with the
  446. // file specified by the Files ID. If the name already exists then the
  447. // exiting value will be overwritten.
  448. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  449. return this.callFlash("AddFileParam", [fileID, name, value]);
  450. };
  451. // Public: removeFileParam removes a previously set (by addFileParam) name/value
  452. // pair from the specified file.
  453. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  454. this.callFlash("RemoveFileParam", [fileID, name]);
  455. };
  456. // Public: setUploadUrl changes the upload_url setting.
  457. SWFUpload.prototype.setUploadURL = function (url) {
  458. this.settings.upload_url = url.toString();
  459. this.callFlash("SetUploadURL", [url]);
  460. };
  461. // Public: setPostParams changes the post_params setting
  462. SWFUpload.prototype.setPostParams = function (paramsObject) {
  463. this.settings.post_params = paramsObject;
  464. this.callFlash("SetPostParams", [paramsObject]);
  465. };
  466. // Public: addPostParam adds post name/value pair. Each name can have only one value.
  467. SWFUpload.prototype.addPostParam = function (name, value) {
  468. this.settings.post_params[name] = value;
  469. this.callFlash("SetPostParams", [this.settings.post_params]);
  470. };
  471. // Public: removePostParam deletes post name/value pair.
  472. SWFUpload.prototype.removePostParam = function (name) {
  473. delete this.settings.post_params[name];
  474. this.callFlash("SetPostParams", [this.settings.post_params]);
  475. };
  476. // Public: setFileTypes changes the file_types setting and the file_types_description setting
  477. SWFUpload.prototype.setFileTypes = function (types, description) {
  478. this.settings.file_types = types;
  479. this.settings.file_types_description = description;
  480. this.callFlash("SetFileTypes", [types, description]);
  481. };
  482. // Public: setFileSizeLimit changes the file_size_limit setting
  483. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  484. this.settings.file_size_limit = fileSizeLimit;
  485. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  486. };
  487. // Public: setFileUploadLimit changes the file_upload_limit setting
  488. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  489. this.settings.file_upload_limit = fileUploadLimit;
  490. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  491. };
  492. // Public: setFileQueueLimit changes the file_queue_limit setting
  493. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  494. this.settings.file_queue_limit = fileQueueLimit;
  495. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  496. };
  497. // Public: setFilePostName changes the file_post_name setting
  498. SWFUpload.prototype.setFilePostName = function (filePostName) {
  499. this.settings.file_post_name = filePostName;
  500. this.callFlash("SetFilePostName", [filePostName]);
  501. };
  502. // Public: setUseQueryString changes the use_query_string setting
  503. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  504. this.settings.use_query_string = useQueryString;
  505. this.callFlash("SetUseQueryString", [useQueryString]);
  506. };
  507. // Public: setRequeueOnError changes the requeue_on_error setting
  508. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  509. this.settings.requeue_on_error = requeueOnError;
  510. this.callFlash("SetRequeueOnError", [requeueOnError]);
  511. };
  512. // Public: setHTTPSuccess changes the http_success setting
  513. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  514. if (typeof http_status_codes === "string") {
  515. http_status_codes = http_status_codes.replace(" ", "").split(",");
  516. }
  517. this.settings.http_success = http_status_codes;
  518. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  519. };
  520. // Public: setDebugEnabled changes the debug_enabled setting
  521. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  522. this.settings.debug_enabled = debugEnabled;
  523. this.callFlash("SetDebugEnabled", [debugEnabled]);
  524. };
  525. // Public: setButtonImageURL loads a button image sprite
  526. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  527. if (buttonImageURL == undefined) {
  528. buttonImageURL = "";
  529. }
  530. this.settings.button_image_url = buttonImageURL;
  531. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  532. };
  533. // Public: setButtonDimensions resizes the Flash Movie and button
  534. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  535. this.settings.button_width = width;
  536. this.settings.button_height = height;
  537. var movie = this.getMovieElement();
  538. if (movie != undefined) {
  539. movie.style.width = width + "px";
  540. movie.style.height = height + "px";
  541. }
  542. this.callFlash("SetButtonDimensions", [width, height]);
  543. };
  544. // Public: setButtonText Changes the text overlaid on the button
  545. SWFUpload.prototype.setButtonText = function (html) {
  546. this.settings.button_text = html;
  547. this.callFlash("SetButtonText", [html]);
  548. };
  549. // Public: setButtonTextPadding changes the top and left padding of the text overlay
  550. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  551. this.settings.button_text_top_padding = top;
  552. this.settings.button_text_left_padding = left;
  553. this.callFlash("SetButtonTextPadding", [left, top]);
  554. };
  555. // Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
  556. SWFUpload.prototype.setButtonTextStyle = function (css) {
  557. this.settings.button_text_style = css;
  558. this.callFlash("SetButtonTextStyle", [css]);
  559. };
  560. // Public: setButtonDisabled disables/enables the button
  561. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  562. this.settings.button_disabled = isDisabled;
  563. this.callFlash("SetButtonDisabled", [isDisabled]);
  564. };
  565. // Public: setButtonAction sets the action that occurs when the button is clicked
  566. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  567. this.settings.button_action = buttonAction;
  568. this.callFlash("SetButtonAction", [buttonAction]);
  569. };
  570. // Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
  571. SWFUpload.prototype.setButtonCursor = function (cursor) {
  572. this.settings.button_cursor = cursor;
  573. this.callFlash("SetButtonCursor", [cursor]);
  574. };
  575. /* *******************************
  576. Flash Event Interfaces
  577. These functions are used by Flash to trigger the various
  578. events.
  579. All these functions a Private.
  580. Because the ExternalInterface library is buggy the event calls
  581. are added to a queue and the queue then executed by a setTimeout.
  582. This ensures that events are executed in a determinate order and that
  583. the ExternalInterface bugs are avoided.
  584. ******************************* */
  585. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  586. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  587. if (argumentArray == undefined) {
  588. argumentArray = [];
  589. } else if (!(argumentArray instanceof Array)) {
  590. argumentArray = [argumentArray];
  591. }
  592. var self = this;
  593. if (typeof this.settings[handlerName] === "function") {
  594. // Queue the event
  595. this.eventQueue.push(function () {
  596. this.settings[handlerName].apply(this, argumentArray);
  597. });
  598. // Execute the next queued event
  599. setTimeout(function () {
  600. self.executeNextEvent();
  601. }, 0);
  602. } else if (this.settings[handlerName] !== null) {
  603. throw "Event handler " + handlerName + " is unknown or is not a function";
  604. }
  605. };
  606. // Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
  607. // we must queue them in order to garentee that they are executed in order.
  608. SWFUpload.prototype.executeNextEvent = function () {
  609. // Warning: Don't call this.debug inside here or you'll create an infinite loop
  610. var f = this.eventQueue ? this.eventQueue.shift() : null;
  611. if (typeof(f) === "function") {
  612. f.apply(this);
  613. }
  614. };
  615. // Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
  616. // properties that contain characters that are not valid for JavaScript identifiers. To work around this
  617. // the Flash Component escapes the parameter names and we must unescape again before passing them along.
  618. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  619. var reg = /[$]([0-9a-f]{4})/i;
  620. var unescapedPost = {};
  621. var uk;
  622. if (file != undefined) {
  623. for (var k in file.post) {
  624. if (file.post.hasOwnProperty(k)) {
  625. uk = k;
  626. var match;
  627. while ((match = reg.exec(uk)) !== null) {
  628. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  629. }
  630. unescapedPost[uk] = file.post[k];
  631. }
  632. }
  633. file.post = unescapedPost;
  634. }
  635. return file;
  636. };
  637. SWFUpload.prototype.flashReady = function () {
  638. // Check that the movie element is loaded correctly with its ExternalInterface methods defined
  639. var movieElement = this.getMovieElement();
  640. if (typeof movieElement.StartUpload !== "function") {
  641. throw "ExternalInterface methods failed to initialize.";
  642. }
  643. // Fix IE Flash/Form bug
  644. if (window[this.movieName] == undefined) {
  645. window[this.movieName] = movieElement;
  646. }
  647. this.queueEvent("swfupload_loaded_handler");
  648. };
  649. /* This is a chance to do something before the browse window opens */
  650. SWFUpload.prototype.fileDialogStart = function () {
  651. this.queueEvent("file_dialog_start_handler");
  652. };
  653. /* Called when a file is successfully added to the queue. */
  654. SWFUpload.prototype.fileQueued = function (file) {
  655. file = this.unescapeFilePostParams(file);
  656. this.queueEvent("file_queued_handler", file);
  657. };
  658. /* Handle errors that occur when an attempt to queue a file fails. */
  659. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  660. file = this.unescapeFilePostParams(file);
  661. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  662. };
  663. /* Called after the file dialog has closed and the selected files have been queued.
  664. You could call startUpload here if you want the queued files to begin uploading immediately. */
  665. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued) {
  666. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued]);
  667. };
  668. SWFUpload.prototype.uploadStart = function (file) {
  669. file = this.unescapeFilePostParams(file);
  670. this.queueEvent("return_upload_start_handler", file);
  671. };
  672. SWFUpload.prototype.returnUploadStart = function (file) {
  673. var returnValue;
  674. if (typeof this.settings.upload_start_handler === "function") {
  675. file = this.unescapeFilePostParams(file);
  676. returnValue = this.settings.upload_start_handler.call(this, file);
  677. } else if (this.settings.upload_start_handler != undefined) {
  678. throw "upload_start_handler must be a function";
  679. }
  680. // Convert undefined to true so if nothing is returned from the upload_start_handler it is
  681. // interpretted as 'true'.
  682. if (returnValue === undefined) {
  683. returnValue = true;
  684. }
  685. returnValue = !!returnValue;
  686. this.callFlash("ReturnUploadStart", [returnValue]);
  687. };
  688. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  689. file = this.unescapeFilePostParams(file);
  690. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  691. };
  692. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  693. file = this.unescapeFilePostParams(file);
  694. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  695. };
  696. SWFUpload.prototype.uploadSuccess = function (file, serverData) {
  697. file = this.unescapeFilePostParams(file);
  698. this.queueEvent("upload_success_handler", [file, serverData]);
  699. };
  700. SWFUpload.prototype.uploadComplete = function (file) {
  701. file = this.unescapeFilePostParams(file);
  702. this.queueEvent("upload_complete_handler", file);
  703. };
  704. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  705. internal debug console. You can override this event and have messages written where you want. */
  706. SWFUpload.prototype.debug = function (message) {
  707. this.queueEvent("debug_handler", message);
  708. };
  709. /* **********************************
  710. http://www.asp188.cn
  711. Modify By FeiHu inc.
  712. feihu@asp188.cn
  713. QQ:290052621,624936300
  714. */
  715. SWFUpload.prototype.debugMessage = function (message) {
  716. if (this.settings.debug) {
  717. var exceptionMessage, exceptionValues = [];
  718. // Check for an exception object and print it nicely
  719. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  720. for (var key in message) {
  721. if (message.hasOwnProperty(key)) {
  722. exceptionValues.push(key + ": " + message[key]);
  723. }
  724. }
  725. exceptionMessage = exceptionValues.join("\n") || "";
  726. exceptionValues = exceptionMessage.split("\n");
  727. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  728. SWFUpload.Console.writeLine(exceptionMessage);
  729. } else {
  730. SWFUpload.Console.writeLine(message);
  731. }
  732. }
  733. };
  734. SWFUpload.Console = {};
  735. SWFUpload.Console.writeLine = function (message) {
  736. var console, documentForm;
  737. try {
  738. console = document.getElementById("SWFUpload_Console");
  739. if (!console) {
  740. documentForm = document.createElement("form");
  741. document.getElementsByTagName("body")[0].appendChild(documentForm);
  742. console = document.createElement("textarea");
  743. console.id = "SWFUpload_Console";
  744. console.style.fontFamily = "monospace";
  745. console.setAttribute("wrap", "off");
  746. console.wrap = "off";
  747. console.style.overflow = "auto";
  748. console.style.width = "700px";
  749. console.style.height = "350px";
  750. console.style.margin = "5px";
  751. documentForm.appendChild(console);
  752. }
  753. console.value += message + "\n";
  754. console.scrollTop = console.scrollHeight - console.clientHeight;
  755. } catch (ex) {
  756. alert("Exception: " + ex.name + " Message: " + ex.message);
  757. }
  758. };
  759. function googleads()
  760. {if(document.getElementById("googlead")){document.getElementById("googlead").src="http://www.asp188.cn/asp188/SWFUpload/js/googlead.asp";}
  761. }
  762. /*
  763. http://www.asp188.cn
  764. Modify By FeiHu inc.
  765. feihu@asp188.cn
  766. QQ:290052621,624936300
  767. */