Skip to content
Browse files

parsing anchor fragment

  • Loading branch information...
1 parent fddf92a commit 808afda20101420b0b1972102d2f374329b60f4a @bartaz committed Mar 23, 2010
View
2 build.properties
@@ -6,4 +6,4 @@ test.dir=test
name=jquery.address
optimizer=jquery.address-optimizer
-version=1.2
+version=1.2.bartaz
View
30 dist/jquery.address-1.2.js → dist/jquery.address-1.2.bartaz.js
@@ -1,12 +1,12 @@
/*
- * jQuery Address Plugin v1.2
+ * jQuery Address Plugin v1.2.bartaz
* 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: 2010-03-20 21:26:11 +0200 (Sat, 20 Mar 2010)
+ * Date: 2010-03-23 10:19:58 +0100 (Tue, 23 Mar 2010)
*/
(function ($) {
@@ -443,7 +443,8 @@
return this;
}
value = this.value();
- return (value.indexOf('?') != -1) ? value.split('?')[0] : value;
+ return (value.indexOf('?') != -1) ? value.split('?')[0] :
+ (value.indexOf('#') != -1) ? value.split('#')[0] : value;
},
queryString: function(value) {
if (value !== undefined) {
@@ -453,7 +454,8 @@
value = this.value();
var index = value.indexOf('?');
if (index != -1 && index < value.length) {
- return value.substr(index + 1);
+ value = value.substr(index + 1);
+ return (value.indexOf('#') != -1) ? value.split('#')[0] : value;
}
},
parameter: function(name, value, append) {
@@ -481,10 +483,8 @@
this.queryString(params.join('&'));
return this;
}
- value = this.value();
- var index = value.indexOf('?');
- if (index != -1) {
- value = value.substr(index + 1);
+ value = this.queryString();
+ if (value) {
params = value.split('&');
var r = [];
for (i = 0; i < params.length; i++) {
@@ -526,6 +526,18 @@
}
}
return names;
+ },
+ fragment: function(value) {
+ if (value !== undefined) {
+ var qs = this.queryString();
+ this.value(this.path() + (qs ? '?' + qs : '') + (value ? '#' + value : ''));
+ return this;
+ }
+ value = this.value();
+ var index = value.indexOf('#');
+ if (index != -1 && index < value.length) {
+ return value.substr(index + 1);
+ }
}
};
@@ -542,4 +554,4 @@
$(this).click(f).live('click', f);
};
-}(jQuery));
+}(jQuery));
View
28 test/jquery.address-1.2.min.js → dist/jquery.address-1.2.bartaz.min.js
@@ -1,25 +1,25 @@
/*
- * jQuery Address Plugin v1.2
+ * jQuery Address Plugin v1.2.bartaz
* 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: 2010-03-20 21:26:11 +0200 (Sat, 20 Mar 2010)
+ * Date: 2010-03-23 10:19:58 +0100 (Tue, 23 Mar 2010)
*/
-(function(c){c.address=function(){var A=function(a){c(c.address).trigger(c.extend(c.Event(a),function(){for(var b={},h=c.address.parameterNames(),f=0,p=h.length;f<p;f++)b[h[f]]=c.address.parameter(h[f]);return{value:c.address.value(),path:c.address.path(),pathNames:c.address.pathNames(),parameterNames:h,parameters:b,queryString:c.address.queryString()}}.call(c.address)))},v=function(a,b,h){if(h||b)c(c.address).bind(a,h||b,h&&b);return c.address},s=function(){var a=d.href.indexOf("#");return a!=-1?
-T(I(t(d.href.substr(a+1),j))):""},U=function(){return"javascript"},V=function(a,b){if(i.strict)a=b?a.substr(0,1)!="/"?"/"+a:a:a==""?"/":a;return a},J=function(a,b){return u&&d.protocol=="file:"?b?g.replace(/\?/,"%3F"):g.replace(/%253F/,"?"):a},t=function(a,b){if(i.crawlable)return b?(a!=""?"!":"")+a:a.replace(/^\!/,"");return a},W=function(a){for(var b,h,f=0,p=a.childNodes.length;f<p;f++){if(a.childNodes[f].src)b=String(a.childNodes[f].src);if(h=W(a.childNodes[f]))b=h}return b},G=function(){if(!K){var a=
-s(),b=g!=a;if(B&&m<523){if(C!=E.length){C=E.length;if(typeof w[C-1]!=x)g=w[C-1];F(j)}}else if(u&&m<7&&b)d.reload();else if(b){g=a;F(j)}}},F=function(a){A("change");A(a?"internalChange":"externalChange");D(X,10)},X=function(){var a=(d.pathname+(/\/$/.test(d.pathname)?"":"/")+c.address.value()).replace(/\/\//,"/").replace(/^\/$/,""),b=window[i.tracker];if(typeof b==L)b(a);else if(typeof _gaq!=x&&typeof _gaq.push==L)_gaq.push(["_trackPageview",a]);else if(typeof pageTracker!=x&&typeof pageTracker._trackPageview==
+(function(c){c.address=function(){var A=function(a){c(c.address).trigger(c.extend(c.Event(a),function(){for(var b={},h=c.address.parameterNames(),g=0,p=h.length;g<p;g++)b[h[g]]=c.address.parameter(h[g]);return{value:c.address.value(),path:c.address.path(),pathNames:c.address.pathNames(),parameterNames:h,parameters:b,queryString:c.address.queryString()}}.call(c.address)))},v=function(a,b,h){if(h||b)c(c.address).bind(a,h||b,h&&b);return c.address},s=function(){var a=d.href.indexOf("#");return a!=-1?
+T(I(t(d.href.substr(a+1),j))):""},U=function(){return"javascript"},V=function(a,b){if(i.strict)a=b?a.substr(0,1)!="/"?"/"+a:a:a==""?"/":a;return a},J=function(a,b){return u&&d.protocol=="file:"?b?f.replace(/\?/,"%3F"):f.replace(/%253F/,"?"):a},t=function(a,b){if(i.crawlable)return b?(a!=""?"!":"")+a:a.replace(/^\!/,"");return a},W=function(a){for(var b,h,g=0,p=a.childNodes.length;g<p;g++){if(a.childNodes[g].src)b=String(a.childNodes[g].src);if(h=W(a.childNodes[g]))b=h}return b},G=function(){if(!K){var a=
+s(),b=f!=a;if(B&&m<523){if(C!=E.length){C=E.length;if(typeof w[C-1]!=x)f=w[C-1];F(j)}}else if(u&&m<7&&b)d.reload();else if(b){f=a;F(j)}}},F=function(a){A("change");A(a?"internalChange":"externalChange");D(X,10)},X=function(){var a=(d.pathname+(/\/$/.test(d.pathname)?"":"/")+c.address.value()).replace(/\/\//,"/").replace(/^\/$/,""),b=window[i.tracker];if(typeof b==L)b(a);else if(typeof _gaq!=x&&typeof _gaq.push==L)_gaq.push(["_trackPageview",a]);else if(typeof pageTracker!=x&&typeof pageTracker._trackPageview==
L)pageTracker._trackPageview(a);else typeof urchinTracker==L&&urchinTracker(a)},Y=function(){var a=k.contentWindow.document;a.open();a.write("<html><head><title>"+l.title+"</title><script>var "+q+' = "'+s()+'";<\/script></head></html>');a.close()},$=function(){if(!Z){Z=e;if(u&&m<8){var a=l.getElementsByTagName("frameset")[0];k=l.createElement((a?"":"i")+"frame");if(a){a.insertAdjacentElement("beforeEnd",k);a[a.cols?"cols":"rows"]+=",0";k.src=U()+":"+j;k.noResize=e;k.frameBorder=k.frameSpacing=0}else{k.src=
-U()+":"+j;k.style.display="none";l.body.insertAdjacentElement("afterBegin",k)}D(function(){c(k).bind("load",function(){var b=k.contentWindow;g=typeof b[q]!=x?b[q]:"";if(g!=s()){F(j);d.hash=J(t(g,e),e)}});typeof k.contentWindow[q]==x&&Y()},50)}else if(B){if(m<418){c(l.body).append('<form id="'+q+'" style="position:absolute;top:-9999px;" method="get"></form>');N=l.getElementById(q)}if(typeof d[q]==x)d[q]={};if(typeof d[q][d.pathname]!=x)w=d[q][d.pathname].split(",")}D(function(){A("init");F(j)},1);
+U()+":"+j;k.style.display="none";l.body.insertAdjacentElement("afterBegin",k)}D(function(){c(k).bind("load",function(){var b=k.contentWindow;f=typeof b[q]!=x?b[q]:"";if(f!=s()){F(j);d.hash=J(t(f,e),e)}});typeof k.contentWindow[q]==x&&Y()},50)}else if(B){if(m<418){c(l.body).append('<form id="'+q+'" style="position:absolute;top:-9999px;" method="get"></form>');N=l.getElementById(q)}if(typeof d[q]==x)d[q]={};if(typeof d[q][d.pathname]!=x)w=d[q][d.pathname].split(",")}D(function(){A("init");F(j)},1);
if(u&&m>7||!u&&"on"+H in o)if(o.addEventListener)o.addEventListener(H,G,false);else o.attachEvent&&o.attachEvent("on"+H,G);else da(G,50);c("a[rel*=address:]").address()}},ea=function(){if(o.removeEventListener)o.removeEventListener(H,G,false);else o.detachEvent&&o.detachEvent("on"+H,G)},q="jQueryAddress",L="function",x="undefined",H="hashchange",e=true,j=false,i={autoUpdate:e,crawlable:e,history:e,strict:e},n=c.browser,m=parseFloat(c.browser.version),aa=n.mozilla,u=n.msie,r=n.opera,B=n.safari,O=j,
-o=function(){try{return top.document!==undefined?top:window}catch(a){return window}}(),l=o.document,E=o.history,d=o.location,da=setInterval,D=setTimeout,I=decodeURI,T=encodeURI;n=navigator.userAgent;var k,N,y=W(document),ba=y?y.indexOf("?"):-1,fa=l.title,C=E.length,K=j,Z=j,P=e,ca=e,M=j,w=[],g=s();if(u){m=parseFloat(n.substr(n.indexOf("MSIE")+4));if(l.documentMode&&l.documentMode!=m)m=l.documentMode!=8?7:8}if(O=aa&&m>=1||u&&m>=6||r&&m>=9.5||B&&m>=312){for(n=1;n<C;n++)w.push("");w.push(g);if(u&&d.hash!=
-g)d.hash="#"+J(t(g,e),e);if(r)history.navigationMode="compatible";if(y&&ba!=-1){y=y.substr(ba+1).split("&");for(n=0;n<y.length;n++){r=y[n].split("=");if(/^(autoUpdate|crawlable|history|strict)$/.test(r[0]))i[r[0]]=isNaN(r[1])?/^(true|yes)$/i.test(r[1]):parseInt(r[1],10)!==0;if(/^tracker$/.test(r[0]))i[r[0]]=r[1]}}document.readyState=="complete"&&$();c($);c(window).bind("unload",ea)}else if(!O&&s()!=""||B&&m<418&&s()!=""&&d.search!=""){l.open();l.write('<html><head><meta http-equiv="refresh" content="0;url='+
+o=function(){try{return top.document!==undefined?top:window}catch(a){return window}}(),l=o.document,E=o.history,d=o.location,da=setInterval,D=setTimeout,I=decodeURI,T=encodeURI;n=navigator.userAgent;var k,N,y=W(document),ba=y?y.indexOf("?"):-1,fa=l.title,C=E.length,K=j,Z=j,P=e,ca=e,M=j,w=[],f=s();if(u){m=parseFloat(n.substr(n.indexOf("MSIE")+4));if(l.documentMode&&l.documentMode!=m)m=l.documentMode!=8?7:8}if(O=aa&&m>=1||u&&m>=6||r&&m>=9.5||B&&m>=312){for(n=1;n<C;n++)w.push("");w.push(f);if(u&&d.hash!=
+f)d.hash="#"+J(t(f,e),e);if(r)history.navigationMode="compatible";if(y&&ba!=-1){y=y.substr(ba+1).split("&");for(n=0;n<y.length;n++){r=y[n].split("=");if(/^(autoUpdate|crawlable|history|strict)$/.test(r[0]))i[r[0]]=isNaN(r[1])?/^(true|yes)$/i.test(r[1]):parseInt(r[1],10)!==0;if(/^tracker$/.test(r[0]))i[r[0]]=r[1]}}document.readyState=="complete"&&$();c($);c(window).bind("unload",ea)}else if(!O&&s()!=""||B&&m<418&&s()!=""&&d.search!=""){l.open();l.write('<html><head><meta http-equiv="refresh" content="0;url='+
d.href.substr(0,d.href.indexOf("#"))+'" /></head></html>');l.close()}else X();return{init:function(a,b){return v("init",a,b)},change:function(a,b){return v("change",a,b)},internalChange:function(a,b){return v("internalChange",a,b)},externalChange:function(a,b){return v("externalChange",a,b)},baseURL:function(){var a=d.href;if(s()!="")a=a.substr(0,a.indexOf("#"));if(/\/$/.test(a))a=a.substr(0,a.length-1);return a},strict:function(a){if(a!==undefined){i.strict=a;return this}return i.strict},crawlable:function(a){if(a!==
-undefined){i.crawlable=a;return this}return i.crawlable},autoUpdate:function(a){if(a!==undefined){i.autoUpdate=a;return this}return i.autoUpdate},update:function(){M=e;this.value(g);M=j;return this},history:function(a){if(a!==undefined){i.history=a;return this}return i.history},tracker:function(a){if(a!==undefined){i.tracker=a;return this}return i.tracker},title:function(a){if(a!==undefined){a=I(a);D(function(){fa=l.title=a;if(ca&&k&&k.contentWindow&&k.contentWindow.document){k.contentWindow.document.title=
-a;ca=j}if(!P&&aa)d.replace(d.href.indexOf("#")!=-1?d.href:d.href+"#");P=j},50);return this}return l.title},value:function(a){if(a!==undefined){a=T(I(V(a,e)));if(a=="/")a="";if(g==a&&!M)return;P=e;g=a;if(i.autoUpdate||M){K=e;F(e);w[E.length]=g;if(B)if(i.history){d[q][d.pathname]=w.toString();C=E.length+1;if(m<418){if(d.search==""){N.action="#"+t(g,e);N.submit()}}else if(m<523||g==""){a=l.createEvent("MouseEvents");a.initEvent("click",e,e);var b=l.createElement("a");b.href="#"+t(g,e);b.dispatchEvent(a)}else d.hash=
-"#"+t(g,e)}else d.replace("#"+t(g,e));else if(g!=s())if(i.history)d.hash="#"+J(t(g,e),e);else d.replace("#"+t(g,e));u&&m<8&&i.history&&D(Y,50);if(B)D(function(){K=j},1);else K=j}return this}if(!O)return null;return I(V(J(g,j),j))},path:function(a){if(a!==undefined){var b=this.queryString();this.value(a+(b?"?"+b:""));return this}a=this.value();return a.indexOf("?")!=-1?a.split("?")[0]:a},queryString:function(a){if(a!==undefined){this.value(this.path()+(a?"?"+a:""));return this}a=this.value();var b=
-a.indexOf("?");if(b!=-1&&b<a.length)return a.substr(b+1)},parameter:function(a,b,h){var f,p;if(b!==undefined){var Q=this.parameterNames();p=[];for(f=0;f<Q.length;f++){var R=Q[f],z=this.parameter(R);if(typeof z=="string")z=[z];if(R==a)z=b===null||b==""?[]:h?z.concat([b]):[b];for(var S=0;S<z.length;S++)p.push(R+"="+z[S])}c.inArray(a,Q)==-1&&p.push(a+"="+b);this.queryString(p.join("&"));return this}b=this.value();f=b.indexOf("?");if(f!=-1){b=b.substr(f+1);p=b.split("&");b=[];for(f=0;f<p.length;f++){h=
-p[f].split("=");h[0]==a&&b.push(h[1])}if(b.length!==0)return b.length!=1?b:b[0]}},pathNames:function(){var a=this.path(),b=a.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},parameterNames:function(){var a=this.value(),b=a.indexOf("?"),h=[];if(b!=-1){a=a.substr(b+1);if(a!=""&&a.indexOf("=")!=-1){a=a.split("&");for(b=0;b<a.length;b++){var f=a[b].split("=")[0];c.inArray(f,h)==-1&&h.push(f)}}}return h}}}();c.fn.address=function(A){var v=
-function(){var s=A?A.call(this):/address:/.test(c(this).attr("rel"))?c(this).attr("rel").split("address:")[1].split(" ")[0]:c(this).attr("href").replace(/^#\!?/,"");c.address.value(s);return false};c(this).click(v).live("click",v)}})(jQuery);
+undefined){i.crawlable=a;return this}return i.crawlable},autoUpdate:function(a){if(a!==undefined){i.autoUpdate=a;return this}return i.autoUpdate},update:function(){M=e;this.value(f);M=j;return this},history:function(a){if(a!==undefined){i.history=a;return this}return i.history},tracker:function(a){if(a!==undefined){i.tracker=a;return this}return i.tracker},title:function(a){if(a!==undefined){a=I(a);D(function(){fa=l.title=a;if(ca&&k&&k.contentWindow&&k.contentWindow.document){k.contentWindow.document.title=
+a;ca=j}if(!P&&aa)d.replace(d.href.indexOf("#")!=-1?d.href:d.href+"#");P=j},50);return this}return l.title},value:function(a){if(a!==undefined){a=T(I(V(a,e)));if(a=="/")a="";if(f==a&&!M)return;P=e;f=a;if(i.autoUpdate||M){K=e;F(e);w[E.length]=f;if(B)if(i.history){d[q][d.pathname]=w.toString();C=E.length+1;if(m<418){if(d.search==""){N.action="#"+t(f,e);N.submit()}}else if(m<523||f==""){a=l.createEvent("MouseEvents");a.initEvent("click",e,e);var b=l.createElement("a");b.href="#"+t(f,e);b.dispatchEvent(a)}else d.hash=
+"#"+t(f,e)}else d.replace("#"+t(f,e));else if(f!=s())if(i.history)d.hash="#"+J(t(f,e),e);else d.replace("#"+t(f,e));u&&m<8&&i.history&&D(Y,50);if(B)D(function(){K=j},1);else K=j}return this}if(!O)return null;return I(V(J(f,j),j))},path:function(a){if(a!==undefined){var b=this.queryString();this.value(a+(b?"?"+b:""));return this}a=this.value();return a.indexOf("?")!=-1?a.split("?")[0]:a.indexOf("#")!=-1?a.split("#")[0]:a},queryString:function(a){if(a!==undefined){this.value(this.path()+(a?"?"+a:""));
+return this}a=this.value();var b=a.indexOf("?");if(b!=-1&&b<a.length){a=a.substr(b+1);return a.indexOf("#")!=-1?a.split("#")[0]:a}},parameter:function(a,b,h){var g,p;if(b!==undefined){var Q=this.parameterNames();p=[];for(g=0;g<Q.length;g++){var R=Q[g],z=this.parameter(R);if(typeof z=="string")z=[z];if(R==a)z=b===null||b==""?[]:h?z.concat([b]):[b];for(var S=0;S<z.length;S++)p.push(R+"="+z[S])}c.inArray(a,Q)==-1&&p.push(a+"="+b);this.queryString(p.join("&"));return this}if(b=this.queryString()){p=b.split("&");
+b=[];for(g=0;g<p.length;g++){h=p[g].split("=");h[0]==a&&b.push(h[1])}if(b.length!==0)return b.length!=1?b:b[0]}},pathNames:function(){var a=this.path(),b=a.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},parameterNames:function(){var a=this.value(),b=a.indexOf("?"),h=[];if(b!=-1){a=a.substr(b+1);if(a!=""&&a.indexOf("=")!=-1){a=a.split("&");for(b=0;b<a.length;b++){var g=a[b].split("=")[0];c.inArray(g,h)==-1&&h.push(g)}}}return h},
+fragment:function(a){if(a!==undefined){var b=this.queryString();this.value(this.path()+(b?"?"+b:"")+(a?"#"+a:""));return this}a=this.value();b=a.indexOf("#");if(b!=-1&&b<a.length)return a.substr(b+1)}}}();c.fn.address=function(A){var v=function(){var s=A?A.call(this):/address:/.test(c(this).attr("rel"))?c(this).attr("rel").split("address:")[1].split(" ")[0]:c(this).attr("href").replace(/^#\!?/,"");c.address.value(s);return false};c(this).click(v).live("click",v)}})(jQuery);
View
4 dist/jquery.address-optimizer-1.2.js → dist/jquery.address-optimizer-1.2.bartaz.js
@@ -1,12 +1,12 @@
/*
- * jQuery Address Plugin v1.2
+ * jQuery Address Plugin v1.2.bartaz
* 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: 2010-03-20 21:26:11 +0200 (Sat, 20 Mar 2010)
+ * Date: 2010-03-23 10:19:58 +0100 (Tue, 23 Mar 2010)
*/
(function() {
View
4 dist/jquery.address-optimizer-1.2.min.js → ...query.address-optimizer-1.2.bartaz.min.js
@@ -1,12 +1,12 @@
/*
- * jQuery Address Plugin v1.2
+ * jQuery Address Plugin v1.2.bartaz
* 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: 2010-03-20 21:26:11 +0200 (Sat, 20 Mar 2010)
+ * Date: 2010-03-23 10:19:58 +0100 (Tue, 23 Mar 2010)
*/
(function(){var m=function(e){for(var h,l,f=0,n=e.childNodes.length;f<n;f++){if(e.childNodes[f].src)h=String(e.childNodes[f].src);if(l=m(e.childNodes[f]))h=l}return h},b=m(document),g=b?b.indexOf("?"):-1,a=function(){try{return top.document!==undefined?top:window}catch(e){return window}}(),o=a.document;a=a.location;var p=navigator,i=a.href.indexOf("#"),j=i!=-1,c={};if(b&&g!=-1){g=b.substr(g+1).split("&");for(var k=0;k<g.length;k++){b=g[k].split("=");if(/^(base|address)$/.test(b[0]))c[b[0]]=unescape(b[1])}}if(j&&
i-(a.href.indexOf(a.pathname,a.protocol.length+2)+a.pathname.indexOf(c.base)+c.base.length)>1)j=false;b=a.href.split(a.hostname)[1].replace(c.base,"");if(c.address!="/"&&(!j||i==a.href.length-1)&&b!=""&&b!="/"){var d;if(window.XMLHttpRequest)d=new XMLHttpRequest;else if(window.ActiveXObject)try{try{d=new ActiveXObject("Msxml2.XMLHTTP")}catch(q){d=new ActiveXObject("Microsoft.XMLHTTP")}}catch(r){}if(d){d.open("get",(typeof c.base!="undefined"?c.base:"")+"/?"+c.address+(a.hash!=""?"&hash="+a.hash.replace(/^#/,
View
26 src/jquery.address.js
@@ -443,7 +443,8 @@
return this;
}
value = this.value();
- return (value.indexOf('?') != -1) ? value.split('?')[0] : value;
+ return (value.indexOf('?') != -1) ? value.split('?')[0] :
+ (value.indexOf('#') != -1) ? value.split('#')[0] : value;
},
queryString: function(value) {
if (value !== undefined) {
@@ -453,7 +454,8 @@
value = this.value();
var index = value.indexOf('?');
if (index != -1 && index < value.length) {
- return value.substr(index + 1);
+ value = value.substr(index + 1);
+ return (value.indexOf('#') != -1) ? value.split('#')[0] : value;
}
},
parameter: function(name, value, append) {
@@ -481,10 +483,8 @@
this.queryString(params.join('&'));
return this;
}
- value = this.value();
- var index = value.indexOf('?');
- if (index != -1) {
- value = value.substr(index + 1);
+ value = this.queryString();
+ if (value) {
params = value.split('&');
var r = [];
for (i = 0; i < params.length; i++) {
@@ -526,6 +526,18 @@
}
}
return names;
+ },
+ fragment: function(value) {
+ if (value !== undefined) {
+ var qs = this.queryString();
+ this.value(this.path() + (qs ? '?' + qs : '') + (value ? '#' + value : ''));
+ return this;
+ }
+ value = this.value();
+ var index = value.indexOf('#');
+ if (index != -1 && index < value.length) {
+ return value.substr(index + 1);
+ }
}
};
@@ -542,4 +554,4 @@
$(this).click(f).live('click', f);
};
-}(jQuery));
+}(jQuery));
View
4 test/index.html
@@ -4,7 +4,7 @@
<title>jQuery Address Test Suite</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
- <script type="text/javascript" src="jquery.address-1.2.min.js"></script>
+ <script type="text/javascript" src="jquery.address-1.2.bartaz.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="test.js"></script>
</head>
@@ -15,4 +15,4 @@ <h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
</body>
-</html>
+</html>
View
28 dist/jquery.address-1.2.min.js → test/jquery.address-1.2.bartaz.min.js
@@ -1,25 +1,25 @@
/*
- * jQuery Address Plugin v1.2
+ * jQuery Address Plugin v1.2.bartaz
* 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: 2010-03-20 21:26:11 +0200 (Sat, 20 Mar 2010)
+ * Date: 2010-03-23 10:19:58 +0100 (Tue, 23 Mar 2010)
*/
-(function(c){c.address=function(){var A=function(a){c(c.address).trigger(c.extend(c.Event(a),function(){for(var b={},h=c.address.parameterNames(),f=0,p=h.length;f<p;f++)b[h[f]]=c.address.parameter(h[f]);return{value:c.address.value(),path:c.address.path(),pathNames:c.address.pathNames(),parameterNames:h,parameters:b,queryString:c.address.queryString()}}.call(c.address)))},v=function(a,b,h){if(h||b)c(c.address).bind(a,h||b,h&&b);return c.address},s=function(){var a=d.href.indexOf("#");return a!=-1?
-T(I(t(d.href.substr(a+1),j))):""},U=function(){return"javascript"},V=function(a,b){if(i.strict)a=b?a.substr(0,1)!="/"?"/"+a:a:a==""?"/":a;return a},J=function(a,b){return u&&d.protocol=="file:"?b?g.replace(/\?/,"%3F"):g.replace(/%253F/,"?"):a},t=function(a,b){if(i.crawlable)return b?(a!=""?"!":"")+a:a.replace(/^\!/,"");return a},W=function(a){for(var b,h,f=0,p=a.childNodes.length;f<p;f++){if(a.childNodes[f].src)b=String(a.childNodes[f].src);if(h=W(a.childNodes[f]))b=h}return b},G=function(){if(!K){var a=
-s(),b=g!=a;if(B&&m<523){if(C!=E.length){C=E.length;if(typeof w[C-1]!=x)g=w[C-1];F(j)}}else if(u&&m<7&&b)d.reload();else if(b){g=a;F(j)}}},F=function(a){A("change");A(a?"internalChange":"externalChange");D(X,10)},X=function(){var a=(d.pathname+(/\/$/.test(d.pathname)?"":"/")+c.address.value()).replace(/\/\//,"/").replace(/^\/$/,""),b=window[i.tracker];if(typeof b==L)b(a);else if(typeof _gaq!=x&&typeof _gaq.push==L)_gaq.push(["_trackPageview",a]);else if(typeof pageTracker!=x&&typeof pageTracker._trackPageview==
+(function(c){c.address=function(){var A=function(a){c(c.address).trigger(c.extend(c.Event(a),function(){for(var b={},h=c.address.parameterNames(),g=0,p=h.length;g<p;g++)b[h[g]]=c.address.parameter(h[g]);return{value:c.address.value(),path:c.address.path(),pathNames:c.address.pathNames(),parameterNames:h,parameters:b,queryString:c.address.queryString()}}.call(c.address)))},v=function(a,b,h){if(h||b)c(c.address).bind(a,h||b,h&&b);return c.address},s=function(){var a=d.href.indexOf("#");return a!=-1?
+T(I(t(d.href.substr(a+1),j))):""},U=function(){return"javascript"},V=function(a,b){if(i.strict)a=b?a.substr(0,1)!="/"?"/"+a:a:a==""?"/":a;return a},J=function(a,b){return u&&d.protocol=="file:"?b?f.replace(/\?/,"%3F"):f.replace(/%253F/,"?"):a},t=function(a,b){if(i.crawlable)return b?(a!=""?"!":"")+a:a.replace(/^\!/,"");return a},W=function(a){for(var b,h,g=0,p=a.childNodes.length;g<p;g++){if(a.childNodes[g].src)b=String(a.childNodes[g].src);if(h=W(a.childNodes[g]))b=h}return b},G=function(){if(!K){var a=
+s(),b=f!=a;if(B&&m<523){if(C!=E.length){C=E.length;if(typeof w[C-1]!=x)f=w[C-1];F(j)}}else if(u&&m<7&&b)d.reload();else if(b){f=a;F(j)}}},F=function(a){A("change");A(a?"internalChange":"externalChange");D(X,10)},X=function(){var a=(d.pathname+(/\/$/.test(d.pathname)?"":"/")+c.address.value()).replace(/\/\//,"/").replace(/^\/$/,""),b=window[i.tracker];if(typeof b==L)b(a);else if(typeof _gaq!=x&&typeof _gaq.push==L)_gaq.push(["_trackPageview",a]);else if(typeof pageTracker!=x&&typeof pageTracker._trackPageview==
L)pageTracker._trackPageview(a);else typeof urchinTracker==L&&urchinTracker(a)},Y=function(){var a=k.contentWindow.document;a.open();a.write("<html><head><title>"+l.title+"</title><script>var "+q+' = "'+s()+'";<\/script></head></html>');a.close()},$=function(){if(!Z){Z=e;if(u&&m<8){var a=l.getElementsByTagName("frameset")[0];k=l.createElement((a?"":"i")+"frame");if(a){a.insertAdjacentElement("beforeEnd",k);a[a.cols?"cols":"rows"]+=",0";k.src=U()+":"+j;k.noResize=e;k.frameBorder=k.frameSpacing=0}else{k.src=
-U()+":"+j;k.style.display="none";l.body.insertAdjacentElement("afterBegin",k)}D(function(){c(k).bind("load",function(){var b=k.contentWindow;g=typeof b[q]!=x?b[q]:"";if(g!=s()){F(j);d.hash=J(t(g,e),e)}});typeof k.contentWindow[q]==x&&Y()},50)}else if(B){if(m<418){c(l.body).append('<form id="'+q+'" style="position:absolute;top:-9999px;" method="get"></form>');N=l.getElementById(q)}if(typeof d[q]==x)d[q]={};if(typeof d[q][d.pathname]!=x)w=d[q][d.pathname].split(",")}D(function(){A("init");F(j)},1);
+U()+":"+j;k.style.display="none";l.body.insertAdjacentElement("afterBegin",k)}D(function(){c(k).bind("load",function(){var b=k.contentWindow;f=typeof b[q]!=x?b[q]:"";if(f!=s()){F(j);d.hash=J(t(f,e),e)}});typeof k.contentWindow[q]==x&&Y()},50)}else if(B){if(m<418){c(l.body).append('<form id="'+q+'" style="position:absolute;top:-9999px;" method="get"></form>');N=l.getElementById(q)}if(typeof d[q]==x)d[q]={};if(typeof d[q][d.pathname]!=x)w=d[q][d.pathname].split(",")}D(function(){A("init");F(j)},1);
if(u&&m>7||!u&&"on"+H in o)if(o.addEventListener)o.addEventListener(H,G,false);else o.attachEvent&&o.attachEvent("on"+H,G);else da(G,50);c("a[rel*=address:]").address()}},ea=function(){if(o.removeEventListener)o.removeEventListener(H,G,false);else o.detachEvent&&o.detachEvent("on"+H,G)},q="jQueryAddress",L="function",x="undefined",H="hashchange",e=true,j=false,i={autoUpdate:e,crawlable:e,history:e,strict:e},n=c.browser,m=parseFloat(c.browser.version),aa=n.mozilla,u=n.msie,r=n.opera,B=n.safari,O=j,
-o=function(){try{return top.document!==undefined?top:window}catch(a){return window}}(),l=o.document,E=o.history,d=o.location,da=setInterval,D=setTimeout,I=decodeURI,T=encodeURI;n=navigator.userAgent;var k,N,y=W(document),ba=y?y.indexOf("?"):-1,fa=l.title,C=E.length,K=j,Z=j,P=e,ca=e,M=j,w=[],g=s();if(u){m=parseFloat(n.substr(n.indexOf("MSIE")+4));if(l.documentMode&&l.documentMode!=m)m=l.documentMode!=8?7:8}if(O=aa&&m>=1||u&&m>=6||r&&m>=9.5||B&&m>=312){for(n=1;n<C;n++)w.push("");w.push(g);if(u&&d.hash!=
-g)d.hash="#"+J(t(g,e),e);if(r)history.navigationMode="compatible";if(y&&ba!=-1){y=y.substr(ba+1).split("&");for(n=0;n<y.length;n++){r=y[n].split("=");if(/^(autoUpdate|crawlable|history|strict)$/.test(r[0]))i[r[0]]=isNaN(r[1])?/^(true|yes)$/i.test(r[1]):parseInt(r[1],10)!==0;if(/^tracker$/.test(r[0]))i[r[0]]=r[1]}}document.readyState=="complete"&&$();c($);c(window).bind("unload",ea)}else if(!O&&s()!=""||B&&m<418&&s()!=""&&d.search!=""){l.open();l.write('<html><head><meta http-equiv="refresh" content="0;url='+
+o=function(){try{return top.document!==undefined?top:window}catch(a){return window}}(),l=o.document,E=o.history,d=o.location,da=setInterval,D=setTimeout,I=decodeURI,T=encodeURI;n=navigator.userAgent;var k,N,y=W(document),ba=y?y.indexOf("?"):-1,fa=l.title,C=E.length,K=j,Z=j,P=e,ca=e,M=j,w=[],f=s();if(u){m=parseFloat(n.substr(n.indexOf("MSIE")+4));if(l.documentMode&&l.documentMode!=m)m=l.documentMode!=8?7:8}if(O=aa&&m>=1||u&&m>=6||r&&m>=9.5||B&&m>=312){for(n=1;n<C;n++)w.push("");w.push(f);if(u&&d.hash!=
+f)d.hash="#"+J(t(f,e),e);if(r)history.navigationMode="compatible";if(y&&ba!=-1){y=y.substr(ba+1).split("&");for(n=0;n<y.length;n++){r=y[n].split("=");if(/^(autoUpdate|crawlable|history|strict)$/.test(r[0]))i[r[0]]=isNaN(r[1])?/^(true|yes)$/i.test(r[1]):parseInt(r[1],10)!==0;if(/^tracker$/.test(r[0]))i[r[0]]=r[1]}}document.readyState=="complete"&&$();c($);c(window).bind("unload",ea)}else if(!O&&s()!=""||B&&m<418&&s()!=""&&d.search!=""){l.open();l.write('<html><head><meta http-equiv="refresh" content="0;url='+
d.href.substr(0,d.href.indexOf("#"))+'" /></head></html>');l.close()}else X();return{init:function(a,b){return v("init",a,b)},change:function(a,b){return v("change",a,b)},internalChange:function(a,b){return v("internalChange",a,b)},externalChange:function(a,b){return v("externalChange",a,b)},baseURL:function(){var a=d.href;if(s()!="")a=a.substr(0,a.indexOf("#"));if(/\/$/.test(a))a=a.substr(0,a.length-1);return a},strict:function(a){if(a!==undefined){i.strict=a;return this}return i.strict},crawlable:function(a){if(a!==
-undefined){i.crawlable=a;return this}return i.crawlable},autoUpdate:function(a){if(a!==undefined){i.autoUpdate=a;return this}return i.autoUpdate},update:function(){M=e;this.value(g);M=j;return this},history:function(a){if(a!==undefined){i.history=a;return this}return i.history},tracker:function(a){if(a!==undefined){i.tracker=a;return this}return i.tracker},title:function(a){if(a!==undefined){a=I(a);D(function(){fa=l.title=a;if(ca&&k&&k.contentWindow&&k.contentWindow.document){k.contentWindow.document.title=
-a;ca=j}if(!P&&aa)d.replace(d.href.indexOf("#")!=-1?d.href:d.href+"#");P=j},50);return this}return l.title},value:function(a){if(a!==undefined){a=T(I(V(a,e)));if(a=="/")a="";if(g==a&&!M)return;P=e;g=a;if(i.autoUpdate||M){K=e;F(e);w[E.length]=g;if(B)if(i.history){d[q][d.pathname]=w.toString();C=E.length+1;if(m<418){if(d.search==""){N.action="#"+t(g,e);N.submit()}}else if(m<523||g==""){a=l.createEvent("MouseEvents");a.initEvent("click",e,e);var b=l.createElement("a");b.href="#"+t(g,e);b.dispatchEvent(a)}else d.hash=
-"#"+t(g,e)}else d.replace("#"+t(g,e));else if(g!=s())if(i.history)d.hash="#"+J(t(g,e),e);else d.replace("#"+t(g,e));u&&m<8&&i.history&&D(Y,50);if(B)D(function(){K=j},1);else K=j}return this}if(!O)return null;return I(V(J(g,j),j))},path:function(a){if(a!==undefined){var b=this.queryString();this.value(a+(b?"?"+b:""));return this}a=this.value();return a.indexOf("?")!=-1?a.split("?")[0]:a},queryString:function(a){if(a!==undefined){this.value(this.path()+(a?"?"+a:""));return this}a=this.value();var b=
-a.indexOf("?");if(b!=-1&&b<a.length)return a.substr(b+1)},parameter:function(a,b,h){var f,p;if(b!==undefined){var Q=this.parameterNames();p=[];for(f=0;f<Q.length;f++){var R=Q[f],z=this.parameter(R);if(typeof z=="string")z=[z];if(R==a)z=b===null||b==""?[]:h?z.concat([b]):[b];for(var S=0;S<z.length;S++)p.push(R+"="+z[S])}c.inArray(a,Q)==-1&&p.push(a+"="+b);this.queryString(p.join("&"));return this}b=this.value();f=b.indexOf("?");if(f!=-1){b=b.substr(f+1);p=b.split("&");b=[];for(f=0;f<p.length;f++){h=
-p[f].split("=");h[0]==a&&b.push(h[1])}if(b.length!==0)return b.length!=1?b:b[0]}},pathNames:function(){var a=this.path(),b=a.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},parameterNames:function(){var a=this.value(),b=a.indexOf("?"),h=[];if(b!=-1){a=a.substr(b+1);if(a!=""&&a.indexOf("=")!=-1){a=a.split("&");for(b=0;b<a.length;b++){var f=a[b].split("=")[0];c.inArray(f,h)==-1&&h.push(f)}}}return h}}}();c.fn.address=function(A){var v=
-function(){var s=A?A.call(this):/address:/.test(c(this).attr("rel"))?c(this).attr("rel").split("address:")[1].split(" ")[0]:c(this).attr("href").replace(/^#\!?/,"");c.address.value(s);return false};c(this).click(v).live("click",v)}})(jQuery);
+undefined){i.crawlable=a;return this}return i.crawlable},autoUpdate:function(a){if(a!==undefined){i.autoUpdate=a;return this}return i.autoUpdate},update:function(){M=e;this.value(f);M=j;return this},history:function(a){if(a!==undefined){i.history=a;return this}return i.history},tracker:function(a){if(a!==undefined){i.tracker=a;return this}return i.tracker},title:function(a){if(a!==undefined){a=I(a);D(function(){fa=l.title=a;if(ca&&k&&k.contentWindow&&k.contentWindow.document){k.contentWindow.document.title=
+a;ca=j}if(!P&&aa)d.replace(d.href.indexOf("#")!=-1?d.href:d.href+"#");P=j},50);return this}return l.title},value:function(a){if(a!==undefined){a=T(I(V(a,e)));if(a=="/")a="";if(f==a&&!M)return;P=e;f=a;if(i.autoUpdate||M){K=e;F(e);w[E.length]=f;if(B)if(i.history){d[q][d.pathname]=w.toString();C=E.length+1;if(m<418){if(d.search==""){N.action="#"+t(f,e);N.submit()}}else if(m<523||f==""){a=l.createEvent("MouseEvents");a.initEvent("click",e,e);var b=l.createElement("a");b.href="#"+t(f,e);b.dispatchEvent(a)}else d.hash=
+"#"+t(f,e)}else d.replace("#"+t(f,e));else if(f!=s())if(i.history)d.hash="#"+J(t(f,e),e);else d.replace("#"+t(f,e));u&&m<8&&i.history&&D(Y,50);if(B)D(function(){K=j},1);else K=j}return this}if(!O)return null;return I(V(J(f,j),j))},path:function(a){if(a!==undefined){var b=this.queryString();this.value(a+(b?"?"+b:""));return this}a=this.value();return a.indexOf("?")!=-1?a.split("?")[0]:a.indexOf("#")!=-1?a.split("#")[0]:a},queryString:function(a){if(a!==undefined){this.value(this.path()+(a?"?"+a:""));
+return this}a=this.value();var b=a.indexOf("?");if(b!=-1&&b<a.length){a=a.substr(b+1);return a.indexOf("#")!=-1?a.split("#")[0]:a}},parameter:function(a,b,h){var g,p;if(b!==undefined){var Q=this.parameterNames();p=[];for(g=0;g<Q.length;g++){var R=Q[g],z=this.parameter(R);if(typeof z=="string")z=[z];if(R==a)z=b===null||b==""?[]:h?z.concat([b]):[b];for(var S=0;S<z.length;S++)p.push(R+"="+z[S])}c.inArray(a,Q)==-1&&p.push(a+"="+b);this.queryString(p.join("&"));return this}if(b=this.queryString()){p=b.split("&");
+b=[];for(g=0;g<p.length;g++){h=p[g].split("=");h[0]==a&&b.push(h[1])}if(b.length!==0)return b.length!=1?b:b[0]}},pathNames:function(){var a=this.path(),b=a.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},parameterNames:function(){var a=this.value(),b=a.indexOf("?"),h=[];if(b!=-1){a=a.substr(b+1);if(a!=""&&a.indexOf("=")!=-1){a=a.split("&");for(b=0;b<a.length;b++){var g=a[b].split("=")[0];c.inArray(g,h)==-1&&h.push(g)}}}return h},
+fragment:function(a){if(a!==undefined){var b=this.queryString();this.value(this.path()+(b?"?"+b:"")+(a?"#"+a:""));return this}a=this.value();b=a.indexOf("#");if(b!=-1&&b<a.length)return a.substr(b+1)}}}();c.fn.address=function(A){var v=function(){var s=A?A.call(this):/address:/.test(c(this).attr("rel"))?c(this).attr("rel").split("address:")[1].split(" ")[0]:c(this).attr("href").replace(/^#\!?/,"");c.address.value(s);return false};c(this).click(v).live("click",v)}})(jQuery);
View
27 test/test.js
@@ -58,6 +58,31 @@ asyncTest("Parameter test", function() {
}, 1000);
});
+asyncTest("Fragment test with params", function() {
+ setTimeout(function() {
+ $.address.fragment('fragment');
+ equals($.address.value(), '/test?p=2&p=3&s=3#fragment');
+ equals($.address.path(), '/test');
+ equals($.address.parameter('p').toString(), '2,3');
+ equals($.address.parameter('s').toString(), 3);
+ equals($.address.parameterNames().toString(), 'p,s');
+ equals($.address.fragment(), 'fragment');
+ start();
+ }, 1000);
+});
+
+asyncTest("Fragment test", function() {
+ setTimeout(function() {
+ $.address.value('/test');
+ $.address.fragment('fragment');
+ equals($.address.value(), '/test#fragment');
+ equals($.address.path(), '/test');
+ equals($.address.fragment(), 'fragment');
+ start();
+ }, 1000);
+});
+
+
setTimeout(function() {
$.address.value('/');
-}, 10000);
+}, 10000);

0 comments on commit 808afda

Please sign in to comment.
Something went wrong with that request. Please try again.