wishthis/node_modules/fomantic-ui/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.9.3
2022-01-13 13:00:31 +00:00
* https://github.com/fomantic/Fomantic-UI
2023-08-17 09:47:40 +00:00
* https://fomantic-ui.com/
2022-01-13 13:00:31 +00:00
*
2023-08-17 09:47:40 +00:00
* Copyright 2023 Contributors
2022-01-13 13:00:31 +00:00
* Released under the MIT license
2023-08-17 09:47:40 +00:00
* https://opensource.org/licenses/MIT
2022-01-13 13:00:31 +00:00
*
*/
!function(D,I,E){"use strict";function S(e){return"function"==typeof e&&"number"!=typeof e.nodeType}I=void 0!==I&&I.Math===Math?I:globalThis,D.fn.checkbox=function(s){var u,e=D(this),b=Date.now(),y=[],C=s,x="string"==typeof C,w=[].slice.call(arguments,1);return e.each(function(){var e,h=D.extend(!0,{},D.fn.checkbox.settings,s),n=h.className,i=h.namespace,g=h.selector,r=h.error,t="."+i,o="module-"+i,p=D(this),a=D(this).children(g.label),f=D(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 I&&((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=D(e);n=S(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&&D(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=D(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(D(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()):v.can.change()?e.ctrlKey||(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))):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 d