11 lines
No EOL
12 KiB
JavaScript
11 lines
No EOL
12 KiB
JavaScript
/*
|
|
* # Fomantic UI - 2.9.0-beta.275+3f2aae7
|
|
* 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=!1,n==o?(v.verbose("Escape key pressed blurring field"),f.blur(),m=!0):!e.ctrlKey&&v.can.change()&&(n==i||n==t&&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 f.prop("indeterminate")!==O&&f.prop("indeterminate")},checked:function(){return f.prop("checked")!==O&&f.prop("checked")},disabled:function(){return f.prop("disabled")!==O&&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"),f.attr("tabindex")===O&&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"+i,v.event.click).on("change"+i,v.event.change).on("keydown"+i,g.input,v.event.keydown).on("keyup"+i,g.input,v.event.keyup)}},unbind:{events:function(){v.debug("Removing events"),p.off(i)}},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(n===O)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(n===O)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,t;h.performance&&(t=(n=(new Date).getTime())-(y||n),y=n,C.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:d,"Execution Time":t})),clearTimeout(v.performance.timer),v.performance.timer=setTimeout(v.performance.display,500)},display:function(){var e=h.name+":",t=0;y=!1,clearTimeout(v.performance.timer),I.each(C,function(e,n){t+=n["Execution Time"]}),e+=" "+t+"ms",b&&(e+=" '"+b+"'"),(console.group!==O||console.table!==O)&&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(i,e,n){var o,a,t,c=l;return e=e||D,n=d||n,"string"==typeof i&&c!==O&&(i=i.split(/[\. ]/),o=i.length-1,I.each(i,function(e,n){var t=e!=o?n+i[e+1].charAt(0).toUpperCase()+i[e+1].slice(1):i;if(I.isPlainObject(c[t])&&e!=o)c=c[t];else{if(c[t]!==O)return a=c[t],!1;{if(!I.isPlainObject(c[n])||e==o)return c[n]!==O?a=c[n]:v.error(r.method,i),!1;c=c[n]}}})),I.isFunction(a)?t=a.apply(n,e):a!==O&&(t=a),Array.isArray(u)?u.push(t):u!==O?u=[u,t]:t!==O&&(u=t),a}};w?(l===O&&v.initialize(),v.invoke(x)):(l!==O&&l.invoke("destroy"),v.initialize())}),u!==O?u:this},I.fn.checkbox.settings={name:"Checkbox",namespace:"checkbox",silent:!1,debug:!1,verbose:!0,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); |