UNPKG

intercooler

Version:

Making AJAX as easy as anchor tags

2 lines 23.4 kB
/*! intercooler 0.4.10 2015-04-17 */ var Intercooler=Intercooler||function(){"use strict";function _defineTransition(a,b){null==b.newContent&&(b.newContent=function(a,b,c,d,e){d?(a.replaceWith(b),e(b)):(a.empty().append(b),e())}),null==b.remove&&(b.remove=function(a){a.remove()}),null==b.show&&(b.show=function(a){a.show()}),null==b.hide&&(b.hide=function(a){a.hide()}),_transitions[a]=b}function fingerprint(a){if(null==a||void 0==a)return 0;var b,c,d,e=a.toString(),f=0;if(0==e.length)return f;for(b=0,d=e.length;d>b;b++)c=e.charCodeAt(b),f=(f<<5)-f+c,f|=0;return f}function log(a,b,c){null==a&&(a=$("body")),a.trigger("log.ic",[b,c,a]),"ERROR"==c&&window.console&&window.console.log("Intercooler Error : "+b)}function uuid(){return _UUID++}function icSelectorFor(a){return"[ic-id='"+getIntercoolerId(a)+"']"}function findById(a){return $("#"+a)}function parseInterval(a){return log(null,"POLL: Parsing interval string "+a,"DEBUG"),"null"==a||"false"==a||""==a?null:a.lastIndexOf("ms")==a.length-2?parseInt(a.substr(0,a.length-2)):a.lastIndexOf("s")==a.length-1?1e3*parseInt(a.substr(0,a.length-1)):1e3}function initScrollHandler(){null==_scrollHandler&&(_scrollHandler=function(){$("[ic-trigger-on='scrolled-into-view']").each(function(){isScrolledIntoView($(this))&&1!=$(this).data("ic-scrolled-into-view-loaded")&&($(this).data("ic-scrolled-into-view-loaded",!0),fireICRequest($(this)))})},$(window).scroll(_scrollHandler))}function currentUrl(){return window.location.pathname+window.location.search+window.location.hash}function getTarget(a){var b=closestAttrValue(a,"ic-target");return b&&0!=b.indexOf("this.")?0==b.indexOf("closest ")?a.closest(b.substr(8)):$(b):a}function handleHistory(a,b,c){b.getResponseHeader("X-IC-PushURL")?(log(a,"X-IC-PushURL: pushing "+b.getResponseHeader("X-IC-PushURL"),"DEBUG"),_historySupport.pushUrl(b.getResponseHeader("X-IC-PushURL"),a,c)):"true"==closestAttrValue(a,"ic-push-url")&&_historySupport.pushUrl(a.attr("ic-src"),a,c)}function processHeaders(elt,xhr){elt.trigger("beforeHeaders.ic",[elt,xhr]),log(elt,"response headers: "+xhr.getAllResponseHeaders(),"DEBUG");var target=null;if(xhr.getResponseHeader("X-IC-Refresh")){var pathsToRefresh=xhr.getResponseHeader("X-IC-Refresh").split(",");log(elt,"X-IC-Refresh: refreshing "+pathsToRefresh,"DEBUG"),$.each(pathsToRefresh,function(a,b){refreshDependencies(b.replace(/ /g,""),elt)})}if(xhr.getResponseHeader("X-IC-Script")&&(log(elt,"X-IC-Script: evaling "+xhr.getResponseHeader("X-IC-Script"),"DEBUG"),eval(xhr.getResponseHeader("X-IC-Script"))),xhr.getResponseHeader("X-IC-Redirect")&&(log(elt,"X-IC-Redirect: redirecting to "+xhr.getResponseHeader("X-IC-Redirect"),"DEBUG"),window.location=xhr.getResponseHeader("X-IC-Redirect")),"true"==xhr.getResponseHeader("X-IC-CancelPolling")&&cancelPolling(elt),xhr.getResponseHeader("X-IC-Open")&&(log(elt,"X-IC-Open: opening "+xhr.getResponseHeader("X-IC-Open"),"DEBUG"),window.open(xhr.getResponseHeader("X-IC-Open"))),xhr.getResponseHeader("X-IC-Transition")&&(log(elt,"X-IC-Transition: setting transition to "+xhr.getResponseHeader("X-IC-Transition"),"DEBUG"),target=getTarget(elt),target.data("ic-tmp-transition",xhr.getResponseHeader("X-IC-Transition"))),xhr.getResponseHeader("X-IC-Trigger")){log(elt,"X-IC-Trigger: found trigger "+xhr.getResponseHeader("X-IC-Trigger"),"DEBUG"),target=getTarget(elt);var triggerArgs=[];xhr.getResponseHeader("X-IC-Trigger-Data")&&(triggerArgs=$.parseJSON(xhr.getResponseHeader("X-IC-Trigger-Data"))),target.trigger(xhr.getResponseHeader("X-IC-Trigger"),triggerArgs)}if(xhr.getResponseHeader("X-IC-Remove")&&elt){target=getTarget(elt),log(elt,"X-IC-REMOVE header found.","DEBUG");var transition=getTransition(elt,target);transition.remove(target)}return elt.trigger("afterHeaders.ic",[elt,xhr]),!0}function beforeRequest(a){a.addClass("disabled"),a.data("ic-request-in-flight",!0)}function afterRequest(a){a.removeClass("disabled"),a.data("ic-request-in-flight",!1),a.data("ic-next-request")&&(a.data("ic-next-request")(),a.data("ic-next-request",null))}function replaceOrAddMethod(a,b){var c=/(&|^)_method=[^&]*/,d="&_method="+b;return c.test(a)?a.replace(c,d):a+"&"+d}function globalEval(a){return window.eval.call(window,a)}function closestAttrValue(a,b){var c=$(a).closest("["+b+"]");return c?c.attr(b):null}function formatError(a){var b=a.toString()+"\n";try{b+=a.stack}catch(a){}return b}function handleRemoteRequest(a,b,c,d,e){beforeRequest(a),d=replaceOrAddMethod(d,b);var f=findIndicator(a),g=getTransition(f,f);f.length>0&&g.show(f);var h=uuid(),i=new Date;_remote.ajax({type:b,url:c,data:d,dataType:"text",headers:{Accept:"text/html-partial, */*; q=0.9","X-IC-Request":!0,"X-HTTP-Method-Override":b},beforeSend:function(e,f){a.trigger("beforeSend.ic",[a,d,f,e,h]),log(a,"before AJAX request "+h+": "+b+" to "+c,"DEBUG");var g=closestAttrValue(a,"ic-on-beforeSend");g&&globalEval("(function (data, settings, xhr) {"+g+"})")(d,f,e)},success:function(b,c,d){a.trigger("success.ic",[a,b,c,d,h]),log(a,"AJAX request "+h+" was successful.","DEBUG");var f=closestAttrValue(a,"ic-on-success");if(!f||0!=globalEval("(function (data, textStatus, xhr) {"+f+"})")(b,c,d)){var g=getTarget(a);g.data("ic-tmp-transition",closestAttrValue(a,"ic-transition"));var i=new Date;try{if(processHeaders(a,d)){log(a,"Processed headers for request "+h+" in "+(new Date-i)+"ms","DEBUG");var j=new Date,k=g.html();e(b,c,a,d),handleHistory(a,d,k),log(a,"Process content for request "+h+" in "+(new Date-j)+"ms","DEBUG")}a.trigger("after.success.ic",[a,b,c,d,h])}catch(l){log(a,"Error processing successful request "+h+" : "+formatError(l),"ERROR")}g.data("ic-tmp-transition",null)}},error:function(b,c,d){a.trigger("error.ic",[a,c,d,b]);var e=closestAttrValue(a,"ic-on-error");e&&globalEval("(function (status, str, xhr) {"+e+"})")(c,d,b),log(a,"AJAX request "+h+" experienced an error: "+d,"ERROR")},complete:function(b,c){log(a,"AJAX request "+h+" completed in "+(new Date-i)+"ms","DEBUG"),afterRequest(a),$("body").trigger("complete.ic",[a,d,c,b,h]);var e=closestAttrValue(a,"ic-on-complete");e&&globalEval("(function (xhr, status) {"+e+"})")(b,c),f.length>0&&g.hide(f)}})}function findIndicator(a){var b=null;if($(a).attr("ic-indicator"))b=$($(a).attr("ic-indicator")).first();else if(b=$(a).find(".ic-indicator").first(),0==b.length){var c=closestAttrValue(a,"ic-indicator");c&&(b=$(c).first())}return b}function processIncludes(a){var b="";if(0==$.trim(a).indexOf("{")){var c=$.parseJSON(a);$.each(c,function(a,c){b+="&"+encodeURIComponent(a)+"="+encodeURIComponent(c)})}else $(a).each(function(){b+="&"+$(this).serialize()});return b}function getParametersForElement(a,b){var c=getTarget(a),d="ic-request=true";d+=a.closest("form").length>0?"&"+a.closest("form").serialize():"&"+a.serialize(),a.attr("id")&&(d+="&ic-element-id="+a.attr("id")),a.attr("name")&&(d+="&ic-element-name="+a.attr("name")),c.attr("ic-id")&&(d+="&ic-id="+c.attr("ic-id")),b&&b.attr("id")&&(d+="&ic-trigger-id="+b.attr("id")),b&&b.attr("name")&&(d+="&ic-trigger-name="+b.attr("name")),c.attr("ic-last-refresh")&&(d+="&ic-last-refresh="+c.attr("ic-last-refresh")),c.attr("ic-fingerprint")&&(d+="&ic-fingerprint="+c.attr("ic-fingerprint"));var e=closestAttrValue(a,"ic-include");return e&&(d+=processIncludes(e)),d+="&ic-current-url="+encodeURIComponent(currentUrl()),log(a,"request parameters "+d,"DEBUG"),d}function maybeSetIntercoolerInfo(a){var b=getTarget(a);getIntercoolerId(b),maybeSetIntercoolerMetadata(b),1!=a.data("elementAdded.ic")&&(a.data("elementAdded.ic",!0),a.trigger("elementAdded.ic"))}function updateIntercoolerMetaData(a){a.attr("ic-fingerprint",fingerprint(a.html())),a.attr("ic-last-refresh",(new Date).getTime())}function maybeSetIntercoolerMetadata(a){a.attr("ic-fingerprint")||updateIntercoolerMetaData(a)}function getIntercoolerId(a){return a.attr("ic-id")||a.attr("ic-id",uuid()),a.attr("ic-id")}function processNodes(a){processMacros(a),processSources(a),processPolling(a),processTriggerOn(a),processRemoveAfter(a),$(a).trigger("nodesProcessed.ic")}function processSources(a){$(a).is("[ic-src]")&&maybeSetIntercoolerInfo($(a)),$(a).find("[ic-src]").each(function(){maybeSetIntercoolerInfo($(this))})}function startPolling(a){if(null==a.data("ic-poll-interval-id")){var b=parseInterval(a.attr("ic-poll"));if(null!=b){var c=icSelectorFor(a),d=parseInt(a.attr("ic-poll-repeats"))||-1,e=0;log(a,"POLL: Starting poll for element "+c,"DEBUG");var f=setInterval(function(){var b=$(c);a.trigger("onPoll.ic",b),0==b.length||e==d?(log(a,"POLL: Clearing poll for element "+c,"DEBUG"),clearTimeout(f)):fireICRequest(b),e++},b);a.data("ic-poll-interval-id",f)}}}function cancelPolling(a){null!=a.data("ic-poll-interval-id")&&clearTimeout(a.data("ic-poll-interval-id"))}function processPolling(a){$(a).is("[ic-poll]")&&(maybeSetIntercoolerInfo($(a)),startPolling(a)),$(a).find("[ic-poll]").each(function(){maybeSetIntercoolerInfo($(this)),startPolling($(this))})}function refreshDependencies(a,b){log(b,"refreshing dependencies for path "+a,"DEBUG"),$("[ic-src]").each(function(){var c=!1;"GET"==verbFor($(this))&&"ignore"!=$(this).attr("ic-deps")&&(isDependent(a,$(this).attr("ic-src"))?(null==b||$(b)[0]!=$(this)[0])&&(fireICRequest($(this)),c=!0):(isDependent(a,$(this).attr("ic-deps"))||"*"==$(this).attr("ic-deps"))&&(null==b||$(b)[0]!=$(this)[0])&&(fireICRequest($(this)),c=!0)),c&&log($(this),"depends on path "+a+", refreshing...","DEBUG")})}function isDependent(a,b){return a&&b&&(0==b.indexOf(a)||0==a.indexOf(b))}function verbFor(a){return a.attr("ic-verb")?a.attr("ic-verb").toUpperCase():"GET"}function eventFor(a,b){return"default"==a?$(b).is("button")?"click":$(b).is("form")?"submit":$(b).is(":input")?"change":"click":a}function preventDefault(a){return a.is("form")||a.is(":submit")&&1==a.closest("form").length}function handleRemoveAfter(a){if($(a).attr("ic-remove-after")){var b=getTransition(a,a),c=parseInterval($(a).attr("ic-remove-after"));setTimeout(function(){b.remove(a)},c)}}function handleTriggerOn(a){if($(a).attr("ic-trigger-on"))if("load"==$(a).attr("ic-trigger-on"))fireICRequest(a);else if("scrolled-into-view"==$(a).attr("ic-trigger-on"))initScrollHandler(),setTimeout(function(){$(window).trigger("scroll")},100);else{var b=$(a).attr("ic-trigger-on").split(" ");$(a).on(eventFor(b[0],$(a)),function(c){if("changed"==b[1]){var d=$(a).val(),e=$(a).data("ic-previous-val");$(a).data("ic-previous-val",d),d!=e&&fireICRequest($(a))}else fireICRequest($(a));return preventDefault(a)?(c.preventDefault(),!1):!0})}}function processTriggerOn(a){handleTriggerOn(a),$(a).find("[ic-trigger-on]").each(function(){handleTriggerOn($(this))})}function processRemoveAfter(a){handleRemoveAfter(a),$(a).find("[ic-remove-after]").each(function(){handleRemoveAfter($(this))})}function processMacros(a){$.each(_MACROS,function(b,c){$(a).is("["+c+"]")&&processMacro(c,$(a)),$(a).find("["+c+"]").each(function(){processMacro(c,$(this))})})}function processMacro(a,b){"ic-post-to"==a&&(setIfAbsent(b,"ic-src",b.attr("ic-post-to")),setIfAbsent(b,"ic-verb","POST"),setIfAbsent(b,"ic-trigger-on","default"),setIfAbsent(b,"ic-deps","ignore")),"ic-put-to"==a&&(setIfAbsent(b,"ic-src",b.attr("ic-put-to")),setIfAbsent(b,"ic-verb","PUT"),setIfAbsent(b,"ic-trigger-on","default"),setIfAbsent(b,"ic-deps","ignore")),"ic-get-from"==a&&(setIfAbsent(b,"ic-src",b.attr("ic-get-from")),setIfAbsent(b,"ic-trigger-on","default"),setIfAbsent(b,"ic-deps","ignore")),"ic-delete-from"==a&&(setIfAbsent(b,"ic-src",b.attr("ic-delete-from")),setIfAbsent(b,"ic-verb","DELETE"),setIfAbsent(b,"ic-trigger-on","default"),setIfAbsent(b,"ic-deps","ignore"));var c=null,d=null;if("ic-style-src"==a){c=b.attr("ic-style-src").split(":");var e=c[0];d=c[1],setIfAbsent(b,"ic-src",d),setIfAbsent(b,"ic-target","this.style."+e)}if("ic-attr-src"==a){c=b.attr("ic-attr-src").split(":");var f=c[0];d=c[1],setIfAbsent(b,"ic-src",d),setIfAbsent(b,"ic-target","this."+f)}"ic-prepend-from"==a&&(setIfAbsent(b,"ic-src",b.attr("ic-prepend-from")),setIfAbsent(b,"ic-transition","prepend")),"ic-append-from"==a&&(setIfAbsent(b,"ic-src",b.attr("ic-append-from")),setIfAbsent(b,"ic-transition","append"))}function setIfAbsent(a,b,c){null==a.attr(b)&&a.attr(b,c)}function isScrolledIntoView(a){var b=$(window).scrollTop(),c=b+$(window).height(),d=$(a).offset().top,e=d+$(a).height();return e>=b&&c>=d&&c>=e&&d>=b}function getTransition(a,b){var c=null;return a.attr("ic-transition")&&(c=_transitions[a.attr("ic-transition")]),b.attr("ic-transition")&&(c=_transitions[b.attr("ic-transition")]),b.data("ic-tmp-transition")&&(c=_transitions[b.data("ic-tmp-transition")]),null==c&&(c=_transitions[_defaultTransition]),null==c&&(c=_transitions.none),c}function processICResponse(a,b){if(a&&/\S/.test(a)){log(b,"response content: \n"+a,"DEBUG");var c=getTarget(b),d="false"!=closestAttrValue(b,"ic-always-update")||a.indexOf("<script>")>=0;if(0==d){var e=document.createElement("div");e.innerHTML=a,processMacros(e),d=fingerprint($(e).html())!=c.attr("ic-fingerprint"),e.remove&&e.remove()}if(d){var f=getTransition(b,c),g="true"==closestAttrValue(b,"ic-replace-target"),h=maybeFilter(a,closestAttrValue(b,"ic-select-from-response"));f.newContent(c,h,!1,g,function(a){a?(processNodes(a),updateIntercoolerMetaData(c)):($(c).children().each(function(){processNodes($(this))}),updateIntercoolerMetaData(c)),updateIntercoolerMetaData(c)})}}}function maybeFilter(a,b){var c=$.parseHTML(a,null,!0),d=$(c);return b&&(d.is(b)||(d=d.find(b))),d}function getStyleTarget(a){var b=closestAttrValue(a,"ic-target");return b&&0==b.indexOf("this.style.")?b.substr(11):null}function getAttrTarget(a){var b=closestAttrValue(a,"ic-target");return b&&0==b.indexOf("this.")?b.substr(5):null}function fireICRequest(a){var b=a;a.is("[ic-src]")||(a=a.closest("[ic-src]"));var c=closestAttrValue(a,"ic-confirm");if((!c||confirm(c))&&a.length>0){var d=uuid();a.data("ic-event-id",d);var e=function(){if(1==a.data("ic-request-in-flight"))return void a.data("ic-next-request",e);if(a.data("ic-event-id")==d){var c=getStyleTarget(a),f=c?null:getAttrTarget(a),g=verbFor(a);handleRemoteRequest(a,g,a.attr("ic-src"),getParametersForElement(a,b),function(b){c?a.css(c,b):f?a.attr(f,b):(processICResponse(b,a),"GET"!=g&&refreshDependencies(a.attr("ic-src"),a))})}},f=closestAttrValue(a,"ic-trigger-delay");f?setTimeout(e,parseInterval(f)):e()}}var _MACROS=["ic-get-from","ic-post-to","ic-put-to","ic-delete-from","ic-style-src","ic-attr-src","ic-prepend-from","ic-append-from"],_remote=$,_scrollHandler=null,_UUID=1,_transitions={},_defaultTransition="fadeFast";_defineTransition("none",{}),_defineTransition("fadeFast",{newContent:function(a,b,c,d,e){if(d)a.fadeOut("fast",function(){e(b.replaceAll(a)),b.fadeIn("fast")});else{var f=a.children().length==a.contents().length&a.contents().length>0?a.children():a;f.fadeOut("fast",function(){a.empty().append(b),f.hide(),e(),f.fadeIn("fast")})}},remove:function(a){a.fadeOut("fast",function(){a.remove()})},show:function(a){a.fadeIn("fast")},hide:function(a){a.fadeOut("fast")}}),_defineTransition("prepend",{newContent:function(a,b,c,d,e){if(b.hide(),a.prepend(b),e(),b.fadeIn(),a.attr("ic-limit-children")){var f=parseInt(a.attr("ic-limit-children"));a.children().length>f&&a.children().slice(f,a.children().length).remove()}}}),_defineTransition("append",{newContent:function(a,b,c,d,e){if(b.hide(),a.append(b),e(),b.fadeIn(),a.attr("ic-limit-children")){var f=parseInt(a.attr("ic-limit-children"));a.children().length>f&&a.children().slice(0,a.children().length-f).remove()}}});var _historySupport={currentRestorationId:null,historyLimit:200,clearHistory:function(){for(var a=[],b=0;b<localStorage.length;b++)0==localStorage.key(b).indexOf("ic-hist-elt-")&&a.push(localStorage.key(b));for(var c=0;c<a.length;c++)localStorage.removeItem(a[c]);localStorage.removeItem("ic-history-support")},newRestorationData:function(a,b){var c=JSON.parse(localStorage.getItem("ic-history-support"));null!=c&&"slot"in c||(_historySupport.clearHistory(),c={slot:0});var d={id:"ic-hist-elt-"+c.slot,elementId:a,content:b,timestamp:(new Date).getTime()};return c.slot=(c.slot+1)%_historySupport.historyLimit,localStorage.setItem(d.id,JSON.stringify(d)),localStorage.setItem("ic-history-support",JSON.stringify(c)),d},updateHistoryData:function(a,b){var c=JSON.parse(localStorage.getItem(a));return null==c?void log($("body"),"Could not find restoration data with id "+a,"ERROR"):(c.content=b,void localStorage.setItem(c.id,JSON.stringify(c)))},onPageLoad:function(){if(null==window.onpopstate||1!=window.onpopstate["ic-on-pop-state-handler"]){var a=window.onpopstate;window.onpopstate=function(b){$("body").trigger("handle.onpopstate.ic"),_historySupport.handlePop(b)||a&&a(b)},window.onpopstate["ic-on-pop-state-handler"]=!0}},pushUrl:function(a,b,c){log(b,"pushing location into history: "+a,"DEBUG");var d=getTarget(b),e=d.attr("id");if(null==e)return void log(b,"To support history for a given element, you must have a valid id attribute on the element","ERROR");if(null!=_historySupport.currentRestorationId)_historySupport.updateHistoryData(_historySupport.currentRestorationId,c);else{var f=_historySupport.newRestorationData(e,c);window.history.replaceState({"ic-id":f.id},"","")}var g=_historySupport.newRestorationData(e,d.html());window.history.pushState({"ic-id":g.id},"",a),_historySupport.currentRestorationId=g.id,b.trigger("pushUrl.ic",d,g)},handlePop:function(a){var b=a.state;if(b&&b["ic-id"]){var c=JSON.parse(localStorage.getItem(b["ic-id"]));if(c){var d=findById(c.elementId);return null!=_historySupport.currentRestorationId&&_historySupport.updateHistoryData(_historySupport.currentRestorationId,d.html()),processICResponse(c.content,d),_historySupport.currentRestorationId=c.id,!0}}return!1}};return $(function(){processNodes("body"),_historySupport.onPageLoad(),location.search&&location.search.indexOf("ic-launch-debugger=true")>=0&&Intercooler.debug()}),{refresh:function(a){return"string"==typeof a||a instanceof String?refreshDependencies(a):fireICRequest(a),Intercooler},updateHistory:function(a){var b=_historySupport.newRestorationData($(a).attr("id"),$(a).html());window.history.replaceState({"ic-id":b.id},"","")},resetHistory:function(){_historySupport.clearHistory()},setHistoryLimit:function(a){_historySupport.historyLimit=a},processNodes:function(a){return processNodes(a)},defaultTransition:function(a){_defaultTransition=a},defineTransition:function(a,b){_defineTransition(a,b)},debug:function(){var a=$(window).data("ic-debug-panel");null==a?!function(){function b(a){var b=$("<div><div><strong>Details</strong></div><div><strong>URL: </strong>"+a.attr("ic-src")+"</div><div><strong>Verb: </strong>"+verbFor(a)+"</div>"+(a.attr("ic-trigger-on")?"<div><strong>Trigger: </strong>"+a.attr("ic-trigger-on")+"</div>":"")+"</div>");if(a.attr("ic-target")&&b.append($("<div><strong>Target: </strong></div>").append(c(getTarget(a)))),a.attr("ic-deps")&&b.append($("<div><strong>Dependencies: </strong></div>").append(a.attr("ic-deps"))),"GET"!=verbFor(a)){var d=$("<div><strong>Dependant Elements:</strong><ul style='list-style-position: inside;font-size:12px;'></ul></div>").appendTo(b).find("ul");$("[ic-src]").each(function(){"GET"==verbFor($(this))&&"ignore"!=$(this).attr("ic-deps")&&(isDependent(a.attr("ic-src"),$(this).attr("ic-src"))||isDependent(a.attr("ic-src"),$(this).attr("ic-deps"))||"*"==$(this).attr("ic-deps"))&&(null==a||a[0]!=$(this)[0])&&$("<li style='font-size:12px'></li>").append(c($(this))).appendTo(d)})}return b}function c(a){return a&&a.length>0?$("<a style='border-bottom: 1px solid #d3d3d3'>&lt;"+a.prop("tagName").toLowerCase()+"&gt;"+(a.attr("ic-src")?" - "+a.attr("ic-src"):"")+"</a>").data("ic-debug-elt",a):$("<span>no element</span>")}function d(){return $("<div id='ic-debug-panel' style='font-size: 14px;font-family: Arial;background:white;width:100%;height:200px;position:fixed;left:0;border-top: 1px solid #d3d3d3;'> <div style='padding:4px;width:100%;border-bottom: 1px solid #d3d3d3;background: #f5f5f5'><img src='/images/Intercooler_CMYK_noType_64.png' height='16px'> <strong>intercooler.js debugger</strong> <span style='float:right'><a>Hide</a> | <a>[x]</a></span> </div> <div style='padding:4px;width:100%;border-bottom: 1px solid #d3d3d3;'> <a style='font-weight: bold'>Elements</a> | <a>Logs</a> | <a>Errors</a> </div> <div> <div id='ic-debug-Elements'> <div id='ic-debug-Elements-list' style='width:200px;float: left;height: 142px;overflow-y: scroll;'> </div> <div id='ic-debug-Elements-detail' style='height: 142px;overflow-y: scroll;'> </div> </div> <div id='ic-debug-Logs' style='display:none;overflow-y: scroll;height: 142px'> </div> <div id='ic-debug-Errors' style='display:none;overflow-y: scroll;height: 142px'> </div> </div></div>")}function e(a){var b=c(a);b.clone(!0).css({display:"block"}).appendTo($("#ic-debug-Elements-list")),a.attr("ic-target")&&0==getTarget(a).length&&$("<div> - bad target selector:"+a.attr("ic-target")+"</div>").prepend(b.clone(!0)).appendTo($("#ic-debug-Errors")),a.attr("ic-indicator")&&0==$(a.attr("ic-indicator")).length&&$("<div> - bad indicator selector:"+a.attr("ic-indicator")+"</div>").prepend(b.clone(!0)).appendTo($("#ic-debug-Errors")),a.attr("ic-push-url")&&null==getTarget($(a)).attr("id")&&$("<div> - ic-push-url requires target to have id</div>").prepend(b.clone(!0)).appendTo($("#ic-debug-Errors"))}function f(){$("#ic-debug-Elements-list").find("a").each(function(){$(this).data("ic-debug-elt")&&$.contains(document.body,$(this).data("ic-debug-elt")[0])||$(this).remove()})}a=d().appendTo($("body")),$(window).data("ic-debug-panel",a);var g;$("#ic-debug-panel").on("click","a",function(){if("Hide"==$(this).text())$("#ic-debug-panel").data("ic-minimized",!0),$(this).text("Show"),$(window).resize();else if("Show"==$(this).text())$("#ic-debug-panel").data("ic-minimized",!1),$(this).text("Hide"),$(window).resize();else if("[x]"==$(this).text())g&&g.css({border:""}),a.hide(),$("html").css("margin-bottom","0");else if(["Elements","Logs","Errors"].indexOf($(this).text())>=0)$(this).parent().find("a").css({"font-weight":"normal"}),$(this).css({"font-weight":"bold"}),$("#ic-debug-"+$(this).text()).parent().children().hide(),$("#ic-debug-"+$(this).text()).show();else if($(this).data("ic-debug-elt")){var c=$(this),d=c.data("ic-debug-elt"),e=Math.min(d.offset().top-75,300);$("html, body").animate({scrollTop:d.offset().top-75},e),g&&g.css({border:""}),g=d,d.css({border:"2px solid red"}),"ic-debug-Elements-list"==c.parent().attr("id")&&$("#ic-debug-Elements-detail").html(b(d))}}),$("[ic-src]").each(function(){e($(this))}),$(window).on("log.ic",function(a,b,d){$("<div style='border-bottom: 1px solid #d3d3d3'>] - "+b.replace(/</g,"&lt;")+"</div>").appendTo($("#ic-debug-Logs")).prepend(c($(a.target))).prepend(d+" [")}).on("elementAdded.ic",function(a){e($(a.target))}).on("nodesProcessed.ic",function(){f()}).on("resize",function(){if(!a.is(":hidden")){var b=$(window).height()-(1==a.data("ic-minimized")?29:200);a.css("top",b+"px"),$("html").css("margin-bottom",(1==a.data("ic-minimized")?29:200)+"px")}})}():a.show(),$(window).resize()},addURLHandler:function(){throw"This method is no longer supported. Please use the jQuery mockjax plugin instead: https://github.com/jakerella/jquery-mockjax"},setRemote:function(a){return _remote=a,Intercooler}}}();