1
0
mirror of https://github.com/j-a-n/raspberrymatic-addon-rmupdate.git synced 2023-10-10 13:37:40 +02:00
raspberrymatic-addon-rmupdate/addon/www/css/components/checkbox.min.js

1 line
11 KiB
JavaScript
Raw Normal View History

2018-12-22 16:58:57 +01:00
!function(D,S,E,O){"use strict";S=void 0!==S&&S.Math==Math?S:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),D.fn.checkbox=function(k){var m,e=D(this),v=e.selector||"",y=(new Date).getTime(),C=[],x=k,w="string"==typeof x,I=[].slice.call(arguments,1);return e.each(function(){var e,r,i=D.extend(!0,{},D.fn.checkbox.settings,k),n=i.className,t=i.namespace,o=i.selector,l=i.error,a="."+t,c="module-"+t,d=D(this),s=D(this).children(o.label),u=D(this).children(o.input),b=u[0],h=!1,g=!1,f=d.data(c),p=this;r={initialize:function(){r.verbose("Initializing checkbox",i),r.create.label(),r.bind.events(),r.set.tabbable(),r.hide.input(),r.observeChanges(),r.instantiate(),r.setup()},instantiate:function(){r.verbose("Storing instance of module",r),f=r,d.data(c,r)},destroy:function(){r.verbose("Destroying module"),r.unbind.events(),r.show.input(),d.removeData(c)},fix:{reference:function(){d.is(o.input)&&(r.debug("Behavior called on <input> adjusting invoked element"),d=d.closest(o.checkbox),r.refresh())}},setup:function(){r.set.initialLoad(),r.is.indeterminate()?(r.debug("Initial value is indeterminate"),r.indeterminate()):r.is.checked()?(r.debug("Initial value is checked"),r.check()):(r.debug("Initial value is unchecked"),r.uncheck()),r.remove.initialLoad()},refresh:function(){s=d.children(o.label),u=d.children(o.input),b=u[0]},hide:{input:function(){r.verbose("Modifying <input> z-index to be unselectable"),u.addClass(n.hidden)}},show:{input:function(){r.verbose("Modifying <input> z-index to be selectable"),u.removeClass(n.hidden)}},observeChanges:function(){"MutationObserver"in S&&((e=new MutationObserver(function(e){r.debug("DOM tree modified, updating selector cache"),r.refresh()})).observe(p,{childList:!0,subtree:!0}),r.debug("Setting up mutation observer",e))},attachEvents:function(e,n){var t=D(e);n=D.isFunction(r[n])?r[n]:r.toggle,0<t.length?(r.debug("Attaching checkbox events to element",e,n),t.on("click"+a,n)):r.error(l.notFound)},event:{click:function(e){var n=D(e.target);n.is(o.input)?r.verbose("Using default check action on initialized checkbox"):n.is(o.link)?r.debug("Clicking link inside checkbox, skipping toggle"):(r.toggle(),u.focus(),e.preventDefault())},keydown:function(e){var n=e.which,t=13,i=32;g=n==27?(r.verbose("Escape key pressed blurring field"),u.blur(),!0):!(e.ctrlKey||n!=i&&n!=t)&&(r.verbose("Enter/space key pressed, toggling checkbox"),r.toggle(),!0)},keyup:function(e){g&&e.preventDefault()}},check:function(){r.should.allowCheck()&&(r.debug("Checking checkbox",u),r.set.checked(),r.should.ignoreCallbacks()||(i.onChecked.call(b),i.onChange.call(b)))},uncheck:function(){r.should.allowUncheck()&&(r.debug("Unchecking checkbox"),r.set.unchecked(),r.should.ignoreCallbacks()||(i.onUnchecked.call(b),i.onChange.call(b)))},indeterminate:function(){r.should.allowIndeterminate()?r.debug("Checkbox is already indeterminate"):(r.debug("Making checkbox indeterminate"),r.set.indeterminate(),r.should.ignoreCallbacks()||(i.onIndeterminate.call(b),i.onChange.call(b)))},determinate:function(){r.should.allowDeterminate()?r.debug("Checkbox is already determinate"):(r.debug("Making checkbox determinate"),r.set.determinate(),r.should.ignoreCallbacks()||(i.onDeterminate.call(b),i.onChange.call(b)))},enable:function(){r.is.enabled()?r.debug("Checkbox is already enabled"):(r.debug("Enabling checkbox"),r.set.enabled(),i.onEnable.call(b),i.onEnabled.call(b))},disable:function(){r.is.disabled()?r.debug("Checkbox is already disabled"):(r.debug("Disabling checkbox"),r.set.disabled(),i.onDisable.call(b),i.onDisabled.call(b))},get:{radios:function(){var e=r.get.name();return D('input[name="'+e+'"]').closest(o.checkbox)},otherRadios:function(){return r.get.radios().not(d)},name:function(){return u.attr("name")}},is:{initialLoad:function(){return h},radio:function(){return u.hasClass(n.radio)||"radio"==u.attr("type")},indeterminate:function(){return u.prop("indeterminate")!==O&&u.prop("indeterminate")},checked:function(){return u.prop("checked")!==O&&u.prop("checked")},disabled:function(){return u.prop("disabled")!==O&&u.prop