From f4e8e490f6cc4de4761823a2e06c8563903e6ff7 Mon Sep 17 00:00:00 2001 From: jlukic Date: Mon, 8 Dec 2014 15:31:21 -0500 Subject: [PATCH] Fixes #1395, Progress poorly handles undefined/false/0 values evaluating as false --- src/definitions/modules/progress.js | 52 ++++++++++++++++++----------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/definitions/modules/progress.js b/src/definitions/modules/progress.js index 78d630495..42c8c0d0f 100644 --- a/src/definitions/modules/progress.js +++ b/src/definitions/modules/progress.js @@ -73,10 +73,9 @@ $.fn.progress = function(parameters) { }, destroy: function() { - module.verbose('Destroying previous dropdown for', $module); - $module - .removeData(moduleNamespace) - ; + module.verbose('Destroying previous progress for', $module); + module.remove.state(); + $module.removeData(moduleNamespace); instance = undefined; }, @@ -216,6 +215,12 @@ $.fn.progress = function(parameters) { }, remove: { + state: function() { + module.verbose('Removing stored state'); + delete module.total; + delete module.percent; + delete module.value; + }, active: function() { module.verbose('Removing active state'); $module.removeClass(className.active); @@ -239,27 +244,34 @@ $.fn.progress = function(parameters) { if(value > 100) { module.error(error.tooHigh, value); } - $bar - .css('width', value + '%') - ; + else if (value < 0) { + module.error(error.tooLow, value); + } + else { + $bar + .css('width', value + '%') + ; + } }, initials: function() { - if(settings.value) { - module.verbose('Current value set in settings', settings.value); - module.value = settings.value; - } - if(settings.total) { + + if(settings.total !== false) { module.verbose('Current total set in settings', settings.total); module.total = settings.total; } - if(settings.percent) { + if(settings.value !== false) { + module.verbose('Current value set in settings', settings.value); + module.value = settings.value; + } + if(settings.percent !== false) { module.verbose('Current percent set in settings', settings.percent); module.percent = settings.percent; } - if(module.percent) { + + if(module.percent !== undefined) { module.set.percent(module.percent); } - else if(module.value) { + else if(module.value !== undefined) { module.set.progress(module.value); } }, @@ -294,7 +306,7 @@ $.fn.progress = function(parameters) { module.remove.active(); } } - else { + else if(percent > 0) { module.set.active(); } $.proxy(settings.onChange, element)(percent, module.value, module.total); @@ -385,8 +397,8 @@ $.fn.progress = function(parameters) { : value, percentComplete ; - if(!numericValue) { - module.error(error.nonNumeric); + if(numericValue === false) { + module.error(error.nonNumeric, value); } if(module.total) { module.value = numericValue; @@ -611,7 +623,9 @@ $.fn.progress.settings = { error : { method : 'The method you called is not defined.', - nonNumeric : 'Progress value is non numeric' + nonNumeric : 'Progress value is non numeric', + tooHigh : 'Value specified is above 100%', + tooLow : 'Value specified is below 0%' }, regExp: {