Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add check to progress bar set methods to update only if changed and r…

…eturn api (this)
  • Loading branch information...
commit 99ddb233c4f3d09800fc9175d3e72a6e7ac05b9f 1 parent fb785b0
@alextk authored
View
30 dist/jquery.progress-bar.js
@@ -8,7 +8,7 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
-* Date: Mon Jul 4 16:59:27 2011 +0300
+* Date: Mon Jul 4 19:25:55 2011 +0300
*/
(function($) {
@@ -29,13 +29,21 @@
},
setValue: function(newValue) {
- this.value = newValue % (this.total + 1);
- this.syncUI();
+ if(this.value != newValue){
+ this.value = newValue % (this.total + 1);
+ this.syncUI();
+ }
+
+ return this;
},
setTotal: function(newTotal) {
- this.total = newTotal;
- this.setValue(this.value);
+ if(this.total != newTotal){
+ this.total = newTotal;
+ this.setValue(this.value);
+ }
+
+ return this;
},
syncUI: function() {
@@ -94,24 +102,22 @@
}
$.fn.progressBar = function(options) {
- if (options) { //create new progress bar widgets
+ var api = $(this).data('api');
+ if(!api){
this.each(function() {
var target = $(this);
- var config = $.extend($.fn.progressBar.defaults, options);
+ var config = $.extend($.fn.progressBar.defaults, options || {});
config.rtl = target.css('direction') == 'rtl';
target.data('api', new ProgressBarClass(createUI(target), config));
});
- return this;
- } else { //return existing instance api
- return $(this).data('api');
}
+ return this;
};
$.fn.progressBar.defaults = {
start: 0,
total: 100,
- cssRange: {0: 'red', 30: 'orange', 75: 'green'},
- width: 200
+ cssRange: {0: 'red', 30: 'orange', 75: 'green'}
};
})(jQuery);
View
4 dist/jquery.progress-bar.min.js
@@ -8,6 +8,6 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
-* Date: Mon Jul 4 16:59:27 2011 +0300
+* Date: Mon Jul 4 19:25:55 2011 +0300
*/
-(function(a){function d(a){var b=[];for(var c in a)b.push({from:parseInt(c,10),css:a[c]});b.sort(function(a,b){a=a.from,b=b.from;return a<b?-1:a===b?0:1});for(var d=1;d<b.length;d++){var e=b[d-1];e.to=b[d].from-1}b[b.length-1].to=100;return b}function c(b){return a('<div class="progress-bar-container"><div class="bar"/><div class="percent"/></div>').appendTo(b)}var b=function(){this.initialize.apply(this,arguments)};a.extend(b.prototype,{initialize:function(b,c){a.extend(this,c),this.el=b.toggleClass("rtl",this.rtl),this.cssRange=d(this.cssRange),this.setValue(this.start)},setValue:function(a){this.value=a%(this.total+1),this.syncUI()},setTotal:function(a){this.total=a,this.setValue(this.value)},syncUI:function(){var b=Math.round(this.value/this.total*100);jQuery.isNaN(b)&&(b=0);var c=this.el.height(),d=this.el.width(),e=Math.round(b/100*d);a(".bar",this.el).width(e).height(c);var f=a(".percent",this.el);f.html(b+"%").height(c).css({"line-height":c+"px"});var g=e-f.outerWidth(!0);g<0&&(g=0),f.css(this.rtl?{right:g+"px"}:{left:g+"px"});for(var h=0;h<this.cssRange.length;h++){var i=this.cssRange[h];this.el.toggleClass(i.css,i.to>=b&&i.from<=b)}}}),a.fn.progressBar=function(d){if(d){this.each(function(){var e=a(this),f=a.extend(a.fn.progressBar.defaults,d);f.rtl=e.css("direction")=="rtl",e.data("api",new b(c(e),f))});return this}return a(this).data("api")},a.fn.progressBar.defaults={start:0,total:100,cssRange:{0:"red",30:"orange",75:"green"},width:200}})(jQuery)
+(function(a){function d(a){var b=[];for(var c in a)b.push({from:parseInt(c,10),css:a[c]});b.sort(function(a,b){a=a.from,b=b.from;return a<b?-1:a===b?0:1});for(var d=1;d<b.length;d++){var e=b[d-1];e.to=b[d].from-1}b[b.length-1].to=100;return b}function c(b){return a('<div class="progress-bar-container"><div class="bar"/><div class="percent"/></div>').appendTo(b)}var b=function(){this.initialize.apply(this,arguments)};a.extend(b.prototype,{initialize:function(b,c){a.extend(this,c),this.el=b.toggleClass("rtl",this.rtl),this.cssRange=d(this.cssRange),this.setValue(this.start)},setValue:function(a){this.value!=a&&(this.value=a%(this.total+1),this.syncUI());return this},setTotal:function(a){this.total!=a&&(this.total=a,this.setValue(this.value));return this},syncUI:function(){var b=Math.round(this.value/this.total*100);jQuery.isNaN(b)&&(b=0);var c=this.el.height(),d=this.el.width(),e=Math.round(b/100*d);a(".bar",this.el).width(e).height(c);var f=a(".percent",this.el);f.html(b+"%").height(c).css({"line-height":c+"px"});var g=e-f.outerWidth(!0);g<0&&(g=0),f.css(this.rtl?{right:g+"px"}:{left:g+"px"});for(var h=0;h<this.cssRange.length;h++){var i=this.cssRange[h];this.el.toggleClass(i.css,i.to>=b&&i.from<=b)}}}),a.fn.progressBar=function(d){var e=a(this).data("api");e||this.each(function(){var e=a(this),f=a.extend(a.fn.progressBar.defaults,d||{});f.rtl=e.css("direction")=="rtl",e.data("api",new b(c(e),f))});return this},a.fn.progressBar.defaults={start:0,total:100,cssRange:{0:"red",30:"orange",75:"green"}}})(jQuery)
View
4 dist/jquery.progress-bar.pack.js
@@ -8,6 +8,6 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
-* Date: Mon Jul 4 16:59:27 2011 +0300
+* Date: Mon Jul 4 19:25:55 2011 +0300
*/
-eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(4(a){4 d(a){3 b=[];o(3 c 13 a)b.1b({j:12(c,10),8:a[c]});b.X(4(a,b){a=a.j,b=b.j;6 a<b?-1:a===b?0:1});o(3 d=1;d<b.t;d++){3 e=b[d-1];e.p=b[d].j-1}b[b.t-1].p=n;6 b}4 c(b){6 a(\'<l s="Z-u-1c"><l s="u"/><l s="F"/></l>\').17(b)}3 b=4(){2.K.18(2,19)};a.z(b.L,{K:4(b,c){a.z(2,c),2.5=b.C("7",2.7),2.9=d(2.9),2.y(2.E)},y:4(a){2.v=a%(2.m+1),2.A()},M:4(a){2.m=a,2.y(2.v)},A:4(){3 b=J.D(2.v/2.m*n);I.O(b)&&(b=0);3 c=2.5.k(),d=2.5.q(),e=J.D(b/n*d);a(".u",2.5).q(e).k(c);3 f=a(".F",2.5);f.R(b+"%").k(c).8({"S-k":c+"r"});3 g=e-f.U(!0);g<0&&(g=0),f.8(2.7?{V:g+"r"}:{W:g+"r"});o(3 h=0;h<2.9.t;h++){3 i=2.9[h];2.5.C(i.8,i.p>=b&&i.j<=b)}}}),a.w.x=4(d){14(d){2.15(4(){3 e=a(2),f=a.z(a.w.x.B,d);f.7=e.8("P")=="7",e.H("G",Q b(c(e),f))});6 2}6 a(2).H("G")},a.w.x.B={E:0,m:n,9:{0:"16",N:"T",Y:"1a"},q:11}})(I)',62,75,'||this|var|function|el|return|rtl|css|cssRange||||||||||from|height|div|total|100|for|to|width|px|class|length|bar|value|fn|progressBar|setValue|extend|syncUI|defaults|toggleClass|round|start|percent|api|data|jQuery|Math|initialize|prototype|setTotal|30|isNaN|direction|new|html|line|orange|outerWidth|right|left|sort|75|progress||200|parseInt|in|if|each|red|appendTo|apply|arguments|green|push|container'.split('|'),0,{}))
+eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(4(a){4 d(a){3 b=[];t(3 c 12 a)b.13({9:14(c,10),j:a[c]});b.11(4(a,b){a=a.9,b=b.9;5 a<b?-1:a===b?0:1});t(3 d=1;d<b.u;d++){3 e=b[d-1];e.s=b[d].9-1}b[b.u-1].s=m;5 b}4 c(b){5 a(\'<o x="15-r-17"><o x="r"/><o x="G"/></o>\').18(b)}3 b=4(){2.z.T(2,L)};a.p(b.M,{z:4(b,c){a.p(2,c),2.6=b.K("8",2.8),2.k=d(2.k),2.v(2.F)},v:4(a){2.l!=a&&(2.l=a%(2.7+1),2.A());5 2},N:4(a){2.7!=a&&(2.7=a,2.v(2.l));5 2},A:4(){3 b=H.B(2.l/2.7*m);J.P(b)&&(b=0);3 c=2.6.n(),d=2.6.C(),e=H.B(b/m*d);a(".r",2.6).C(e).n(c);3 f=a(".G",2.6);f.R(b+"%").n(c).j({"U-n":c+"y"});3 g=e-f.V(!0);g<0&&(g=0),f.j(2.8?{W:g+"y"}:{Y:g+"y"});t(3 h=0;h<2.k.u;h++){3 i=2.k[h];2.6.K(i.j,i.s>=b&&i.9<=b)}}}),a.w.q=4(d){3 e=a(2).I("E");e||2.19(4(){3 e=a(2),f=a.p(a.w.q.D,d||{});f.8=e.j("Q")=="8",e.I("E",X b(c(e),f))});5 2},a.w.q.D={F:0,7:m,k:{0:"S",Z:"16",O:"1a"}}})(J)',62,73,'||this|var|function|return|el|total|rtl|from||||||||||css|cssRange|value|100|height|div|extend|progressBar|bar|to|for|length|setValue|fn|class|px|initialize|syncUI|round|width|defaults|api|start|percent|Math|data|jQuery|toggleClass|arguments|prototype|setTotal|75|isNaN|direction|html|red|apply|line|outerWidth|right|new|left|30||sort|in|push|parseInt|progress|orange|container|appendTo|each|green'.split('|'),0,{}))
View
2  example/index.html
@@ -23,7 +23,7 @@
});
function progressNext(bar){
- var api = bar.progressBar();
+ var api = bar.progressBar().data('api');
api.setValue((api.value + 1)%(api.total+1));
}
View
25 src/jquery.progress-bar.js
@@ -16,13 +16,21 @@
},
setValue: function(newValue) {
- this.value = newValue % (this.total + 1);
- this.syncUI();
+ if(this.value != newValue){
+ this.value = newValue % (this.total + 1);
+ this.syncUI();
+ }
+
+ return this;
},
setTotal: function(newTotal) {
- this.total = newTotal;
- this.setValue(this.value);
+ if(this.total != newTotal){
+ this.total = newTotal;
+ this.setValue(this.value);
+ }
+
+ return this;
},
syncUI: function() {
@@ -81,17 +89,16 @@
}
$.fn.progressBar = function(options) {
- if (options) { //create new progress bar widgets
+ var api = $(this).data('api');
+ if(!api){
this.each(function() {
var target = $(this);
- var config = $.extend($.fn.progressBar.defaults, options);
+ var config = $.extend($.fn.progressBar.defaults, options || {});
config.rtl = target.css('direction') == 'rtl';
target.data('api', new ProgressBarClass(createUI(target), config));
});
- return this;
- } else { //return existing instance api
- return $(this).data('api');
}
+ return this;
};
$.fn.progressBar.defaults = {
Please sign in to comment.
Something went wrong with that request. Please try again.