From 3552fb525731ff5e9e584cd620a0f570e438cd6c Mon Sep 17 00:00:00 2001 From: Jack Lukic Date: Wed, 12 Aug 2015 18:39:00 -0400 Subject: [PATCH] formatting and build dist #2656 --- dist/components/checkbox.js | 172 ++++++++++++++++++++-------- dist/components/checkbox.min.js | 2 +- dist/semantic.js | 172 ++++++++++++++++++++-------- dist/semantic.min.js | 20 ++-- src/definitions/modules/checkbox.js | 2 +- 5 files changed, 262 insertions(+), 106 deletions(-) diff --git a/dist/components/checkbox.js b/dist/components/checkbox.js index cc3fbe27b..7a902bbc6 100644 --- a/dist/components/checkbox.js +++ b/dist/components/checkbox.js @@ -43,9 +43,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, @@ -95,35 +96,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: { @@ -174,10 +166,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(); @@ -213,47 +212,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() { @@ -263,7 +268,7 @@ $.fn.checkbox = function(parameters) { } module.debug('Enabling checkbox'); module.set.enabled(); - settings.onEnable.call($input[0]); + settings.onEnable.call(input); }, disable: function() { @@ -273,7 +278,7 @@ $.fn.checkbox = function(parameters) { } module.debug('Disabling checkbox'); module.set.disabled(); - settings.onDisable.call($input[0]); + settings.onDisable.call(input); }, get: { @@ -292,6 +297,9 @@ $.fn.checkbox = function(parameters) { }, is: { + initialLoad: function() { + return initialLoad; + }, radio: function() { return ($input.hasClass(className.radio) || $input.attr('type') == 'radio'); }, @@ -315,6 +323,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') ); @@ -328,6 +389,9 @@ $.fn.checkbox = function(parameters) { }, set: { + initialLoad: function() { + initialLoad = true; + }, checked: function() { module.verbose('Setting class to checked'); $module @@ -341,7 +405,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) @@ -430,6 +494,12 @@ $.fn.checkbox = function(parameters) { } }, + remove: { + initialLoad: function() { + initialLoad = false; + } + }, + trigger: { change: function() { module.verbose('Triggering change event from programmatic change'); @@ -682,27 +752,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', @@ -721,6 +796,7 @@ $.fn.checkbox.settings = { checkbox : '.ui.checkbox', label : 'label, .box', input : 'input[type="checkbox"], input[type="radio"]', + link : 'a[href]' } }; diff --git a/dist/components/checkbox.min.js b/dist/components/checkbox.min.js index d322ba5d7..f4fef39a1 100644 --- a/dist/components/checkbox.min.js +++ b/dist/components/checkbox.min.js @@ -8,4 +8,4 @@ * http://opensource.org/licenses/MIT * */ -!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 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 z-index to be unselectable"),C.addClass(h.hidden)}},show:{input:function(){b.verbose("Modfying 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("