-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathjquery.fs.pronto.min.js
9 lines (8 loc) · 3.63 KB
/
jquery.fs.pronto.min.js
1
2
3
4
5
6
7
8
9
/*
* Pronto v3.2.1 - 2015-04-04
* A jQuery plugin for faster page loads. Part of the formstone library.
* http://classic.formstone.it/pronto/
*
* Copyright 2015 Ben Plum; MIT Licensed
*/
!function(a,b){"use strict";function c(c){n&&(l=a("body"),l.hasClass("pronto")||(a.extend(!0,r,c||{}),r.$container=a(r.container),r.render===a.noop&&(r.render=h),r.transitionOut===a.noop&&(r.transitionOut=function(){return a.Deferred().resolve()}),o=b.location.href,i(),m.on("popstate.pronto",e),s.enable()))}function d(a){var c=a.currentTarget;if(!(a.which>1||a.metaKey||a.ctrlKey||a.shiftKey||a.altKey||b.location.protocol!==c.protocol||b.location.host!==c.host||"_blank"===c.target)){if(c.hash&&(c.href.replace(c.hash,"")===b.location.href.replace(location.hash,"")||c.href===b.location.href+"#"))return void i();a.preventDefault(),a.stopPropagation(),a.stopImmediatePropagation(),o===c.href?i():f(c.href)}}function e(a){var c=a.originalEvent.state;c&&(r.modal&&0===p&&c.url&&!c.initial?b.location.href=c.url:c.url!==o&&(r.force?f(c.url):(m.trigger("pronto.request",[!0]),g(c.url,c.hash,c.data,c.scroll,!1))))}function f(c){m.trigger("pronto.request",[!1]),r.transitionOutDeferred=r.transitionOut.apply(b,[!1]);var d=c.indexOf("?"),e=c.indexOf("#"),f=d>-1?k(c.slice(d+1)):{},h="",i=a.Deferred(),j="User error",l=null;e>-1&&(h=d>-1?c.slice(e,d):c.slice(e)),f[r.requestKey]=!0,q=a.ajax({url:c,data:f,dataType:"json",cache:r.cache,xhr:function(){var a=new b.XMLHttpRequest;return a.addEventListener("progress",function(a){if(a.lengthComputable){var b=a.loaded/a.total;m.trigger("pronto.progress",[b])}},!1),a},success:function(b,d,e){l="string"==typeof b?a.parseJSON(b):b,b.location&&(c=b.location),i.resolve()},error:function(a,b,c){j=c,i.reject();try{}catch(d){}}}),a.when(i,r.transitionOutDeferred).done(function(){g(c,h,l,r.jump?0:!1,!0)}).fail(function(){m.trigger("pronto.error",[j])})}function g(b,c,d,e,f){if(m.trigger("pronto.load"),j(b),i(),r.render.call(this,d,c),o=b,f?(history.pushState({url:o,data:d,scroll:e,hash:c},"state-"+o,o),p++):i(),m.trigger("pronto.render"),""!==c){var g=a(c);g.length&&(e=g.offset().top)}e!==!1&&m.scrollTop(e)}function h(b,c){if("undefined"!=typeof b)for(var d in r.target)r.target.hasOwnProperty(d)&&b.hasOwnProperty(d)&&a(r.target[d]).html(b[d])}function i(){var b=[];for(var c in r.target)r.target.hasOwnProperty(c)&&(b[c]=a(r.target[c]).html());history.replaceState({url:o,data:b,scroll:m.scrollTop()},"state-"+o,o)}function j(a){if(a=a.replace(b.location.protocol+"//"+b.location.host,""),r.tracking.legacy)b._gaq=b._gaq||[],b._gaq.push(["_trackPageview",a]);else if(r.tracking.manager){var c={};c[r.tracking.variable]=a,b.dataLayer=b.dataLayer||[],b.dataLayer.push(c),b.dataLayer.push({event:r.tracking.event})}else"function"==typeof ga&&ga("send","pageview",a)}function k(a){for(var b={},c=a.slice(a.indexOf("?")+1).split("&"),d=0;d<c.length;d++){var e=c[d].split("=");b[e[0]]=e[1]}return b}var l,m=a(b),n=b.history&&b.history.pushState&&b.history.replaceState,o="",p=0,q=null,r={cache:!0,force:!1,jump:!0,modal:!1,selector:"a",render:a.noop,requestKey:"pronto",target:{title:"title",content:"#pronto"},tracking:{legacy:!1,manager:!1,variable:"currentURL",event:"PageView"},transitionOut:a.noop},s={defaults:function(b){return r=a.extend(r,b||{}),"object"==typeof this?a(this):!0},disable:function(){l&&l.hasClass("pronto")&&l.off("click.pronto").removeClass("pronto")},enable:function(){l&&!l.hasClass("pronto")&&l.on("click.pronto",r.selector,d).addClass("pronto")},load:function(a){n?a&&f(a):b.location.href=a}};a.pronto=function(a){return s[a]?s[a].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof a&&a?this:c.apply(this,arguments)}}(jQuery,this);