Няма описание

progressbar.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*!
  2. * jQuery UI Progressbar 1.12.1
  3. * http://jqueryui.com
  4. *
  5. * Copyright jQuery Foundation and other contributors
  6. * Released under the MIT license.
  7. * http://jquery.org/license
  8. */
  9. //>>label: Progressbar
  10. //>>group: Widgets
  11. // jscs:disable maximumLineLength
  12. //>>description: Displays a status indicator for loading state, standard percentage, and other progress indicators.
  13. // jscs:enable maximumLineLength
  14. //>>docs: http://api.jqueryui.com/progressbar/
  15. //>>demos: http://jqueryui.com/progressbar/
  16. //>>css.structure: ../../themes/base/core.css
  17. //>>css.structure: ../../themes/base/progressbar.css
  18. //>>css.theme: ../../themes/base/theme.css
  19. ( function( factory ) {
  20. if ( typeof define === "function" && define.amd ) {
  21. // AMD. Register as an anonymous module.
  22. define( [
  23. "jquery",
  24. "./core"
  25. ], factory );
  26. } else {
  27. // Browser globals
  28. factory( jQuery );
  29. }
  30. }( function( $ ) {
  31. return $.widget( "ui.progressbar", {
  32. version: "1.12.1",
  33. options: {
  34. classes: {
  35. "ui-progressbar": "ui-corner-all",
  36. "ui-progressbar-value": "ui-corner-left",
  37. "ui-progressbar-complete": "ui-corner-right"
  38. },
  39. max: 100,
  40. value: 0,
  41. change: null,
  42. complete: null
  43. },
  44. min: 0,
  45. _create: function() {
  46. // Constrain initial value
  47. this.oldValue = this.options.value = this._constrainedValue();
  48. this.element.attr( {
  49. // Only set static values; aria-valuenow and aria-valuemax are
  50. // set inside _refreshValue()
  51. role: "progressbar",
  52. "aria-valuemin": this.min
  53. } );
  54. this._addClass( "ui-progressbar", "ui-widget ui-widget-content" );
  55. this.valueDiv = $( "<div>" ).appendTo( this.element );
  56. this._addClass( this.valueDiv, "ui-progressbar-value", "ui-widget-header" );
  57. this._refreshValue();
  58. },
  59. _destroy: function() {
  60. this.element.removeAttr( "role aria-valuemin aria-valuemax aria-valuenow" );
  61. this.valueDiv.remove();
  62. },
  63. value: function( newValue ) {
  64. if ( newValue === undefined ) {
  65. return this.options.value;
  66. }
  67. this.options.value = this._constrainedValue( newValue );
  68. this._refreshValue();
  69. },
  70. _constrainedValue: function( newValue ) {
  71. if ( newValue === undefined ) {
  72. newValue = this.options.value;
  73. }
  74. this.indeterminate = newValue === false;
  75. // Sanitize value
  76. if ( typeof newValue !== "number" ) {
  77. newValue = 0;
  78. }
  79. return this.indeterminate ? false :
  80. Math.min( this.options.max, Math.max( this.min, newValue ) );
  81. },
  82. _setOptions: function( options ) {
  83. // Ensure "value" option is set after other values (like max)
  84. var value = options.value;
  85. delete options.value;
  86. this._super( options );
  87. this.options.value = this._constrainedValue( value );
  88. this._refreshValue();
  89. },
  90. _setOption: function( key, value ) {
  91. if ( key === "max" ) {
  92. // Don't allow a max less than min
  93. value = Math.max( this.min, value );
  94. }
  95. this._super( key, value );
  96. },
  97. _setOptionDisabled: function( value ) {
  98. this._super( value );
  99. this.element.attr( "aria-disabled", value );
  100. this._toggleClass( null, "ui-state-disabled", !!value );
  101. },
  102. _percentage: function() {
  103. return this.indeterminate ?
  104. 100 :
  105. 100 * ( this.options.value - this.min ) / ( this.options.max - this.min );
  106. },
  107. _refreshValue: function() {
  108. var value = this.options.value,
  109. percentage = this._percentage();
  110. this.valueDiv
  111. .toggle( this.indeterminate || value > this.min )
  112. .width( percentage.toFixed( 0 ) + "%" );
  113. this
  114. ._toggleClass( this.valueDiv, "ui-progressbar-complete", null,
  115. value === this.options.max )
  116. ._toggleClass( "ui-progressbar-indeterminate", null, this.indeterminate );
  117. if ( this.indeterminate ) {
  118. this.element.removeAttr( "aria-valuenow" );
  119. if ( !this.overlayDiv ) {
  120. this.overlayDiv = $( "<div>" ).appendTo( this.valueDiv );
  121. this._addClass( this.overlayDiv, "ui-progressbar-overlay" );
  122. }
  123. } else {
  124. this.element.attr( {
  125. "aria-valuemax": this.options.max,
  126. "aria-valuenow": value
  127. } );
  128. if ( this.overlayDiv ) {
  129. this.overlayDiv.remove();
  130. this.overlayDiv = null;
  131. }
  132. }
  133. if ( this.oldValue !== value ) {
  134. this.oldValue = value;
  135. this._trigger( "change" );
  136. }
  137. if ( value === this.options.max ) {
  138. this._trigger( "complete" );
  139. }
  140. }
  141. } );
  142. } ) );