-
Notifications
You must be signed in to change notification settings - Fork 175
/
jquery.address-1.4.1.min.js
29 lines (29 loc) · 9.53 KB
/
jquery.address-1.4.1.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
* jQuery Address Plugin v1.4.1
* http://www.asual.com/jquery/address/
*
* Copyright (c) 2009-2010 Rostislav Hristov
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* Date: 2011-06-08 17:53:57 +0300 (Wed, 08 Jun 2011)
*/
(function(c){c.address=function(){var v=function(a){c(c.address).trigger(c.extend(c.Event(a),function(){for(var b={},e=c.address.parameterNames(),k=0,s=e.length;k<s;k++)b[e[k]]=c.address.parameter(e[k]);return{value:c.address.value(),path:c.address.path(),pathNames:c.address.pathNames(),parameterNames:e,parameters:b,queryString:c.address.queryString()}}.call(c.address)))},p=function(a){return Array.prototype.slice.call(a)},q=function(){c().bind.apply(c(c.address),Array.prototype.slice.call(arguments));
return c.address},I=function(){return L.pushState&&d.state!==j},V=function(){return("/"+f.pathname.replace(new RegExp(d.state),"")+f.search+(C()?"#"+C():"")).replace(U,"/")},C=function(){var a=f.href.indexOf("#");return a!=-1?A(f.href.substr(a+1),l):""},u=function(){return I()?V():C()},ha=function(){return"javascript"},M=function(a){a=a.toString();return(d.strict&&a.substr(0,1)!="/"?"/":"")+a},A=function(a,b){if(d.crawlable&&b)return(a!==""?"!":"")+a;return a.replace(/^\!/,"")},w=function(a,b){return parseInt(a.css(b),
10)},E=function(){if(!J){var a=u();if(g!=a)if(x&&r<7)f.reload();else{x&&r<8&&d.history&&t(N,50);g=a;D(l)}}},D=function(a){v(W);v(a?X:Y);t(Z,10)},Z=function(){if(d.tracker!=="null"&&d.tracker!==null){var a=c.isFunction(d.tracker)?d.tracker:h[d.tracker],b=(f.pathname+f.search+(c.address&&!I()?c.address.value():"")).replace(/\/\//,"/").replace(/^\/$/,"");if(c.isFunction(a))a(b);else if(c.isFunction(h.urchinTracker))h.urchinTracker(b);else if(h.pageTracker!==j&&c.isFunction(h.pageTracker._trackPageview))h.pageTracker._trackPageview(b);
else h._gaq!==j&&c.isFunction(h._gaq.push)&&h._gaq.push(["_trackPageview",decodeURI(b)])}},N=function(){var a=ha()+":"+l+";document.open();document.writeln('<html><head><title>"+n.title.replace("'","\\'")+"</title><script>var "+B+' = "'+encodeURIComponent(u())+(n.domain!=f.hostname?'";document.domain="'+n.domain:"")+"\";<\/script></head></html>');document.close();";if(r<7)m.src=a;else m.contentWindow.location.replace(a)},aa=function(){if(F&&$!=-1){var a,b=F.substr($+1).split("&");for(i=0;i<b.length;i++){a=
b[i].split("=");if(/^(autoUpdate|crawlable|history|strict|wrap)$/.test(a[0]))d[a[0]]=isNaN(a[1])?/^(true|yes)$/i.test(a[1]):parseInt(a[1],10)!==0;if(/^(state|tracker)$/.test(a[0]))d[a[0]]=a[1]}F=null}g=u()},ca=function(){if(!ba){ba=o;aa();var a=function(){ia.call(this);ja.call(this)},b=c("body").ajaxComplete(a);a();if(d.wrap){c("body > *").wrapAll('<div style="padding:'+(w(b,"marginTop")+w(b,"paddingTop"))+"px "+(w(b,"marginRight")+w(b,"paddingRight"))+"px "+(w(b,"marginBottom")+w(b,"paddingBottom"))+
"px "+(w(b,"marginLeft")+w(b,"paddingLeft"))+'px;" />').parent().wrap('<div id="'+B+'" style="height:100%;overflow:auto;position:relative;'+(G&&!window.statusbar.visible?"resize:both;":"")+'" />');c("html, body").css({height:"100%",margin:0,padding:0,overflow:"hidden"});G&&c('<style type="text/css" />').appendTo("head").text("#"+B+"::-webkit-resizer { background-color: #fff; }")}if(x&&r<8){a=n.getElementsByTagName("frameset")[0];m=n.createElement((a?"":"i")+"frame");if(a){a.insertAdjacentElement("beforeEnd",
m);a[a.cols?"cols":"rows"]+=",0";m.noResize=o;m.frameBorder=m.frameSpacing=0}else{m.style.display="none";m.style.width=m.style.height=0;m.tabIndex=-1;n.body.insertAdjacentElement("afterBegin",m)}t(function(){c(m).bind("load",function(){var e=m.contentWindow;g=e[B]!==j?e[B]:"";if(g!=u()){D(l);f.hash=A(g,o)}});m.contentWindow[B]===j&&N()},50)}t(function(){v("init");D(l)},1);if(!I())if(x&&r>7||!x&&"on"+H in h)if(h.addEventListener)h.addEventListener(H,E,l);else h.attachEvent&&h.attachEvent("on"+H,E);
else ka(E,50)}},ia=function(){var a,b=c("a"),e=b.size(),k=-1,s=function(){if(++k!=e){a=c(b.get(k));a.is('[rel*="address:"]')&&a.address();t(s,1)}};t(s,1)},la=function(){if(g!=u()){g=u();D(l)}},ma=function(){if(h.removeEventListener)h.removeEventListener(H,E,l);else h.detachEvent&&h.detachEvent("on"+H,E)},ja=function(){if(d.crawlable){var a=f.pathname.replace(/\/$/,"");c("body").html().indexOf("_escaped_fragment_")!=-1&&c('a[href]:not([href^=http]), a[href*="'+document.domain+'"]').each(function(){var b=
c(this).attr("href").replace(/^http:/,"").replace(new RegExp(a+"/?$"),"");if(b===""||b.indexOf("_escaped_fragment_")!=-1)c(this).attr("href","#"+b.replace(/\/(.*)\?_escaped_fragment_=(.*)$/,"!$2"))})}},j,B="jQueryAddress",H="hashchange",W="change",X="internalChange",Y="externalChange",o=true,l=false,d={autoUpdate:o,crawlable:l,history:o,strict:o,wrap:l},y=c.browser,r=parseFloat(c.browser.version),da=y.mozilla,x=y.msie,ea=y.opera,G=y.webkit||y.safari,O=l,h=function(){try{return top.document!==j?top:
window}catch(a){return window}}(),n=h.document,L=h.history,f=h.location,ka=setInterval,t=setTimeout,U=/\/{2,9}/g;y=navigator.userAgent;var m,F=c("script:last").attr("src"),$=F?F.indexOf("?"):-1,P=n.title,J=l,ba=l,Q=o,fa=o,K=l,g=u();if(x){r=parseFloat(y.substr(y.indexOf("MSIE")+4));if(n.documentMode&&n.documentMode!=r)r=n.documentMode!=8?7:8;var ga=n.onpropertychange;n.onpropertychange=function(){ga&&ga.call(n);if(n.title!=P&&n.title.indexOf("#"+u())!=-1)n.title=P}}if(O=da&&r>=1||x&&r>=6||ea&&r>=9.5||
G&&r>=523){if(ea)history.navigationMode="compatible";if(document.readyState=="complete")var na=setInterval(function(){if(c.address){ca();clearInterval(na)}},50);else{aa();c(ca)}c(window).bind("popstate",la).bind("unload",ma)}else!O&&C()!==""?f.replace(f.href.substr(0,f.href.indexOf("#"))):Z();return{bind:function(){return q.apply(this,p(arguments))},init:function(){return q.apply(this,["init"].concat(p(arguments)))},change:function(){return q.apply(this,[W].concat(p(arguments)))},internalChange:function(){return q.apply(this,
[X].concat(p(arguments)))},externalChange:function(){return q.apply(this,[Y].concat(p(arguments)))},baseURL:function(){var a=f.href;if(a.indexOf("#")!=-1)a=a.substr(0,a.indexOf("#"));if(/\/$/.test(a))a=a.substr(0,a.length-1);return a},autoUpdate:function(a){if(a!==j){d.autoUpdate=a;return this}return d.autoUpdate},crawlable:function(a){if(a!==j){d.crawlable=a;return this}return d.crawlable},history:function(a){if(a!==j){d.history=a;return this}return d.history},state:function(a){if(a!==j){d.state=
a;var b=V();if(d.state!==j)if(L.pushState)b.substr(0,3)=="/#/"&&f.replace(d.state.replace(/^\/$/,"")+b.substr(2));else b!="/"&&b.replace(/^\/#/,"")!=C()&&t(function(){f.replace(d.state.replace(/^\/$/,"")+"/#"+b)},1);return this}return d.state},strict:function(a){if(a!==j){d.strict=a;return this}return d.strict},tracker:function(a){if(a!==j){d.tracker=a;return this}return d.tracker},wrap:function(a){if(a!==j){d.wrap=a;return this}return d.wrap},update:function(){K=o;this.value(g);K=l;return this},
title:function(a){if(a!==j){t(function(){P=n.title=a;if(fa&&m&&m.contentWindow&&m.contentWindow.document){m.contentWindow.document.title=a;fa=l}if(!Q&&da)f.replace(f.href.indexOf("#")!=-1?f.href:f.href+"#");Q=l},50);return this}return n.title},value:function(a){if(a!==j){a=M(a);if(a=="/")a="";if(g==a&&!K)return;Q=o;g=a;if(d.autoUpdate||K){D(o);if(I())L[d.history?"pushState":"replaceState"]({},"",d.state.replace(/\/$/,"")+(g===""?"/":g));else{J=o;if(G)if(d.history)f.hash="#"+A(g,o);else f.replace("#"+
A(g,o));else if(g!=u())if(d.history)f.hash="#"+A(g,o);else f.replace("#"+A(g,o));x&&r<8&&d.history&&t(N,50);if(G)t(function(){J=l},1);else J=l}}return this}if(!O)return null;return M(g)},path:function(a){if(a!==j){var b=this.queryString(),e=this.hash();this.value(a+(b?"?"+b:"")+(e?"#"+e:""));return this}return M(g).split("#")[0].split("?")[0]},pathNames:function(){var a=this.path(),b=a.replace(U,"/").split("/");if(a.substr(0,1)=="/"||a.length===0)b.splice(0,1);a.substr(a.length-1,1)=="/"&&b.splice(b.length-
1,1);return b},queryString:function(a){if(a!==j){var b=this.hash();this.value(this.path()+(a?"?"+a:"")+(b?"#"+b:""));return this}a=g.split("?");return a.slice(1,a.length).join("?").split("#")[0]},parameter:function(a,b,e){var k,s;if(b!==j){var R=this.parameterNames();s=[];b=b?b.toString():"";for(k=0;k<R.length;k++){var S=R[k],z=this.parameter(S);if(typeof z=="string")z=[z];if(S==a)z=b===null||b===""?[]:e?z.concat([b]):[b];for(var T=0;T<z.length;T++)s.push(S+"="+z[T])}c.inArray(a,R)==-1&&b!==null&&
b!==""&&s.push(a+"="+b);this.queryString(s.join("&"));return this}if(b=this.queryString()){e=[];s=b.split("&");for(k=0;k<s.length;k++){b=s[k].split("=");b[0]==a&&e.push(b.slice(1).join("="))}if(e.length!==0)return e.length!=1?e:e[0]}},parameterNames:function(){var a=this.queryString(),b=[];if(a&&a.indexOf("=")!=-1){a=a.split("&");for(var e=0;e<a.length;e++){var k=a[e].split("=")[0];c.inArray(k,b)==-1&&b.push(k)}}return b},hash:function(a){if(a!==j){this.value(g.split("#")[0]+(a?"#"+a:""));return this}a=
g.split("#");return a.slice(1,a.length).join("#")}}}();c.fn.address=function(v){c(this).attr("address")||c(this).live("click",function(p){if(p.shiftKey||p.ctrlKey||p.metaKey||p.which==2)return true;if(c(this).is("a")){var q=v?v.call(this):/address:/.test(c(this).attr("rel"))?c(this).attr("rel").split("address:")[1].split(" ")[0]:c.address.state()!==undefined&&c.address.state()!="/"?c(this).attr("href").replace(new RegExp("^(.*"+c.address.state()+"|\\.)"),""):c(this).attr("href").replace(/^(#\!?|\.)/,
"");c.address.value(q);p.preventDefault()}}).live("submit",function(p){if(c(this).is("form")){var q=c(this).attr("action");q=v?v.call(this):(q.indexOf("?")!=-1?q.replace(/&$/,""):q+"?")+c(this).serialize();c.address.value(q);p.preventDefault()}}).attr("address",true);return this}})(jQuery);