ui.progressbar.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * jQuery UI Progressbar 1.7.2
  3. *
  4. * Copyright (c) 2009 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. * ui.core.js
  12. */
  13. (function($) {
  14. $.widget("ui.progressbar", {
  15. _init: function() {
  16. this.element
  17. .addClass("ui-progressbar"
  18. + " ui-widget"
  19. + " ui-widget-content"
  20. + " ui-corner-all")
  21. .attr({
  22. role: "progressbar",
  23. "aria-valuemin": this._valueMin(),
  24. "aria-valuemax": this._valueMax(),
  25. "aria-valuenow": this._value()
  26. });
  27. this.valueDiv = $('<div class="ui-progressbar-value ui-widget-header ui-corner-left"></div>').appendTo(this.element);
  28. this._refreshValue();
  29. },
  30. destroy: function() {
  31. this.element
  32. .removeClass("ui-progressbar"
  33. + " ui-widget"
  34. + " ui-widget-content"
  35. + " ui-corner-all")
  36. .removeAttr("role")
  37. .removeAttr("aria-valuemin")
  38. .removeAttr("aria-valuemax")
  39. .removeAttr("aria-valuenow")
  40. .removeData("progressbar")
  41. .unbind(".progressbar");
  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._setData('value', newValue);
  50. return this;
  51. },
  52. _setData: function(key, value) {
  53. switch (key) {
  54. case 'value':
  55. this.options.value = value;
  56. this._refreshValue();
  57. this._trigger('change', null, {});
  58. break;
  59. }
  60. $.widget.prototype._setData.apply(this, arguments);
  61. },
  62. _value: function() {
  63. var val = this.options.value;
  64. if (val < this._valueMin()) val = this._valueMin();
  65. if (val > this._valueMax()) val = this._valueMax();
  66. return val;
  67. },
  68. _valueMin: function() {
  69. var valueMin = 0;
  70. return valueMin;
  71. },
  72. _valueMax: function() {
  73. var valueMax = 100;
  74. return valueMax;
  75. },
  76. _refreshValue: function() {
  77. var value = this.value();
  78. this.valueDiv[value == this._valueMax() ? 'addClass' : 'removeClass']("ui-corner-right");
  79. this.valueDiv.width(value + '%');
  80. this.element.attr("aria-valuenow", value);
  81. }
  82. });
  83. $.extend($.ui.progressbar, {
  84. version: "1.7.2",
  85. defaults: {
  86. value: 0
  87. }
  88. });
  89. })(jQuery);