(function(e,t){"use strict";"function"==typeof define&&define.amd!==void 0?define("phery",["jquery"],function(r){return t(e,r)}):e.phery=t(e,e.jQuery||e.$)})(this,function(window,$,undefined){"use strict";function debug(e,t){options.debug.enable&&"undefined"!=typeof console&&"function"==typeof console.dir&&options.debug.display[t]!==undefined&&options.debug.display[t]===!0&&console.dir(e)}function do_cursor(e){options.cursor&&(null===$body_html&&($body_html=$("body,html"),$original_cursor=$body_html.css("cursor")),e?$body_html.css("cursor",e):$body_html.css("cursor",$original_cursor))}function clean_up(e){e.phery("data","temp")&&(e.off(),$.removeData(e[0]),e.remove(),e=null)}function set_events(){$document.off(".phery"),$document.on(options.delegate.confirm.join(".phery,")+".phery",":phery-confirm:not(form)",function(e){confirm($(this).phery("data","confirm"))?e.preventDefault():e.stopImmediatePropagation()}),$document.on(options.delegate.form.join(".phery,")+".phery","form:phery-remote",function(){var e=$(this);return functions.form_submit(e),!1}),$document.on(options.delegate.tags.join(".phery,")+".phery",":phery-remote:not(form,select)",function(e){var t=$(this);return options.enable.clickable_structure||"number"!=typeof structural_html[this.tagName]||t.phery("data","clickable")?(functions.ajax_call.call(t),t.is('input[type="text"],input[type="checkbox"],input[type="radio"],input[type="image"]')||e.preventDefault(),!0):!1}),$document.on(options.delegate.select.join(".phery,")+".phery","select:phery-remote:not([multiple])",function(e){functions.ajax_call.call($(e.currentTarget))}),$document.on(options.delegate.select_multiple.join(".phery,")+".phery","select:phery-remote[multiple]",function(e){functions.ajax_call.call($(e.currentTarget))})}function _apply(e,t,r){t=t||!1;for(var n in e)if(functions.hop(e,n))if("object"==typeof e[n]&&e[n].constructor!==Array){if(_apply(e[n],t,n)===!1)return!1}else switch(debug(["config",{group:r,name:n,value:e[n]}],"config"),r){case"inline":switch(n){case"enabled":break;case"once":vars.inline_load=!0}break;case"delegate":switch(n){case"confirm":case"form":case"select_multiple":case"select":case"tags":if(!functions.compare_array(e[n],options.delegate[n])||t)return set_events(),!1}}return!0}function refresh_changes(e,t){var r=$.extend(!0,{},options);if(!vars.locked_config){if(t===undefined)for(var n in e)functions.hop(e,n)&&functions.dot_notation_option(n,options,e[n]);else functions.dot_notation_option(e,options,t);_apply(r)}}var functions={},vars={},$document=$(window.document),$window=$(window),structural_html={HTML:1,BODY:1,DIV:1,BLOCKQUOTE:1,BR:1,HR:1,HEAD:1,H1:1,H2:1,H3:1,H4:1,H5:1,H6:1,P:1,HEADER:1,FOOTER:1,NAV:1,SECTION:1,ASIDE:1,ARTICLE:1,HGROUP:1,FIGURE:1},phery=function(){return function(){return phery}}();vars.locked_config=!1,vars.inline_load=!0,vars.special_match=/\{([#~\+\-=!])[\d]+\}/,vars.$version=$().jquery,vars.has_formdata="FormData"in window,vars.has_file=vars.has_formdata&&"File"in window,vars.FormData=vars.has_formdata?FormData:null,vars.subscribed=[],vars.call_cache=[],phery.version="2.7.0",functions.hop=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},functions.is_subscribed=function(e,t,r){if(!r)return!1;var n,i,a=null;for(t=t===undefined?!0:!!t,n=0,i=vars.subscribed.length;i>n;n++)if(vars.subscribed[n].topic===e&&vars.subscribed[n].element.is(r))return vars.subscribed[n];if(t===!0){var o=$.Callbacks();return a={callback:o,pub:function(e){return e=e||[],a.callback.fireWith(r,e),a},sub:function(e){return a.callback.add(e),a},unsub:function(e){return a.callback.remove(e),a},element:r,topic:e},vars.subscribed.push(a),a}return!1},functions.assign_object=function(e,t,r,n,i,a,o){if(!t||!t.length)return!1;if("array"!==$.type(t)){if("number"!==$.type(t)&&"string"!==$.type(t))return!1;t=[t]}var s,c=t.length-1;n=n===undefined?!0:n,i=i===undefined?!1:i,a=a===undefined?!1:a,o=o===undefined?!1:o,r!==undefined&&a&&(a=!1);for(var l=0;c>l;l++)if(s=t[l],s in e)e=e[s];else{if(!n)return!1;e[s]={},e=e[s]}return e[t[c]]!==undefined&&r!==undefined?"array"!==$.type(e[t[c]])||i||o?e[t[c]]=o?Array.prototype.concat.call(e[t[c]],r):r:"array"===$.type(r)?Array.prototype.push.apply(e[t[c]],r):e[t[c]].push(r):r!==undefined&&(e[t[c]]=r),a?e[t[c]]:[e,t[c]]},functions.obj_to_str=function(e,t,r){r="object"==typeof r?r:{};var n,i,a;for(n in e)functions.hop(e,n)&&(i=e[n],a=t?t+"["+n+"]":n,"object"!=typeof i||vars.has_file&&i instanceof window.File?r[a]=i:functions.obj_to_str(i,a,r));return r},functions.files_to_array=function(e){var t=[];if(vars.has_file)if(e instanceof window.File)t.push(e);else if(e instanceof window.FileList&&e.length)t.push(e[0]);else if(e.files instanceof window.FileList&&e.files.length)if(e.files.length>1)for(var r=0;e.files.length>r;r++)t.push(e.files[r]);else t.push(e.files[0]);return t},functions.to_formdata=function(e){e="object"===$.type(e)?functions.obj_to_str(e):e;var t,r=new vars.FormData;for(t in e)functions.hop(e,t)&&r.append(t,e[t]);return r},functions.per_data=function(e,t){var r,n,i=$.type(e),a=$.type(t);switch(i){case"array":switch(a){case"array":Array.prototype.push.apply(e,t);break;case"object":case"string":case"null":case"boolean":case"number":e.push(t)}break;case"object":switch(a){case"object":e=$.extend(e,t);break;case"array":for(n=0,r=0;t.length>r;r++){for(;e[n]!==undefined;)n++;e[n]=t[r]}break;case"number":case"string":case"null":case"boolean":for(n=0;e[n]!==undefined;)n++;e[n]=t}break;case"string":case"number":case"null":case"boolean":e=Array.prototype.concat.call(e,t);break;case"undefined":e="object"===a||null==t?t:Array.prototype.concat.call(t)}return e},functions.filter_prop=function(e){return function(){return $(this).prop(e)}},functions.form_element=function(e){var t,r,n=e.prop("name")||null,i=null,a=e.prop("tagName").toLowerCase();return e.is('[type="radio"]')||e.is('[type="checkbox"]')?e.is('[type="radio"]')?(t=e.prop("form")?$(e.prop("form")).find('[type="radio"][name="'+e.prop("name")+'"]'):$('[type="radio"][name="'+e.prop("name")+'"]'),t.filter(functions.filter_prop("checked")).length&&(i=t.filter(functions.filter_prop("checked")).val())):e.prop("checked")&&(i=e.is("[value]")?e.val():!0):e.is("select")?(r=e.find("option").filter(functions.filter_prop("selected")),i=e.prop("multiple")?r.map(function(){return this.value||this.innerHTML}).get():r.val(),n=n||""):e.is('[type="file"]')?vars.has_file?(n&&(n=n.replace("[]","")),i=functions.files_to_array(e[0]),a="file"):n=null:i=e.val(),{name:n,value:i,type:a}},functions.append_args=function(e){var t,r;e[0]!==undefined&&e[0].constructor===Array&&(e=e[0]);for(r in e)functions.hop(e,r)&&(t=this.phery("data","args"),this.phery("data","args",functions.per_data(t,e[r])))},functions.set_args=function(e){"function"!==$.type(e)&&this.phery("data","args",functions.per_data(undefined,e[0]))},functions.compare_array=function(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(var r=0;e.length>r;r++)if(e[r]!==t[r])return!1;return!0},functions.str_is_function=function(e,t){if(!e||"function"!=typeof e.toString)return!1;e=""+e;var r=-1!==e.search(/^[\s;]*function\(/im)&&e.search(/\};?$/m);if(r&&t){var n,i=vars.call_cache.length,a=null,o=(new Date).getTime();for(n=0;i>n;n++)if(vars.call_cache[n].str===e){a=vars.call_cache[n].fn,vars.call_cache[n].lu=o;break}for(n=i-1;n>=0;n--)o>vars.call_cache[n].lu+6e4&&vars.call_cache.splice(n,1);if("function"!=typeof a){var s=e.match(/function\s*\(([^\)]*)\)/im)[1],c=e.slice(e.indexOf("{")+1,e.lastIndexOf("}"));if(!c)return!1;a=Function(s,c),vars.call_cache.push({str:e,fn:a,lu:o})}return a}return r},vars.defaults={cursor:!0,default_href:!1,ajax:{retries:0,timeout:0},enable:{log:!1,autolock:!1,log_history:!1,per_element:{events:!0},clickable_structure:!1,only:!1},inline:{enabled:!1,once:!0},debug:{enable:!1,display:{events:!0,remote:!0,config:!0}},delegate:{confirm:["click"],form:["submit"],select_multiple:["blur"],select:["change"],tags:["click"]}};var options={},callbacks=$("
"),_log=[],$original_cursor,$body_html=null;return vars._callbacks={before:function(){return!0},beforeSend:function(){return!0},params:function(){return!0},always:function(){return!0},fail:function(){return!0},progress:function(){return!0},done:function(){return!0},after:function(){return!0},exception:function(){return!0},json:function(){return!0}},functions.trigger_and_return=function(e,t,r,n,i){n=n||null;var a=$.Event(t);return a.$target=e instanceof $?e:$(e),n&&(a.target=n instanceof $?n[0]:n,a.$target=n instanceof $?n:$(n)),r="array"===$.type(r)?r:[r],i?e.trigger(a,r):e.each(function(){$.event.trigger(a,r,this,!0)}),debug(["event triggered",{name:t,"event result":a.result,element:e,data:r}],"events"),a},functions.trigger_phery_event=function(e,t,r,n){r=r||[],n=n===undefined?!1:n;var i;if(n)i=functions.trigger_and_return(callbacks,t,r,e),e&&options.enable.per_element.events&&functions.trigger_and_return(e,"phery:"+t,r,null,!0),i.result===undefined&&(i.result=!0);else{if(i=functions.trigger_and_return(callbacks,t,r,e),i.result===!1&&i.isImmediatePropagationStopped())return i;i.result===undefined&&(i.result=!0),e&&options.enable.per_element.events&&(i.result=i.result&&functions.trigger_and_return(e,"phery:"+t,r,null,!0).result)}return i},functions.count_properties=function(e){var t=0;if("object"==typeof e)for(var r in e)functions.hop(e,r)&&++t;else e.length!==undefined&&(t=e.length);return t},functions.form_submit=function(e){var t=e.phery("data","confirm");return t&&!confirm(t)?!1:functions.ajax_call.call(e)},functions.ajax_call=function(e,t){var r,n;if(r=this.phery("data","proxy")instanceof $?this.phery("data","proxy"):t?t:this,n=functions.trigger_phery_event(r,"before"),n.result===!1)return n.isImmediatePropagationStopped()||functions.trigger_phery_event(r,"always",[null]),clean_up(this),!1;if(!this.phery("data","remote")&&!this.phery("data","view"))return functions.trigger_phery_event(r,"exception",[phery.log("Current element have no remote data information")]),functions.trigger_phery_event(r,"always",[null]),clean_up(this),!1;var i,a,o,s,c,l,f={"X-Requested-With":"XMLHttpRequest","X-Phery":1},u=t||this,p=this,d=p.attr("action")||p.attr("href")||p.phery("data","target")||u.attr("action")||u.attr("href")||u.phery("data","target")||options.default_href||window.location.href,h=p.phery("data","type")||u.phery("data","type")||"json",y=p.attr("method")||u.attr("method")||u.phery("data","method")||"GET",g=u.attr("id")||u.parent().attr("id")||null,m=!!p.phery("data","cache")||!!u.phery("data","cache")||!1,v={},_={args:undefined,phery:{method:y}};if((u.phery("data","only")||options.enable.only===!0)&&u.phery("inprogress"))return!1;if(u.phery("data","inprogress",!0),(l=$("head meta#csrf-token")).length&&(_.phery.csrf=l.prop("content")),u.phery("data","args"))try{_.args=functions.per_data({},u.phery("data","args"))}catch(b){functions.trigger_phery_event(r,"exception",[phery.log(b)])}if(e&&(_.args=functions.per_data(_.args,e)),u.is("form"))try{i=u.serializeForm(u.phery("data","submit")?$.extend({},u.phery("data","submit"),{files_apart:!0}):{files_apart:!0}),_.args=functions.per_data(_.args,i.inputs),$.extend(v,i.files)}catch(b){functions.trigger_phery_event(r,"exception",[phery.log(b)])}if(u.is('textarea,input[type!="file"]')&&(i=u.serializeForm(),_.args=functions.per_data(_.args,i)),u.is('input[type="file"]')&&vars.has_file&&(i=u.serializeForm(),$.extend(v,i)),u.is("select")){var w=functions.form_element(u);if(w.name){var x={};x[w.name]=w.value,_.args=functions.per_data(_.args,x)}else _.args=functions.per_data(_.args,w.value)}if(u.phery("data","related"))try{var k,j,O=u.phery("data","related"),F=$();switch(typeof O){case"string":if(O.indexOf(",")>-1)for(k=O.split(","),c=0;k.length>c;c++)j=u.find(k[c]),j.length||(j=$(k[c])),j.length&&(F=F.add(j));else j=u.find(O),j.length||(j=$(O)),j.length&&(F=F.add(j));break;case"object":F=O;break;default:F=!1}if(F!==!1)if(F.length){var P={},A=0;F.each(function(){var e=$(this);if(e.is("form"))i=e.serializeForm({files_apart:!0}),P=functions.per_data(P,i.inputs),$.extend(v,i.files);else if(e.is('input[type="checkbox"]')&&e.attr("name")&&e.attr("name").indexOf("[")>0&&e.attr("name").indexOf("]")>0){var t=e.serializeForm();for(var r in t)P[r]===undefined&&(P[r]=[]),P[r]=functions.per_data(P[r],t[r])}else e.attr("name")?P[e.attr("name")]=e.val():e.attr("id")?P[e.attr("id")]=e.val():P[A++]=e.val()}),_.args=functions.per_data(_.args,P)}else functions.trigger_phery_event(r,"exception",[phery.log("related selector found no elements",u.phery("data","related"))])}catch(b){functions.trigger_phery_event(r,"exception",[phery.log(b,"invalid data-phery-related info")])}g&&(_.phery.submit_id=g),u.phery("data","view")?_.phery.view="#"+u.attr("id"):(p.phery("data","remote")||u.phery("data","remote"))&&(_.phery.remote=p.phery("data","remote")||u.phery("data","remote"));var D={};functions.trigger_phery_event(r,"params",D,!0),_.phery=$.extend(D,_.phery),a=new Date,debug(["remote call",{data:_,timestamp:a.getTime(),time:a.toLocaleString()}],"remote"),a=a.getTime(),s=functions.count_properties(v)>0;var T={url:m?d:-1===d.indexOf("_=")?(-1!==d.indexOf("#")?d.substr(0,d.indexOf("#")):d)+(d.indexOf("?")>-1?"&":"?")+"_="+a:d.replace(/_=(\d+)/,"_="+a),data:s?functions.to_formdata($.extend(v,_)):_,contentType:s?!1:"application/x-www-form-urlencoded",processData:!s,dataType:h,type:"POST",el:p,global:!1,try_count:0,timeout:options.ajax.timeout,retry_limit:options.ajax.retries,cache:m,headers:f,xhr:function(){var e=$.ajaxSettings.xhr();return e.upload!==undefined&&(e.upload.onprogress=function(e){functions.trigger_phery_event(r,"progress",[e])}),e},beforeSend:function(e,t){do_cursor("wait");var n=functions.trigger_phery_event(r,"beforeSend",[e,t]);return n.result===!1&&e.abort(),n.result!==!1}},H=function(e,t,n){return this.retry_limit>0&&"timeout"===t&&(this.try_count++,this.try_count<=this.retry_limit)?(functions.trigger_phery_event(r,"before"),this.dataType="text "+h,this.url=-1===this.url.indexOf("_try_count=")?this.url+"&_try_count="+this.try_count:this.url.replace(/_try_count=(\d+)/,"_try_count="+this.try_count),m||(this.url=this.url.replace(/_=(\d+)/,"_="+(new Date).getTime())),o=L(this),!1):(do_cursor(!1),u.phery("data","inprogress",!1),functions.trigger_phery_event(r,"fail",[e,t,n]).result===!1?(clean_up(this.el),!1):(clean_up(this.el),!0))},S=function(e,t,n){return functions.trigger_phery_event(r,"done",[e,t,n]).result===!1?!1:(functions.process_request.call(r,e,r!==p),!0)},E=function(e,t,n){return"timeout"===t&&4!==e.readyState&&this.try_count>0&&this.try_count<=this.retry_limit?(functions.trigger_phery_event(r,"always",[e]),!1):(do_cursor(!1),"timeout"!==t&&u.phery("data","inprogress",!1),functions.trigger_phery_event(r,"always",["timeout"===t?e:n]).result===!1?(clean_up(this.el),!1):(clean_up(this.el),!0))},L=function(e){var t=$.ajax(e);return t.done(S).always(E).fail(H),t};return o=L(T)},functions.convertible=function($element,data,force_current){var self=this,special,selector,cmd;if(self.$current=null,self.$last=null,self.skip=!1,self.stack=[],self.phery=$element.phery(),force_current=force_current===undefined?!1:force_current,self.set_selector=function(e){self.$last=self.$current,self.$current=e,self.stack.push(e)},self.restore_selector=function(){null!==self.$last&&(self.$current=self.$last,self.$last=self.$current)},self.convert_special=function(e,t){var r;if(t===undefined&&(t=5),t--,0>t)return e;if($.isPlainObject(e)||"array"===$.type(e))if("PF"in e)(r=functions.str_is_function(e.PF,!0))?(e.PF=null,delete e.PF,e=r,r=null):(r===!1&&debug(["PheryFunction passed is invalid",e.PF],"events"),e.PF=null,delete e.PF);else if("PR"in e)r=new functions.convertible($element,e.PR),delete e.PR,e=r.$current,r.destroy(),r=null;else for(var n in e)functions.hop(e,n)&&(e[n]=self.convert_special(e[n],t));return e},self.selector=function(){var e,t;if("="===special||"!"===special){if(!cmd)return;if(e=cmd.a[0],"function"===$.type(e))self.skip=!0,"="===special&&e.call(self.$last||self.$current||$element)?(self.restore_selector(),self.skip=!1):"!"!==special||e.call(self.$last||self.$current||$element)||(self.restore_selector(),self.skip=!1);else if("boolean"===$.type(e))self.skip=!0,"="===special&&e?(self.restore_selector(),self.skip=!1):"!"!==special||e||(self.restore_selector(),self.skip=!1);else if("object"===$.type(e)||"string"===$.type(e))try{self.skip=!0,"="===special?e instanceof $&&e.length?(self.skip=!1,self.restore_selector()):$(e).length&&(self.skip=!1,self.restore_selector()):"!"===special&&(e instanceof $&&!e.length?(self.skip=!1,self.restore_selector()):$(e).length||(self.skip=!1,self.restore_selector()))}catch(r){self.trigger([phery.log(r)])}}else if("+"===special){if(!cmd)return;"string"==typeof cmd.a[1]&&cmd.a[1].match(vars.special_match)?(t={},t[cmd.a[1]]=[],e=new functions.convertible($element,t)):e=null,t=functions.assign_object(null!==e&&null!==e.$current?e.$current:window,cmd.c,undefined,!1,!1,!0),t?self.set_selector(cmd.a[0]?new t:t):self.trigger([phery.log("failed access to object","window."+cmd.c.join("."))]),e instanceof functions.convertible&&e.destroy(),e=null}else"~"===special?self.set_selector($element):"-"===special?self.set_selector(phery.remote.apply(phery,cmd.a)):"#"===special?self.set_selector($):"window"===selector.toLowerCase()?self.set_selector($window):"document"===selector.toLowerCase()?self.set_selector($document):"string"==typeof selector&&self.set_selector($(selector))},self.trigger=function(e,t){t=t||"exception",functions.trigger_phery_event($element,t,e)},self.process_parameters=function(){if(cmd&&cmd.a!==undefined)for(var e in cmd.a)functions.hop(cmd.a,e)&&(cmd.a[e]=self.convert_special(cmd.a[e]))},self.command=function(){var argc,argv,command,tmp,view,pass,args;if(cmd)switch(argc=cmd.a.length,argv=cmd.a,command=Number(cmd.c)){case 1:argv[0]!==undefined?alert(""+argv[0]):self.trigger([phery.log("missing message for alert()",argv)]);break;case 2:try{if(tmp=functions.assign_object(window,argv[0],undefined,!1),tmp===!1||"function"!=typeof tmp[0][tmp[1]])throw'no function "'+tmp.join(".")+'" found';tmp[0][tmp[1]].apply(tmp[0],argv[1]||[])}catch(exception){self.trigger([phery.log(exception,argv)])}break;case 3:try{eval("(function(){ "+argv[0]+" })();")}catch(exception){self.trigger([phery.log(exception,argv[0])])}break;case 4:try{self.trigger([$.parseJSON(argv[0])],"json")}catch(exception){self.trigger([phery.log(exception,argv[0])])}break;case 5:view=self.phery.data("view"),args=$.extend(!0,{},{url:self.phery.data("target")},argv[1]),tmp=self.phery.data("passdata"),tmp?(pass=tmp,$.removeData($element[0],"phery-passdata")):pass={},"function"==typeof view.beforeHtml&&view.beforeHtml.call($element,args,pass),"function"!=typeof view.render?$element.html("").html(argv[0]):view.render.call($element,argv[0],args,pass),"function"==typeof view.afterHtml&&view.afterHtml.call($element,args,pass);break;case 6:try{if("undefined"!=typeof console&&console.log!==undefined)for(var l=0;argc>l;l++)console.log(argv[l][0])}catch(exception){self.trigger([phery.log(exception,argv[0])])}break;case 7:argc>1?(args=Array.prototype.concat.call(argv),self.trigger(args),args=null):self.trigger([argv[0]]);break;case 8:if(2===argc)if(argv[1])try{self.phery.data("inprogress",!1),phery.view(argv[1]).navigate_to(argv[0])}catch(e){self.trigger([phery.log('phery view "'+argv[1]+'" not found')])}else window.location.assign(argv[0]);break;case 9:tmp=functions.assign_object(window,argv[0],undefined,2===argc,!0),tmp&&tmp.length>0?2===argc?(pass=new functions.convertible($element,argv[1][0],!0),tmp[0][tmp[1]]=pass.$current,pass.destroy(),pass=null):1===argc&&delete tmp[0][tmp[1]]:self.trigger([phery.log("object path not found in window."+argv[0].join("."))]),tmp=null;break;case 10:var head=$("head"),file=null,i;switch(argv[0]){case"j":for(i in argv[1])functions.hop(argv[1],i)&&(file=$("",{type:"text/javascript",src:argv[1][i],id:i}),head.find("script#"+i).length?argv[2]&&head.find("script#"+i).replaceWith(file):head[0].appendChild(file[0]));break;case"c":for(i in argv[1])functions.hop(argv[1],i)&&(file=$("",{type:"text/css",rel:"stylesheet",href:argv[1][i],id:i}),head.find("link#"+i).length?argv[2]&&head.find("link#"+i).replaceWith(file):head[0].appendChild(file[0]),file=null)}head=null;break;case 11:break;case 12:try{3===argc?phery.broadcast(argv[0],argv[1][0]):2===argc&&self.phery.publish(argv[0],argv[1][0])}catch(e){self.trigger([phery.log("invalid pub/sub operation")])}break;case 13:var meta=$("head meta#csrf-token");meta.length?meta.replaceWith(argv[0]):$("head").append(argv[0]);break;default:self.trigger([phery.log('invalid command "'+cmd.c+'" issued')])}},self.select=function(){if(special=selector.match(vars.special_match),null!==special&&(special=special[1]),special||"<"===selector.charAt(0)||-1===selector.search(/^[0-9]+$/)){("!"===special||"="===special||"+"===special)&&(cmd=data[selector][0],self.process_parameters()),self.selector();for(var e in data[selector])if(functions.hop(data[selector],e)){if(data[selector][e]===cmd)continue;if(self.skip){self.skip=!1;continue}cmd=data[selector][e],self.process_parameters();try{if("function"!=typeof self.$current[cmd.c])throw'no function "'+cmd.c+'" found in object';self.set_selector(self.$current[cmd.c].apply(self.$current,cmd.a))}catch(t){self.trigger([phery.log(t)])}}}else cmd=data[selector],self.process_parameters(),self.command()},self.destroy=function(){self.stack=self.$current=self.$last=self.phery=data=cmd=null},force_current)self.set_selector(self.convert_special(data));else if($.isPlainObject(data))for(selector in data)if(functions.hop(data,selector)){if(self.skip){self.skip=!1;continue}self.select()}},functions.process_request=function(e,t){if(!this.phery("data","remote")&&!this.phery("data","view")&&!t)return functions.trigger_phery_event(this,"after",[null]),undefined;var r=new functions.convertible(this,e);functions.trigger_phery_event(this,"after",[r.$current]),r.destroy(),r=null},functions.dot_notation_option=function(e,t,r){if(-1!==e.indexOf(".")){var n=e.split(".");if(n&&n[0]&&t[n[0]]!==undefined)return functions.dot_notation_option(n.slice(1).join("."),t[n[0]],r)}else if(t[e]!==undefined)return r!==undefined?(t[e].constructor===Array&&"string"==typeof r?t[e].push(r):t[e]=r,t):t[e];return null},options=$.extend(!0,{},vars.defaults,options),$window.on({load:function(){options.enable.autolock&&(vars.locked_config=!0),options.inline.enabled&&options.inline.once&&(vars.inline_load=!1)}}),phery.config=function(e,t){return"object"==typeof e&&e.constructor===Object?(refresh_changes(e),phery):"string"==typeof e&&t!==undefined?(refresh_changes(e,t),phery):"string"==typeof e&&t===undefined?e in options?options[e]:functions.dot_notation_option(e,options):0===arguments.length?$.extend(!0,{},options):phery},phery.lock_config=function(){return vars.locked_config=!0,phery},phery.reset_to_defaults=function(){return options=$.extend(!0,{},vars.defaults),_apply(options,!0),phery},phery.log=function(){var e=Array.prototype.slice.call(arguments);return e.length?(options.enable.log&&(options.enable.log_history&&_log.push(e),"undefined"!=typeof console&&console.log!==undefined&&("object"==typeof console.log?console.log(e):console.log.apply(console,e))),e.join("\n")):options.enable.log_history?_log:[]},phery.broadcast=function(e,t){var r,n,i;for(r=0,n=vars.subscribed.length;n>r;r++)i=vars.subscribed[r],i.topic===e&&i.pub(t);return phery},phery.subscribe=function(e,t,r,n){var i=phery.remote(e,r,n,!1);return i.phery("subscribe",t),i},phery.timer=function(e,t){var r=!1,n=null,i=t,a=function(){if(e.constructor===Array){var t=$.makeArray(e);phery.remotes(t).done(function(){r===!1&&(n=setTimeout(a,i))})}else{var o=functions.ajax_call.call(e);o&&o.always(function(){r===!1&&(n=setTimeout(a,i))})}};return t!==undefined&&a(),{start:function(e){return e!==undefined&&(r=!1,i=e,clearTimeout(n),a()),this},stop:function(){return r=!0,clearTimeout(n),this}}},phery.remote=function(e,t,r,n){if(!this)return!1;if(this===phery&&!e)return phery.log('first argument "function_name" on phery.remote() must be specified when calling directly'),!1;if(n!==!1&&(n=!0),this!==phery)return functions.ajax_call.call(this);var i=$(""),a=[t],o=!1;if(i.phery("data","remote",e),n===!0&&(r!==undefined?r.temp!==undefined?(i.phery("data","temp",!0),o=!0):r.proxy===undefined&&r.el===undefined&&(i.phery("data","temp",!0),o=!0):(i.phery("data","temp",!0),o=!0)),r!==undefined&&$.isPlainObject(r)){if(r.proxy!==undefined)if(r.proxy instanceof $)r.proxy=r.proxy;else if("string"===$.type(r.proxy)){var s=$(r.proxy);s.length?r.proxy=s:delete r.proxy}else delete r.proxy;r.el!==undefined&&(r.el instanceof $&&a.push(r.el),delete r.el);for(var c in r)functions.hop(r,c)&&(-1!=="target method type proxy cache".indexOf(c.toLowerCase())?i.phery("data",c,r[c]):i.attr(r))}return o===!1&&t&&i.phery("set_args",t),n?functions.ajax_call.apply(i,a):i},phery.element=function(e,t){return t=t||null,phery.remote(e,null,t,!1)},phery.json=function(e,t,r){var n=phery.remote(e,null,{temp:!0},!1);return n.on("phery:json",function(e,t){return r(t)}),t!==undefined&&null!==t?n.phery("remote",t):n.phery("remote"),n},phery.remotes=function(e){var t=$.Deferred(),r=[],n=0,i=function(){var a=e instanceof $?e.eq(n++):e.shift();if(a&&a.length){var o=e instanceof $?phery.remote.apply(a):phery.remote.apply(phery,a);o instanceof $.Deferred?(r.push(o),t.notifyWith(a,o),o.always(i)):i()}else t.resolve(r)};if("array"===$.type(e)&&e.length)for(var a=0;e.length>a;a++)"array"===$.type(e[a])?e[a].length>3&&(e[a]=e[a].slice(0,3)):e.splice(a,1);else if(!(e instanceof $))return t.resolve([]),t.promise();return i(),t.promise()},phery.on=function(e,t){if("object"==typeof e){if($.isPlainObject(e))for(var r in e)functions.hop(e,r)&&phery.on(r,e[r])}else"string"==typeof e&&"function"==typeof t&&e in vars._callbacks&&(debug(["phery.on",{event:e,callback:t}],"events"),callbacks.on(e+".phery",t));return phery},phery.off=function(e){return debug(["phery.off",{event:e}],"events"),callbacks.off(e+".phery"),phery},phery.load=function(e,t){if(options.inline.enabled){if(!vars.inline_load)return phery;t||(t=$(""),t.phery("data","temp",!0)),"string"===$.type(e)&&t instanceof $&&functions.process_request.call(t,$.parseJSON(e),!0)}return phery},vars._containers={},functions.excluded_url=function(e,t){if("#"===e)return!0;for(var r=0;t.length>r;r++)switch(typeof t[r]){case"string":if(-1!==e.indexOf(t[r]))return!0;break;case"object":if(-1!==e.search(t[r]))return!0;break;case"function":if(t[r].call(null,e)===!0)return!0}return!1},functions.phery_view=function(e){this.container=e,this.data=$.extend({},this.container.phery("data","view")),this.is_excluded_url=function(e){var t=this.container.phery("data","view").exclude||!1;return t&&e?functions.excluded_url(e,t):!1},this.navigate_to=function(e,t,r){e&&this.container.phery("data","target",e);var n;return r!==undefined&&this.container.phery("data","passdata",r),n=t!==undefined&&null!==t?functions.ajax_call.call(this.container,t):functions.ajax_call.call(this.container)}},phery.view=function(e){if("string"==typeof e)return vars._containers[e]!==undefined?vars._containers[e]:phery;if("object"==typeof e&&$.isEmptyObject(e))return debug(["phery.view needs config"],"config"),phery;if(!$.isPlainObject(e))return debug(["phery.view needs a plain object"],"config"),phery;var t,r,n,i,a=function(e){var t=$(this),r=t.attr("href");return 2===e.which||e.metaKey?!0:e.data.is_excluded_url(r)?!0:(debug(["phery.view link clicked, loading content",e.data.container,t.attr("href")],"events"),e.data.navigate_to(t.attr("href")),e.stopPropagation(),e.preventDefault(),!1)};$document.off("click.view");for(t in e)if(functions.hop(e,t))if(n=$(t),1===n.length){if(r=t.replace(/[#\.\s>:,~=\+\-_\*]/g,""),e[t]===!1){n.off(".pheryview"),$document.off("click.view."+r),debug(["phery.view uninstalled and events unbound",n],"config");continue}i="string"==typeof e[t].selector&&-1!==e[t].selector.search(/(^|\s)a($|\s|\.)/i)?t+" "+e[t].selector:'a[href]:not(.no-phery,[target],[data-phery-remote],[href*=":"],[rel~="nofollow"])',i=i+',a[href][rel="'+t+'"]';for(var o in e[t])functions.hop(e[t],o)&&"string"==typeof o&&vars._callbacks[o]!==undefined&&(n.on("phery:"+o+".pheryview",e[t][o]),delete e[t][o]);n.phery("data","view",$.extend(!0,{},e[t],{selector:i})),vars._containers[t]=new functions.phery_view(n),$document.on("click.view."+r,i,vars._containers[t],a),debug(["phery.view installed",n],"config")}else debug(["phery.view container",n,"isnt unique or does not exist"],"config");return phery},functions.reset=function(){return this.each(function(){$(this).is("form")&&this.reset()})},functions.phery=function(e){var t=this,r=function(){return{publish:function(e,r){return t.each(function(){var t,n=$(this);t=functions.is_subscribed(e,!1,n),t!==!1&&t.pub(r)})},subscribe:function(e,r){return t.each(function(){var t,n,i=$(this);for(t in e)functions.hop(e,t)&&(n=functions.is_subscribed(t,!0,i),n!==!1&&(r===!0?n.unsub(e[t]):n.sub(e[t])))})},exception:function(e,r){return t.each(function(){var t=$(this);functions.trigger_phery_event(t,"exception",[e,r])})},data:function(e,r){var n;if(r!==undefined)return t.data("phery-"+e,r),t;if(e!==undefined){if($.isPlainObject(e)){for(n in e)functions.hop(e,n)&&t.data("phery-"+n,e[n]);return t}return t.data("phery-"+e)}r=$.extend({},t.data());for(n in r)functions.hop(r,n)&&!/^phery/.test(n)&&delete r[n];return r},proxy:function(e){return t.each(function(){var t=$(this);if(e instanceof $)e.length&&t.phery("data","proxy",e);else if("string"===$.type(e))try{e=$(e),e.length&&t.phery("data","proxy",e)}catch(r){}else $.removeData(this,"phery-proxy")})},remote:function(e){return t.each(function(){var t=$(this);t.is(":phery-remote")&&(t.is("form")?functions.form_submit(t):functions.ajax_call.call(t,e))})},one:function(e){return t.is(":phery-remote")?t.is("form")?functions.form_submit(t):functions.ajax_call.call(t,e):undefined},append_args:function(){var e=Array.prototype.slice.call(arguments);return e.length&&t.each(function(){var t=$(this);functions.append_args.apply(t,[e])}),r},set_args:function(e){return t.each(function(){var t=$(this);functions.set_args.call(t,[e])}),r},get_args:function(){return r.data("args")},remove:function(){t.each(function(){var e=$(this);e.phery("data","temp",!0),clean_up(e)})},make:function(e,r){return"string"===$.type(e)?t.each(function(){var t=$(this);t.attr("data-phery-remote",e).phery("data",{remote:e,inprogress:!1}),r!==undefined&&functions.set_args.call(t,[r])}):t},inprogress:function(){return!!r.data("inprogress")},unmake:function(e){return t.each(function(){var t=$(this);e&&t.off(".phery"),$.removeData(this,"remote"),t.removeAttr("data-phery-remote").removeAttr("data-phery-args").removeAttr("data-phery-confirm")})}}}();if(e&&$.isPlainObject(e)){var n;for(var i in e)functions.hop(e,i)&&i in r&&(n=r[i].apply(t,e[i]));return n}return e&&e in r?r[e].apply(t,Array.prototype.slice.call(arguments,1)):r},functions.serializeForm=function(e){e=$.extend({disabled:!1,all:!1,empty:!0,files_apart:!1},e||{});var t=$(this),r=e.files_apart?{inputs:{},files:{}}:{},n=function(){var e=$(this);return!vars.has_file&&e.is('input[type="file"]')?null:functions.form_element(e)},i=t.is("form")?t.find("input,textarea,select").filter(function(){var t=!0;return e.disabled||(t=!this.disabled),t&&""!==$.trim(this.name)}).map(n).get():t.is("select,textarea,input")?[functions.form_element(t)]:[];if(i.length){var a,o,s,c,l,f,u,p,d;for(a=0;i.length>a;a++){if(s=i[a].name,o=i[a].value,p=i[a].type,e.all)null===o&&(o="");else if(null===o)continue;if((""!==o||e.empty)&&("file"!==p||0!==o.length)&&s){for(c=s.split(/\[/),l=c.length,u=1;l>u;u++)c[u]=c[u].replace(/\]/g,"");for(d=[],u=0;l>u;u++)(c[u]||l-1>u)&&d.push(c[u].replace(/['"]+/g,""));""===c[l-1]?(f=functions.assign_object(e.files_apart?"file"===p?r.files:r.inputs:r,d,[],!0,!1,!1),"array"===$.type(o)?Array.prototype.push.apply(f[0][f[1]],o):f[0][f[1]].push(o)):functions.assign_object(e.files_apart?"file"===p?r.files:r.inputs:r,d,o,!0,!1,!1,"file"===p) }}}return r},$.extend($.expr[":"],{"phery-remote":function(e){return"string"==typeof(e instanceof $?e.phery("data","remote"):$(e).phery("data","remote"))},"phery-confirm":function(e){return"string"==typeof(e instanceof $?e.phery("data","confirm"):$(e).phery("data","confirm"))},"phery-view":function(e){return!!(e instanceof $?e.phery("data","view"):$(e).phery("data","view"))}}),$.fn.reset=functions.reset,$.fn.phery=functions.phery,$.fn.serializeForm=functions.serializeForm,$.inArray(window.location.host,["127.0.0.1","::1","localhost"])>-1&&(phery.vars=vars,phery.functions=functions),"vars"in phery||"functions"in phery||"function"==typeof Object.freeze&&Object.freeze(phery),_apply(options,!0),phery});