jquery.fileupload-ui.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. /*
  2. * jQuery File Upload User Interface Plugin
  3. * https://github.com/blueimp/jQuery-File-Upload
  4. *
  5. * Copyright 2010, Sebastian Tschan
  6. * https://blueimp.net
  7. *
  8. * Licensed under the MIT license:
  9. * https://opensource.org/licenses/MIT
  10. */
  11. /* global define, require */
  12. (function (factory) {
  13. 'use strict';
  14. if (typeof define === 'function' && define.amd) {
  15. // Register as an anonymous AMD module:
  16. define([
  17. 'jquery',
  18. 'blueimp-tmpl',
  19. './jquery.fileupload-image',
  20. './jquery.fileupload-audio',
  21. './jquery.fileupload-video',
  22. './jquery.fileupload-validate'
  23. ], factory);
  24. } else if (typeof exports === 'object') {
  25. // Node/CommonJS:
  26. factory(
  27. require('jquery'),
  28. require('blueimp-tmpl'),
  29. require('./jquery.fileupload-image'),
  30. require('./jquery.fileupload-audio'),
  31. require('./jquery.fileupload-video'),
  32. require('./jquery.fileupload-validate')
  33. );
  34. } else {
  35. // Browser globals:
  36. factory(window.jQuery, window.tmpl);
  37. }
  38. })(function ($, tmpl) {
  39. 'use strict';
  40. $.blueimp.fileupload.prototype._specialOptions.push(
  41. 'filesContainer',
  42. 'uploadTemplateId',
  43. 'downloadTemplateId'
  44. );
  45. // The UI version extends the file upload widget
  46. // and adds complete user interface interaction:
  47. $.widget('blueimp.fileupload', $.blueimp.fileupload, {
  48. options: {
  49. // By default, files added to the widget are uploaded as soon
  50. // as the user clicks on the start buttons. To enable automatic
  51. // uploads, set the following option to true:
  52. autoUpload: false,
  53. // The class to show/hide UI elements:
  54. showElementClass: 'in',
  55. // The ID of the upload template:
  56. uploadTemplateId: 'template-upload',
  57. // The ID of the download template:
  58. downloadTemplateId: 'template-download',
  59. // The container for the list of files. If undefined, it is set to
  60. // an element with class "files" inside of the widget element:
  61. filesContainer: undefined,
  62. // By default, files are appended to the files container.
  63. // Set the following option to true, to prepend files instead:
  64. prependFiles: false,
  65. // The expected data type of the upload response, sets the dataType
  66. // option of the $.ajax upload requests:
  67. dataType: 'json',
  68. // Error and info messages:
  69. messages: {
  70. unknownError: 'Unknown error'
  71. },
  72. // Function returning the current number of files,
  73. // used by the maxNumberOfFiles validation:
  74. getNumberOfFiles: function () {
  75. return this.filesContainer.children().not('.processing').length;
  76. },
  77. // Callback to retrieve the list of files from the server response:
  78. getFilesFromResponse: function (data) {
  79. if (data.result && $.isArray(data.result.files)) {
  80. return data.result.files;
  81. }
  82. return [];
  83. },
  84. // The add callback is invoked as soon as files are added to the fileupload
  85. // widget (via file input selection, drag & drop or add API call).
  86. // See the basic file upload widget for more information:
  87. add: function (e, data) {
  88. if (e.isDefaultPrevented()) {
  89. return false;
  90. }
  91. var $this = $(this),
  92. that = $this.data('blueimp-fileupload') || $this.data('fileupload'),
  93. options = that.options;
  94. data.context = that
  95. ._renderUpload(data.files)
  96. .data('data', data)
  97. .addClass('processing');
  98. options.filesContainer[options.prependFiles ? 'prepend' : 'append'](
  99. data.context
  100. );
  101. that._forceReflow(data.context);
  102. that._transition(data.context);
  103. data
  104. .process(function () {
  105. return $this.fileupload('process', data);
  106. })
  107. .always(function () {
  108. data.context
  109. .each(function (index) {
  110. $(this)
  111. .find('.size')
  112. .text(that._formatFileSize(data.files[index].size));
  113. })
  114. .removeClass('processing');
  115. that._renderPreviews(data);
  116. })
  117. .done(function () {
  118. data.context.find('.edit,.start').prop('disabled', false);
  119. if (
  120. that._trigger('added', e, data) !== false &&
  121. (options.autoUpload || data.autoUpload) &&
  122. data.autoUpload !== false
  123. ) {
  124. data.submit();
  125. }
  126. })
  127. .fail(function () {
  128. if (data.files.error) {
  129. data.context.each(function (index) {
  130. var error = data.files[index].error;
  131. if (error) {
  132. $(this).find('.error').text(error);
  133. }
  134. });
  135. }
  136. });
  137. },
  138. // Callback for the start of each file upload request:
  139. send: function (e, data) {
  140. if (e.isDefaultPrevented()) {
  141. return false;
  142. }
  143. var that =
  144. $(this).data('blueimp-fileupload') || $(this).data('fileupload');
  145. if (
  146. data.context &&
  147. data.dataType &&
  148. data.dataType.substr(0, 6) === 'iframe'
  149. ) {
  150. // Iframe Transport does not support progress events.
  151. // In lack of an indeterminate progress bar, we set
  152. // the progress to 100%, showing the full animated bar:
  153. data.context
  154. .find('.progress')
  155. .addClass(!$.support.transition && 'progress-animated')
  156. .attr('aria-valuenow', 100)
  157. .children()
  158. .first()
  159. .css('width', '100%');
  160. }
  161. return that._trigger('sent', e, data);
  162. },
  163. // Callback for successful uploads:
  164. done: function (e, data) {
  165. if (e.isDefaultPrevented()) {
  166. return false;
  167. }
  168. var that =
  169. $(this).data('blueimp-fileupload') || $(this).data('fileupload'),
  170. getFilesFromResponse =
  171. data.getFilesFromResponse || that.options.getFilesFromResponse,
  172. files = getFilesFromResponse(data),
  173. template,
  174. deferred;
  175. if (data.context) {
  176. data.context.each(function (index) {
  177. var file = files[index] || { error: 'Empty file upload result' };
  178. deferred = that._addFinishedDeferreds();
  179. that._transition($(this)).done(function () {
  180. var node = $(this);
  181. template = that._renderDownload([file]).replaceAll(node);
  182. that._forceReflow(template);
  183. that._transition(template).done(function () {
  184. data.context = $(this);
  185. that._trigger('completed', e, data);
  186. that._trigger('finished', e, data);
  187. deferred.resolve();
  188. });
  189. });
  190. });
  191. } else {
  192. template = that
  193. ._renderDownload(files)
  194. [that.options.prependFiles ? 'prependTo' : 'appendTo'](
  195. that.options.filesContainer
  196. );
  197. that._forceReflow(template);
  198. deferred = that._addFinishedDeferreds();
  199. that._transition(template).done(function () {
  200. data.context = $(this);
  201. that._trigger('completed', e, data);
  202. that._trigger('finished', e, data);
  203. deferred.resolve();
  204. });
  205. }
  206. },
  207. // Callback for failed (abort or error) uploads:
  208. fail: function (e, data) {
  209. if (e.isDefaultPrevented()) {
  210. return false;
  211. }
  212. var that =
  213. $(this).data('blueimp-fileupload') || $(this).data('fileupload'),
  214. template,
  215. deferred;
  216. if (data.context) {
  217. data.context.each(function (index) {
  218. if (data.errorThrown !== 'abort') {
  219. var file = data.files[index];
  220. file.error =
  221. file.error || data.errorThrown || data.i18n('unknownError');
  222. deferred = that._addFinishedDeferreds();
  223. that._transition($(this)).done(function () {
  224. var node = $(this);
  225. template = that._renderDownload([file]).replaceAll(node);
  226. that._forceReflow(template);
  227. that._transition(template).done(function () {
  228. data.context = $(this);
  229. that._trigger('failed', e, data);
  230. that._trigger('finished', e, data);
  231. deferred.resolve();
  232. });
  233. });
  234. } else {
  235. deferred = that._addFinishedDeferreds();
  236. that._transition($(this)).done(function () {
  237. $(this).remove();
  238. that._trigger('failed', e, data);
  239. that._trigger('finished', e, data);
  240. deferred.resolve();
  241. });
  242. }
  243. });
  244. } else if (data.errorThrown !== 'abort') {
  245. data.context = that
  246. ._renderUpload(data.files)
  247. [that.options.prependFiles ? 'prependTo' : 'appendTo'](
  248. that.options.filesContainer
  249. )
  250. .data('data', data);
  251. that._forceReflow(data.context);
  252. deferred = that._addFinishedDeferreds();
  253. that._transition(data.context).done(function () {
  254. data.context = $(this);
  255. that._trigger('failed', e, data);
  256. that._trigger('finished', e, data);
  257. deferred.resolve();
  258. });
  259. } else {
  260. that._trigger('failed', e, data);
  261. that._trigger('finished', e, data);
  262. that._addFinishedDeferreds().resolve();
  263. }
  264. },
  265. // Callback for upload progress events:
  266. progress: function (e, data) {
  267. if (e.isDefaultPrevented()) {
  268. return false;
  269. }
  270. var progress = Math.floor((data.loaded / data.total) * 100);
  271. if (data.context) {
  272. data.context.each(function () {
  273. $(this)
  274. .find('.progress')
  275. .attr('aria-valuenow', progress)
  276. .children()
  277. .first()
  278. .css('width', progress + '%');
  279. });
  280. }
  281. },
  282. // Callback for global upload progress events:
  283. progressall: function (e, data) {
  284. if (e.isDefaultPrevented()) {
  285. return false;
  286. }
  287. var $this = $(this),
  288. progress = Math.floor((data.loaded / data.total) * 100),
  289. globalProgressNode = $this.find('.fileupload-progress'),
  290. extendedProgressNode = globalProgressNode.find('.progress-extended');
  291. if (extendedProgressNode.length) {
  292. extendedProgressNode.html(
  293. (
  294. $this.data('blueimp-fileupload') || $this.data('fileupload')
  295. )._renderExtendedProgress(data)
  296. );
  297. }
  298. globalProgressNode
  299. .find('.progress')
  300. .attr('aria-valuenow', progress)
  301. .children()
  302. .first()
  303. .css('width', progress + '%');
  304. },
  305. // Callback for uploads start, equivalent to the global ajaxStart event:
  306. start: function (e) {
  307. if (e.isDefaultPrevented()) {
  308. return false;
  309. }
  310. var that =
  311. $(this).data('blueimp-fileupload') || $(this).data('fileupload');
  312. that._resetFinishedDeferreds();
  313. that
  314. ._transition($(this).find('.fileupload-progress'))
  315. .done(function () {
  316. that._trigger('started', e);
  317. });
  318. },
  319. // Callback for uploads stop, equivalent to the global ajaxStop event:
  320. stop: function (e) {
  321. if (e.isDefaultPrevented()) {
  322. return false;
  323. }
  324. var that =
  325. $(this).data('blueimp-fileupload') || $(this).data('fileupload'),
  326. deferred = that._addFinishedDeferreds();
  327. $.when.apply($, that._getFinishedDeferreds()).done(function () {
  328. that._trigger('stopped', e);
  329. });
  330. that
  331. ._transition($(this).find('.fileupload-progress'))
  332. .done(function () {
  333. $(this)
  334. .find('.progress')
  335. .attr('aria-valuenow', '0')
  336. .children()
  337. .first()
  338. .css('width', '0%');
  339. $(this).find('.progress-extended').html(' ');
  340. deferred.resolve();
  341. });
  342. },
  343. processstart: function (e) {
  344. if (e.isDefaultPrevented()) {
  345. return false;
  346. }
  347. $(this).addClass('fileupload-processing');
  348. },
  349. processstop: function (e) {
  350. if (e.isDefaultPrevented()) {
  351. return false;
  352. }
  353. $(this).removeClass('fileupload-processing');
  354. },
  355. // Callback for file deletion:
  356. destroy: function (e, data) {
  357. if (e.isDefaultPrevented()) {
  358. return false;
  359. }
  360. var that =
  361. $(this).data('blueimp-fileupload') || $(this).data('fileupload'),
  362. removeNode = function () {
  363. that._transition(data.context).done(function () {
  364. $(this).remove();
  365. that._trigger('destroyed', e, data);
  366. });
  367. };
  368. if (data.url) {
  369. data.dataType = data.dataType || that.options.dataType;
  370. $.ajax(data)
  371. .done(removeNode)
  372. .fail(function () {
  373. that._trigger('destroyfailed', e, data);
  374. });
  375. } else {
  376. removeNode();
  377. }
  378. }
  379. },
  380. _resetFinishedDeferreds: function () {
  381. this._finishedUploads = [];
  382. },
  383. _addFinishedDeferreds: function (deferred) {
  384. // eslint-disable-next-line new-cap
  385. var promise = deferred || $.Deferred();
  386. this._finishedUploads.push(promise);
  387. return promise;
  388. },
  389. _getFinishedDeferreds: function () {
  390. return this._finishedUploads;
  391. },
  392. // Link handler, that allows to download files
  393. // by drag & drop of the links to the desktop:
  394. _enableDragToDesktop: function () {
  395. var link = $(this),
  396. url = link.prop('href'),
  397. name = link.prop('download'),
  398. type = 'application/octet-stream';
  399. link.on('dragstart', function (e) {
  400. try {
  401. e.originalEvent.dataTransfer.setData(
  402. 'DownloadURL',
  403. [type, name, url].join(':')
  404. );
  405. } catch (ignore) {
  406. // Ignore exceptions
  407. }
  408. });
  409. },
  410. _formatFileSize: function (bytes) {
  411. if (typeof bytes !== 'number') {
  412. return '';
  413. }
  414. if (bytes >= 1000000000) {
  415. return (bytes / 1000000000).toFixed(2) + ' GB';
  416. }
  417. if (bytes >= 1000000) {
  418. return (bytes / 1000000).toFixed(2) + ' MB';
  419. }
  420. return (bytes / 1000).toFixed(2) + ' KB';
  421. },
  422. _formatBitrate: function (bits) {
  423. if (typeof bits !== 'number') {
  424. return '';
  425. }
  426. if (bits >= 1000000000) {
  427. return (bits / 1000000000).toFixed(2) + ' Gbit/s';
  428. }
  429. if (bits >= 1000000) {
  430. return (bits / 1000000).toFixed(2) + ' Mbit/s';
  431. }
  432. if (bits >= 1000) {
  433. return (bits / 1000).toFixed(2) + ' kbit/s';
  434. }
  435. return bits.toFixed(2) + ' bit/s';
  436. },
  437. _formatTime: function (seconds) {
  438. var date = new Date(seconds * 1000),
  439. days = Math.floor(seconds / 86400);
  440. days = days ? days + 'd ' : '';
  441. return (
  442. days +
  443. ('0' + date.getUTCHours()).slice(-2) +
  444. ':' +
  445. ('0' + date.getUTCMinutes()).slice(-2) +
  446. ':' +
  447. ('0' + date.getUTCSeconds()).slice(-2)
  448. );
  449. },
  450. _formatPercentage: function (floatValue) {
  451. return (floatValue * 100).toFixed(2) + ' %';
  452. },
  453. _renderExtendedProgress: function (data) {
  454. return (
  455. this._formatBitrate(data.bitrate) +
  456. ' | ' +
  457. this._formatTime(((data.total - data.loaded) * 8) / data.bitrate) +
  458. ' | ' +
  459. this._formatPercentage(data.loaded / data.total) +
  460. ' | ' +
  461. this._formatFileSize(data.loaded) +
  462. ' / ' +
  463. this._formatFileSize(data.total)
  464. );
  465. },
  466. _renderTemplate: function (func, files) {
  467. if (!func) {
  468. return $();
  469. }
  470. var result = func({
  471. files: files,
  472. formatFileSize: this._formatFileSize,
  473. options: this.options
  474. });
  475. if (result instanceof $) {
  476. return result;
  477. }
  478. return $(this.options.templatesContainer).html(result).children();
  479. },
  480. _renderPreviews: function (data) {
  481. data.context.find('.preview').each(function (index, elm) {
  482. $(elm).empty().append(data.files[index].preview);
  483. });
  484. },
  485. _renderUpload: function (files) {
  486. return this._renderTemplate(this.options.uploadTemplate, files);
  487. },
  488. _renderDownload: function (files) {
  489. return this._renderTemplate(this.options.downloadTemplate, files)
  490. .find('a[download]')
  491. .each(this._enableDragToDesktop)
  492. .end();
  493. },
  494. _editHandler: function (e) {
  495. e.preventDefault();
  496. if (!this.options.edit) return;
  497. var that = this,
  498. button = $(e.currentTarget),
  499. template = button.closest('.template-upload'),
  500. data = template.data('data'),
  501. index = button.data().index;
  502. this.options.edit(data.files[index]).then(function (file) {
  503. if (!file) return;
  504. data.files[index] = file;
  505. data.context.addClass('processing');
  506. template.find('.edit,.start').prop('disabled', true);
  507. $(that.element)
  508. .fileupload('process', data)
  509. .always(function () {
  510. template
  511. .find('.size')
  512. .text(that._formatFileSize(data.files[index].size));
  513. data.context.removeClass('processing');
  514. that._renderPreviews(data);
  515. })
  516. .done(function () {
  517. template.find('.edit,.start').prop('disabled', false);
  518. })
  519. .fail(function () {
  520. template.find('.edit').prop('disabled', false);
  521. var error = data.files[index].error;
  522. if (error) {
  523. template.find('.error').text(error);
  524. }
  525. });
  526. });
  527. },
  528. _startHandler: function (e) {
  529. e.preventDefault();
  530. var button = $(e.currentTarget),
  531. template = button.closest('.template-upload'),
  532. data = template.data('data');
  533. button.prop('disabled', true);
  534. if (data && data.submit) {
  535. data.submit();
  536. }
  537. },
  538. _cancelHandler: function (e) {
  539. e.preventDefault();
  540. var template = $(e.currentTarget).closest(
  541. '.template-upload,.template-download'
  542. ),
  543. data = template.data('data') || {};
  544. data.context = data.context || template;
  545. if (data.abort) {
  546. data.abort();
  547. } else {
  548. data.errorThrown = 'abort';
  549. this._trigger('fail', e, data);
  550. }
  551. },
  552. _deleteHandler: function (e) {
  553. e.preventDefault();
  554. var button = $(e.currentTarget);
  555. this._trigger(
  556. 'destroy',
  557. e,
  558. $.extend(
  559. {
  560. context: button.closest('.template-download'),
  561. type: 'DELETE'
  562. },
  563. button.data()
  564. )
  565. );
  566. },
  567. _forceReflow: function (node) {
  568. return $.support.transition && node.length && node[0].offsetWidth;
  569. },
  570. _transition: function (node) {
  571. // eslint-disable-next-line new-cap
  572. var dfd = $.Deferred();
  573. if (
  574. $.support.transition &&
  575. node.hasClass('fade') &&
  576. node.is(':visible')
  577. ) {
  578. var transitionEndHandler = function (e) {
  579. // Make sure we don't respond to other transition events
  580. // in the container element, e.g. from button elements:
  581. if (e.target === node[0]) {
  582. node.off($.support.transition.end, transitionEndHandler);
  583. dfd.resolveWith(node);
  584. }
  585. };
  586. node
  587. .on($.support.transition.end, transitionEndHandler)
  588. .toggleClass(this.options.showElementClass);
  589. } else {
  590. node.toggleClass(this.options.showElementClass);
  591. dfd.resolveWith(node);
  592. }
  593. return dfd;
  594. },
  595. _initButtonBarEventHandlers: function () {
  596. var fileUploadButtonBar = this.element.find('.fileupload-buttonbar'),
  597. filesList = this.options.filesContainer;
  598. this._on(fileUploadButtonBar.find('.start'), {
  599. click: function (e) {
  600. e.preventDefault();
  601. filesList.find('.start').trigger('click');
  602. }
  603. });
  604. this._on(fileUploadButtonBar.find('.cancel'), {
  605. click: function (e) {
  606. e.preventDefault();
  607. filesList.find('.cancel').trigger('click');
  608. }
  609. });
  610. this._on(fileUploadButtonBar.find('.delete'), {
  611. click: function (e) {
  612. e.preventDefault();
  613. filesList
  614. .find('.toggle:checked')
  615. .closest('.template-download')
  616. .find('.delete')
  617. .trigger('click');
  618. fileUploadButtonBar.find('.toggle').prop('checked', false);
  619. }
  620. });
  621. this._on(fileUploadButtonBar.find('.toggle'), {
  622. change: function (e) {
  623. filesList
  624. .find('.toggle')
  625. .prop('checked', $(e.currentTarget).is(':checked'));
  626. }
  627. });
  628. },
  629. _destroyButtonBarEventHandlers: function () {
  630. this._off(
  631. this.element
  632. .find('.fileupload-buttonbar')
  633. .find('.start, .cancel, .delete'),
  634. 'click'
  635. );
  636. this._off(this.element.find('.fileupload-buttonbar .toggle'), 'change.');
  637. },
  638. _initEventHandlers: function () {
  639. this._super();
  640. this._on(this.options.filesContainer, {
  641. 'click .edit': this._editHandler,
  642. 'click .start': this._startHandler,
  643. 'click .cancel': this._cancelHandler,
  644. 'click .delete': this._deleteHandler
  645. });
  646. this._initButtonBarEventHandlers();
  647. },
  648. _destroyEventHandlers: function () {
  649. this._destroyButtonBarEventHandlers();
  650. this._off(this.options.filesContainer, 'click');
  651. this._super();
  652. },
  653. _enableFileInputButton: function () {
  654. this.element
  655. .find('.fileinput-button input')
  656. .prop('disabled', false)
  657. .parent()
  658. .removeClass('disabled');
  659. },
  660. _disableFileInputButton: function () {
  661. this.element
  662. .find('.fileinput-button input')
  663. .prop('disabled', true)
  664. .parent()
  665. .addClass('disabled');
  666. },
  667. _initTemplates: function () {
  668. var options = this.options;
  669. options.templatesContainer = this.document[0].createElement(
  670. options.filesContainer.prop('nodeName')
  671. );
  672. if (tmpl) {
  673. if (options.uploadTemplateId) {
  674. options.uploadTemplate = tmpl(options.uploadTemplateId);
  675. }
  676. if (options.downloadTemplateId) {
  677. options.downloadTemplate = tmpl(options.downloadTemplateId);
  678. }
  679. }
  680. },
  681. _initFilesContainer: function () {
  682. var options = this.options;
  683. if (options.filesContainer === undefined) {
  684. options.filesContainer = this.element.find('.files');
  685. } else if (!(options.filesContainer instanceof $)) {
  686. options.filesContainer = $(options.filesContainer);
  687. }
  688. },
  689. _initSpecialOptions: function () {
  690. this._super();
  691. this._initFilesContainer();
  692. this._initTemplates();
  693. },
  694. _create: function () {
  695. this._super();
  696. this._resetFinishedDeferreds();
  697. if (!$.support.fileInput) {
  698. this._disableFileInputButton();
  699. }
  700. },
  701. enable: function () {
  702. var wasDisabled = false;
  703. if (this.options.disabled) {
  704. wasDisabled = true;
  705. }
  706. this._super();
  707. if (wasDisabled) {
  708. this.element.find('input, button').prop('disabled', false);
  709. this._enableFileInputButton();
  710. }
  711. },
  712. disable: function () {
  713. if (!this.options.disabled) {
  714. this.element.find('input, button').prop('disabled', true);
  715. this._disableFileInputButton();
  716. }
  717. this._super();
  718. }
  719. });
  720. });