jquery.progressbar.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * EasyUI for jQuery 1.5.5.6
  3. *
  4. * Copyright (c) 2009-2018 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the freeware license: http://www.jeasyui.com/license_freeware.php
  7. * To use it on other terms please contact us: info@jeasyui.com
  8. *
  9. */
  10. /**
  11. * progressbar - EasyUI for jQuery
  12. *
  13. * Dependencies:
  14. * none
  15. *
  16. */
  17. (function($){
  18. function init(target){
  19. $(target).addClass('progressbar');
  20. $(target).html('<div class="progressbar-text"></div><div class="progressbar-value"><div class="progressbar-text"></div></div>');
  21. $(target).bind('_resize', function(e,force){
  22. if ($(this).hasClass('easyui-fluid') || force){
  23. setSize(target);
  24. }
  25. return false;
  26. });
  27. return $(target);
  28. }
  29. function setSize(target,width){
  30. var opts = $.data(target, 'progressbar').options;
  31. var bar = $.data(target, 'progressbar').bar;
  32. if (width) opts.width = width;
  33. bar._size(opts);
  34. bar.find('div.progressbar-text').css('width', bar.width());
  35. bar.find('div.progressbar-text,div.progressbar-value').css({
  36. height: bar.height()+'px',
  37. lineHeight: bar.height()+'px'
  38. });
  39. }
  40. $.fn.progressbar = function(options, param){
  41. if (typeof options == 'string'){
  42. var method = $.fn.progressbar.methods[options];
  43. if (method){
  44. return method(this, param);
  45. }
  46. }
  47. options = options || {};
  48. return this.each(function(){
  49. var state = $.data(this, 'progressbar');
  50. if (state){
  51. $.extend(state.options, options);
  52. } else {
  53. state = $.data(this, 'progressbar', {
  54. options: $.extend({}, $.fn.progressbar.defaults, $.fn.progressbar.parseOptions(this), options),
  55. bar: init(this)
  56. });
  57. }
  58. $(this).progressbar('setValue', state.options.value);
  59. setSize(this);
  60. });
  61. };
  62. $.fn.progressbar.methods = {
  63. options: function(jq){
  64. return $.data(jq[0], 'progressbar').options;
  65. },
  66. resize: function(jq, width){
  67. return jq.each(function(){
  68. setSize(this, width);
  69. });
  70. },
  71. getValue: function(jq){
  72. return $.data(jq[0], 'progressbar').options.value;
  73. },
  74. setValue: function(jq, value){
  75. if (value < 0) value = 0;
  76. if (value > 100) value = 100;
  77. return jq.each(function(){
  78. var opts = $.data(this, 'progressbar').options;
  79. var text = opts.text.replace(/{value}/, value);
  80. var oldValue = opts.value;
  81. opts.value = value;
  82. $(this).find('div.progressbar-value').width(value+'%');
  83. $(this).find('div.progressbar-text').html(text);
  84. if (oldValue != value){
  85. opts.onChange.call(this, value, oldValue);
  86. }
  87. });
  88. }
  89. };
  90. $.fn.progressbar.parseOptions = function(target){
  91. return $.extend({}, $.parser.parseOptions(target, ['width','height','text',{value:'number'}]));
  92. };
  93. $.fn.progressbar.defaults = {
  94. width: 'auto',
  95. height: 22,
  96. value: 0, // percentage value
  97. text: '{value}%',
  98. onChange:function(newValue,oldValue){}
  99. };
  100. })(jQuery);