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.
 
 
 
 
 
 

108 rivejä
2.1 KiB

  1. /*
  2. * jQuery UI Progressbar 1.8
  3. *
  4. * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
  5. * Dual licensed under the MIT (MIT-LICENSE.txt)
  6. * and GPL (GPL-LICENSE.txt) licenses.
  7. *
  8. * http://docs.jquery.com/UI/Progressbar
  9. *
  10. * Depends:
  11. * jquery.ui.core.js
  12. * jquery.ui.widget.js
  13. */
  14. (function( $ ) {
  15. $.widget( "ui.progressbar", {
  16. options: {
  17. value: 0
  18. },
  19. _create: function() {
  20. this.element
  21. .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
  22. .attr({
  23. role: "progressbar",
  24. "aria-valuemin": this._valueMin(),
  25. "aria-valuemax": this._valueMax(),
  26. "aria-valuenow": this._value()
  27. });
  28. this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
  29. .appendTo( this.element );
  30. this._refreshValue();
  31. },
  32. destroy: function() {
  33. this.element
  34. .removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
  35. .removeAttr( "role" )
  36. .removeAttr( "aria-valuemin" )
  37. .removeAttr( "aria-valuemax" )
  38. .removeAttr( "aria-valuenow" );
  39. this.valueDiv.remove();
  40. $.Widget.prototype.destroy.apply( this, arguments );
  41. },
  42. value: function( newValue ) {
  43. if ( newValue === undefined ) {
  44. return this._value();
  45. }
  46. this._setOption( "value", newValue );
  47. return this;
  48. },
  49. _setOption: function( key, value ) {
  50. switch ( key ) {
  51. case "value":
  52. this.options.value = value;
  53. this._refreshValue();
  54. this._trigger( "change" );
  55. break;
  56. }
  57. $.Widget.prototype._setOption.apply( this, arguments );
  58. },
  59. _value: function() {
  60. var val = this.options.value;
  61. // normalize invalid value
  62. if ( typeof val !== "number" ) {
  63. val = 0;
  64. }
  65. if ( val < this._valueMin() ) {
  66. val = this._valueMin();
  67. }
  68. if ( val > this._valueMax() ) {
  69. val = this._valueMax();
  70. }
  71. return val;
  72. },
  73. _valueMin: function() {
  74. return 0;
  75. },
  76. _valueMax: function() {
  77. return 100;
  78. },
  79. _refreshValue: function() {
  80. var value = this.value();
  81. this.valueDiv
  82. [ value === this._valueMax() ? "addClass" : "removeClass"]( "ui-corner-right" )
  83. .width( value + "%" );
  84. this.element.attr( "aria-valuenow", value );
  85. }
  86. });
  87. $.extend( $.ui.progressbar, {
  88. version: "1.8"
  89. });
  90. })( jQuery );