wishthis/semantic/dist/components/checkbox.min.js

11 lines
12 KiB
JavaScript
Raw Normal View History

2022-01-13 13:00:31 +00:00
/*
* # Fomantic UI - 2.8.8
* https://github.com/fomantic/Fomantic-UI
* http://fomantic-ui.com/
*
* Copyright 2022 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!function(I,E,S,O){"use strict";I.isFunction=I.isFunction||function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},E=void 0!==E&&E.Math==Math?E:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),I.fn.checkbox=function(s){var u,e=I(this),b=e.selector||"",y=(new Date).getTime(),C=[],x=s,w="string"==typeof x,D=[].slice.call(arguments,1);return e.each(function(){var e,h=I.extend(!0,{},I.fn.checkbox.settings,s),n=h.className,t=h.namespace,g=h.selector,r=h.error,i="."+t,o="module-"+t,p=I(this),a=I(this).children(g.label),f=I(this).children(g.input),k=f[0],c=!1,m=!1,l=p.data(o),d=this,v={initialize:function(){v.verbose("Initializing checkbox",h),v.create.label(),v.bind.events(),v.set.tabbable(),v.hide.input(),v.observeChanges(),v.instantiate(),v.setup()},instantiate:function(){v.verbose("Storing instance of module",v),l=v,p.data(o,v)},destroy:function(){v.verbose("Destroying module"),v.unbind.events(),v.show.input(),p.removeData(o)},fix:{reference:function(){p.is(g.input)&&(v.debug("Behavior called on <input> adjusting invoked element"),p=p.closest(g.checkbox),v.refresh())}},setup:function(){v.set.initialLoad(),v.is.indeterminate()?(v.debug("Initial value is indeterminate"),v.indeterminate()):v.is.checked()?(v.debug("Initial value is checked"),v.check()):(v.debug("Initial value is unchecked"),v.uncheck()),v.remove.initialLoad()},refresh:function(){a=p.children(g.label),f=p.children(g.input),k=f[0]},hide:{input:function(){v.verbose("Modifying <input> z-index to be unselectable"),f.addClass(n.hidden)}},show:{input:function(){v.verbose("Modifying <input> z-index to be selectable"),f.removeClass(n.hidden)}},observeChanges:function(){"MutationObserver"in E&&((e=new MutationObserver(function(e){v.debug("DOM tree modified, updating selector cache"),v.refresh()})).observe(d,{childList:!0,subtree:!0}),v.debug("Setting up mutation observer",e))},attachEvents:function(e,n){var t=I(e);n=I.isFunction(v[n])?v[n]:v.toggle,0<t.length?(v.debug("Attaching checkbox events to element",e,n),t.on("click"+i,n)):v.error(r.notFound)},preventDefaultOnInputTarget:function(){"undefined"!=typeof event&&null!==event&&I(event.target).is(g.input)&&(v.verbose("Preventing default check action after manual check action"),event.preventDefault())},event:{change:function(e){v.should.ignoreCallbacks()||h.onChange.call(k)},click:function(e){var n=I(e.target);n.is(g.input)?v.verbose("Using default check action on initialized checkbox"):n.is(g.link)?v.debug("Clicking link inside checkbox, skipping toggle"):(v.toggle(),f.focus(),e.preventDefault())},keydown:function(e){var n=e.which,t=13,i=32,o=27,a=37,c=38,r=39,l=40,d=v.get.radios(),s=d.index(p),u=d.length,b=!1;if(n==a||n==c?b=(0===s?u:s)-1:n!=r&&n!=l||(b=s===u-1?0:s+1),!v.should.ignoreCallbacks()&&!1!==b){if(!1===h.beforeUnchecked.apply(k))return v.verbose("Option not allowed to be unchecked, cancelling key navigation"),!1;if(!1===h.beforeChecked.apply(I(d[b]).children(g.input)[0]))return v.verbose("Next option should not allow check, cancelling key navigation"),!1}m=n==o?(v.verbose("Escape key pressed blurring field"),f.blur(),!0):!(e.ctrlKey||!(n==i||n==t&&h.enableEnterKey))&&(v.verbose("Enter/space key pressed, toggling checkbox"),v.toggle(),!0)},keyup:function(e){m&&e.preventDefault()}},check:function(){v.should.allowCheck()&&(v.debug("Checking checkbox",f),v.set.checked(),v.should.ignoreCallbacks()||(h.onChecked.call(k),v.trigger.change()),v.preventDefaultOnInputTarget())},uncheck:function(){v.should.allowUncheck()&&(v.debug("Unchecking checkbox"),v.set.unchecked(),v.should.ignoreCallbacks()||(h.onUnchecked.call(k),v.trigger.change()),v.preventDefaultOnInputTarget())},indeterminate:function(){v.should.allowIndeterminate()?v.debug("Checkbox is already indeterminate"):(v.debug("Making checkbox indeterminate"),v.set.indeterminate(),v.should.ignoreCallbacks()||(h.onIndeterminate.call(k),v.trigger.change()))},determinate:function(){v.should.allowDeterminate()?v.debug("Checkbox is already determinate"):(v.debug("Making checkbox determinate"),v.set.determinate(),v.should.ignoreCallbac