Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

uploader-debug.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /*
  2. Copyright (c) 2010, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.com/yui/license.html
  5. version: 3.4.0
  6. build: nightly
  7. */
  8. YUI.add('uploader', function(Y) {
  9. /**
  10. * Upload files to the server with support for file filtering, multiple file uploads
  11. * and progress monitoring.
  12. * @module uploader
  13. */
  14. var Event = Y.Event,
  15. Node = Y.Node;
  16. var SWFURL = Y.Env.cdn + "uploader/assets/uploader.swf";
  17. /**
  18. * The Uploader widget is a tool for uploading files to the server.
  19. * @module uploader
  20. * @title Uploader
  21. * @requires base, node, event, swf
  22. */
  23. /**
  24. * Creates the Uploader instance and keeps the initialization data
  25. *
  26. * @class Uploader
  27. * @extends Y.Base
  28. * @constructor
  29. * @param {Object} config (optional) Configuration parameters for the Uploader. The following parameters are available:
  30. * <dl>
  31. * <dt>boundingBox : String|Node (required)</dt>
  32. * <dd></dd>
  33. * <dt>buttonSkin : String (optional)</dt>
  34. * <dd></dd>
  35. * <dt>transparent : String (optional)</dt>
  36. * <dd></dd>
  37. * <dt>swfURL : String (optional)</dt>
  38. * <dd></dd>
  39. * </dl>
  40. */
  41. function Uploader (config /*Object*/) {
  42. Uploader.superclass.constructor.apply(this, arguments);
  43. if (config.hasOwnProperty("boundingBox")) {
  44. this.set("boundingBox", config.boundingBox);
  45. };
  46. if (config.hasOwnProperty("buttonSkin")) {
  47. this.set("buttonSkin", config.buttonSkin);
  48. };
  49. if (config.hasOwnProperty("transparent")) {
  50. this.set("transparent", config.transparent);
  51. };
  52. if (config.hasOwnProperty("swfURL")) {
  53. this.set("swfURL", config.swfURL);
  54. };
  55. };
  56. Y.extend(Uploader, Y.Base, {
  57. /**
  58. * The reference to the instance of Y.SWF that encapsulates the instance of the Flash player with uploader logic.
  59. *
  60. * @private
  61. * @property uploaderswf
  62. * @type {SWF}
  63. * @default null
  64. */
  65. uploaderswf:null,
  66. /**
  67. * The id of this instance of uploader.
  68. *
  69. * @private
  70. * @property _id
  71. * @type {String}
  72. */
  73. _id:"",
  74. /**
  75. * Construction logic executed during Uploader instantiation.
  76. *
  77. * @method initializer
  78. * @protected
  79. */
  80. initializer : function () {
  81. this._id = Y.guid("uploader");
  82. var oElement = Node.one(this.get("boundingBox"));
  83. var params = {version: "10.0.45",
  84. fixedAttributes: {allowScriptAccess:"always", allowNetworking:"all", scale: "noscale"},
  85. flashVars: {}};
  86. if (this.get("buttonSkin") != "") {
  87. params.flashVars["buttonSkin"] = this.get("buttonSkin");
  88. }
  89. if (this.get("transparent")) {
  90. params.fixedAttributes["wmode"] = "transparent";
  91. }
  92. this.uploaderswf = new Y.SWF(oElement, this.get("swfURL"), params);
  93. var upswf = this.uploaderswf;
  94. var relEvent = Y.bind(this._relayEvent, this);
  95. /**
  96. * Announces that the uploader is ready and available for calling methods
  97. * and setting properties
  98. *
  99. * @event uploaderReady
  100. * @param event {Event} The event object for the uploaderReady.
  101. */
  102. upswf.on ("swfReady", Y.bind(this._initializeUploader, this));
  103. /**
  104. * Fired when the mouse button is clicked on the Uploader's 'Browse' button.
  105. *
  106. * @event click
  107. * @param event {Event} The event object for the click.
  108. */
  109. upswf.on ("click", relEvent);
  110. /**
  111. * Fires when the user has finished selecting a set of files to be uploaded.
  112. *
  113. * @event fileselect
  114. * @param event {Event} The event object for the fileSelect.
  115. * <dl>
  116. * <dt>fileList</dt>
  117. * <dd>The file list Object with entries in the following format:
  118. fileList[fileID] = {id: fileID, name: fileName, cDate: fileCDate, mDate: fileMDate, size: fileSize}</dd>
  119. * </dl>
  120. */
  121. upswf.on ("fileselect", relEvent);
  122. /**
  123. * Fired when the mouse button is pressed on the Uploader's 'Browse' button.
  124. *
  125. * @event mousedown
  126. * @param event {Event} The event object for the mousedown.
  127. */
  128. upswf.on ("mousedown", relEvent);
  129. /**
  130. * Fired when the mouse button is raised on the Uploader's 'Browse' button.
  131. *
  132. * @event mouseup
  133. * @param event {Event} The event object for the mouseup.
  134. */
  135. upswf.on ("mouseup", relEvent);
  136. /**
  137. * Fired when the mouse leaves the Uploader's 'Browse' button.
  138. *
  139. * @event mouseleave
  140. * @param event {Event} The event object for the mouseleave.
  141. */
  142. upswf.on ("mouseleave", relEvent);
  143. /**
  144. * Fired when the mouse enters the Uploader's 'Browse' button.
  145. *
  146. * @event mouseenter
  147. * @param event {Event} The event object for the mouseenter.
  148. */
  149. upswf.on ("mouseenter", relEvent);
  150. /**
  151. * Announces that the uploader is ready and available for calling methods
  152. * and setting properties
  153. *
  154. * @event uploadcancel
  155. * @param event {Event} The event object for the uploaderReady.
  156. * <dl>
  157. * <dt>ddEvent</dt>
  158. * <dd><code>drag:start</code> event from the thumb</dd>
  159. * </dl>
  160. */
  161. upswf.on ("uploadcancel", relEvent);
  162. /**
  163. * Fires when a specific file's upload is cancelled.
  164. *
  165. * @event uploadcomplete
  166. * @param event {Event} The event object for the uploadcancel.
  167. * <dl>
  168. * <dt>id</dt>
  169. * <dd>The id of the file whose upload has been cancelled.</dd>
  170. * </dl>
  171. */
  172. upswf.on ("uploadcomplete", relEvent);
  173. /**
  174. * If the server has sent a response to the file upload, this event is
  175. * fired and the response is added to its payload.
  176. *
  177. * @event uploadcompletedata
  178. * @param event {Event} The event object for the uploadcompletedata.
  179. * <dl>
  180. * <dt>id</dt>
  181. * <dd>The id of the file for which the response is being provided.</dd>
  182. * <dt>data</dt>
  183. * <dd>The content of the server response.</dd>
  184. * </dl>
  185. */
  186. upswf.on ("uploadcompletedata", relEvent);
  187. /**
  188. * Provides error information if an error has occurred during the upload.
  189. *
  190. * @event uploaderror
  191. * @param event {Event} The event object for the uploadeerror.
  192. * <dl>
  193. * <dt>id</dt>
  194. * <dd>The id of the file for which the upload error has occurred.</dd>
  195. * <dt>status</dt>
  196. * <dd>Relevant error information.</dd>
  197. * </dl>
  198. */
  199. upswf.on ("uploaderror", relEvent);
  200. /**
  201. * Provides progress information on a specific file upload.
  202. *
  203. * @event uploadprogress
  204. * @param event {Event} The event object for the uploadprogress.
  205. * <dl>
  206. * <dt>id</dt>
  207. * <dd>The id of the file for which the progress information is being provided.</dd>
  208. * <dt>bytesLoaded</dt>
  209. * <dd>The number of bytes of the file that has been uploaded.</dd>
  210. * <dt>bytesTotal</dt>
  211. * <dd>The total number of bytes in the file that is being uploaded.</dd>
  212. * </dl>
  213. */
  214. upswf.on ("uploadprogress", relEvent);
  215. /**
  216. * Announces that the upload has been started for a specific file.
  217. *
  218. * @event uploadstart
  219. * @param event {Event} The event object for the uploadstart.
  220. * <dl>
  221. * <dt>id</dt>
  222. * <dd>The id of the file whose upload has been started.</dd>
  223. * </dl>
  224. */
  225. upswf.on ("uploadstart", relEvent);
  226. },
  227. /**
  228. * Removes a specific file from the upload queue.
  229. *
  230. * @method removeFile
  231. * @param fileID {String} The ID of the file to be removed
  232. * @return {Object} The updated file list, which is an object of the format:
  233. * fileList[fileID] = {id: fileID, name: fileName, cDate: fileCDate, mDate: fileMDate, size: fileSize}
  234. */
  235. removeFile : function (fileID /*String*/) {
  236. return this.uploaderswf.callSWF("removeFile", [fileID]);
  237. },
  238. /**
  239. * Clears the upload queue.
  240. *
  241. * @method clearFileList
  242. * @return {Boolean} This method always returns true.
  243. */
  244. clearFileList : function () {
  245. return this.uploaderswf.callSWF("clearFileList", []);
  246. },
  247. /**
  248. * Starts the upload of a specific file.
  249. *
  250. * @method upload
  251. * @param fileID {String} The ID of the file to be uploaded.
  252. * @param url {String} The URL to upload the file to.
  253. * @param method {String} (optional) The HTTP method to use for sending additional variables, either 'GET' or 'POST' ('GET' by default)
  254. * @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
  255. * @param postFileVarName {String} (optional) The name of the POST variable that should contain the uploaded file ('Filedata' by default)
  256. * @return {Boolean} This method always returns true.
  257. */
  258. upload : function (fileID /*String*/, url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
  259. if (Y.Lang.isArray(fileID)) {
  260. return this.uploaderswf.callSWF("uploadThese", [fileID, url, method, postVars, postFileVarName]);
  261. }
  262. else if (Y.Lang.isString(fileID)) {
  263. return this.uploaderswf.callSWF("upload", [fileID, url, method, postVars, postFileVarName]);
  264. }
  265. },
  266. /**
  267. * Starts the upload of a set of files, as specified in the first argument.
  268. * The upload queue is managed automatically.
  269. *
  270. * @method uploadThese
  271. * @param fileIDs {Array} The array of IDs of the files to be uploaded.
  272. * @param url {String} The URL to upload the files to.
  273. * @param method {String} (optional) The HTTP method to use for sending additional variables, either 'GET' or 'POST' ('GET' by default)
  274. * @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
  275. * @param postFileVarName {String} (optional) The name of the POST variable that should contain the uploaded file ('Filedata' by default)
  276. */
  277. uploadThese : function (fileIDs /*Array*/, url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
  278. return this.uploaderswf.callSWF("uploadThese", [fileIDs, url, method, postVars, postFileVarName]);
  279. },
  280. /**
  281. * Starts the upload of the files in the upload queue.
  282. * The upload queue is managed automatically.
  283. *
  284. * @method uploadAll
  285. * @param url {String} The URL to upload the files to.
  286. * @param method {String} (optional) The HTTP method to use for sending additional variables, either 'GET' or 'POST' ('GET' by default)
  287. * @param postVars {Object} (optional) A set of key-value pairs to send as variables along with the file upload HTTP request.
  288. * @param postFileVarName {String} (optional) The name of the POST variable that should contain the uploaded file ('Filedata' by default).
  289. */
  290. uploadAll : function (url /*String*/, method /*String*/, postVars /*Object*/, postFileVarName /*String*/) {
  291. return this.uploaderswf.callSWF("uploadAll", [url, method, postVars,postFileVarName]);
  292. },
  293. /**
  294. * Cancels the upload of a specific file, if currently in progress.
  295. *
  296. * @method cancel
  297. * @param fileID {String} (optional) The ID of the file whose upload should be cancelled. If no ID is specified, all uploads are cancelled.
  298. */
  299. cancel : function (fileID /*String*/) {
  300. return this.uploaderswf.callSWF("cancel", [fileID]);
  301. },
  302. /**
  303. * @private
  304. * Setter for the 'log' property.
  305. * @method setAllowLogging
  306. * @param value {Boolean} The value for the 'log' property.
  307. */
  308. setAllowLogging : function (value /*Boolean*/) {
  309. this.uploaderswf.callSWF("setAllowLogging", [value]);
  310. },
  311. /**
  312. * @private
  313. * Setter for the 'multiFiles' property.
  314. * @method setAllowMultipleFiles
  315. * @param value {Boolean} The value for the 'multiFiles' property.
  316. */
  317. setAllowMultipleFiles : function (value /*Boolean*/) {
  318. this.uploaderswf.callSWF("setAllowMultipleFiles", [value]);
  319. },
  320. /**
  321. * @private
  322. * Setter for the 'simLimit' property.
  323. * @method setSimUploadLimit
  324. * @param value {Boolean} The value for the 'simLimit' property.
  325. */
  326. setSimUploadLimit : function (value /*int*/) {
  327. this.uploaderswf.callSWF("setSimUploadLimit", [value]);
  328. },
  329. /**
  330. * @private
  331. * Setter for the 'fileFilters' property.
  332. * @method setFileFilters
  333. * @param value {Boolean} The value for the 'fileFilters' property.
  334. */
  335. setFileFilters : function (fileFilters /*Array*/) {
  336. this.uploaderswf.callSWF("setFileFilters", [fileFilters]);
  337. },
  338. /**
  339. * Enables the uploader user input (mouse clicks on the 'Browse' button). If the button skin
  340. * is applied, the sprite is reset from the "disabled" state.
  341. *
  342. * @method enable
  343. */
  344. enable : function () {
  345. this.uploaderswf.callSWF("enable");
  346. },
  347. /**
  348. * Disables the uploader user input (mouse clicks on the 'Browse' button). If the button skin
  349. * is applied, the sprite is set to the 'disabled' state.
  350. *
  351. * @method enable
  352. */
  353. disable : function () {
  354. this.uploaderswf.callSWF("disable");
  355. },
  356. /**
  357. * @private
  358. * Called when the uploader SWF is initialized
  359. * @method _initializeUploader
  360. * @param event {Object} The event to be propagated from Flash.
  361. */
  362. _initializeUploader: function (event) {
  363. this.publish("uploaderReady", {fireOnce:true});
  364. this.fire("uploaderReady", {});
  365. },
  366. /**
  367. * @private
  368. * Called when an event is dispatched from Uploader
  369. * @method _relayEvent
  370. * @param event {Object} The event to be propagated from Flash.
  371. */
  372. _relayEvent: function (event) {
  373. Y.log("Firing event...");
  374. Y.log(event.type);
  375. this.fire(event.type, event);
  376. },
  377. toString: function()
  378. {
  379. return "Uploader " + this._id;
  380. }
  381. },
  382. {
  383. ATTRS: {
  384. /**
  385. * The flag that allows Flash player to
  386. * output debug messages to its trace stack
  387. * (if the Flash debug player is used).
  388. *
  389. * @attribute log
  390. * @type {Boolean}
  391. * @default false
  392. */
  393. log: {
  394. value: false,
  395. setter : "setAllowLogging"
  396. },
  397. /**
  398. * The flag that allows the user to select
  399. * more than one files during the 'Browse'
  400. * dialog (using 'Shift' or 'Ctrl' keys).
  401. *
  402. * @attribute multiFiles
  403. * @type {Boolean}
  404. * @default false
  405. */
  406. multiFiles : {
  407. value: false,
  408. setter : "setAllowMultipleFiles"
  409. },
  410. /**
  411. * The number of files that can be uploaded
  412. * simultaneously if the automatic queue management
  413. * is used. This value can be in the range between 2
  414. * and 5.
  415. *
  416. * @attribute simLimit
  417. * @type {Number}
  418. * @default 2
  419. */
  420. simLimit : {
  421. value: 2,
  422. setter : "setSimUploadLimit"
  423. },
  424. /**
  425. * The array of filters on file extensions for
  426. * the 'Browse' dialog. These filters only provide
  427. * convenience for the user and do not strictly
  428. * limit the selection to certain file extensions.
  429. * Each item in the array must contain a 'description'
  430. * property, and an 'extensions' property that must be
  431. * in the form "*.ext;*.ext;*.ext;..."
  432. *
  433. * @attribute fileFilters
  434. * @type {Array}
  435. * @default []
  436. */
  437. fileFilters : {
  438. value: [],
  439. setter : "setFileFilters"
  440. },
  441. /**
  442. * The Node containing the uploader's 'Browse' button.
  443. *
  444. * @attribute boundingBox
  445. * @type {Node}
  446. * @default null
  447. * @writeOnce
  448. */
  449. boundingBox : {
  450. value: null,
  451. writeOnce: 'initOnly'
  452. },
  453. /**
  454. * The URL of the image sprite for skinning the uploader's 'Browse' button.
  455. *
  456. * @attribute buttonSkin
  457. * @type {String}
  458. * @default null
  459. * @writeOnce
  460. */
  461. buttonSkin : {
  462. value: null,
  463. writeOnce: 'initOnly'
  464. },
  465. /**
  466. * The flag indicating whether the uploader is rendered
  467. * with a transparent background.
  468. *
  469. * @attribute transparent
  470. * @type {Boolean}
  471. * @default true
  472. * @writeOnce
  473. */
  474. transparent : {
  475. value: true,
  476. writeOnce: 'initOnly'
  477. },
  478. /**
  479. * The URL of the uploader's SWF.
  480. *
  481. * @attribute swfURL
  482. * @type {String}
  483. * @default "assets/uploader.swf"
  484. * @writeOnce
  485. */
  486. swfURL : {
  487. value : SWFURL,
  488. writeOnce: 'initOnly'
  489. }
  490. }
  491. }
  492. );
  493. Y.Uploader = Uploader;
  494. }, '3.4.0' ,{requires:['swf', 'base', 'node', 'event-custom']});