You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10 lines
6.2 KiB

9 years ago
9 years ago
10 years ago
  1. /*!
  2. * # Semantic UI 1.11.4 - Checkbox
  3. * http://github.com/semantic-org/semantic-ui/
  4. *
  5. *
  6. * Copyright 2014 Contributors
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. !function(e,n,o,t){"use strict";e.fn.checkbox=function(o){var c,i=e(this),r=i.selector||"",a=(new Date).getTime(),s=[],l=arguments[0],u="string"==typeof l,d=[].slice.call(arguments,1);return i.each(function(){var i,b,h=e.extend(!0,{},e.fn.checkbox.settings,o),g=h.className,f=h.namespace,p=h.selector,m=h.error,k="."+f,v="module-"+f,y=e(this),x=e(this).find(p.label),C=e(this).find(p.input),D=y.data(v),E=this;b={initialize:function(){b.verbose("Initializing checkbox",h),b.create.label(),b.add.events(),b.is.checked()?(b.set.checked(),h.fireOnInit&&h.onChecked.call(C.get())):(b.remove.checked(),h.fireOnInit&&h.onUnchecked.call(C.get())),b.observeChanges(),b.instantiate()},instantiate:function(){b.verbose("Storing instance of module",b),D=b,y.data(v,b)},destroy:function(){b.verbose("Destroying module"),b.remove.events(),y.removeData(v)},refresh:function(){x=y.find(p.label),C=y.find(p.input)},observeChanges:function(){"MutationObserver"in n&&(i=new MutationObserver(function(){b.debug("DOM tree modified, updating selector cache"),b.refresh()}),i.observe(E,{childList:!0,subtree:!0}),b.debug("Setting up mutation observer",i))},attachEvents:function(n,o){var t=e(n);o=e.isFunction(b[o])?b[o]:b.toggle,t.length>0?(b.debug("Attaching checkbox events to element",n,o),t.on("click"+k,o)):b.error(m.notFound)},event:{keydown:function(e){var n=e.which,o={enter:13,space:32,escape:27};n==o.escape&&(b.verbose("Escape key pressed blurring field"),y.blur()),e.ctrlKey||n!=o.enter&&n!=o.space||(b.verbose("Enter key pressed, toggling checkbox"),b.toggle.call(this),e.preventDefault())}},get:{radios:function(){return e('input[name="'+b.get.name()+'"]').closest(p.checkbox)},name:function(){return C.attr("name")}},is:{radio:function(){return C.hasClass(g.radio)||"radio"==C.attr("type")},checked:function(){return C.prop("checked")!==t&&C.prop("checked")},unchecked:function(){return!b.is.checked()}},can:{change:function(){return!(y.hasClass(g.disabled)||y.hasClass(g.readOnly)||C.prop("disabled"))},uncheck:function(){return"boolean"==typeof h.uncheckable?h.uncheckable:!b.is.radio()}},set:{checked:function(){var e;b.is.radio()&&(e=b.get.radios(),b.debug("Unchecking other radios",e),e.removeClass(g.checked)),y.addClass(g.checked)},tab:function(){C.attr("tabindex")===t&&C.attr("tabindex",0)}},create:{label:function(){C.prevAll(p.label).length>0?(C.prev(p.label).detach().insertAfter(C),b.debug("Moving existing label",x)):b.has.label()||(x=e("<label>").insertAfter(C),b.debug("Creating label",x))}},has:{label:function(){return x.length>0}},add:{events:function(){b.verbose("Attaching checkbox events"),y.on("click"+k,b.toggle).on("keydown"+k,p.input,b.event.keydown)}},remove:{checked:function(){y.removeClass(g.checked)},events:function(){b.debug("Removing events"),y.off(k).removeData(v),C.off(k,b.event.keydown),x.off(k)}},enable:function(){b.debug("Enabling checkbox functionality"),y.removeClass(g.disabled),C.prop("disabled",!1),h.onEnabled.call(C[0])},disable:function(){b.debug("Disabling checkbox functionality"),y.addClass(g.disabled),C.prop("disabled","disabled"),h.onDisabled.call(C[0])},check:function(){b.debug("Enabling checkbox",C),C.prop("checked",!0).trigger("change"),b.set.checked(),C.trigger("blur"),h.onChange.call(C[0]),h.onChecked.call(C[0])},uncheck:function(){b.debug("Disabling checkbox"),C.prop("checked",!1).trigger("change"),b.remove.checked(),C.trigger("blur"),h.onChange.call(C[0]),h.onUnchecked.call(C[0])},toggle:function(){return b.can.change()?(b.verbose("Determining new checkbox state"),void(b.is.unchecked()?b.check():b.is.checked()&&b.can.uncheck()&&b.uncheck())):void(b.is.radio()||b.debug("Checkbox is read-only or disabled, ignoring toggle"))},setting:function(n,o){if(b.debug("Changing setting",n,o),e.isPlainObject(n))e.extend(!0,h,n);else{if(o===t)return h[n];h[n]=o}},internal:function(n,o){if(e.isPlainObject(n))e.extend(!0,b,n);else{if(o===t)return b[n];b[n]=o}},debug:function(){h.debug&&(h.performance?b.performance.log(arguments):(b.debug=Function.prototype.bind.call(console.info,console,h.name+":"),b.debug.apply(console,arguments)))},ve