From 7c85f5474a88091e43e1a75914f6483c80625fc2 Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Mon, 3 Sep 2018 10:03:27 -0400 Subject: [PATCH] Pjax page transitions that use the main page nav buttons Things remain to do on this: - Make the indicator less blatant - Fix page titles - apply lots of other places --- brutaldon/static/css/brutaldon.css | 18 +++++++++++ brutaldon/static/js/intercooler.js | 3 +- brutaldon/static/js/intercooler.min.js | 3 ++ brutaldon/templates/base.html | 45 ++++++++++++++++++++++---- 4 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 brutaldon/static/js/intercooler.min.js diff --git a/brutaldon/static/css/brutaldon.css b/brutaldon/static/css/brutaldon.css index 87ad55d..64b73a1 100644 --- a/brutaldon/static/css/brutaldon.css +++ b/brutaldon/static/css/brutaldon.css @@ -103,3 +103,21 @@ emoji-link display: block; } } + +#page-load-indicator +{ + width: 100%; + height: 4px; + background-color: blue; + opacity: 1; + position: fixed; + top: 0; + left: 0; + z-index: 666; + transition: all 500ms; +} + +#page-load-indicator.ic-use-transition +{ + width:0; +} diff --git a/brutaldon/static/js/intercooler.js b/brutaldon/static/js/intercooler.js index ff2b172..e5b5b4a 100644 --- a/brutaldon/static/js/intercooler.js +++ b/brutaldon/static/js/intercooler.js @@ -4,7 +4,7 @@ define(["jquery"], function (a0) { return (root['Intercooler'] = factory(a0)); }); - } else if (typeof exports === 'object') { + } else if (typeof module === 'object' && module.exports) { // Node. Does not work with strict CommonJS, but // only CommonJS-like environments that support module.exports, // like Node. @@ -497,7 +497,6 @@ var Intercooler = Intercooler || (function() { if (xhr.getResponseHeader("X-IC-PushURL") || closestAttrValue(elt, 'ic-push-url') == "true") { try { - requestCleanup(indicator, elt); // clean up before snap-shotting HTML var newUrl = xhr.getResponseHeader("X-IC-PushURL") || closestAttrValue(elt, 'ic-src'); if(_history) { _history.snapshotForHistory(newUrl); diff --git a/brutaldon/static/js/intercooler.min.js b/brutaldon/static/js/intercooler.min.js new file mode 100644 index 0000000..dfaf0dd --- /dev/null +++ b/brutaldon/static/js/intercooler.min.js @@ -0,0 +1,3 @@ +/*! intercooler 1.2.1 2018-09-02 */ + +!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(c){return a.Intercooler=b(c)}):"object"==typeof module&&module.exports?module.exports=b(require("jquery")):a.Intercooler=b(a.jQuery)}(this,function($){var Intercooler=Intercooler||function(){"use strict";function remove(a){a.remove()}function showIndicator(a){a.closest(".ic-use-transition").length>0?(a.data("ic-use-transition",!0),a.removeClass("ic-use-transition")):a.show()}function hideIndicator(a){a.data("ic-use-transition")?(a.data("ic-use-transition",null),a.addClass("ic-use-transition")):a.hide()}function fixICAttributeName(a){return USE_DATA?"data-"+a:a}function getICAttribute(a,b){return a.attr(fixICAttributeName(b))}function setICAttribute(a,b,c){a.attr(fixICAttributeName(b),c)}function prepend(a,b){try{a.prepend(b)}catch(b){log(a,formatError(b),"ERROR")}if(getICAttribute(a,"ic-limit-children")){var c=parseInt(getICAttribute(a,"ic-limit-children"));a.children().length>c&&a.children().slice(c,a.children().length).remove()}}function append(a,b){try{a.append(b)}catch(b){log(a,formatError(b),"ERROR")}if(getICAttribute(a,"ic-limit-children")){var c=parseInt(getICAttribute(a,"ic-limit-children"));a.children().length>c&&a.children().slice(0,a.children().length-c).remove()}}function triggerEvent(a,b,c){$.zepto&&(b=b.split(".").reverse().join(":")),a.trigger(b,c)}function log(a,b,c){if(null==a&&(a=$("body")),triggerEvent(a,"log.ic",[b,c,a]),"ERROR"==c){window.console&&window.console.log("Intercooler Error : "+b);var d=closestAttrValue($("body"),"ic-post-errors-to");d&&$.post(d,{error:b})}}function uuid(){return _UUID++}function icSelectorFor(a){return getICAttributeSelector("ic-id='"+getIntercoolerId(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?parseFloat(a.substr(0,a.length-2)):a.lastIndexOf("s")==a.length-1?1e3*parseFloat(a.substr(0,a.length-1)):1e3}function getICAttributeSelector(a){return"["+fixICAttributeName(a)+"]"}function initScrollHandler(){null==_scrollHandler&&(_scrollHandler=function(){$(getICAttributeSelector("ic-trigger-on='scrolled-into-view'")).each(function(){var a=$(this);isScrolledIntoView(getTriggeredElement(a))&&1!=a.data("ic-scrolled-into-view-loaded")&&(a.data("ic-scrolled-into-view-loaded",!0),fireICRequest(a))})},$(window).scroll(_scrollHandler))}function currentUrl(){return window.location.pathname+window.location.search+window.location.hash}function createDocument(a){var b=null;return/<(html|body)/i.test(a)?(b=document.documentElement.cloneNode(),b.innerHTML=a):(b=document.documentElement.cloneNode(!0),b.querySelector("body").innerHTML=a),$(b)}function getTarget(a){return getTargetImpl(a,"ic-target")}function getTargetImpl(a,b){var c=$(a).closest(getICAttributeSelector(b)),d=getICAttribute(c,b);return"this"==d?c:d&&0!=d.indexOf("this.")?0==d.indexOf("closest ")?a.closest(d.substr(8)):0==d.indexOf("find ")?a.find(d.substr(5)):$(d):a}function processHeaders(a,b){a=$(a),triggerEvent(a,"beforeHeaders.ic",[a,b]),log(a,"response headers: "+b.getAllResponseHeaders(),"DEBUG");var c=null;if(b.getResponseHeader("X-IC-Title")&&(document.title=b.getResponseHeader("X-IC-Title")),b.getResponseHeader("X-IC-Refresh")){var d=b.getResponseHeader("X-IC-Refresh").split(",");log(a,"X-IC-Refresh: refreshing "+d,"DEBUG"),$.each(d,function(b,c){refreshDependencies(c.replace(/ /g,""),a)})}if(b.getResponseHeader("X-IC-Script")&&(log(a,"X-IC-Script: evaling "+b.getResponseHeader("X-IC-Script"),"DEBUG"),globalEval(b.getResponseHeader("X-IC-Script"),[["elt",a]])),b.getResponseHeader("X-IC-Redirect")&&(log(a,"X-IC-Redirect: redirecting to "+b.getResponseHeader("X-IC-Redirect"),"DEBUG"),window.location=b.getResponseHeader("X-IC-Redirect")),"true"==b.getResponseHeader("X-IC-CancelPolling")&&cancelPolling(a.closest(getICAttributeSelector("ic-poll"))),"true"==b.getResponseHeader("X-IC-ResumePolling")){var e=a.closest(getICAttributeSelector("ic-poll"));setICAttribute(e,"ic-pause-polling",null),startPolling(e)}if(b.getResponseHeader("X-IC-SetPollInterval")){var e=a.closest(getICAttributeSelector("ic-poll"));cancelPolling(e),setICAttribute(e,"ic-poll",b.getResponseHeader("X-IC-SetPollInterval")),startPolling(e)}b.getResponseHeader("X-IC-Open")&&(log(a,"X-IC-Open: opening "+b.getResponseHeader("X-IC-Open"),"DEBUG"),window.open(b.getResponseHeader("X-IC-Open")));var f=b.getResponseHeader("X-IC-Trigger");if(f)if(log(a,"X-IC-Trigger: found trigger "+f,"DEBUG"),c=getTarget(a),b.getResponseHeader("X-IC-Trigger-Data")){var g=$.parseJSON(b.getResponseHeader("X-IC-Trigger-Data"));triggerEvent(c,f,g)}else f.indexOf("{")>=0?$.each($.parseJSON(f),function(a,b){triggerEvent(c,a,b)}):triggerEvent(c,f,[]);var h=b.getResponseHeader("X-IC-Set-Local-Vars");if(h&&$.each($.parseJSON(h),function(a,b){localStorage.setItem(a,b)}),b.getResponseHeader("X-IC-Remove")&&a){var i=b.getResponseHeader("X-IC-Remove");i+="";var j=parseInterval(i);log(a,"X-IC-Remove header found.","DEBUG"),c=getTarget(a),"true"==i||null==j?remove(c):(c.addClass("ic-removing"),setTimeout(function(){remove(c)},j))}return triggerEvent(a,"afterHeaders.ic",[a,b]),!0}function beforeRequest(a){a.addClass("disabled"),a.data("ic-request-in-flight",!0)}function requestCleanup(a,b){a.length>0&&hideIndicator(a),b.removeClass("disabled"),b.data("ic-request-in-flight",!1),b.data("ic-next-request")&&(b.data("ic-next-request").req(),b.data("ic-next-request",null))}function replaceOrAddMethod(a,b){if("string"===$.type(a)){var c=/(&|^)_method=[^&]*/,d="&_method="+b;return c.test(a)?a.replace(c,d):a+d}return a.append("_method",b),a}function isIdentifier(a){return/^[$A-Z_][0-9A-Z_$]*$/i.test(a)}function globalEval(a,b){var c=[],d=[];if(b)for(var e=0;e0?getICAttribute(c,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);f.length>0&&showIndicator(f);var g,h=uuid(),i=new Date;g=USE_ACTUAL_HTTP_METHOD?b:"GET"==b?"GET":"POST";var j={type:g,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){triggerEvent(a,"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(g,[["elt",a],["data",d],["settings",f],["xhr",e]]),maybeInvokeLocalAction(a,"-beforeSend")},success:function(b,c,d){triggerEvent(a,"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(f,[["elt",a],["data",b],["textStatus",c],["xhr",d]])){var g=new Date;try{if(processHeaders(a,d)){log(a,"Processed headers for request "+h+" in "+(new Date-g)+"ms","DEBUG");var i=new Date;if(d.getResponseHeader("X-IC-PushURL")||"true"==closestAttrValue(a,"ic-push-url"))try{var j=d.getResponseHeader("X-IC-PushURL")||closestAttrValue(a,"ic-src");if(!_history)throw"History support not enabled";_history.snapshotForHistory(j)}catch(b){log(a,"Error during history snapshot for "+h+": "+formatError(b),"ERROR")}e(b,c,a,d),log(a,"Process content for request "+h+" in "+(new Date-i)+"ms","DEBUG")}triggerEvent(a,"after.success.ic",[a,b,c,d,h]),maybeInvokeLocalAction(a,"-success")}catch(b){log(a,"Error processing successful request "+h+" : "+formatError(b),"ERROR")}}},error:function(b,d,e){triggerEvent(a,"error.ic",[a,d,e,b]);var f=closestAttrValue(a,"ic-on-error");f&&globalEval(f,[["elt",a],["status",d],["str",e],["xhr",b]]),processHeaders(a,b),maybeInvokeLocalAction(a,"-error"),log(a,"AJAX request "+h+" to "+c+" experienced an error: "+e,"ERROR")},complete:function(b,c){log(a,"AJAX request "+h+" completed in "+(new Date-i)+"ms","DEBUG"),requestCleanup(f,a);try{$.contains(document,a[0])?triggerEvent(a,"complete.ic",[a,d,c,b,h]):triggerEvent($("body"),"complete.ic",[a,d,c,b,h])}catch(b){log(a,"Error during complete.ic event for "+h+" : "+formatError(b),"ERROR")}var e=closestAttrValue(a,"ic-on-complete");e&&globalEval(e,[["elt",a],["xhr",b],["status",c]]),maybeInvokeLocalAction(a,"-complete")}};"string"!=$.type(d)&&(j.dataType=null,j.processData=!1,j.contentType=!1),triggerEvent($(document),"beforeAjaxSend.ic",[j,a]),j.cancel?requestCleanup(f,a):$.ajax(j)}function findIndicator(a){var b=null;if(a=$(a),getICAttribute(a,"ic-indicator"))b=$(getICAttribute(a,"ic-indicator")).first();else if(b=a.find(".ic-indicator").first(),0==b.length){var c=closestAttrValue(a,"ic-indicator");c?b=$(c).first():a.next().is(".ic-indicator")&&(b=a.next())}return b}function processIncludes(a,b){if(0==$.trim(b).indexOf("{")){var c=$.parseJSON(b);$.each(c,function(b,c){a=appendData(a,b,c)})}else $(b).each(function(){var b=$(this).serializeArray();$.each(b,function(b,c){a=appendData(a,c.name,c.value)})});return a}function processLocalVars(a,b){return $(b.split(",")).each(function(){var b=$.trim(this),c=localStorage.getItem(b);c&&(a=appendData(a,b,c))}),a}function appendData(a,b,c){return"string"===$.type(a)?("string"!==$.type(c)&&(c=JSON.stringify(c)),a+"&"+b+"="+encodeURIComponent(c)):(a.append(b,c),a)}function getParametersForElement(a,b,c){var d=getTarget(b),e=null;if(b.is("form")&&"multipart/form-data"==b.attr("enctype"))e=new FormData(b[0]),e=appendData(e,"ic-request",!0);else{e="ic-request=true";var f=b.closest("form");if(b.is("form")||"GET"!=a&&f.length>0){e+="&"+f.serialize();var g=b.data("ic-last-clicked-button");g&&(e=appendData(e,g.name,g.value))}else e+="&"+b.serialize()}var h=closestAttrValue(b,"ic-prompt");if(h){var i=prompt(h);if(!i)return null;var j=closestAttrValue(b,"ic-prompt-name")||"ic-prompt-value";e=appendData(e,j,i)}b.attr("id")&&(e=appendData(e,"ic-element-id",b.attr("id"))),b.attr("name")&&(e=appendData(e,"ic-element-name",b.attr("name"))),getICAttribute(d,"ic-id")&&(e=appendData(e,"ic-id",getICAttribute(d,"ic-id"))),d.attr("id")&&(e=appendData(e,"ic-target-id",d.attr("id"))),c&&c.attr("id")&&(e=appendData(e,"ic-trigger-id",c.attr("id"))),c&&c.attr("name")&&(e=appendData(e,"ic-trigger-name",c.attr("name")));var k=closestAttrValue(b,"ic-include");k&&(e=processIncludes(e,k));var l=closestAttrValue(b,"ic-local-vars");l&&(e=processLocalVars(e,l)),$(getICAttributeSelector("ic-global-include")).each(function(){e=processIncludes(e,getICAttribute($(this),"ic-global-include"))}),e=appendData(e,"ic-current-url",currentUrl());var m=closestAttrValue(b,"ic-select-from-response");return m&&(e=appendData(e,"ic-select-from-response",m)),log(b,"request parameters "+e,"DEBUG"),e}function maybeSetIntercoolerInfo(a){getIntercoolerId(getTarget(a)),1!=a.data("elementAdded.ic")&&(a.data("elementAdded.ic",!0),triggerEvent(a,"elementAdded.ic"))}function getIntercoolerId(a){return getICAttribute(a,"ic-id")||setICAttribute(a,"ic-id",uuid()),getICAttribute(a,"ic-id")}function processNodes(a){a=$(a),a.length>1?a.each(function(){processNodes(this)}):(processMacros(a),processSources(a),processPolling(a),processEventSources(a),processTriggerOn(a),processRemoveAfter(a),processAddClasses(a),processRemoveClasses(a))}function fireReadyStuff(a){triggerEvent(a,"nodesProcessed.ic"),$.each(_readyHandlers,function(b,c){try{c(a)}catch(b){log(a,formatError(b),"ERROR")}})}function autoFocus(a){a.find("[autofocus]").last().focus()}function processMacros(a){$.each(_MACROS,function(b,c){0==a.closest(".ic-ignore").length&&(a.is("["+c+"]")&&processMacro(c,a),a.find("["+c+"]").each(function(){var a=$(this);0==a.closest(".ic-ignore").length&&processMacro(c,a)}))})}function processSources(a){0==a.closest(".ic-ignore").length&&(a.is(getICAttributeSelector("ic-src"))&&maybeSetIntercoolerInfo(a),a.find(getICAttributeSelector("ic-src")).each(function(){var a=$(this);0==a.closest(".ic-ignore").length&&maybeSetIntercoolerInfo(a)}))}function processPolling(a){0==a.closest(".ic-ignore").length&&(a.is(getICAttributeSelector("ic-poll"))&&(maybeSetIntercoolerInfo(a),startPolling(a)),a.find(getICAttributeSelector("ic-poll")).each(function(){var a=$(this);0==a.closest(".ic-ignore").length&&(maybeSetIntercoolerInfo(a),startPolling(a))}))}function processTriggerOn(a){0==a.closest(".ic-ignore").length&&(handleTriggerOn(a),a.find(getICAttributeSelector("ic-trigger-on")).each(function(){var a=$(this);0==a.closest(".ic-ignore").length&&handleTriggerOn(a)}))}function processRemoveAfter(a){0==a.closest(".ic-ignore").length&&(handleRemoveAfter(a),a.find(getICAttributeSelector("ic-remove-after")).each(function(){var a=$(this);0==a.closest(".ic-ignore").length&&handleRemoveAfter(a)}))}function processAddClasses(a){0==a.closest(".ic-ignore").length&&(handleAddClasses(a),a.find(getICAttributeSelector("ic-add-class")).each(function(){var a=$(this);0==a.closest(".ic-ignore").length&&handleAddClasses(a)}))}function processRemoveClasses(a){0==a.closest(".ic-ignore").length&&(handleRemoveClasses(a),a.find(getICAttributeSelector("ic-remove-class")).each(function(){var a=$(this);0==a.closest(".ic-ignore").length&&handleRemoveClasses(a)}))}function processEventSources(a){0==a.closest(".ic-ignore").length&&(handleEventSource(a),a.find(getICAttributeSelector("ic-sse-src")).each(function(){var a=$(this);0==a.closest(".ic-ignore").length&&handleEventSource(a)}))}function startPolling(a){if(null==a.data("ic-poll-interval-id")&&"true"!=getICAttribute(a,"ic-pause-polling")){var b=parseInterval(getICAttribute(a,"ic-poll"));if(null!=b){var c=icSelectorFor(a),d=parseInt(getICAttribute(a,"ic-poll-repeats"))||-1,e=0;log(a,"POLL: Starting poll for element "+c,"DEBUG");var f=setInterval(function(){var b=$(c);triggerEvent(a,"onPoll.ic",b),0==b.length||e==d||a.data("ic-poll-interval-id")!=f?(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")),a.data("ic-poll-interval-id",null))}function refreshDependencies(a,b){log(b,"refreshing dependencies for path "+a,"DEBUG"),$(getICAttributeSelector("ic-src")).each(function(){var c=!1,d=$(this);"GET"==verbFor(d)&&"ignore"!=getICAttribute(d,"ic-deps")&&(isDependent(a,getICAttribute(d,"ic-src"))?null!=b&&$(b)[0]==d[0]||(fireICRequest(d),c=!0):(isICDepsDependent(a,getICAttribute(d,"ic-deps"))||"*"==getICAttribute(d,"ic-deps"))&&(null!=b&&$(b)[0]==d[0]||(fireICRequest(d),c=!0))),c&&log(d,"depends on path "+a+", refreshing...","DEBUG")})}function isICDepsDependent(a,b){if(b)for(var c=b.split(","),d=0;d0){var f=a.split(":");d=f[0],e=parseInterval(f[1])}else d=a;setTimeout(function(){b[c](d)},e)}function handleAddClasses(a){if(a=$(a),getICAttribute(a,"ic-add-class"))for(var b=getICAttribute(a,"ic-add-class").split(","),c=b.length,d=0;d=b&&d<=c&&e<=c&&d>=b}function maybeScrollToTarget(a,b){if("false"!=closestAttrValue(a,"ic-scroll-to-target")&&("true"==closestAttrValue(a,"ic-scroll-to-target")||"true"==closestAttrValue(b,"ic-scroll-to-target"))){var c=-50;closestAttrValue(a,"ic-scroll-offset")?c=parseInt(closestAttrValue(a,"ic-scroll-offset")):closestAttrValue(b,"ic-scroll-offset")&&(c=parseInt(closestAttrValue(b,"ic-scroll-offset")));var d=b.offset().top,e=$(window).scrollTop(),f=e+window.innerHeight;(df)&&(c+=d,$("html,body").animate({scrollTop:c},400))}}function getTransitionDuration(a,b){var c=closestAttrValue(a,"ic-transition-duration");if(c)return parseInterval(c);if(c=closestAttrValue(b,"ic-transition-duration"))return parseInterval(c);b=$(b);var d=0,e=b.css("transition-duration");e&&(d+=parseInterval(e));var f=b.css("transition-delay");return f&&(d+=parseInterval(f)),d}function closeSSESource(a){var b=a.data("ic-event-sse-source");try{b&&b.close()}catch(b){log(a,"Error closing ServerSentEvent source"+b,"ERROR")}}function beforeSwapCleanup(a){a.find(getICAttributeSelector("ic-sse-src")).each(function(){closeSSESource($(this))}),triggerEvent(a,"beforeSwap.ic")}function processICResponse(a,b,c,d){if(a&&""!=a&&" "!=a){log(b,"response content: \n"+a,"DEBUG");var e=getTarget(b),f=closestAttrValue(b,"ic-transform-response");f&&(a=globalEval(f,[["content",a],["url",d],["elt",b]]));var g=maybeFilter(a,closestAttrValue(b,"ic-select-from-response"));"true"==closestAttrValue(b,"ic-fix-ids")&&fixIDs(g);var h=function(){if("true"==closestAttrValue(b,"ic-replace-target")){try{beforeSwapCleanup(e),closeSSESource(e),e.replaceWith(g),e=g}catch(a){log(b,formatError(a),"ERROR")}processNodes(g),fireReadyStuff(e),autoFocus(e)}else{if("prepend"==getICAttribute(b,"ic-swap-style"))prepend(e,g),processNodes(g),fireReadyStuff(e),autoFocus(e);else if("append"==getICAttribute(b,"ic-swap-style"))append(e,g),processNodes(g),fireReadyStuff(e),autoFocus(e);else{try{beforeSwapCleanup(e),e.empty().append(g)}catch(a){log(b,formatError(a),"ERROR")}e.children().each(function(){processNodes(this)}),fireReadyStuff(e),autoFocus(e)}1!=c&&maybeScrollToTarget(b,e)}};if(0==e.length)return void log(b,"Invalid target for element: "+getICAttribute(b.closest(getICAttributeSelector("ic-target")),"ic-target"),"ERROR");var i=getTransitionDuration(b,e);e.addClass("ic-transitioning"),setTimeout(function(){try{h()}catch(a){log(b,"Error during content swap : "+formatError(a),"ERROR")}setTimeout(function(){try{e.removeClass("ic-transitioning"),_history&&_history.updateHistory(),triggerEvent(e,"complete_transition.ic",[e])}catch(a){log(b,"Error during transition complete : "+formatError(a),"ERROR")}},20)},i)}else log(b,"Empty response, nothing to do here.","DEBUG")}function maybeFilter(a,b){var c;if($.zepto){var d=createDocument(a);c=$(d).find("body").contents()}else c=$($.parseHTML(a,null,!0));return b?walkTree(c,b).contents():c}function walkTree(a,b){return a.filter(b).add(a.find(b))}function fixIDs(a){var b={};walkTree(a,"[id]").each(function(){var a,c=$(this).attr("id");do{a="ic-fixed-id-"+uuid()}while($("#"+a).length>0);b[c]=a,$(this).attr("id",a)}),walkTree(a,"label[for]").each(function(){var a=$(this).attr("for");$(this).attr("for",b[a]||a)}),walkTree(a,"*").each(function(){$.each(this.attributes,function(){-1!==this.value.indexOf("#")&&(this.value=this.value.replace(/#([-_A-Za-z0-9]+)/g,function(a,c){return"#"+(b[c]||c)}))})})}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,b){a=$(a);var c=a;a.is(getICAttributeSelector("ic-src"))||void 0!=getICAttribute(a,"ic-action")||(a=a.closest(getICAttributeSelector("ic-src")));var d=closestAttrValue(a,"ic-confirm");if((!d||confirm(d))&&("true"!=closestAttrValue(a,"ic-disable-when-doc-hidden")||!document.hidden)&&("true"!=closestAttrValue(a,"ic-disable-when-doc-inactive")||document.hasFocus())&&a.length>0){var e=uuid();a.data("ic-event-id",e);var f=function(){if(1==a.data("ic-request-in-flight"))return void a.data("ic-next-request",{req:f});if(a.data("ic-event-id")==e){var d=getStyleTarget(a),g=d?null:getAttrTarget(a),h=verbFor(a),i=getICAttribute(a,"ic-src");if(i){var j=b||function(b){d?a.css(d,b):g?a.attr(g,b):(processICResponse(b,a,!1,i),"GET"!=h&&refreshDependencies(getICAttribute(a,"ic-src"),a))},k=getParametersForElement(h,a,c);k&&handleRemoteRequest(a,h,i,k,j)}maybeInvokeLocalAction(a,"")}},g=closestAttrValue(a,"ic-trigger-delay");g?setTimeout(f,parseInterval(g)):f()}}function maybeInvokeLocalAction(a,b){var c=getICAttribute(a,"ic"+b+"-action");c&&invokeLocalAction(a,c,b)}function invokeLocalAction(a,b,c){var d=closestAttrValue(a,"ic"+c+"-action-target");null===d&&""!==c&&(d=closestAttrValue(a,"ic-action-target"));var e=null;e=d?getTargetImpl(a,"ic-action-target"):getTarget(a);var f=b.split(";"),g=[],h=0;$.each(f,function(a,b){var c=$.trim(b),d=c,f=[];c.indexOf(":")>0&&(d=c.substr(0,c.indexOf(":")),f=computeArgs(c.substr(c.indexOf(":")+1,c.length))),""==d||("delay"==d?(null==h&&(h=0),h+=parseInterval(f[0]+"")):(null==h&&(h=420),g.push([h,makeApplyAction(e,d,f)]),h=null))}),h=0,$.each(g,function(a,b){h+=b[0],setTimeout(b[1],h)})}function computeArgs(args){try{return eval("["+args+"]")}catch(a){return[$.trim(args)]}}function makeApplyAction(a,b,c){return function(){var d=a[b]||window[b];d?d.apply(a,c):log(a,"Action "+b+" was not found","ERROR")}}function newIntercoolerHistory(a,b,c,d){function e(){for(var b=[],e=0;e=0)log(e,"URL found in LRU list, moving to end","INFO"),c.splice(d,1),c.push(b);else if(log(e,"URL not found in LRU list, adding","INFO"),c.push(b),c.length>s.slotLimit){var f=c.shift();log(e,"History overflow, removing local history for "+f,"INFO"),a.removeItem(r+f)}return a.setItem(q,JSON.stringify(s)),c}function g(b){var d=JSON.stringify(b);try{a.setItem(b.id,d)}catch(f){try{e(),a.setItem(b.id,d)}catch(a){log(m($("body")),"Unable to save intercooler history with entire history cleared, is something else eating local storage? History Limit:"+c,"ERROR")}}}function h(a,b,c){var d={url:c,id:r+c,content:a,yOffset:b,timestamp:(new Date).getTime()};return f(c),g(d),d}function i(a){if(null==a.onpopstate||1!=a.onpopstate["ic-on-pop-state-handler"]){var b=a.onpopstate;a.onpopstate=function(a){triggerEvent(m($("body")),"handle.onpopstate.ic"),l(a)||b&&b(a),triggerEvent(m($("body")),"pageLoad.ic")},a.onpopstate["ic-on-pop-state-handler"]=!0}}function j(){t&&(k(t.newUrl,currentUrl(),t.oldHtml,t.yOffset),t=null)}function k(a,c,d,e){var f=h(d,e,c);b.replaceState({"ic-id":f.id},"","");var g=m($("body")),i=h(g.html(),window.pageYOffset,a);b.pushState({"ic-id":i.id},"",a),triggerEvent(g,"pushUrl.ic",[g,i])}function l(b){var c=b.state;if(c&&c["ic-id"]){var d=JSON.parse(a.getItem(c["ic-id"]));if(d)return processICResponse(d.content,m($("body")),!0),d.yOffset&&window.scrollTo(0,d.yOffset),!0;$.get(currentUrl(),{"ic-restore-history":!0},function(a,b){processICResponse(m(createDocument(a)).html(),m($("body")),!0)})}return!1}function m(a){var b=a.find(getICAttributeSelector("ic-history-elt"));return b.length>0?b:a}function n(a){var b=m($("body"));triggerEvent(b,"beforeHistorySnapshot.ic",[b]),t={newUrl:a,oldHtml:b.html(),yOffset:window.pageYOffset}}function o(){var b="",c=[];for(var d in a)c.push(d);c.sort();var e=0;for(var f in c){var g=2*a[c[f]].length;e+=g,b+=c[f]+"="+(g/1024/1024).toFixed(2)+" MB\n"}return b+"\nTOTAL LOCAL STORAGE: "+(e/1024/1024).toFixed(2)+" MB"}function p(){return s}var q="ic-history-support",r="ic-hist-elt-",s=JSON.parse(a.getItem(q)),t=null;return function(a){return null==a||a.slotLimit!=c||a.historyVersion!=d||null==a.lruList}(s)&&(log(m($("body")),"Intercooler History configuration changed, clearing history","INFO"),e()),null==s&&(s={slotLimit:c,historyVersion:d,lruList:[]}),{clearHistory:e,updateHistory:j,addPopStateHandler:i,snapshotForHistory:n,_internal:{addPopStateHandler:i,supportData:p,dumpLocalStorage:o,updateLRUList:f}}}function getSlotLimit(){return 20}function refresh(a){return"string"==typeof a||a instanceof String?refreshDependencies(a):fireICRequest(a),Intercooler}function init(){var a=$("body");processNodes(a),fireReadyStuff(a),_history&&_history.addPopStateHandler(window),$.zepto&&($("body").data("zeptoDataTest",{}),"string"==typeof $("body").data("zeptoDataTest")&&console.log("!!!! Please include the data module with Zepto! Intercooler requires full data support to function !!!!")),location.search&&location.search.indexOf("ic-launch-debugger=true")>=0&&Intercooler.debug()}"undefined"!=typeof Zepto&&null==$&&($=Zepto);var USE_DATA="true"==$('meta[name="intercoolerjs:use-data-prefix"]').attr("content"),USE_ACTUAL_HTTP_METHOD="true"==$('meta[name="intercoolerjs:use-actual-http-method"]').attr("content"),_MACROS=$.map(["ic-get-from","ic-post-to","ic-put-to","ic-patch-to","ic-delete-from","ic-style-src","ic-attr-src","ic-prepend-from","ic-append-from","ic-action"],function(a){return fixICAttributeName(a)}),_scrollHandler=null,_UUID=1,_readyHandlers=[],_isDependentFunction=function(a,b){if(!a||!b)return!1;var c=a.split(/[\?#]/,1)[0].split("/").filter(function(a){return""!=a}),d=b.split(/[\?#]/,1)[0].split("/").filter(function(a){return""!=a});return""!=c&&""!=d&&(d.slice(0,c.length).join("/")==c.join("/")||c.slice(0,d.length).join("/")==d.join("/"))},_history=null;try{_history=newIntercoolerHistory(localStorage,window.history,20,.1)}catch(a){log($("body"),"Could not initialize history","WARN")}return $.ajaxTransport&&$.ajaxTransport("text",function(a,b){if("#"==b.url[0]){var c=fixICAttributeName("ic-local-"),d=$(b.url),e=[],f=200,g="OK";d.each(function(a,b){$.each(b.attributes,function(a,b){if(b.name.substr(0,c.length)==c){var d=b.name.substring(c.length);if("status"==d){var h=b.value.match(/(\d+)\s?(.*)/);null!=h?(f=h[1],g=h[2]):(f="500",g="Attribute Error")}else e.push(d+": "+b.value)}})});var h=d.length>0?d.html():"";return{send:function(a,b){b(f,g,{html:h},e.join("\n"))},abort:function(){}}}return null}),$(function(){init()}),{refresh:refresh,history:_history,triggerRequest:fireICRequest,processNodes:processNodes,closestAttrValue:closestAttrValue,verbFor:verbFor,isDependent:isDependent,getTarget:getTarget,processHeaders:processHeaders,setIsDependentFunction:function(a){_isDependentFunction=a},ready:function(a){_readyHandlers.push(a)},debug:function(){var a=closestAttrValue("body","ic-debugger-url")||"https://intercoolerreleases-leaddynocom.netdna-ssl.com/intercooler-debugger.js";$.getScript(a).fail(function(a,b,c){log($("body"),formatError(c),"ERROR")})},_internal:{init:init,replaceOrAddMethod:replaceOrAddMethod,initEventSource:function(a){return new EventSource(a)},globalEval:globalEval}}}();return Intercooler}); \ No newline at end of file diff --git a/brutaldon/templates/base.html b/brutaldon/templates/base.html index 1d5bc1d..6f60fac 100644 --- a/brutaldon/templates/base.html +++ b/brutaldon/templates/base.html @@ -60,27 +60,57 @@