!function(t){"use strict";var e=function(t){return t},n=function(e){return t.isArray(e)},r=function(t){return!n(t)&&t instanceof Object},i=function(e,n){return t.inArray(n,e)},u=function(t,e){for(var n in t)t.hasOwnProperty(n)&&e(t[n],n,t)},a=function(t){return t[t.length-1]},c=function(t){return Array.prototype.slice.call(t)},o=function(){var t={};return u(c(arguments),(function(e){u(e,(function(e,n){t[n]=e}))})),t},f=function(t,e,r){return n(t)?function(t,e){var n=[];return u(t,(function(t,r,i){n.push(e(t,r,i))})),n}(t,e):function(t,e,n){var r={};return u(t,(function(t,i,u){i=n?n(i,t):i,r[i]=e(t,i,u)})),r}(t,e,r)},s=function(t,e){var r;return n(t)?(r=[],u(t,(function(t,n,i){e(t,n,i)&&r.push(t)}))):(r={},u(t,(function(t,n,i){e(t,n,i)&&(r[n]=t)}))),r},p=function(t,e,n){return f(t,(function(t,r){return t[e].apply(t,n||[])}))};!function(t){var e=function(t,e){var n=function(t){var e={};return(t=t||{}).publish=function(t,n){u(e[t],(function(t){t(n)}))},t.subscribe=function(t,n){e[t]=e[t]||[],e[t].push(n)},t.unsubscribe=function(t){u(e,(function(e){var n=i(e,t);-1!==n&&e.splice(n,1)}))},t}(),r=t.$;return n.getType=function(){throw'implement me (return type. "text", "radio", etc.)'},n.$=function(t){return t?r.find(t):r},n.disable=function(){n.$().prop("disabled",!0),n.publish("isEnabled",!1)},n.enable=function(){n.$().prop("disabled",!1),n.publish("isEnabled",!0)},e.equalTo=function(t,e){return t===e},e.publishChange=function(){var t;return function(r,i){var u=n.get();e.equalTo(u,t)||n.publish("change",{e:r,domElement:i}),t=u}}(),n},c=function(t,n){var r=e(t,n);return r.get=function(){return r.$().val()},r.set=function(t){r.$().val(t)},r.clear=function(){r.set("")},n.buildSetter=function(t){return function(e){t.call(r,e)}},r},o=function(t,e){t=n(t)?t:[t],e=n(e)?e:[e];var r=!0;return t.length!==e.length?r=!1:u(t,(function(t){(function(t,e){return-1!==i(t,e)})(e,t)||(r=!1)})),r},f=function(t){var e={},n=c(t,e);return n.getType=function(){return"button"},n.$().on("change",(function(t){e.publishChange(t,this)})),n},s=function(e){var r={},i=c(e,r);return i.getType=function(){return"checkbox"},i.get=function(){var e=[];return i.$().filter(":checked").each((function(){e.push(t(this).val())})),e},i.set=function(e){e=n(e)?e:[e],i.$().each((function(){t(this).prop("checked",!1)})),u(e,(function(t){i.$().filter('[value="'+t+'"]').prop("checked",!0)}))},r.equalTo=o,i.$().change((function(t){r.publishChange(t,this)})),i},l=function(t){var e=k(t,{});return e.getType=function(){return"email"},e},h=function(n){var r={},i=e(n,r);return i.getType=function(){return"file"},i.get=function(){return a(i.$().val().split("\\"))},i.clear=function(){this.$().each((function(){t(this).wrap("<form>").closest("form").get(0).reset(),t(this).unwrap()}))},i.$().change((function(t){r.publishChange(t,this)})),i},d=function(t){var e={},n=c(t,e);return n.getType=function(){return"hidden"},n.$().change((function(t){e.publishChange(t,this)})),n},v=function(n){var r={},i=e(n,r);return i.getType=function(){return"file[multiple]"},i.get=function(){var t,e=i.$().get(0).files||[],n=[];for(t=0;t<(e.length||0);t+=1)n.push(e[t].name);return n},i.clear=function(){this.$().each((function(){t(this).wrap("<form>").closest("form").get(0).reset(),t(this).unwrap()}))},i.$().change((function(t){r.publishChange(t,this)})),i},m=function(t){var e={},r=c(t,e);return r.getType=function(){return"select[multiple]"},r.get=function(){return r.$().val()||[]},r.set=function(t){r.$().val(""===t?[]:n(t)?t:[t])},e.equalTo=o,r.$().change((function(t){e.publishChange(t,this)})),r},g=function(t){var e=k(t,{});return e.getType=function(){return"password"},e},y=function(e){var n={},r=c(e,n);return r.getType=function(){return"radio"},r.get=function(){return r.$().filter(":checked").val()||null},r.set=function(e){e?r.$().filter('[value="'+e+'"]').prop("checked",!0):r.$().each((function(){t(this).prop("checked",!1)}))},r.$().change((function(t){n.publishChange(t,this)})),r},b=function(t){var e={},n=c(t,e);return n.getType=function(){return"range"},n.$().change((function(t){e.publishChange(t,this)})),n},$=function(t){var e={},n=c(t,e);return n.getType=function(){return"select"},n.$().change((function(t){e.publishChange(t,this)})),n},k=function(t){var e={},n=c(t,e);return n.getType=function(){return"text"},n.$().on("change keyup keydown",(function(t){e.publishChange(t,this)})),n},x=function(t){var e={},n=c(t,e);return n.getType=function(){return"textarea"},n.$().on("change keyup keydown",(function(t){e.publishChange(t,this)})),n},T=function(t){var e=k(t,{});return e.getType=function(){return"url"},e},w=function(e){var n={},a=e.$,c=e.constructorOverride||{button:f,text:k,url:T,email:l,password:g,range:b,textarea:x,select:$,"select[multiple]":m,radio:y,checkbox:s,file:h,"file[multiple]":v,hidden:d},o=function(e,i){(r(i)?i:a.find(i)).each((function(){var r=t(this).attr("name");n[r]=c[e]({$:t(this)})}))},p=function(e,o){var f=[],s=r(o)?o:a.find(o);r(o)?n[s.attr("name")]=c[e]({$:s}):(s.each((function(){-1===i(f,t(this).attr("name"))&&f.push(t(this).attr("name"))})),u(f,(function(t){n[t]=c[e]({$:a.find('input[name="'+t+'"]')})})))};return a.is("input, select, textarea")?a.is('input[type="button"], button, input[type="submit"]')?o("button",a):a.is("textarea")?o("textarea",a):a.is('input[type="text"]')||a.is("input")&&!a.attr("type")?o("text",a):a.is('input[type="password"]')?o("password",a):a.is('input[type="email"]')?o("email",a):a.is('input[type="url"]')?o("url",a):a.is('input[type="range"]')?o("range",a):a.is("select")?a.is("[multiple]")?o("select[multiple]",a):o("select",a):a.is('input[type="file"]')?a.is("[multiple]")?o("file[multiple]",a):o("file",a):a.is('input[type="hidden"]')?o("hidden",a):a.is('input[type="radio"]')?p("radio",a):a.is('input[type="checkbox"]')?p("checkbox",a):o("text",a):(o("button",'input[type="button"], button, input[type="submit"]'),o("text",'input[type="text"]'),o("password",'input[type="password"]'),o("email",'input[type="email"]'),o("url",'input[type="url"]'),o("range",'input[type="range"]'),o("textarea","textarea"),o("select","select:not([multiple])"),o("select[multiple]","select[multiple]"),o("file",'input[type="file"]:not([multiple])'),o("file[multiple]",'input[type="file"][multiple]'),o("hidden",'input[type="hidden"]'),p("radio",'input[type="radio"]'),p("checkbox",'input[type="checkbox"]')),n};t.fn.inputVal=function(e){var n=t(this),r=w({$:n});return n.is("input, textarea, select")?void 0===e?r[n.attr("name")].get():(r[n.attr("name")].set(e),n):void 0===e?p(r,"get"):(u(e,(function(t,e){r[e].set(t)})),n)},t.fn.inputOnChange=function(e){var n=t(this),r=w({$:n});return u(r,(function(t){t.subscribe("change",(function(t){e.call(t.domElement,t.e)}))})),n},t.fn.inputDisable=function(){var e=t(this);return p(w({$:e}),"disable"),e},t.fn.inputEnable=function(){var e=t(this);return p(w({$:e}),"enable"),e},t.fn.inputClear=function(){var e=t(this);return p(w({$:e}),"clear"),e}}(jQuery),t.fn.repeaterVal=function(){var e=function(t){if(1===t.length&&(0===t[0].key.length||1===t[0].key.length&&!t[0].key[0]))return t[0].val;u(t,(function(t){t.head=t.key.shift()}));var n,r=function(){var e={};return u(t,(function(t){e[t.head]||(e[t.head]=[]),e[t.head].push(t)})),e}();return/^[0-9]+$/.test(t[0].head)?(n=[],u(r,(function(t){n.push(e(t))}))):(n={},u(r,(function(t,r){n[r]=e(t)}))),n};return e(function(t){var e=[];return u(t,(function(t,n){var r=[];"undefined"!==n&&(r.push(n.match(/^[^\[]*/)[0]),r=r.concat(f(n.match(/\[[^\]]*\]/g),(function(t){return t.replace(/[\[\]]/g,"")}))),e.push({val:t,key:r}))})),e}(t(this).inputVal()))},t.fn.repeater=function(n){var r;return n=n||{},t(this).each((function(){var i=t(this),c=n.show||function(){t(this).show()},p=n.hide||function(t){t()},l=i.find("[data-repeater-list]").first(),h=function(e,n){return e.filter((function(){return!n||0===t(this).closest(function(t,e){return f(t,(function(t){return t[e]}))}(n,"selector").join(",")).length}))},d=function(){return h(l.find("[data-repeater-item]"),n.repeaters)},v=l.find("[data-repeater-item]").first().clone().hide(),m=h(h(t(this).find("[data-repeater-item]"),n.repeaters).first().find("[data-repeater-delete]"),n.repeaters);n.isFirstItemUndeletable&&m&&m.remove();var g=function(){var t=l.data("repeater-list");return n.$parent?n.$parent.data("item-name")+"["+t+"]":t},y=function(e){n.repeaters&&e.each((function(){var e=t(this);u(n.repeaters,(function(t){e.find(t.selector).repeater(o(t,{$parent:e}))}))}))},b=function(t,e,n){t&&u(t,(function(t){n.call(e.find(t.selector)[0],t)}))},$=function(e,n,r){e.each((function(e){var i=t(this);i.data("item-name",n+"["+e+"]"),h(i.find("[name]"),r).each((function(){var u=t(this),c=u.attr("name").match(/\[[^\]]+\]/g),o=c?a(c).replace(/\[|\]/g,""):u.attr("name"),f=n+"["+e+"]["+o+"]"+(u.is(":checkbox")||u.attr("multiple")?"[]":"");u.attr("name",f),b(r,i,(function(r){var i=t(this);$(h(i.find("[data-repeater-item]"),r.repeaters||[]),n+"["+e+"]["+i.find("[data-repeater-list]").first().data("repeater-list")+"]",r.repeaters)}))}))})),l.find("input[name][checked]").removeAttr("checked").prop("checked",!0)};$(d(),g(),n.repeaters),y(d()),n.initEmpty&&d().remove(),n.ready&&n.ready((function(){$(d(),g(),n.repeaters)}));var k=function(){var r=function(i,a,c){if(a||n.defaultValues){var o={};h(i.find("[name]"),c).each((function(){var e=t(this).attr("name").match(/\[([^\]]*)(\]|\]\[\])$/)[1];o[e]=t(this).attr("name")})),i.inputVal(f(s(a||n.defaultValues,(function(t,e){return o[e]})),e,(function(t){return o[t]})))}b(c,i,(function(e){var n=t(this);h(n.find("[data-repeater-item]"),e.repeaters).each((function(){var i=n.find("[data-repeater-list]").data("repeater-list");if(a&&a[i]){var c=t(this).clone();n.find("[data-repeater-item]").remove(),u(a[i],(function(t){var i=c.clone();r(i,t,e.repeaters||[]),n.find("[data-repeater-list]").append(i)}))}else r(t(this),e.defaultValues,e.repeaters||[])}))}))};return function(e,i){l.append(e),$(d(),g(),n.repeaters),e.find("[name]").each((function(){t(this).inputClear()})),r(e,i||n.defaultValues,n.repeaters)}}(),x=function(t){var e=v.clone();k(e,t),n.repeaters&&y(e),c.call(e.get(0))};r=function(t){d().remove(),u(t,x)},h(i.find("[data-repeater-create]"),n.repeaters).click((function(){x()})),l.on("click","[data-repeater-delete]",(function(){var e=t(this).closest("[data-repeater-item]").get(0);p.call(e,(function(){t(e).remove(),$(d(),g(),n.repeaters)}))}))})),this.setList=r,this}}(jQuery);