You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
4.1 KiB

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