/**
 * @author alexander.farkas
 * @version 1.4.4pre
 */
(function (a) { var b; (function () { if (!a.prop || b) { return } var c = function () { b = !!a("<input />").prop("validity") }; c(); a(c) })(); a.widget("ui.checkBox", { options: { hideInput: true, addVisualElement: true, addLabel: true }, _create: function () { var b = this, c = this.options; if (!this.element.is(":radio,:checkbox")) { if (this.element[0].elements && a.nodeName(this.element[0], "form")) { a(this.element[0].elements).filter(":radio,:checkbox").checkBox(c) } return false } this._proxiedReflectUI = a.proxy(this, "reflectUI"); this.labels = a([]); this.checkedStatus = false; this.disabledStatus = false; this.hoverStatus = false; this.inputType = this.element[0].type; this.radio = this.inputType == "radio"; this.visualElement = a([]); if (c.hideInput) { this.element.addClass("ui-helper-hidden-accessible"); if (c.addVisualElement) { this.visualElement = a("<span />").addClass("ui-" + this.inputType); this.element.after(this.visualElement[0]) } } if (c.addLabel) { var d = this.element[0].id; if (d) { this.labels = a('label[for="' + d + '"]', this.element[0].form || this.element[0].ownerDocument).add(this.element.parent("label")) } if (!this.labels[0]) { this.labels = this.element.closest("label", this.element[0].form) } this.labels.addClass(this.radio ? "ui-radio" : "ui-checkbox") } if (a.webshims && a.webshims.addShadowDom) { a.webshims.addShadowDom(this.element, c.addVisualElement ? this.visualElement[0] : this.labels[0], { shadowFocusElement: this.element[0] }) } this.visualGroup = this.visualElement.add(this.labels); this._addEvents(); this.initialized = true; this.reflectUI({ type: "initialreflect" }); return undefined }, _addEvents: function () { var a = this, b = this.options, c = function (b) { if (a.disabledStatus) { return false } a.hover = b.type == "focus" || b.type == "mouseenter"; if (b.type == "focus") { a.visualGroup.addClass(a.inputType + "-focused") } else if (b.type == "blur") { a.visualGroup.removeClass(a.inputType + "-focused") } a._changeStateClassChain(); return undefined }; this.element.bind("click.checkBox invalid.checkBox", this._proxiedReflectUI).bind("focus.checkBox blur.checkBox", c); if (b.hideInput) { this.element.bind("usermode", function (b) { b.enabled && a.destroy.call(a, true) }) } if (b.addVisualElement) { this.visualElement.bind("click.checkBox", function (b) { a.element[0].click(); return false }) } this.visualGroup.bind("mouseenter.checkBox mouseleave.checkBox", c) }, _changeStateClassChain: function () { function e() { var b = this.className.split(" "), e = false; a.each(b, function (a, f) { if (f.indexOf(d) === 0) { e = true; b[a] = c; return false } return undefined }); if (!e) { b.push(c) } this.className = b.join(" ") } var b = this.labels.add(this.visualElement), c = "", d = "ui-" + this.inputType; if (this.checkedStatus) { c += "-checked"; b.addClass(d + "-checked") } else { b.removeClass(d + "-checked") } if (this.disabledStatus) { c += "-disabled"; b.addClass(d + "-disabled") } else { b.removeClass(d + "-disabled") } if (this.hover) { c += "-hover"; b.addClass(d + "-hover") } else { b.removeClass(d + "-hover") } d += "-state"; if (c) { c = d + c } this.visualGroup.each(e) }, destroy: function (a) { this.element.removeClass("ui-helper-hidden-accessible"); this.visualElement.addClass("ui-helper-hidden"); if (!a) { var b = this.options; this.element.unbind(".checkBox"); this.visualElement.remove(); this.labels.unbind(".checkBox").removeClass("ui-state-hover ui-state-checked ui-state-disabled") } }, disable: function (a) { if (a === undefined) { a = true } this.element[0].disabled = a; this.reflectUI({ type: "manuallydisabled" }) }, enable: function () { this.element[0].disabled = false; this.reflectUI({ type: "manuallyenabled" }) }, toggle: function (a) { this.changeCheckStatus(!this.element.is(":checked"), a) }, changeCheckStatus: function (a, b) { if (b && b.type == "click" && this.element[0].disabled) { return false } this.element[0].checked = !!a; this.reflectUI(b || { type: "changecheckstatus" }); return undefined }, propagate: function (b, c, d) { if (!c || c.type != "initialreflect") { if (this.radio && !d) { var e = this.element[0]; a('[name="' + e.name + '"]', e.form || e.ownerDocument).checkBox("reflectUI", c, true) } return this._trigger(b, c, { options: this.options, checked: this.checkedStatus, labels: this.labels, disabled: this.disabledStatus }) } return undefined }, changeValidityState: function () { if (b) { this.visualGroup[!this.element.prop("willValidate") || (this.element.prop("validity") || { valid: true }).valid ? "removeClass" : "addClass"](this.inputType + "-invalid") } }, reflectUI: function (a) { var b = this.checkedStatus, c = this.disabledStatus; this.disabledStatus = this.element.is(":disabled"); this.checkedStatus = this.element.is(":checked"); if (!a || a.type !== "initialreflect") { this.changeValidityState() } if (this.disabledStatus != c || this.checkedStatus !== b) { this._changeStateClassChain(); this.disabledStatus != c && this.propagate("disabledchange", a); this.checkedStatus !== b && this.propagate("change", a) } } }); if (a.propHooks) { a.each({ checked: "changeCheckStatus", disabled: "disable" }, function (b, c) { if (!a.propHooks[b]) { a.propHooks[b] = {} } var d = a.propHooks[b].set; a.propHooks[b].set = function (b, e) { var f = a.data(b, "checkBox"); if (f) { f[c](!!e) } return d && d(b, e) } }) } })(jQuery)
