wishthis/node_modules/fomantic-ui/dist/components/checkbox.min.js
2023-08-17 11:47:40 +02:00

11 lines
No EOL
12 KiB
JavaScript

/*
* # Fomantic UI - 2.9.2
* https://github.com/fomantic/Fomantic-UI
* https://fomantic-ui.com/
*
* Copyright 2023 Contributors
* Released under the MIT license
* https://opensource.org/licenses/MIT
*
*/
!function(I,E,S){"use strict";function O(e){return"function"==typeof e&&"number"!=typeof e.nodeType}E=void 0!==E&&E.Math===Math?E:globalThis,I.fn.checkbox=function(s){var u,e=I(this),b=e.selector||"",y=Date.now(),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,i=h.namespace,g=h.selector,r=h.error,t="."+i,o="module-"+i,p=I(this),a=I(this).children(g.label),f=I(this).children(g.input),k=f[0],c=!1,m=!1,d=p.data(o),l=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),d=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(l,{childList:!0,subtree:!0}),v.debug("Setting up mutation observer",e))},attachEvents:function(e,n){var i=I(e);n=O(v[n])?v[n]:v.toggle,0<i.length?(v.debug("Attaching checkbox events to element",e,n),i.on("click"+t,n)):v.error(r.notFound)},preventDefaultOnInputTarget:function(){void 0!==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.trigger("focus"),e.preventDefault())},keydown:function(e){var n=e.which,i=13,t=32,o=27,a=37,c=38,r=39,d=40,l=v.get.radios(),s=l.index(p),u=l.length,b=!1;if(n===a||n===c?b=(0===s?u:s)-1:n!==r&&n!==d||(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(l[b]).children(g.input)[0]))return v.verbose("Next option should not allow check, cancelling key navigation"),!1}m=!1,n===o?(v.verbose("Escape key pressed blurring field"),f.trigger("blur"),m=!0,e.stopPropagation()):!e.ctrlKey&&v.can.change()&&(n===t||n===i&&h.enableEnterKey?(v.verbose("Enter/space key pressed, toggling checkbox"),v.toggle(),m=!0):p.is(".toggle, .slider")&&!v.is.radio()&&(n===a&&v.is.checked()?(v.uncheck(),m=!0):n===r&&v.is.unchecked()&&(v.check(),m=!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.ignoreCallbacks()||(h.onDeterminate.call(k),v.trigger.change()))},enable:function(){v.is.enabled()?v.debug("Checkbox is already enabled"):(v.debug("Enabling checkbox"),v.set.enabled(),v.should.ignoreCallbacks()||(h.onEnable.call(k),h.onEnabled.call(k)))},disable:function(){v.is.disabled()?v.debug("Checkbox is already disabled"):(v.debug("Disabling checkbox"),v.set.disabled(),v.should.ignoreCallbacks()||(h.onDisable.call(k),h.onDisabled.call(k)))},get:{radios:function(){var e=v.get.name();return I('input[name="'+e+'"]').closest(g.checkbox)},otherRadios:function(){return v.get.radios().not(p)},name:function(){return f.attr("name")}},is:{initialLoad:function(){return c},radio:function(){return f.hasClass(n.radio)||"radio"===f.attr("type")},indeterminate:function(){return void 0!==f.prop("indeterminate")&&f.prop("indeterminate")},checked:function(){return void 0!==f.prop("checked")&&f.prop("checked")},disabled:function(){return void 0!==f.prop("disabled")&&f.prop("disabled")},enabled:function(){return!v.is.disabled()},determinate:function(){return!v.is.indeterminate()},unchecked:function(){return!v.is.checked()}},should:{allowCheck:function(){return v.is.determinate()&&v.is.checked()&&!v.is.initialLoad()?(v.debug("Should not allow check, checkbox is already checked"),!1):!(!v.should.ignoreCallbacks()&&!1===h.beforeChecked.apply(k))||(v.debug("Should not allow check, beforeChecked cancelled"),!1)},allowUncheck:function(){return v.is.determinate()&&v.is.unchecked()&&!v.is.initialLoad()?(v.debug("Should not allow uncheck, checkbox is already unchecked"),!1):!(!v.should.ignoreCallbacks()&&!1===h.beforeUnchecked.apply(k))||(v.debug("Should not allow uncheck, beforeUnchecked cancelled"),!1)},allowIndeterminate:function(){return v.is.indeterminate()&&!v.is.initialLoad()?(v.debug("Should not allow indeterminate, checkbox is already indeterminate"),!1):!(!v.should.ignoreCallbacks()&&!1===h.beforeIndeterminate.apply(k))||(v.debug("Should not allow indeterminate, beforeIndeterminate cancelled"),!1)},allowDeterminate:function(){return v.is.determinate()&&!v.is.initialLoad()?(v.debug("Should not allow determinate, checkbox is already determinate"),!1):!(!v.should.ignoreCallbacks()&&!1===h.beforeDeterminate.apply(k))||(v.debug("Should not allow determinate, beforeDeterminate cancelled"),!1)},ignoreCallbacks:function(){return c&&!h.fireOnInit}},can:{change:function(){return!(p.hasClass(n.disabled)||p.hasClass(n.readOnly)||f.prop("disabled")||f.prop("readonly"))},uncheck:function(){return"boolean"==typeof h.uncheckable?h.uncheckable:!v.is.radio()}},set:{initialLoad:function(){c=!0},checked:function(){v.verbose("Setting class to checked"),p.removeClass(n.indeterminate).addClass(n.checked),v.is.radio()&&v.uncheckOthers(),!v.is.indeterminate()&&v.is.checked()?v.debug("Input is already checked, skipping input property change"):(v.verbose("Setting state to checked",k),f.prop("indeterminate",!1).prop("checked",!0))},unchecked:function(){v.verbose("Removing checked class"),p.removeClass(n.indeterminate).removeClass(n.checked),!v.is.indeterminate()&&v.is.unchecked()?v.debug("Input is already unchecked"):(v.debug("Setting state to unchecked"),f.prop("indeterminate",!1).prop("checked",!1))},indeterminate:function(){v.verbose("Setting class to indeterminate"),p.addClass(n.indeterminate),v.is.indeterminate()?v.debug("Input is already indeterminate, skipping input property change"):(v.debug("Setting state to indeterminate"),f.prop("indeterminate",!0))},determinate:function(){v.verbose("Removing indeterminate class"),p.removeClass(n.indeterminate),v.is.determinate()?v.debug("Input is already determinate, skipping input property change"):(v.debug("Setting state to determinate"),f.prop("indeterminate",!1))},disabled:function(){v.verbose("Setting class to disabled"),p.addClass(n.disabled),v.is.disabled()?v.debug("Input is already disabled, skipping input property change"):(v.debug("Setting state to disabled"),f.prop("disabled","disabled"))},enabled:function(){v.verbose("Removing disabled class"),p.removeClass(n.disabled),v.is.enabled()?v.debug("Input is already enabled, skipping input property change"):(v.debug("Setting state to enabled"),f.prop("disabled",!1))},tabbable:function(){v.verbose("Adding tabindex to checkbox"),void 0===f.attr("tabindex")&&f.attr("tabindex",0)}},remove:{initialLoad:function(){c=!1}},trigger:{change:function(){var e,n=f[0];n&&(e=S.createEvent("HTMLEvents"),v.verbose("Triggering native change event"),e.initEvent("change",!0,!1),n.dispatchEvent(e))}},create:{label:function(){0<f.prevAll(g.label).length?(f.prev(g.label).detach().insertAfter(f),v.debug("Moving existing label",a)):v.has.label()||(a=I("<label>").insertAfter(f),v.debug("Creating label",a))}},has:{label:function(){return 0<a.length}},bind:{events:function(){v.verbose("Attaching checkbox events"),p.on("click"+t,v.event.click).on("change"+t,v.event.change).on("keydown"+t,g.input,v.event.keydown).on("keyup"+t,g.input,v.event.keyup)}},unbind:{events:function(){v.debug("Removing events"),p.off(t)}},uncheckOthers:function(){var e=v.get.otherRadios();v.debug("Unchecking other radios",e),e.removeClass(n.checked)},toggle:function(){v.can.change()?v.is.indeterminate()||v.is.unchecked()?(v.debug("Currently unchecked"),v.check()):v.is.checked()&&v.can.uncheck()&&(v.debug("Currently checked"),v.uncheck()):v.is.radio()||v.debug("Checkbox is read-only or disabled, ignoring toggle")},setting:function(e,n){if(v.debug("Changing setting",e,n),I.isPlainObject(e))I.extend(!0,h,e);else{if(void 0===n)return h[e];I.isPlainObject(h[e])?I.extend(!0,h[e],n):h[e]=n}},internal:function(e,n){if(I.isPlainObject(e))I.extend(!0,v,e);else{if(void 0===n)return v[e];v[e]=n}},debug:function(){!h.silent&&h.debug&&(h.performance?v.performance.log(arguments):(v.debug=Function.prototype.bind.call(console.info,console,h.name+":"),v.debug.apply(console,arguments)))},verbose:function(){!h.silent&&h.verbose&&h.debug&&(h.performance?v.performance.log(arguments):(v.verbose=Function.prototype.bind.call(console.info,console,h.name+":"),v.verbose.apply(console,arguments)))},error:function(){h.silent||(v.error=Function.prototype.bind.call(console.error,console,h.name+":"),v.error.apply(console,arguments))},performance:{log:function(e){var n,i;h.performance&&(i=(n=Date.now())-(y||n),y=n,C.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:l,"Execution Time":i})),clearTimeout(v.performance.timer),v.performance.timer=setTimeout(v.performance.display,500)},display:function(){var e=h.name+":",i=0;y=!1,clearTimeout(v.performance.timer),I.each(C,function(e,n){i+=n["Execution Time"]}),e+=" "+i+"ms",b&&(e+=" '"+b+"'"),0<C.length&&(console.groupCollapsed(e),console.table?console.table(C):I.each(C,function(e,n){console.log(n.Name+": "+n["Execution Time"]+"ms")}),console.groupEnd()),C=[]}},invoke:function(t,e,n){var o,a,i,c=d;return e=e||D,n=n||l,"string"==typeof t&&void 0!==c&&(t=t.split(/[ .]/),o=t.length-1,I.each(t,function(e,n){var i=e!==o?n+t[e+1].charAt(0).toUpperCase()+t[e+1].slice(1):t;if(I.isPlainObject(c[i])&&e!==o)c=c[i];else{if(void 0!==c[i])return a=c[i],!1;{if(!I.isPlainObject(c[n])||e===o)return void 0!==c[n]?a=c[n]:v.error(r.method,t),!1;c=c[n]}}})),O(a)?i=a.apply(n,e):void 0!==a&&(i=a),Array.isArray(u)?u.push(i):void 0!==u?u=[u,i]:void 0!==i&&(u=i),a}};w?(void 0===d&&v.initialize(),v.invoke(x)):(void 0!==d&&d.invoke("destroy"),v.initialize())}),void 0!==u?u:this},I.fn.checkbox.settings={name:"Checkbox",namespace:"checkbox",silent:!1,debug:!1,verbose:!1,performance:!0,uncheckable:"auto",fireOnInit:!1,enableEnterKey:!0,onChange:function(){},beforeChecked:function(){},beforeUnchecked:function(){},beforeDeterminate:function(){},beforeIndeterminate:function(){},onChecked:function(){},onUnchecked:function(){},onDeterminate:function(){},onIndeterminate:function(){},onEnable:function(){},onDisable: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",input:'input[type="checkbox"], input[type="radio"]',link:"a[href]"}}}(jQuery,window,document);