!function(a){"use strict";var b="vanderlee.tristate",c=a.fn.val;a.widget("vanderlee.tristate",{options:{state:void 0,value:void 0,checked:void 0,unchecked:void 0,indeterminate:void 0,change:void 0,init:void 0},_create:function(){var a,b=this;return this.element.click(function(a){switch(!a.isTrigger&&a.hasOwnProperty("which")||a.preventDefault(),b.options.state){case!0:b.options.state=null;break;case!1:b.options.state=!0;break;default:b.options.state=!1}b._refresh(b.options.change)}),this.options.checked=this.element.attr("checkedvalue")||this.options.checked,this.options.unchecked=this.element.attr("uncheckedvalue")||this.options.unchecked,this.options.indeterminate=this.element.attr("indeterminatevalue")||this.options.indeterminate,"undefined"==typeof this.options.state&&(this.options.state="undefined"!=typeof this.element.attr("indeterminate")?null:this.element.is(":checked")),"undefined"!=typeof this.options.value&&(a=this._parseValue(this.options.value),"undefined"!=typeof a&&(this.options.state=a)),this._refresh(this.options.init),this},_refresh:function(c){var d=this.value();this.element.data(b,d),this.element[null===this.options.state?"attr":"removeAttr"]("indeterminate","indeterminate"),this.element.prop("indeterminate",null===this.options.state),this.element.get(0).indeterminate=null===this.options.state,this.element[this.options.state?"attr":"removeAttr"]("checked",!0),this.element.prop("checked",this.options.state===!0),a.isFunction(c)&&c.call(this.element,this.options.state,this.value())},state:function(a){return"undefined"==typeof a?this.options.state:(a!==!0&&a!==!1&&null!==a||(this.options.state=a,this._refresh(this.options.change)),this)},_parseValue:function(a){return a===this.options.checked||a!==this.options.unchecked&&(a===this.options.indeterminate?null:void 0)},value:function(a){if("undefined"==typeof a){var a;switch(this.options.state){case!0:a=this.options.checked;break;case!1:a=this.options.unchecked;break;case null:a=this.options.indeterminate}return"undefined"==typeof a?this.element.attr("value"):a}var b=this._parseValue(a);"undefined"!=typeof b&&(this.options.state=b,this._refresh(this.options.change))}}),a.fn.val=function(a){var d=this.data(b);return"undefined"==typeof d?"undefined"==typeof a?c.call(this):c.call(this,a):"undefined"==typeof a?d:(this.data(b,a),this)},a.expr.filters.indeterminate=function(c){var d=a(c);return"undefined"!=typeof d.data(b)&&d.prop("indeterminate")},a.expr.filters.determinate=function(b){return!a.expr.filters.indeterminate(b)},a.expr.filters.tristate=function(c){return"undefined"!=typeof a(c).data(b)}}(jQuery);