1ad3e85edc21c72400b7e1463a9355046720218a.svn-base 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * jQuery EasyUI 1.3.6
  3. *
  4. * Copyright (c) 2009-2014 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the GPL license: http://www.gnu.org/licenses/gpl.txt
  7. * To use it on other terms please contact us at info@jeasyui.com
  8. *
  9. */
  10. /**
  11. * progressbar - jQuery EasyUI
  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. return $(target);
  22. }
  23. function setSize(target,width){
  24. var opts = $.data(target, 'progressbar').options;
  25. var bar = $.data(target, 'progressbar').bar;
  26. if (width) opts.width = width;
  27. bar._outerWidth(opts.width)._outerHeight(opts.height);
  28. bar.find('div.progressbar-text').width(bar.width());
  29. bar.find('div.progressbar-text,div.progressbar-value').css({
  30. height: bar.height()+'px',
  31. lineHeight: bar.height()+'px'
  32. });
  33. }
  34. $.fn.progressbar = function(options, param){
  35. if (typeof options == 'string'){
  36. var method = $.fn.progressbar.methods[options];
  37. if (method){
  38. return method(this, param);
  39. }
  40. }
  41. options = options || {};
  42. return this.each(function(){
  43. var state = $.data(this, 'progressbar');
  44. if (state){
  45. $.extend(state.options, options);
  46. } else {
  47. state = $.data(this, 'progressbar', {
  48. options: $.extend({}, $.fn.progressbar.defaults, $.fn.progressbar.parseOptions(this), options),
  49. bar: init(this)
  50. });
  51. }
  52. $(this).progressbar('setValue', state.options.value);
  53. setSize(this);
  54. });
  55. };
  56. $.fn.progressbar.methods = {
  57. options: function(jq){
  58. return $.data(jq[0], 'progressbar').options;
  59. },
  60. resize: function(jq, width){
  61. return jq.each(function(){
  62. setSize(this, width);
  63. });
  64. },
  65. getValue: function(jq){
  66. return $.data(jq[0], 'progressbar').options.value;
  67. },
  68. setValue: function(jq, value){
  69. if (value < 0) value = 0;
  70. if (value > 100) value = 100;
  71. return jq.each(function(){
  72. var opts = $.data(this, 'progressbar').options;
  73. var text = opts.text.replace(/{value}/, value);
  74. var oldValue = opts.value;
  75. opts.value = value;
  76. $(this).find('div.progressbar-value').width(value+'%');
  77. $(this).find('div.progressbar-text').html(text);
  78. if (oldValue != value){
  79. opts.onChange.call(this, value, oldValue);
  80. }
  81. });
  82. }
  83. };
  84. $.fn.progressbar.parseOptions = function(target){
  85. return $.extend({}, $.parser.parseOptions(target, ['width','height','text',{value:'number'}]));
  86. };
  87. $.fn.progressbar.defaults = {
  88. width: 'auto',
  89. height: 22,
  90. value: 0, // percentage value
  91. text: '{value}%',
  92. onChange:function(newValue,oldValue){}
  93. };
  94. })(jQuery);