Browse Source

Fixes #1395, Progress poorly handles undefined/false/0 values evaluating as false

pull/1407/head
jlukic 10 years ago
parent
commit
f4e8e490f6
1 changed files with 33 additions and 19 deletions
  1. 52
      src/definitions/modules/progress.js

52
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: {

Loading…
Cancel
Save