forked from hotsh/rstat.us
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery-cb102f78b7a38730cfb9af1b66582215.pjax.js
4 lines (4 loc) · 1.98 KB
/
jquery-cb102f78b7a38730cfb9af1b66582215.pjax.js
1
2
3
4
// jquery.pjax.js
// copyright chris wanstrath
// https://github.com/defunkt/jquery-pjax
(function(a){a.fn.pjax=function(b,c){c?c.container=b:c=a.isPlainObject(b)?b:{container:b};return this.live("click",function(b){if(b.which>1||b.metaKey)return!0;var d={url:this.href,container:a(this).attr("data-pjax"),clickedElement:a(this)};a.pjax(a.extend({},d,c)),b.preventDefault()})},a.pjax=function(b){var c=a(b.container),d=b.success||a.noop;delete b.success;var e={timeout:650,push:!0,replace:!1,data:{_pjax:!0},type:"GET",dataType:"html",beforeSend:function(a){c.trigger("start.pjax"),a.setRequestHeader("X-PJAX","true")},error:function(){window.location=b.url},complete:function(){c.trigger("end.pjax")},success:function(e){if(!a.trim(e)||/<html/i.test(e))return window.location=b.url;c.html(e);var f=document.title,g=a.trim(c.find("title").remove().text());g&&(document.title=g);var h={pjax:b.container,timeout:b.timeout};a.isPlainObject(h.pjax)&&(h.pjax=h.pjax.selector);var i=a.param(b.data);i!="_pjax=true"&&(h.url=b.url+(/\?/.test(b.url)?"&":"?")+i),b.replace?window.history.replaceState(h,document.title,b.url):b.push&&(a.pjax.active||(window.history.replaceState(a.extend({},h,{url:null}),f),a.pjax.active=!0),window.history.pushState(h,document.title,b.url)),(b.replace||b.push)&&window._gaq&&_gaq.push(["_trackPageview"]),d.apply(this,arguments)}};b=a.extend(!0,{},e,b),a.isFunction(b.url)&&(b.url=b.url());var f=a.pjax.xhr;f&&f.readyState<4&&(f.onreadystatechange=a.noop,f.abort()),a.pjax.xhr=a.ajax(b),a(document).trigger("pjax",a.pjax.xhr,b);return a.pjax.xhr};var b="state"in window.history,c=location.href;a(window).bind("popstate",function(d){var e=!b&&location.href==c;b=!0;if(!e){var f=d.state;if(f&&f.pjax){var g=a(f.pjax+"");g.length?a.pjax({url:f.url||location.href,container:g,push:!1,timeout:f.timeout}):window.location=location.href}}}),a.event.props.indexOf("state")<0&&a.event.props.push("state");if(!window.history||!window.history.pushState)a.pjax=a.noop,a.fn.pjax=function(){return this}})(jQuery)