semantic-ui-checkbox
Advanced tools
Comparing version 2.0.8 to 2.1.3
174
checkbox.js
/*! | ||
* # Semantic UI 2.0.8 - Checkbox | ||
* # Semantic UI 2.1.3 - Checkbox | ||
* http://github.com/semantic-org/semantic-ui/ | ||
@@ -46,5 +46,6 @@ * | ||
$input = $(this).children(selector.input), | ||
input = $input[0], | ||
initialLoad = false, | ||
shortcutPressed = false, | ||
instance = $module.data(moduleNamespace), | ||
@@ -99,26 +100,16 @@ | ||
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(); | ||
}, | ||
@@ -129,2 +120,3 @@ | ||
$input = $module.children(selector.input); | ||
input = $input[0]; | ||
}, | ||
@@ -180,6 +172,13 @@ | ||
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(); | ||
@@ -220,4 +219,3 @@ $input.focus(); | ||
check: function() { | ||
if( !module.is.indeterminate() && module.is.checked() ) { | ||
module.debug('Checkbox is already checked'); | ||
if( !module.should.allowCheck() ) { | ||
return; | ||
@@ -227,9 +225,10 @@ } | ||
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; | ||
@@ -239,8 +238,10 @@ } | ||
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'); | ||
@@ -251,8 +252,10 @@ return; | ||
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'); | ||
@@ -263,4 +266,6 @@ return; | ||
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); | ||
} | ||
}, | ||
@@ -275,3 +280,3 @@ | ||
module.set.enabled(); | ||
settings.onEnable.call($input[0]); | ||
settings.onEnable.call(input); | ||
}, | ||
@@ -286,3 +291,3 @@ | ||
module.set.disabled(); | ||
settings.onDisable.call($input[0]); | ||
settings.onDisable.call(input); | ||
}, | ||
@@ -306,2 +311,5 @@ | ||
is: { | ||
initialLoad: function() { | ||
return initialLoad; | ||
}, | ||
radio: function() { | ||
@@ -330,2 +338,55 @@ return ($input.hasClass(className.radio) || $input.attr('type') == 'radio'); | ||
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: { | ||
@@ -344,2 +405,5 @@ change: function() { | ||
set: { | ||
initialLoad: function() { | ||
initialLoad = true; | ||
}, | ||
checked: function() { | ||
@@ -358,3 +422,3 @@ module.verbose('Setting class to checked'); | ||
} | ||
module.verbose('Setting state to checked', $input[0]); | ||
module.verbose('Setting state to checked', input); | ||
$input | ||
@@ -448,2 +512,8 @@ .prop('indeterminate', false) | ||
remove: { | ||
initialLoad: function() { | ||
initialLoad = false; | ||
} | ||
}, | ||
trigger: { | ||
@@ -701,24 +771,29 @@ change: function() { | ||
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(){}, | ||
onChecked : function(){}, | ||
onUnchecked : function(){}, | ||
beforeChecked : function(){}, | ||
beforeUnchecked : function(){}, | ||
beforeDeterminate : function(){}, | ||
beforeIndeterminate : function(){}, | ||
onDeterminate : function() {}, | ||
onIndeterminate : function() {}, | ||
onChecked : function(){}, | ||
onUnchecked : function(){}, | ||
onEnabled : function(){}, | ||
onDisabled : function(){}, | ||
onDeterminate : function() {}, | ||
onIndeterminate : function() {}, | ||
onEnabled : function(){}, | ||
onDisabled : function(){}, | ||
className : { | ||
@@ -741,2 +816,3 @@ checked : 'checked', | ||
input : 'input[type="checkbox"], input[type="radio"]', | ||
link : 'a[href]' | ||
} | ||
@@ -743,0 +819,0 @@ |
/*! | ||
* # Semantic UI 2.0.8 - Checkbox | ||
* # Semantic UI 2.1.3 - Checkbox | ||
* http://github.com/semantic-org/semantic-ui/ | ||
@@ -11,2 +11,2 @@ * | ||
*/ | ||
!function(e,n,t,i){"use strict";e.fn.checkbox=function(t){var o,r=e(this),a=r.selector||"",c=(new Date).getTime(),d=[],s=arguments[0],l="string"==typeof s,u=[].slice.call(arguments,1);return r.each(function(){var r,b,g=e.extend(!0,{},e.fn.checkbox.settings,t),h=g.className,p=g.namespace,m=g.selector,f=g.error,k="."+p,v="module-"+p,y=e(this),x=e(this).children(m.label),C=e(this).children(m.input),I=!1,O=y.data(v),D=this;b={initialize:function(){b.verbose("Initializing checkbox",g),b.create.label(),b.bind.events(),b.set.tabbable(),b.hide.input(),b.observeChanges(),b.instantiate(),b.setup()},instantiate:function(){b.verbose("Storing instance of module",b),O=b,y.data(v,b)},destroy:function(){b.verbose("Destroying module"),b.unbind.events(),b.show.input(),y.removeData(v)},fix:{reference:function(){y.is(m.input)&&(b.debug("Behavior called on <input> adjusting invoked element"),y=y.closest(m.checkbox),b.refresh())}},setup:function(){b.is.indeterminate()?(b.debug("Initial value is indeterminate"),b.set.indeterminate(),g.fireOnInit&&(g.onIndeterminate.call(C[0]),g.onChange.call(C[0]))):b.is.checked()?(b.debug("Initial value is checked"),b.set.checked(),g.fireOnInit&&(g.onChecked.call(C[0]),g.onChange.call(C[0]))):(b.debug("Initial value is unchecked"),b.set.unchecked(),g.fireOnInit&&(g.onUnchecked.call(C[0]),g.onChange.call(C[0])))},refresh:function(){x=y.children(m.label),C=y.children(m.input)},hide:{input:function(){b.verbose("Modfying <input> z-index to be unselectable"),C.addClass(h.hidden)}},show:{input:function(){b.verbose("Modfying <input> z-index to be selectable"),C.removeClass(h.hidden)}},observeChanges:function(){"MutationObserver"in n&&(r=new MutationObserver(function(e){b.debug("DOM tree modified, updating selector cache"),b.refresh()}),r.observe(D,{childList:!0,subtree:!0}),b.debug("Setting up mutation observer",r))},attachEvents:function(n,t){var i=e(n);t=e.isFunction(b[t])?b[t]:b.toggle,i.length>0?(b.debug("Attaching checkbox events to element",n,t),i.on("click"+k,t)):b.error(f.notFound)},event:{click:function(n){return e(n.target).is(m.input)?void b.verbose("Using default check action on initialized checkbox"):(b.toggle(),C.focus(),void n.preventDefault())},keydown:function(e){var n=e.which,t={enter:13,space:32,escape:27};n==t.escape?(b.verbose("Escape key pressed blurring field"),C.blur(),I=!0):e.ctrlKey||n!=t.space&&n!=t.enter?I=!1:(b.verbose("Enter/space key pressed, toggling checkbox"),b.toggle(),I=!0)},keyup:function(e){I&&e.preventDefault()}},check:function(){return!b.is.indeterminate()&&b.is.checked()?void b.debug("Checkbox is already checked"):(b.debug("Checking checkbox",C),b.set.checked(),g.onChecked.call(C[0]),void g.onChange.call(C[0]))},uncheck:function(){return!b.is.indeterminate()&&b.is.unchecked()?void b.debug("Checkbox is already unchecked"):(b.debug("Unchecking checkbox"),b.set.unchecked(),g.onUnchecked.call(C[0]),void g.onChange.call(C[0]))},indeterminate:function(){return b.is.indeterminate()?void b.debug("Checkbox is already indeterminate"):(b.debug("Making checkbox indeterminate"),b.set.indeterminate(),g.onIndeterminate.call(C[0]),void g.onChange.call(C[0]))},determinate:function(){return b.is.determinate()?void b.debug("Checkbox is already determinate"):(b.debug("Making checkbox determinate"),b.set.determinate(),g.onDeterminate.call(C[0]),void g.onChange.call(C[0]))},enable:function(){return b.is.enabled()?void b.debug("Checkbox is already enabled"):(b.debug("Enabling checkbox"),b.set.enabled(),void g.onEnable.call(C[0]))},disable:function(){return b.is.disabled()?void b.debug("Checkbox is already disabled"):(b.debug("Disabling checkbox"),b.set.disabled(),void g.onDisable.call(C[0]))},get:{radios:function(){var n=b.get.name();return e('input[name="'+n+'"]').closest(m.checkbox)},otherRadios:function(){return b.get.radios().not(y)},name:function(){return C.attr("name")}},is:{radio:function(){return C.hasClass(h.radio)||"radio"==C.attr("type")},indeterminate:function(){return C.prop("indeterminate")!==i&&C.prop("indeterminate")},checked:function(){return C.prop("checked")!==i&&C.prop("checked")},disabled:function(){return C.prop("disabled")!==i&&C.prop("disabled")},enabled:function(){return!b.is.disabled()},determinate:function(){return!b.is.indeterminate()},unchecked:function(){return!b.is.checked()}},can:{change:function(){return!(y.hasClass(h.disabled)||y.hasClass(h.readOnly)||C.prop("disabled")||C.prop("readonly"))},uncheck:function(){return"boolean"==typeof g.uncheckable?g.uncheckable:!b.is.radio()}},set:{checked:function(){return b.verbose("Setting class to checked"),y.removeClass(h.indeterminate).addClass(h.checked),b.is.radio()&&b.uncheckOthers(),!b.is.indeterminate()&&b.is.checked()?void b.debug("Input is already checked, skipping input property change"):(b.verbose("Setting state to checked",C[0]),C.prop("indeterminate",!1).prop("checked",!0),void b.trigger.change())},unchecked:function(){return b.verbose("Removing checked class"),y.removeClass(h.indeterminate).removeClass(h.checked),!b.is.indeterminate()&&b.is.unchecked()?void b.debug("Input is already unchecked"):(b.debug("Setting state to unchecked"),C.prop("indeterminate",!1).prop("checked",!1),void b.trigger.change())},indeterminate:function(){return b.verbose("Setting class to indeterminate"),y.addClass(h.indeterminate),b.is.indeterminate()?void b.debug("Input is already indeterminate, skipping input property change"):(b.debug("Setting state to indeterminate"),C.prop("indeterminate",!0),void b.trigger.change())},determinate:function(){return b.verbose("Removing indeterminate class"),y.removeClass(h.indeterminate),b.is.determinate()?void b.debug("Input is already determinate, skipping input property change"):(b.debug("Setting state to determinate"),void C.prop("indeterminate",!1))},disabled:function(){return b.verbose("Setting class to disabled"),y.addClass(h.disabled),b.is.disabled()?void b.debug("Input is already disabled, skipping input property change"):(b.debug("Setting state to disabled"),C.prop("disabled","disabled"),void b.trigger.change())},enabled:function(){return b.verbose("Removing disabled class"),y.removeClass(h.disabled),b.is.enabled()?void b.debug("Input is already enabled, skipping input property change"):(b.debug("Setting state to enabled"),C.prop("disabled",!1),void b.trigger.change())},tabbable:function(){b.verbose("Adding tabindex to checkbox"),C.attr("tabindex")===i&&C.attr("tabindex",0)}},trigger:{change:function(){b.verbose("Triggering change event from programmatic change"),C.trigger("change")}},create:{label:function(){C.prevAll(m.label).length>0?(C.prev(m.label).detach().insertAfter(C),b.debug("Moving existing label",x)):b.has.label()||(x=e("<label>").insertAfter(C),b.debug("Creating label",x))}},has:{label:function(){return x.length>0}},bind:{events:function(){b.verbose("Attaching checkbox events"),y.on("click"+k,b.event.click).on("keydown"+k,m.input,b.event.keydown).on("keyup"+k,m.input,b.event.keyup)}},unbind:{events:function(){b.debug("Removing events"),y.off(k)}},uncheckOthers:function(){var e=b.get.otherRadios();b.debug("Unchecking other radios",e),e.removeClass(h.checked)},toggle:function(){return b.can.change()?void(b.is.indeterminate()||b.is.unchecked()?(b.debug("Currently unchecked"),b.check()):b.is.checked()&&b.can.uncheck()&&(b.debug("Currently checked"),b.uncheck())):void(b.is.radio()||b.debug("Checkbox is read-only or disabled, ignoring toggle"))},setting:function(n,t){if(b.debug("Changing setting",n,t),e.isPlainObject(n))e.extend(!0,g,n);else{if(t===i)return g[n];g[n]=t}},internal:function(n,t){if(e.isPlainObject(n))e.extend(!0,b,n);else{if(t===i)return b[n];b[n]=t}},debug:function(){g.debug&&(g.performance?b.performance.log(arguments):(b.debug=Function.prototype.bind.call(console.info,console,g.name+":"),b.debug.apply(console,arguments)))},verbose:function(){g.verbose&&g.debug&&(g.performance?b.performance.log(arguments):(b.verbose=Function.prototype.bind.call(console.info,console,g.name+":"),b.verbose.apply(console,arguments)))},error:function(){b.error=Function.prototype.bind.call(console.error,console,g.name+":"),b.error.apply(console,arguments)},performance:{log:function(e){var n,t,i;g.performance&&(n=(new Date).getTime(),i=c||n,t=n-i,c=n,d.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:D,"Execution Time":t})),clearTimeout(b.performance.timer),b.performance.timer=setTimeout(b.performance.display,500)},display:function(){var n=g.name+":",t=0;c=!1,clearTimeout(b.performance.timer),e.each(d,function(e,n){t+=n["Execution Time"]}),n+=" "+t+"ms",a&&(n+=" '"+a+"'"),(console.group!==i||console.table!==i)&&d.length>0&&(console.groupCollapsed(n),console.table?console.table(d):e.each(d,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),d=[]}},invoke:function(n,t,r){var a,c,d,s=O;return t=t||u,r=D||r,"string"==typeof n&&s!==i&&(n=n.split(/[\. ]/),a=n.length-1,e.each(n,function(t,o){var r=t!=a?o+n[t+1].charAt(0).toUpperCase()+n[t+1].slice(1):n;if(e.isPlainObject(s[r])&&t!=a)s=s[r];else{if(s[r]!==i)return c=s[r],!1;if(!e.isPlainObject(s[o])||t==a)return s[o]!==i?(c=s[o],!1):(b.error(f.method,n),!1);s=s[o]}})),e.isFunction(c)?d=c.apply(r,t):c!==i&&(d=c),e.isArray(o)?o.push(d):o!==i?o=[o,d]:d!==i&&(o=d),c}},l?(O===i&&b.initialize(),b.invoke(s)):(O!==i&&O.invoke("destroy"),b.initialize())}),o!==i?o:this},e.fn.checkbox.settings={name:"Checkbox",namespace:"checkbox",debug:!1,verbose:!0,performance:!0,uncheckable:"auto",fireOnInit:!1,onChange:function(){},onChecked:function(){},onUnchecked:function(){},onDeterminate:function(){},onIndeterminate:function(){},onEnabled:function(){},onDisabled:function(){},className:{checked:"checked",indeterminate:"indeterminate",disabled:"disabled",hidden:"hidden",radio:"radio",readOnly:"read-only"},error:{method:"The method you called is not defined"},selector:{checkbox:".ui.checkbox",label:"label, .box",input:'input[type="checkbox"], input[type="radio"]'}}}(jQuery,window,document); | ||
!function(e,n,t,i){"use strict";e.fn.checkbox=function(t){var o,a=e(this),c=a.selector||"",r=(new Date).getTime(),d=[],l=arguments[0],s="string"==typeof l,u=[].slice.call(arguments,1);return a.each(function(){var a,b,h=e.extend(!0,{},e.fn.checkbox.settings,t),g=h.className,p=h.namespace,f=h.selector,k=h.error,m="."+p,v="module-"+p,y=e(this),C=e(this).children(f.label),x=e(this).children(f.input),w=x[0],I=!1,S=!1,D=y.data(v),O=this;b={initialize:function(){b.verbose("Initializing checkbox",h),b.create.label(),b.bind.events(),b.set.tabbable(),b.hide.input(),b.observeChanges(),b.instantiate(),b.setup()},instantiate:function(){b.verbose("Storing instance of module",b),D=b,y.data(v,b)},destroy:function(){b.verbose("Destroying module"),b.unbind.events(),b.show.input(),y.removeData(v)},fix:{reference:function(){y.is(f.input)&&(b.debug("Behavior called on <input> adjusting invoked element"),y=y.closest(f.checkbox),b.refresh())}},setup:function(){b.set.initialLoad(),b.is.indeterminate()?(b.debug("Initial value is indeterminate"),b.indeterminate()):b.is.checked()?(b.debug("Initial value is checked"),b.check()):(b.debug("Initial value is unchecked"),b.uncheck()),b.remove.initialLoad()},refresh:function(){C=y.children(f.label),x=y.children(f.input),w=x[0]},hide:{input:function(){b.verbose("Modfying <input> z-index to be unselectable"),x.addClass(g.hidden)}},show:{input:function(){b.verbose("Modfying <input> z-index to be selectable"),x.removeClass(g.hidden)}},observeChanges:function(){"MutationObserver"in n&&(a=new MutationObserver(function(e){b.debug("DOM tree modified, updating selector cache"),b.refresh()}),a.observe(O,{childList:!0,subtree:!0}),b.debug("Setting up mutation observer",a))},attachEvents:function(n,t){var i=e(n);t=e.isFunction(b[t])?b[t]:b.toggle,i.length>0?(b.debug("Attaching checkbox events to element",n,t),i.on("click"+m,t)):b.error(k.notFound)},event:{click:function(n){var t=e(n.target);return t.is(f.input)?void b.verbose("Using default check action on initialized checkbox"):t.is(f.link)?void b.debug("Clicking link inside checkbox, skipping toggle"):(b.toggle(),x.focus(),void n.preventDefault())},keydown:function(e){var n=e.which,t={enter:13,space:32,escape:27};n==t.escape?(b.verbose("Escape key pressed blurring field"),x.blur(),S=!0):e.ctrlKey||n!=t.space&&n!=t.enter?S=!1:(b.verbose("Enter/space key pressed, toggling checkbox"),b.toggle(),S=!0)},keyup:function(e){S&&e.preventDefault()}},check:function(){b.should.allowCheck()&&(b.debug("Checking checkbox",x),b.set.checked(),b.should.ignoreCallbacks()||(h.onChecked.call(w),h.onChange.call(w)))},uncheck:function(){b.should.allowUncheck()&&(b.debug("Unchecking checkbox"),b.set.unchecked(),b.should.ignoreCallbacks()||(h.onUnchecked.call(w),h.onChange.call(w)))},indeterminate:function(){return b.should.allowIndeterminate()?void b.debug("Checkbox is already indeterminate"):(b.debug("Making checkbox indeterminate"),b.set.indeterminate(),void(b.should.ignoreCallbacks()||(h.onIndeterminate.call(w),h.onChange.call(w))))},determinate:function(){return b.should.allowDeterminate()?void b.debug("Checkbox is already determinate"):(b.debug("Making checkbox determinate"),b.set.determinate(),void(b.should.ignoreCallbacks()||(h.onDeterminate.call(w),h.onChange.call(w))))},enable:function(){return b.is.enabled()?void b.debug("Checkbox is already enabled"):(b.debug("Enabling checkbox"),b.set.enabled(),void h.onEnable.call(w))},disable:function(){return b.is.disabled()?void b.debug("Checkbox is already disabled"):(b.debug("Disabling checkbox"),b.set.disabled(),void h.onDisable.call(w))},get:{radios:function(){var n=b.get.name();return e('input[name="'+n+'"]').closest(f.checkbox)},otherRadios:function(){return b.get.radios().not(y)},name:function(){return x.attr("name")}},is:{initialLoad:function(){return I},radio:function(){return x.hasClass(g.radio)||"radio"==x.attr("type")},indeterminate:function(){return x.prop("indeterminate")!==i&&x.prop("indeterminate")},checked:function(){return x.prop("checked")!==i&&x.prop("checked")},disabled:function(){return x.prop("disabled")!==i&&x.prop("disabled")},enabled:function(){return!b.is.disabled()},determinate:function(){return!b.is.indeterminate()},unchecked:function(){return!b.is.checked()}},should:{allowCheck:function(){return b.is.determinate()&&b.is.checked()&&!b.should.forceCallbacks()?(b.debug("Should not allow check, checkbox is already checked"),!1):h.beforeChecked.apply(w)===!1?(b.debug("Should not allow check, beforeChecked cancelled"),!1):!0},allowUncheck:function(){return b.is.determinate()&&b.is.unchecked()&&!b.should.forceCallbacks()?(b.debug("Should not allow uncheck, checkbox is already unchecked"),!1):h.beforeUnchecked.apply(w)===!1?(b.debug("Should not allow uncheck, beforeUnchecked cancelled"),!1):!0},allowIndeterminate:function(){return b.is.indeterminate()&&!b.should.forceCallbacks()?(b.debug("Should not allow indeterminate, checkbox is already indeterminate"),!1):h.beforeIndeterminate.apply(w)===!1?(b.debug("Should not allow indeterminate, beforeIndeterminate cancelled"),!1):!0},allowDeterminate:function(){return b.is.determinate()&&!b.should.forceCallbacks()?(b.debug("Should not allow determinate, checkbox is already determinate"),!1):h.beforeDeterminate.apply(w)===!1?(b.debug("Should not allow determinate, beforeDeterminate cancelled"),!1):!0},forceCallbacks:function(){return b.is.initialLoad()&&h.fireOnInit},ignoreCallbacks:function(){return I&&!h.fireOnInit}},can:{change:function(){return!(y.hasClass(g.disabled)||y.hasClass(g.readOnly)||x.prop("disabled")||x.prop("readonly"))},uncheck:function(){return"boolean"==typeof h.uncheckable?h.uncheckable:!b.is.radio()}},set:{initialLoad:function(){I=!0},checked:function(){return b.verbose("Setting class to checked"),y.removeClass(g.indeterminate).addClass(g.checked),b.is.radio()&&b.uncheckOthers(),!b.is.indeterminate()&&b.is.checked()?void b.debug("Input is already checked, skipping input property change"):(b.verbose("Setting state to checked",w),x.prop("indeterminate",!1).prop("checked",!0),void b.trigger.change())},unchecked:function(){return b.verbose("Removing checked class"),y.removeClass(g.indeterminate).removeClass(g.checked),!b.is.indeterminate()&&b.is.unchecked()?void b.debug("Input is already unchecked"):(b.debug("Setting state to unchecked"),x.prop("indeterminate",!1).prop("checked",!1),void b.trigger.change())},indeterminate:function(){return b.verbose("Setting class to indeterminate"),y.addClass(g.indeterminate),b.is.indeterminate()?void b.debug("Input is already indeterminate, skipping input property change"):(b.debug("Setting state to indeterminate"),x.prop("indeterminate",!0),void b.trigger.change())},determinate:function(){return b.verbose("Removing indeterminate class"),y.removeClass(g.indeterminate),b.is.determinate()?void b.debug("Input is already determinate, skipping input property change"):(b.debug("Setting state to determinate"),void x.prop("indeterminate",!1))},disabled:function(){return b.verbose("Setting class to disabled"),y.addClass(g.disabled),b.is.disabled()?void b.debug("Input is already disabled, skipping input property change"):(b.debug("Setting state to disabled"),x.prop("disabled","disabled"),void b.trigger.change())},enabled:function(){return b.verbose("Removing disabled class"),y.removeClass(g.disabled),b.is.enabled()?void b.debug("Input is already enabled, skipping input property change"):(b.debug("Setting state to enabled"),x.prop("disabled",!1),void b.trigger.change())},tabbable:function(){b.verbose("Adding tabindex to checkbox"),x.attr("tabindex")===i&&x.attr("tabindex",0)}},remove:{initialLoad:function(){I=!1}},trigger:{change:function(){b.verbose("Triggering change event from programmatic change"),x.trigger("change")}},create:{label:function(){x.prevAll(f.label).length>0?(x.prev(f.label).detach().insertAfter(x),b.debug("Moving existing label",C)):b.has.label()||(C=e("<label>").insertAfter(x),b.debug("Creating label",C))}},has:{label:function(){return C.length>0}},bind:{events:function(){b.verbose("Attaching checkbox events"),y.on("click"+m,b.event.click).on("keydown"+m,f.input,b.event.keydown).on("keyup"+m,f.input,b.event.keyup)}},unbind:{events:function(){b.debug("Removing events"),y.off(m)}},uncheckOthers:function(){var e=b.get.otherRadios();b.debug("Unchecking other radios",e),e.removeClass(g.checked)},toggle:function(){return b.can.change()?void(b.is.indeterminate()||b.is.unchecked()?(b.debug("Currently unchecked"),b.check()):b.is.checked()&&b.can.uncheck()&&(b.debug("Currently checked"),b.uncheck())):void(b.is.radio()||b.debug("Checkbox is read-only or disabled, ignoring toggle"))},setting:function(n,t){if(b.debug("Changing setting",n,t),e.isPlainObject(n))e.extend(!0,h,n);else{if(t===i)return h[n];h[n]=t}},internal:function(n,t){if(e.isPlainObject(n))e.extend(!0,b,n);else{if(t===i)return b[n];b[n]=t}},debug:function(){h.debug&&(h.performance?b.performance.log(arguments):(b.debug=Function.prototype.bind.call(console.info,console,h.name+":"),b.debug.apply(console,arguments)))},verbose:function(){h.verbose&&h.debug&&(h.performance?b.performance.log(arguments):(b.verbose=Function.prototype.bind.call(console.info,console,h.name+":"),b.verbose.apply(console,arguments)))},error:function(){b.error=Function.prototype.bind.call(console.error,console,h.name+":"),b.error.apply(console,arguments)},performance:{log:function(e){var n,t,i;h.performance&&(n=(new Date).getTime(),i=r||n,t=n-i,r=n,d.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:O,"Execution Time":t})),clearTimeout(b.performance.timer),b.performance.timer=setTimeout(b.performance.display,500)},display:function(){var n=h.name+":",t=0;r=!1,clearTimeout(b.performance.timer),e.each(d,function(e,n){t+=n["Execution Time"]}),n+=" "+t+"ms",c&&(n+=" '"+c+"'"),(console.group!==i||console.table!==i)&&d.length>0&&(console.groupCollapsed(n),console.table?console.table(d):e.each(d,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),d=[]}},invoke:function(n,t,a){var c,r,d,l=D;return t=t||u,a=O||a,"string"==typeof n&&l!==i&&(n=n.split(/[\. ]/),c=n.length-1,e.each(n,function(t,o){var a=t!=c?o+n[t+1].charAt(0).toUpperCase()+n[t+1].slice(1):n;if(e.isPlainObject(l[a])&&t!=c)l=l[a];else{if(l[a]!==i)return r=l[a],!1;if(!e.isPlainObject(l[o])||t==c)return l[o]!==i?(r=l[o],!1):(b.error(k.method,n),!1);l=l[o]}})),e.isFunction(r)?d=r.apply(a,t):r!==i&&(d=r),e.isArray(o)?o.push(d):o!==i?o=[o,d]:d!==i&&(o=d),r}},s?(D===i&&b.initialize(),b.invoke(l)):(D!==i&&D.invoke("destroy"),b.initialize())}),o!==i?o:this},e.fn.checkbox.settings={name:"Checkbox",namespace:"checkbox",debug:!1,verbose:!0,performance:!0,uncheckable:"auto",fireOnInit:!1,onChange:function(){},beforeChecked:function(){},beforeUnchecked:function(){},beforeDeterminate:function(){},beforeIndeterminate:function(){},onChecked:function(){},onUnchecked:function(){},onDeterminate:function(){},onIndeterminate:function(){},onEnabled:function(){},onDisabled:function(){},className:{checked:"checked",indeterminate:"indeterminate",disabled:"disabled",hidden:"hidden",radio:"radio",readOnly:"read-only"},error:{method:"The method you called is not defined"},selector:{checkbox:".ui.checkbox",label:"label, .box",input:'input[type="checkbox"], input[type="radio"]',link:"a[href]"}}}(jQuery,window,document); |
@@ -18,3 +18,3 @@ { | ||
"license": "MIT", | ||
"version": "2.0.8" | ||
"version": "2.1.3" | ||
} |
174
index.js
/*! | ||
* # Semantic UI 2.0.8 - Checkbox | ||
* # Semantic UI 2.1.3 - Checkbox | ||
* http://github.com/semantic-org/semantic-ui/ | ||
@@ -47,5 +47,6 @@ * | ||
$input = $(this).children(selector.input), | ||
input = $input[0], | ||
initialLoad = false, | ||
shortcutPressed = false, | ||
instance = $module.data(moduleNamespace), | ||
@@ -100,26 +101,16 @@ | ||
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(); | ||
}, | ||
@@ -130,2 +121,3 @@ | ||
$input = $module.children(selector.input); | ||
input = $input[0]; | ||
}, | ||
@@ -181,6 +173,13 @@ | ||
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(); | ||
@@ -221,4 +220,3 @@ $input.focus(); | ||
check: function() { | ||
if( !module.is.indeterminate() && module.is.checked() ) { | ||
module.debug('Checkbox is already checked'); | ||
if( !module.should.allowCheck() ) { | ||
return; | ||
@@ -228,9 +226,10 @@ } | ||
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; | ||
@@ -240,8 +239,10 @@ } | ||
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'); | ||
@@ -252,8 +253,10 @@ return; | ||
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'); | ||
@@ -264,4 +267,6 @@ return; | ||
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); | ||
} | ||
}, | ||
@@ -276,3 +281,3 @@ | ||
module.set.enabled(); | ||
settings.onEnable.call($input[0]); | ||
settings.onEnable.call(input); | ||
}, | ||
@@ -287,3 +292,3 @@ | ||
module.set.disabled(); | ||
settings.onDisable.call($input[0]); | ||
settings.onDisable.call(input); | ||
}, | ||
@@ -307,2 +312,5 @@ | ||
is: { | ||
initialLoad: function() { | ||
return initialLoad; | ||
}, | ||
radio: function() { | ||
@@ -331,2 +339,55 @@ return ($input.hasClass(className.radio) || $input.attr('type') == 'radio'); | ||
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: { | ||
@@ -345,2 +406,5 @@ change: function() { | ||
set: { | ||
initialLoad: function() { | ||
initialLoad = true; | ||
}, | ||
checked: function() { | ||
@@ -359,3 +423,3 @@ module.verbose('Setting class to checked'); | ||
} | ||
module.verbose('Setting state to checked', $input[0]); | ||
module.verbose('Setting state to checked', input); | ||
$input | ||
@@ -449,2 +513,8 @@ .prop('indeterminate', false) | ||
remove: { | ||
initialLoad: function() { | ||
initialLoad = false; | ||
} | ||
}, | ||
trigger: { | ||
@@ -702,24 +772,29 @@ change: function() { | ||
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(){}, | ||
onChecked : function(){}, | ||
onUnchecked : function(){}, | ||
beforeChecked : function(){}, | ||
beforeUnchecked : function(){}, | ||
beforeDeterminate : function(){}, | ||
beforeIndeterminate : function(){}, | ||
onDeterminate : function() {}, | ||
onIndeterminate : function() {}, | ||
onChecked : function(){}, | ||
onUnchecked : function(){}, | ||
onEnabled : function(){}, | ||
onDisabled : function(){}, | ||
onDeterminate : function() {}, | ||
onIndeterminate : function() {}, | ||
onEnabled : function(){}, | ||
onDisabled : function(){}, | ||
className : { | ||
@@ -742,2 +817,3 @@ checked : 'checked', | ||
input : 'input[type="checkbox"], input[type="radio"]', | ||
link : 'a[href]' | ||
} | ||
@@ -744,0 +820,0 @@ |
@@ -5,3 +5,3 @@ | ||
summary : 'Semantic UI - Checkbox: Single component release', | ||
version : '2.0.8', | ||
version : '2.1.3', | ||
git : 'git://github.com/Semantic-Org/UI-Checkbox.git', | ||
@@ -8,0 +8,0 @@ }); |
{ | ||
"name": "semantic-ui-checkbox", | ||
"version": "2.0.8", | ||
"version": "2.1.3", | ||
"title": "Semantic UI - Checkbox", | ||
@@ -5,0 +5,0 @@ "description": "Single component release of checkbox", |
@@ -0,1 +1,11 @@ | ||
#### Features | ||
- **Checkbox** - Added 4 new callbacks `beforeChecked`, `beforeUnchecked`, `beforeDeterminate`, `beforeIndeterminate`. You can now cancel a state change by returning false from these callbacks. | ||
#### Bugs | ||
- **Checkbox** - Clicking a link inside an initialized checkbox `label` will now work correctly, and will not toggle the checkbox. [#2804](https://github.com/Semantic-Org/Semantic-UI/issues/2804) | ||
- **Form** - `disabled field(s)` now remove `pointer-events` allowing it to disable checkbox and dropdown functionality [#555](https://github.com/Semantic-Org/Semantic-UI/issues/#555) | ||
- **Form Validation** - Fixed issue with `get value(s)` where unchecked checkboxes would not correctly retrieve values | ||
### Version 2.0.7 - July 23, 2015 | ||
@@ -2,0 +12,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
98206
2113