/*
 * jQuery - Conditioner - v1.0
 * http://www.aakashweb.com/
 * Copyright 2016, Aakash Chakravarthy
 * Released under the MIT License.
 */
!function(o){o.fn.conditioner=function(n){var t=o.extend({events:"",conditions:[],onTrue:"",onFalse:""},n);function e(n){return conds=n.data("conditioner-conds"),finalCheck=null,o.each(conds,function(n,t){indCheck=function(n){var t="",i=!1;if("radio"==n.input.attr("type"))t=n.input.filter(":checked").val();else{if("checkbox"==n.input.attr("type"))return!!n.input.is(":checked");t=n.input.val()}void 0===n.type&&(n.type="simple");void 0!==n.value&&void 0!==t&&("pattern"==n.type?i=null!==t.match(new RegExp(n.value,"g")):"simple"==n.type&&(i=t==n.value));return i}(t),finalCheck=null==finalCheck?indCheck:finalCheck&&indCheck}),void 0!==n.data("condr-action")?(condrAction=n.data("condr-action"),actionSplit=condrAction.split("?"),actions=actionSplit[1].split(":"),finalCheck?n[actions[0]]():n[actions[1]](),!0):""!=t.onTrue&&""!=t.onFalse?(finalCheck?"function"==typeof t.onTrue&&t.onTrue.call(n):"function"==typeof t.onFalse&&t.onFalse.call(n),!0):void 0}return this.each(function(){var i;$ele=o(this).data("conditioner-opts",t),$inputs=(i=$ele,$inputs=!1,t=i.data("conditioner-opts"),conds=[],void 0!==i.data("condr-input")&&(inputAttr=i.data("condr-input"),$inputEle=i,-1!=inputAttr.indexOf("(")?o.each(inputAttr.match(/\(.+?\)/g),function(n,t){t=t.replace(/[()]/g,""),methodSplit=t.split("::"),$inputEle=$inputEle[methodSplit[0]](methodSplit[1])}):$inputEle=o(inputAttr),void 0!==i.data("condr-action")&&(conds.push({input:$inputEle,value:i.data("condr-value"),type:i.data("condr-action").split("?")[0]}),$inputs=0==$inputs?$inputEle:$inputs.add($inputEle))),0<t.conditions.length&&o.each(t.conditions,function(n,t){if(""!=t.input&&"function"==typeof t.input)$indInput=t.input.call(i);else{if("string"!=typeof t.input)return!0;$indInput=o(t.input)}conds.push({input:$indInput,value:"function"==typeof t.value?t.value.call(i):t.value,type:t.type}),$inputs=0==$inputs?$indInput:$inputs.add($indInput)}),i.data("conditioner-conds",conds),$inputs),events=void 0!==$ele.data("condr-events")?$ele.data("condr-events"):t.events,0<$inputs.length&&""!=events&&(void 0===$inputs.data("conditioner-ele")?$inputs.data("conditioner-ele",$ele):($eles=$inputs.data("conditioner-ele").add($ele),$inputs.data("conditioner-ele",$eles)),$inputs.on(events,function(){o(this).data("conditioner-ele").each(function(){e(o(this))})}),e($ele))})}}(jQuery);
