jquery.ba-bbq.min.js 3.8 KB

123456789101112131415161718
  1. /*
  2. * jQuery BBQ: Back Button & Query Library - v1.1 - 1/9/2010
  3. * http://benalman.com/projects/jquery-bbq-plugin/
  4. *
  5. * Copyright (c) 2010 "Cowboy" Ben Alman
  6. * Dual licensed under the MIT and GPL licenses.
  7. * http://benalman.com/about/license/
  8. */
  9. (function($,c){var g,m=c.location,i=Array.prototype.slice,D=decodeURIComponent,a=$.param,n,d,q,o=$.bbq=$.bbq||{},p,C,e,k=$.event.special,b="hashchange",v="querystring",y="fragment",x="elemUrlAttr",h="href",B="src",r=/^.*\?|#.*$/g,z=/^.*\#/,t={};function s(E){return typeof E==="string"}function w(F){var E=i.call(arguments,1);return function(){return F.apply(this,E.concat(i.call(arguments)))}}function j(E){return E.replace(/^[^#]*#?(.*)$/,"$1")}function l(E){return E.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")}function f(F,M,E,G,J){var L,K,I,N,H;if(G!==g){I=E.match(F?/^([^#]*)\#?(.*)$/:/^([^#?]*)\??([^#]*)(#?.*)/);H=I[3]||"";if(J===2&&s(G)){K=G.replace(F?z:r,"")}else{N=d(I[2]);G=s(G)?d[F?y:v](G):G;K=J===2?G:J===1?$.extend({},G,N):$.extend({},N,G);K=a(K)}L=I[1]+(F?"#":K||!I[1]?"?":"")+K+H}else{L=M(E!==g?E:m[h])}return L}a[v]=w(f,0,l);a[y]=n=w(f,1,j);$.deparam=d=function(H,F){var G={},E={"true":!0,"false":!1,"null":null};$.each(H.replace(/\+/g," ").split("&"),function(L,N){var K=N.split("="),O=D(K[0]),J,P=G,M=0,Q=O.split("]["),I=Q.length-1;if(/\[/.test(Q[0])&&/\]$/.test(Q[I])){Q[I]=Q[I].replace(/\]$/,"");Q=Q.shift().split("[").concat(Q);I=Q.length-1}else{I=0}if(K.length===2){J=D(K[1]);if(F){J=J&&!isNaN(J)?+J:J==="undefined"?g:E[J]!==g?E[J]:J}if(I){for(;M<=I;M++){O=Q[M]===""?P.length:Q[M];P=P[O]=M<I?P[O]||(Q[M+1]&&isNaN(Q[M+1])?{}:[]):J}}else{if($.isArray(G[O])){G[O].push(J)}else{if(G[O]!==g){G[O]=[G[O],J]}else{G[O]=J}}}}else{if(O){G[O]=F?g:""}}});return G};function u(G,F,E){if(F===g||typeof F==="boolean"){E=F;F=a[G?y:v]()}else{F=s(F)?F.replace(G?z:r,""):F}return d(F,E)}d[v]=w(u,0);d[y]=q=w(u,1);$[x]||($[x]=function(E){return $.extend(t,E)})({a:h,base:h,iframe:B,img:B,input:B,form:"action",link:h,script:B});e=$[x];function A(H,E,G,F){if(!s(G)&&typeof G!=="object"){F=G;G=E;E=g}return this.each(function(){var K=$(this),I=E||e()[(this.nodeName||"").toLowerCase()]||"",J=I&&K.attr(I)||"";K.attr(I,a[H](J,G,F))})}$.fn[v]=w(A,v);$.fn[y]=w(A,y);o.pushState=p=function(H,G){if(s(H)&&/^#/.test(H)&&G===g){G=2}var F=H!==g,E=n(m[h],F?H:{},F?G:2);m[h]=E+(/#/.test(E)?"":"#")};o.getState=C=function(F,E){return F===g||typeof F==="boolean"?q(F):q(E)[F]};o.removeState=function(E){var F={};if(E!==g){F=C();$.each($.isArray(E)?E:arguments,function(H,G){delete F[G]})}p(F,2)};k[b]=$.extend(k[b],{add:function(E,G,F){return function(I){var H=I[y]=n();I.getState=function(K,J){return K===g||typeof K==="boolean"?d(H,K):d(H,J)[K]};E.apply(this,arguments)}}})})(jQuery,this);
  10. /*
  11. * jQuery hashchange event - v1.0 - 1/9/2010
  12. * http://benalman.com/projects/jquery-hashchange-plugin/
  13. *
  14. * Copyright (c) 2010 "Cowboy" Ben Alman
  15. * Dual licensed under the MIT and GPL licenses.
  16. * http://benalman.com/about/license/
  17. */
  18. (function($,b){var g=b.location,h,i=$.event.special,d="hashchange",f=$.browser,c=f.msie&&f.version<8,e="on"+d in b&&!c;function a(j){j=j||g.href;return j.replace(/^[^#]*#?(.*)$/,"$1")}$[d+"Delay"]=100;i[d]=$.extend(i[d],{setup:function(){if(e){return false}h.start()},teardown:function(){if(e){return false}h.stop()}});h=(function(){var k={},o,j,l,n;function m(){l=n=function(p){return p};if(c){j=$('<iframe src="javascript:0"/>').hide().appendTo("body")[0].contentWindow;n=function(){return a(j.document.location.href)};l=function(r,p){if(r!==p){var q=j.document;q.open().close();q.location.hash="#"+r}};l(a())}}k.start=function(){if(o){return}var q=a();l||m();(function p(){var s=a(),r=n(q);if(s!==q){l(q=s,r);$(b).trigger(d)}else{if(r!==q){g.href=g.href.replace(/#.*/,"")+"#"+r}}o=setTimeout(p,$[d+"Delay"])})()};k.stop=function(){if(!j){o&&clearTimeout(o);o=0}};return k})()})(jQuery,this);