jquery.fileupload-jquery-ui.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. * http://www.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(['jquery', './jquery.fileupload-ui'], factory);
  18. } else if (typeof exports === 'object') {
  19. // Node/CommonJS:
  20. factory(require('jquery'));
  21. } else {
  22. // Browser globals:
  23. factory(window.jQuery);
  24. }
  25. }(function ($) {
  26. 'use strict';
  27. $.widget('blueimp.fileupload', $.blueimp.fileupload, {
  28. options: {
  29. processdone: function (e, data) {
  30. data.context.find('.start').button('enable');
  31. },
  32. progress: function (e, data) {
  33. if (data.context) {
  34. data.context.find('.progress').progressbar(
  35. 'option',
  36. 'value',
  37. parseInt(data.loaded / data.total * 100, 10)
  38. );
  39. }
  40. },
  41. progressall: function (e, data) {
  42. var $this = $(this);
  43. $this.find('.fileupload-progress')
  44. .find('.progress').progressbar(
  45. 'option',
  46. 'value',
  47. parseInt(data.loaded / data.total * 100, 10)
  48. ).end()
  49. .find('.progress-extended').each(function () {
  50. $(this).html(
  51. ($this.data('blueimp-fileupload') ||
  52. $this.data('fileupload'))
  53. ._renderExtendedProgress(data)
  54. );
  55. });
  56. }
  57. },
  58. _renderUpload: function (func, files) {
  59. var node = this._super(func, files),
  60. showIconText = $(window).width() > 480;
  61. node.find('.progress').empty().progressbar();
  62. node.find('.start').button({
  63. icons: {primary: 'ui-icon-circle-arrow-e'},
  64. text: showIconText
  65. });
  66. node.find('.cancel').button({
  67. icons: {primary: 'ui-icon-cancel'},
  68. text: showIconText
  69. });
  70. if (node.hasClass('fade')) {
  71. node.hide();
  72. }
  73. return node;
  74. },
  75. _renderDownload: function (func, files) {
  76. var node = this._super(func, files),
  77. showIconText = $(window).width() > 480;
  78. node.find('.delete').button({
  79. icons: {primary: 'ui-icon-trash'},
  80. text: showIconText
  81. });
  82. if (node.hasClass('fade')) {
  83. node.hide();
  84. }
  85. return node;
  86. },
  87. _startHandler: function (e) {
  88. $(e.currentTarget).button('disable');
  89. this._super(e);
  90. },
  91. _transition: function (node) {
  92. var deferred = $.Deferred();
  93. if (node.hasClass('fade')) {
  94. node.fadeToggle(
  95. this.options.transitionDuration,
  96. this.options.transitionEasing,
  97. function () {
  98. deferred.resolveWith(node);
  99. }
  100. );
  101. } else {
  102. deferred.resolveWith(node);
  103. }
  104. return deferred;
  105. },
  106. _create: function () {
  107. this._super();
  108. this.element
  109. .find('.fileupload-buttonbar')
  110. .find('.fileinput-button').each(function () {
  111. var input = $(this).find('input:file').detach();
  112. $(this)
  113. .button({icons: {primary: 'ui-icon-plusthick'}})
  114. .append(input);
  115. })
  116. .end().find('.start')
  117. .button({icons: {primary: 'ui-icon-circle-arrow-e'}})
  118. .end().find('.cancel')
  119. .button({icons: {primary: 'ui-icon-cancel'}})
  120. .end().find('.delete')
  121. .button({icons: {primary: 'ui-icon-trash'}})
  122. .end().find('.progress').progressbar();
  123. },
  124. _destroy: function () {
  125. this.element
  126. .find('.fileupload-buttonbar')
  127. .find('.fileinput-button').each(function () {
  128. var input = $(this).find('input:file').detach();
  129. $(this)
  130. .button('destroy')
  131. .append(input);
  132. })
  133. .end().find('.start')
  134. .button('destroy')
  135. .end().find('.cancel')
  136. .button('destroy')
  137. .end().find('.delete')
  138. .button('destroy')
  139. .end().find('.progress').progressbar('destroy');
  140. this._super();
  141. }
  142. });
  143. }));