|
|
@ -2444,9 +2444,10 @@ $.fn.checkbox = function(parameters) { |
|
|
|
$module = $(this), |
|
|
|
$label = $(this).children(selector.label), |
|
|
|
$input = $(this).children(selector.input), |
|
|
|
input = $input[0], |
|
|
|
|
|
|
|
initialLoad = false, |
|
|
|
shortcutPressed = false, |
|
|
|
|
|
|
|
instance = $module.data(moduleNamespace), |
|
|
|
|
|
|
|
observer, |
|
|
@ -2496,35 +2497,26 @@ $.fn.checkbox = function(parameters) { |
|
|
|
}, |
|
|
|
|
|
|
|
setup: function() { |
|
|
|
module.set.initialLoad(); |
|
|
|
if( module.is.indeterminate() ) { |
|
|
|
module.debug('Initial value is indeterminate'); |
|
|
|
module.set.indeterminate(); |
|
|
|
if(settings.fireOnInit) { |
|
|
|
settings.onIndeterminate.call($input[0]); |
|
|
|
settings.onChange.call($input[0]); |
|
|
|
} |
|
|
|
module.indeterminate(); |
|
|
|
} |
|
|
|
else if( module.is.checked() ) { |
|
|
|
module.debug('Initial value is checked'); |
|
|
|
module.set.checked(); |
|
|
|
if(settings.fireOnInit) { |
|
|
|
settings.onChecked.call($input[0]); |
|
|
|
settings.onChange.call($input[0]); |
|
|
|
} |
|
|
|
module.check(); |
|
|
|
} |
|
|
|
else { |
|
|
|
module.debug('Initial value is unchecked'); |
|
|
|
module.set.unchecked(); |
|
|
|
if(settings.fireOnInit) { |
|
|
|
settings.onUnchecked.call($input[0]); |
|
|
|
settings.onChange.call($input[0]); |
|
|
|
} |
|
|
|
module.uncheck(); |
|
|
|
} |
|
|
|
module.remove.initialLoad(); |
|
|
|
}, |
|
|
|
|
|
|
|
refresh: function() { |
|
|
|
$label = $module.children(selector.label); |
|
|
|
$input = $module.children(selector.input); |
|
|
|
input = $input[0]; |
|
|
|
}, |
|
|
|
|
|
|
|
hide: { |
|
|
@ -2575,10 +2567,17 @@ $.fn.checkbox = function(parameters) { |
|
|
|
|
|
|
|
event: { |
|
|
|
click: function(event) { |
|
|
|
if( $(event.target).is(selector.input) ) { |
|
|
|
var |
|
|
|
$target = $(event.target) |
|
|
|
; |
|
|
|
if( $target.is(selector.input) ) { |
|
|
|
module.verbose('Using default check action on initialized checkbox'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if( $target.is(selector.link) ) { |
|
|
|
module.debug('Clicking link inside checkbox, skipping toggle'); |
|
|
|
return; |
|
|
|
} |
|
|
|
module.toggle(); |
|
|
|
$input.focus(); |
|
|
|
event.preventDefault(); |
|
|
@ -2614,47 +2613,53 @@ $.fn.checkbox = function(parameters) { |
|
|
|
}, |
|
|
|
|
|
|
|
check: function() { |
|
|
|
if( !module.is.indeterminate() && module.is.checked() ) { |
|
|
|
module.debug('Checkbox is already checked'); |
|
|
|
if( !module.should.allowCheck() ) { |
|
|
|
return; |
|
|
|
} |
|
|
|
module.debug('Checking checkbox', $input); |
|
|
|
module.set.checked(); |
|
|
|
settings.onChecked.call($input[0]); |
|
|
|
settings.onChange.call($input[0]); |
|
|
|
if( !module.should.ignoreCallbacks() ) { |
|
|
|
settings.onChecked.call(input); |
|
|
|
settings.onChange.call(input); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
uncheck: function() { |
|
|
|
if( !module.is.indeterminate() && module.is.unchecked() ) { |
|
|
|
module.debug('Checkbox is already unchecked'); |
|
|
|
if( !module.should.allowUncheck() ) { |
|
|
|
return; |
|
|
|
} |
|
|
|
module.debug('Unchecking checkbox'); |
|
|
|
module.set.unchecked(); |
|
|
|
settings.onUnchecked.call($input[0]); |
|
|
|
settings.onChange.call($input[0]); |
|
|
|
if( !module.should.ignoreCallbacks() ) { |
|
|
|
settings.onUnchecked.call(input); |
|
|
|
settings.onChange.call(input); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
indeterminate: function() { |
|
|
|
if( module.is.indeterminate() ) { |
|
|
|
if( module.should.allowIndeterminate() ) { |
|
|
|
module.debug('Checkbox is already indeterminate'); |
|
|
|
return; |
|
|
|
} |
|
|
|
module.debug('Making checkbox indeterminate'); |
|
|
|
module.set.indeterminate(); |
|
|
|
settings.onIndeterminate.call($input[0]); |
|
|
|
settings.onChange.call($input[0]); |
|
|
|
if( !module.should.ignoreCallbacks() ) { |
|
|
|
settings.onIndeterminate.call(input); |
|
|
|
settings.onChange.call(input); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
determinate: function() { |
|
|
|
if( module.is.determinate() ) { |
|
|
|
if( module.should.allowDeterminate() ) { |
|
|
|
module.debug('Checkbox is already determinate'); |
|
|
|
return; |
|
|
|
} |
|
|
|
module.debug('Making checkbox determinate'); |
|
|
|
module.set.determinate(); |
|
|
|
settings.onDeterminate.call($input[0]); |
|
|
|
settings.onChange.call($input[0]); |
|
|
|
if( !module.should.ignoreCallbacks() ) { |
|
|
|
settings.onDeterminate.call(input); |
|
|
|
settings.onChange.call(input); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
enable: function() { |
|
|
@ -2664,7 +2669,7 @@ $.fn.checkbox = function(parameters) { |
|
|
|
} |
|
|
|
module.debug('Enabling checkbox'); |
|
|
|
module.set.enabled(); |
|
|
|
settings.onEnable.call($input[0]); |
|
|
|
settings.onEnable.call(input); |
|
|
|
}, |
|
|
|
|
|
|
|
disable: function() { |
|
|
@ -2674,7 +2679,7 @@ $.fn.checkbox = function(parameters) { |
|
|
|
} |
|
|
|
module.debug('Disabling checkbox'); |
|
|
|
module.set.disabled(); |
|
|
|
settings.onDisable.call($input[0]); |
|
|
|
settings.onDisable.call(input); |
|
|
|
}, |
|
|
|
|
|
|
|
get: { |
|
|
@ -2693,6 +2698,9 @@ $.fn.checkbox = function(parameters) { |
|
|
|
}, |
|
|
|
|
|
|
|
is: { |
|
|
|
initialLoad: function() { |
|
|
|
return initialLoad; |
|
|
|
}, |
|
|
|
radio: function() { |
|
|
|
return ($input.hasClass(className.radio) || $input.attr('type') == 'radio'); |
|
|
|
}, |
|
|
@ -2716,6 +2724,59 @@ $.fn.checkbox = function(parameters) { |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
should: { |
|
|
|
allowCheck: function() { |
|
|
|
if(module.is.determinate() && module.is.checked() && !module.should.forceCallbacks() ) { |
|
|
|
module.debug('Should not allow check, checkbox is already checked'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if(settings.beforeChecked.apply(input) === false) { |
|
|
|
module.debug('Should not allow check, beforeChecked cancelled'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
}, |
|
|
|
allowUncheck: function() { |
|
|
|
if(module.is.determinate() && module.is.unchecked() && !module.should.forceCallbacks() ) { |
|
|
|
module.debug('Should not allow uncheck, checkbox is already unchecked'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if(settings.beforeUnchecked.apply(input) === false) { |
|
|
|
module.debug('Should not allow uncheck, beforeUnchecked cancelled'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
}, |
|
|
|
allowIndeterminate: function() { |
|
|
|
if(module.is.indeterminate() && !module.should.forceCallbacks() ) { |
|
|
|
module.debug('Should not allow indeterminate, checkbox is already indeterminate'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if(settings.beforeIndeterminate.apply(input) === false) { |
|
|
|
module.debug('Should not allow indeterminate, beforeIndeterminate cancelled'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
}, |
|
|
|
allowDeterminate: function() { |
|
|
|
if(module.is.determinate() && !module.should.forceCallbacks() ) { |
|
|
|
module.debug('Should not allow determinate, checkbox is already determinate'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if(settings.beforeDeterminate.apply(input) === false) { |
|
|
|
module.debug('Should not allow determinate, beforeDeterminate cancelled'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
}, |
|
|
|
forceCallbacks: function() { |
|
|
|
return (module.is.initialLoad() && settings.fireOnInit); |
|
|
|
}, |
|
|
|
ignoreCallbacks: function() { |
|
|
|
return (initialLoad && !settings.fireOnInit); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
can: { |
|
|
|
change: function() { |
|
|
|
return !( $module.hasClass(className.disabled) || $module.hasClass(className.readOnly) || $input.prop('disabled') || $input.prop('readonly') ); |
|
|
@ -2729,6 +2790,9 @@ $.fn.checkbox = function(parameters) { |
|
|
|
}, |
|
|
|
|
|
|
|
set: { |
|
|
|
initialLoad: function() { |
|
|
|
initialLoad = true; |
|
|
|
}, |
|
|
|
checked: function() { |
|
|
|
module.verbose('Setting class to checked'); |
|
|
|
$module |
|
|
@ -2742,7 +2806,7 @@ $.fn.checkbox = function(parameters) { |
|
|
|
module.debug('Input is already checked, skipping input property change'); |
|
|
|
return; |
|
|
|
} |
|
|
|
module.verbose('Setting state to checked', $input[0]); |
|
|
|
module.verbose('Setting state to checked', input); |
|
|
|
$input |
|
|
|
.prop('indeterminate', false) |
|
|
|
.prop('checked', true) |
|
|
@ -2831,6 +2895,12 @@ $.fn.checkbox = function(parameters) { |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
remove: { |
|
|
|
initialLoad: function() { |
|
|
|
initialLoad = false; |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
trigger: { |
|
|
|
change: function() { |
|
|
|
module.verbose('Triggering change event from programmatic change'); |
|
|
@ -3083,27 +3153,32 @@ $.fn.checkbox = function(parameters) { |
|
|
|
|
|
|
|
$.fn.checkbox.settings = { |
|
|
|
|
|
|
|
name : 'Checkbox', |
|
|
|
namespace : 'checkbox', |
|
|
|
name : 'Checkbox', |
|
|
|
namespace : 'checkbox', |
|
|
|
|
|
|
|
debug : false, |
|
|
|
verbose : true, |
|
|
|
performance : true, |
|
|
|
debug : false, |
|
|
|
verbose : true, |
|
|
|
performance : true, |
|
|
|
|
|
|
|
// delegated event context
|
|
|
|
uncheckable : 'auto', |
|
|
|
fireOnInit : false, |
|
|
|
uncheckable : 'auto', |
|
|
|
fireOnInit : false, |
|
|
|
|
|
|
|
onChange : function(){}, |
|
|
|
|
|
|
|
onChange : function(){}, |
|
|
|
beforeChecked : function(){}, |
|
|
|
beforeUnchecked : function(){}, |
|
|
|
beforeDeterminate : function(){}, |
|
|
|
beforeIndeterminate : function(){}, |
|
|
|
|
|
|
|
onChecked : function(){}, |
|
|
|
onUnchecked : function(){}, |
|
|
|
onChecked : function(){}, |
|
|
|
onUnchecked : function(){}, |
|
|
|
|
|
|
|
onDeterminate : function() {}, |
|
|
|
onIndeterminate : function() {}, |
|
|
|
onDeterminate : function() {}, |
|
|
|
onIndeterminate : function() {}, |
|
|
|
|
|
|
|
onEnabled : function(){}, |
|
|
|
onDisabled : function(){}, |
|
|
|
onEnabled : function(){}, |
|
|
|
onDisabled : function(){}, |
|
|
|
|
|
|
|
className : { |
|
|
|
checked : 'checked', |
|
|
@ -3122,6 +3197,7 @@ $.fn.checkbox.settings = { |
|
|
|
checkbox : '.ui.checkbox', |
|
|
|
label : 'label, .box', |
|
|
|
input : 'input[type="checkbox"], input[type="radio"]', |
|
|
|
link : 'a[href]' |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|