jquery.fileupload-jquery-ui.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * jQuery File Upload jQuery UI Plugin
  3. * https://github.com/blueimp/jQuery-File-Upload
  4. *
  5. * Copyright 2013, Sebastian Tschan
  6. * https://blueimp.net
  7. *
  8. * Licensed under the MIT license:
  9. * https://opensource.org/licenses/MIT
  10. */
  11. /* jshint nomen:false */
  12. /* global define, require, window */
  13. ;(function (factory) {
  14. 'use strict';
  15. if (typeof define === 'function' && define.amd) {
  16. // Register as an anonymous AMD module:
  17. define([
  18. 'jquery',
  19. './jquery.fileupload-ui'
  20. ], factory);
  21. } else if (typeof exports === 'object') {
  22. // Node/CommonJS:
  23. factory(
  24. require('jquery'),
  25. require('./jquery.fileupload-ui')
  26. );
  27. } else {
  28. // Browser globals:
  29. factory(window.jQuery);
  30. }
  31. }(function ($) {
  32. 'use strict';
  33. $.widget('blueimp.fileupload', $.blueimp.fileupload, {
  34. options: {
  35. processdone: function (e, data) {
  36. data.context.find('.start').button('enable');
  37. },
  38. progress: function (e, data) {
  39. if (data.context) {
  40. data.context.find('.progress').progressbar(
  41. 'option',
  42. 'value',
  43. parseInt(data.loaded / data.total * 100, 10)
  44. );
  45. }
  46. },
  47. progressall: function (e, data) {
  48. var $this = $(this);
  49. $this.find('.fileupload-progress')
  50. .find('.progress').progressbar(
  51. 'option',
  52. 'value',
  53. parseInt(data.loaded / data.total * 100, 10)
  54. ).end()
  55. .find('.progress-extended').each(function () {
  56. $(this).html(
  57. ($this.data('blueimp-fileupload') ||
  58. $this.data('fileupload'))
  59. ._renderExtendedProgress(data)
  60. );
  61. });
  62. }
  63. },
  64. _renderUpload: function (func, files) {
  65. var node = this._super(func, files),
  66. showIconText = $(window).width() > 480;
  67. node.find('.progress').empty().progressbar();
  68. node.find('.start').button({
  69. icons: {primary: 'ui-icon-circle-arrow-e'},
  70. text: showIconText
  71. });
  72. node.find('.cancel').button({
  73. icons: {primary: 'ui-icon-cancel'},
  74. text: showIconText
  75. });
  76. if (node.hasClass('fade')) {
  77. node.hide();
  78. }
  79. return node;
  80. },
  81. _renderDownload: function (func, files) {
  82. var node = this._super(func, files),
  83. showIconText = $(window).width() > 480;
  84. node.find('.delete').button({
  85. icons: {primary: 'ui-icon-trash'},
  86. text: showIconText
  87. });
  88. if (node.hasClass('fade')) {
  89. node.hide();
  90. }
  91. return node;
  92. },
  93. _startHandler: function (e) {
  94. $(e.currentTarget).button('disable');
  95. this._super(e);
  96. },
  97. _transition: function (node) {
  98. var deferred = $.Deferred();
  99. if (node.hasClass('fade')) {
  100. node.fadeToggle(
  101. this.options.transitionDuration,
  102. this.options.transitionEasing,
  103. function () {
  104. deferred.resolveWith(node);
  105. }
  106. );
  107. } else {
  108. deferred.resolveWith(node);
  109. }
  110. return deferred;
  111. },
  112. _create: function () {
  113. this._super();
  114. this.element
  115. .find('.fileupload-buttonbar')
  116. .find('.fileinput-button').each(function () {
  117. var input = $(this).find('input:file').detach();
  118. $(this)
  119. .button({icons: {primary: 'ui-icon-plusthick'}})
  120. .append(input);
  121. })
  122. .end().find('.start')
  123. .button({icons: {primary: 'ui-icon-circle-arrow-e'}})
  124. .end().find('.cancel')
  125. .button({icons: {primary: 'ui-icon-cancel'}})
  126. .end().find('.delete')
  127. .button({icons: {primary: 'ui-icon-trash'}})
  128. .end().find('.progress').progressbar();
  129. },
  130. _destroy: function () {
  131. this.element
  132. .find('.fileupload-buttonbar')
  133. .find('.fileinput-button').each(function () {
  134. var input = $(this).find('input:file').detach();
  135. $(this)
  136. .button('destroy')
  137. .append(input);
  138. })
  139. .end().find('.start')
  140. .button('destroy')
  141. .end().find('.cancel')
  142. .button('destroy')
  143. .end().find('.delete')
  144. .button('destroy')
  145. .end().find('.progress').progressbar('destroy');
  146. this._super();
  147. }
  148. });
  149. }));