/CS198/WebContent/js/jqueryui/jquery.ui.progressbar.js

https://bitbucket.org/kristoferdlp/cs198 · JavaScript · 109 lines · 76 code · 19 blank · 14 comment · 5 complexity · 8a7123e1246db71eede8bae0c6379efa MD5 · raw file

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