jquery.fileupload-jquery-ui.js 4.7 KB

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