1234567 |
- /*!
- * Copyright 2012, Chris Wanstrath
- * Released under the MIT License
- * https://github.com/defunkt/jquery-pjax
- */
- (function(v){var y={};function h(K,L,M){var N=this;return this.on("click.pjax",K,function(Q){var P=v.extend({},I(L,M)),O=v(this).attr("data-pjax");if(!P.container){if(O===""){P.container="#admui-pageContent"}else{P.container=v(this).attr("data-pjax")||N}}a(Q,P)})}function a(P,L,M){M=I(L,M);var O=P.currentTarget;if(O.tagName.toUpperCase()!=="A"){throw"$.fn.pjax or $.pjax.click requires an anchor element"}if(P.which>1||P.metaKey||P.ctrlKey||P.shiftKey||P.altKey){return}if(location.protocol!==O.protocol||location.hostname!==O.hostname){return}if(O.href.indexOf("#")>-1&&s(O)==s(location)){return}if(P.isDefaultPrevented()){return}var Q={url:O.href,container:v(O).attr("data-pjax"),target:O};var N=v.extend({},Q,M);var K=v.Event("pjax:click");v(O).trigger(K,[N]);y.link=N;if(y.script&&y.script.length!==0){P.preventDefault();return}if(!K.isDefaultPrevented()){E(N);P.preventDefault();v(O).trigger("pjax:clicked",[N])}}function p(O,K,M){M=I(K,M);var N=O.currentTarget;var L=v(N);if(N.tagName.toUpperCase()!=="FORM"){throw"$.pjax.submit requires a form element"}var P={type:(L.attr("method")||"GET").toUpperCase(),url:L.attr("action"),container:L.attr("data-pjax"),target:N};if(P.type!=="GET"&&window.FormData!==undefined){P.data=new FormData(N);P.processData=false;P.contentType=false}else{if(v(N).find(":file").length){return}P.data=v(N).serializeArray()}E(v.extend({},P,M));O.preventDefault()}function E(K){K=v.extend(true,{},v.ajaxSettings,E.defaults,K);if(v.isFunction(K.url)){K.url=K.url()}var P=K.target;var O=n(K.url).hash;var L=K.context=w(K.container);if(!K.data){K.data={}}if(v.isArray(K.data)){K.data.push({name:"_pjax",value:L.selector})}else{K.data._pjax=L.selector}function N(T,R,S){if(!S){S={}}S.relatedTarget=P;var U=v.Event(T,S);L.trigger(U,R);return !U.isDefaultPrevented()}var M;K.beforeSend=function(T,S){if(S.type!=="GET"){S.timeout=0}T.setRequestHeader("X-PJAX","true");T.setRequestHeader("X-PJAX-Container",L.selector);if(!N("pjax:beforeSend",[T,S])){return false}if(S.timeout>0){M=setTimeout(function(){if(N("pjax:timeout",[T,K])){T.abort("timeout")}},S.timeout);S.timeout=0}var R=n(S.url);if(O){R.hash=O}K.requestUrl=k(R)};K.complete=function(R,S){if(M){clearTimeout(M)}N("pjax:complete",[R,S,K]);N("pjax:end",[R,K])};K.error=function(U,V,S){var R=t("",U,K);var T=N("pjax:error",[U,V,S,K]);if(K.type=="GET"&&V!=="abort"&&T){o(R.url)}};K.success=function(W,V,ad){var Z=E.state;var ac=(typeof v.pjax.defaults.version==="function")?v.pjax.defaults.version():v.pjax.defaults.version;var ae=ad.getResponseHeader("X-PJAX-Version");var T=t(W,ad,K);var S=n(T.url);if(O){S.hash=O;T.url=S.href}if(ac&&ae&&ac!==ae){o(T.url);return}if(!T.contents){o(T.url);return}E.state={id:K.id||f(),url:T.url,title:T.title,container:L.selector,fragment:K.fragment,timeout:K.timeout};if(K.push||K.replace){window.history.replaceState(E.state,T.title,T.url)}var U=v.contains(K.container,document.activeElement);if(U){try{document.activeElement.blur()}catch(ab){}}if(T.title){document.title=T.title}N("pjax:beforeReplace",[T.contents,K],{state:E.state,previousState:Z});L.html(T.contents);var Y=L.find("input[autofocus], textarea[autofocus]").last()[0];if(Y&&document.activeElement!==Y){Y.focus()}u(L,T.scripts);var X=K.scrollTo;if(O){var R=decodeURIComponent(O.slice(1));var aa=document.getElementById(R)||document.getElementsByName(R)[0];if(aa){X=v(aa).offset().top}}if(typeof X=="number"){v(window).scrollTop(X)}N("pjax:success",[W,V,ad,K])};if(!E.state){E.state={id:f(),url:window.location.href,title:document.title,container:L.selector,fragment:K.fragment,timeout:K.timeout};window.history.replaceState(E.state,document.title)}J(E.xhr);E.options=K;var Q=E.xhr=v.ajax(K);if(Q.readyState>0){if(K.push&&!K.replace){z(E.state.id,d(L));window.history.pushState(null,"",K.requestUrl)}N("pjax:start",[Q,K]);N("pjax:send",[Q,K])}return E.xhr}function A(K,L){var M={url:window.location.href,push:false,replace:true,scrollTo:false};return E(v.extend(M,I(K,L)))}function o(K){window.history.replaceState(null,"",E.state.url);window.location.replace(K)}var r=true;var C=window.location.href;var D=window.history.state;if(D&&D.container){E.state=D}if("state" in window.history){r=false}function b(M){if(!r){J(E.xhr)}var R=E.state;var L=M.state;var S;if(L&&L.container){if(r&&C==L.url){return}if(R){if(R.id===L.id){return}S=R.id<L.id?"forward":"back"}var K=G[L.id]||[];var N=v(K[0]||L.container),P=K[1];if(N.length){if(R){m(S,R.id,d(N))}var Q=v.Event("pjax:popstate",{state:L,direction:S});N.trigger(Q);var T={id:L.id,url:L.url,container:N,push:false,fragment:L.fragment,timeout:L.timeout,scrollTo:false};if(P){N.trigger("pjax:start",[null,T]);E.state=L;if(L.title){document.title=L.title}var O=v.Event("pjax:beforeReplace",{state:L,previousState:R});N.trigger(O,[P,T]);N.html(P);N.trigger("pjax:end",[null,T])}else{E(T)}N[0].offsetHeight}else{o(location.href)}}r=false}function e(L){var K=v.isFunction(L.url)?L.url():L.url,P=L.type?L.type.toUpperCase():"GET";
- var N=v("<form>",{method:P==="GET"?"GET":"POST",action:K,style:"display:none"});if(P!=="GET"&&P!=="POST"){N.append(v("<input>",{type:"hidden",name:"_method",value:P.toLowerCase()}))}var O=L.data;if(typeof O==="string"){v.each(O.split("&"),function(Q,R){var S=R.split("=");N.append(v("<input>",{type:"hidden",name:S[0],value:S[1]}))})}else{if(v.isArray(O)){v.each(O,function(Q,R){N.append(v("<input>",{type:"hidden",name:R.name,value:R.value}))})}else{if(typeof O==="object"){var M;for(M in O){N.append(v("<input>",{type:"hidden",name:M,value:O[M]}))}}}}v(document.body).append(N);N.submit()}function J(K){if(K&&K.readyState<4){K.onreadystatechange=v.noop;K.abort()}}function f(){return(new Date).getTime()}function d(L){var K=L.clone();K.find("script").each(function(){if(!this.src){jQuery._data(this,"globalEval",false)}});return[L.selector,K.contents()]}function k(K){K.search=K.search.replace(/([?&])(_pjax|_)=[^&]*/g,"");return K.href.replace(/\?($|#)/,"$1")}function n(L){var K=document.createElement("a");K.href=L;return K}function s(K){return K.href.replace(/#.*/,"")}function I(K,L){if(K&&L){L.container=K}else{if(v.isPlainObject(K)){L=K}else{L={container:K}}}if(L.container){L.container=w(L.container)}return L}function w(K){K=v(K);if(!K.length){throw"no pjax container for "+K.selector}else{if(K.selector!==""&&K.context===document){return K}else{if(K.attr("id")){return v("#"+K.attr("id"))}else{throw"cant get selector for pjax container!"}}}}function q(L,K){return L.filter(K).add(L.find(K))}function i(K){return v.parseHTML(K,document,true)}function t(O,Q,S){var N={},K=/<html/i.test(O);var L=Q.getResponseHeader("X-PJAX-URL");N.url=L?k(n(L)):S.requestUrl;if(K){var P=v(i(O.match(/<head[^>]*>([\s\S.]*)<\/head>/i)[0]));var M=v(i(O.match(/<body[^>]*>([\s\S.]*)<\/body>/i)[0]))}else{var P=M=v(i(O))}if(M.length===0){return N}N.title=q(P,"title").first().text();if(S.fragment){if(S.fragment==="body"){var R=M}else{var R=q(M,S.fragment).first()}if(R.length){N.contents=S.fragment==="body"?R:R.contents();if(!N.title){N.title=R.attr("title")||R.data("title")}}}else{if(!K){N.contents=M}}if(N.contents){N.contents=N.contents.not(function(){return v(this).is("title")});N.contents=N.contents.not(function(){return v(this).is("meta")});N.contents.find("title").remove();N.contents.find("meta").remove();N.scripts=q(N.contents,"script[src]").remove();N.contents=N.contents.not(N.scripts)}if(N.title){N.title=v.trim(N.title)}return N}function u(M,K){y.link="";if(!K){return}var L=v("script[src]");y.script=Array.isArray(K)?K:K.toArray();H(L,K);var N=setInterval(function(){if(y.script.length===0){clearInterval(N);v.Event("pjax:callback");v(M).trigger("pjax:callback");if(y.link!==""){E(y.link)}}},5)}function H(M,K){var L=arguments.callee;if(K.length===0){return}v.each(K,function(P,O){var T=v(O),N=T.attr("src"),V=T.data("deps");var U=M.filter(function(){return this.src===N});if(U.length){return}if(V){var R=x(V,y.script);var Q=K.length;if(R!==0){setTimeout(function(){for(var W=0;W<Q;W++){if(K[0]===""){K.splice(0,1)}}L(M,K)},5);return false}else{K.splice(P,1,"")}}else{K.splice(P,1,"")}var S=document.createElement("script");S.src=N;if(S.readyState){S.onreadystatechange=function(){if(S.readyState=="loaded"||S.readyState=="complete"){S.onreadystatechange=null;for(var W=0;W<y.script.length;W++){if(y.script[W].src===this.src){y.script.splice(W,1)}}}}}else{S.onload=function(){for(var W=0;W<y.script.length;W++){if(y.script[W].src===this.src){y.script.splice(W,1)}}}}document.head.appendChild(S)})}function x(N,M){N=N.split(",");var K=[];for(var L=0;L<N.length;L++){for(var O=0;O<M.length;O++){if(N[L]===v(M[O]).data("name")){K.push("wait")}}}return K.length}var G={};var B=[];var l=[];function z(L,K){G[L]=K;l.push(L);j(B,0);j(l,E.defaults.maxCacheLength)}function m(M,O,L){var N,K;G[O]=L;if(M==="forward"){N=l;K=B}else{N=B;K=l}N.push(O);if(O=K.pop()){delete G[O]}j(N,E.defaults.maxCacheLength)}function j(K,L){while(K.length>L){delete G[K.shift()]}}function F(){return v("meta").filter(function(){var K=v(this).attr("http-equiv");return K&&K.toUpperCase()==="X-PJAX-VERSION"}).attr("content")}function g(){v.fn.pjax=h;v.pjax=E;v.pjax.enable=v.noop;v.pjax.disable=c;v.pjax.click=a;v.pjax.submit=p;v.pjax.reload=A;v.pjax.defaults={timeout:650,push:true,replace:false,type:"GET",dataType:"html",scrollTo:0,maxCacheLength:20,version:F};v(window).on("popstate.pjax",b)}function c(){v.fn.pjax=function(){return this};v.pjax=e;v.pjax.enable=g;v.pjax.disable=v.noop;v.pjax.click=v.noop;v.pjax.submit=v.noop;v.pjax.reload=function(){window.location.reload()};v(window).off("popstate.pjax",b)}if(v.inArray("state",v.event.props)<0){v.event.props.push("state")}v.support.pjax=window.history&&window.history.pushState&&window.history.replaceState&&!navigator.userAgent.match(/((iPod|iPhone|iPad).+\bOS\s+[1-4]\D|WebApps\/.+CFNetwork)/);v.support.pjax?g():c()})(jQuery);
|