Permalink
Browse files

Build 0.8.46 - Added pathnameGetter for missing leading slash in IE …

…pathname
  • Loading branch information...
1 parent 882b53e commit c956cfb4ca53794bf913b767c5202532aa7ca5b2 @draeton committed Jan 18, 2012
View
4 README.md
@@ -1,7 +1,7 @@
## Tanchor
[Tanchor](http://draeton.github.com/tanchor/) is a small utility library for working with URLs using the DOM's anchor element.
-The current version is `0.8.45`. Documentation is available
+The current version is `0.8.46`. Documentation is available
[here](http://draeton.github.com/tanchor/tanchor/docs/tanchor.html). Unit tests are available
[here](http://draeton.github.com/tanchor/tanchor/tests/).
@@ -10,7 +10,7 @@ The current version is `0.8.45`. Documentation is available
Tanchor is a single-script utility.
- <script src="js/tanchor-0.8.45-min.js"></script>
+ <script src="js/tanchor-0.8.46-min.js"></script>
## Usage
View
4 build.properties
@@ -1,4 +1,4 @@
-#Tue, 17 Jan 2012 20:58:33 -0500
+#Tue, 17 Jan 2012 21:06:08 -0500
build.major=0
build.minor=8
-build.number=45
+build.number=46
View
2 build/js/tanchor-0.8.45-min.js → build/js/tanchor-0.8.46-min.js
@@ -1 +1 @@
-var Tanchor=(function(window,document){var isObject=function(o){return typeof o==="object"&&o!==null;};var isArray=function(o){return Object.prototype.toString.call(o)==="[object Array]";};var extend=function(o,o2){var args=Array.prototype.slice.call(arguments,2),i;for(i in o2){if(o2.hasOwnProperty(i)){o[i]=o2[i];}}if(args.length){args.unshift(o);extend.apply(this,args);}return o;};var append=function(o,key,val){if(isObject(o)&&o.hasOwnProperty(key)){if(isArray(o[key])){o[key].push(val);}else{o[key]=[o[key],val];}}else{o[key]=val;}};var stringify=function(key,val,eq,sep){var s="",i,l;if(isArray(val)){for(i=0,l=val.length;i<l;i++){s+=sep+key+eq+val[i];}}else{s+=sep+key+eq+val;}return s;};var update=function(o,key,val){if(isObject(o)){if(typeof val==="undefined"){delete o[key];}else{o[key]=val;}}};var privateMethods={toObject_:function(type){var str,eq,sep,list,map,i,l,pair;if(type==="search"){str=this.anchor.search.replace(/^\?/,"");eq=this.seq;sep=this.ssp;}else{str=this.anchor.hash.replace(/^\#/,"");eq=this.heq;sep=this.hsp;}list=str.split(sep);map={};for(i=0,l=list.length;i<l;i++){pair=list[i].split(eq);if(pair[0]!==""){append(map,pair[0],pair[1]);}}return map;},toString_:function(type,map){var str="",eq,sep,i;if(type==="search"){eq=this.seq;sep=this.ssp;}else{eq=this.heq;sep=this.hsp;}for(i in map){if(map.hasOwnProperty(i)){str+=stringify(i,map[i],eq,sep);}}return str.replace(new RegExp("^\\"+sep),"");},getUrlVars_:function(type){var vars;vars={search:this.toObject_("search"),hash:this.toObject_("hash")};return type?vars[type]:vars;},setUrlVars_:function(type,map){var vars=this.getUrlVars_(type),i;for(i in map){if(map.hasOwnProperty(i)){update(vars,i,map[i]);}}return this.toString_(type,vars);}};var publicMethods={getSearchVars:function(){return this.getUrlVars_("search");},getHashVars:function(){return this.getUrlVars_("hash");},getUrlVars:function(hashFirst){var vars=this.getUrlVars_(),search=vars.search,hash=vars.hash,combined;if(hashFirst){combined=extend(hash,search);}else{combined=extend(search,hash);}return combined;},setSearchVars:function(map){this.anchor.search=this.setUrlVars_("search",map);return this;},setSearchVar:function(key,val){var o={};o[key]=val;return this.setSearchVars(o);},setHashVars:function(map){this.anchor.hash=this.setUrlVars_("hash",map);return this;},setHashVar:function(key,val){var o={};o[key]=val;return this.setHashVars(o);},delSearchVar:function(key){return this.setSearchVar(key);},delHashVar:function(key){return this.setHashVar(key);},toString:function(){return this.anchor.href;}};var nativeGetter=function(prop){return function(){return this.anchor[prop];};};var nativeMethods=(function(){var methods={},props,prop,i,l;props=["href","protocol","host","hostname","port","pathname","search","hash"];for(i=0,l=props.length;i<l;i++){prop=props[i];methods[prop]=nativeGetter(prop);}return methods;}());var regexP=/^(http|https|ftp):/;var regexPD=/^(http|https|ftp):\/\/([\w\-\d]+\.)+[\w\-\d]+/;var Anchor=function(href,searchEq,searchSep,hashEq,hashSep){if(typeof href==="undefined"||href===""){throw new Error("The href argument must be defined and non-empty.");}this.anchor=this.a=document.createElement("a");this.anchor.href=href;if(!regexP.test(this.anchor.protocol)){this.anchor.protocol=location.protocol;}if(!this.anchor.hostname){this.anchor.hostname=location.hostname;}this.seq=searchEq||"=";this.ssp=searchSep||"&";this.heq=hashEq||"=";this.hsp=hashSep||"&";};Anchor.prototype=extend({},nativeMethods,privateMethods,publicMethods);Anchor.factory=function(href,searchEq,searchSep,hashEq,hashSep){return new Anchor(href,searchEq,searchSep,hashEq,hashSep);};Anchor.factory.getQuery=function(key){var href=window.location.href,t=new Anchor(href),vars=t.getUrlVars(),result={},l;if(typeof key==="string"&&vars[key]){return vars[key];}if(isArray(key)){for(l=key.length;l--;){result[key[l]]=false;if(vars[key[l]]){result[key[l]]=vars[key[l]];}}return result;}if(typeof key==="undefined"){return vars;}return false;};return Anchor.factory;}(window,document));
+var Tanchor=(function(window,document){var isObject=function(o){return typeof o==="object"&&o!==null;};var isArray=function(o){return Object.prototype.toString.call(o)==="[object Array]";};var extend=function(o,o2){var args=Array.prototype.slice.call(arguments,2),i;for(i in o2){if(o2.hasOwnProperty(i)){o[i]=o2[i];}}if(args.length){args.unshift(o);extend.apply(this,args);}return o;};var append=function(o,key,val){if(isObject(o)&&o.hasOwnProperty(key)){if(isArray(o[key])){o[key].push(val);}else{o[key]=[o[key],val];}}else{o[key]=val;}};var stringify=function(key,val,eq,sep){var s="",i,l;if(isArray(val)){for(i=0,l=val.length;i<l;i++){s+=sep+key+eq+val[i];}}else{s+=sep+key+eq+val;}return s;};var update=function(o,key,val){if(isObject(o)){if(typeof val==="undefined"){delete o[key];}else{o[key]=val;}}};var privateMethods={toObject_:function(type){var str,eq,sep,list,map,i,l,pair;if(type==="search"){str=this.anchor.search.replace(/^\?/,"");eq=this.seq;sep=this.ssp;}else{str=this.anchor.hash.replace(/^\#/,"");eq=this.heq;sep=this.hsp;}list=str.split(sep);map={};for(i=0,l=list.length;i<l;i++){pair=list[i].split(eq);if(pair[0]!==""){append(map,pair[0],pair[1]);}}return map;},toString_:function(type,map){var str="",eq,sep,i;if(type==="search"){eq=this.seq;sep=this.ssp;}else{eq=this.heq;sep=this.hsp;}for(i in map){if(map.hasOwnProperty(i)){str+=stringify(i,map[i],eq,sep);}}return str.replace(new RegExp("^\\"+sep),"");},getUrlVars_:function(type){var vars;vars={search:this.toObject_("search"),hash:this.toObject_("hash")};return type?vars[type]:vars;},setUrlVars_:function(type,map){var vars=this.getUrlVars_(type),i;for(i in map){if(map.hasOwnProperty(i)){update(vars,i,map[i]);}}return this.toString_(type,vars);}};var publicMethods={getSearchVars:function(){return this.getUrlVars_("search");},getHashVars:function(){return this.getUrlVars_("hash");},getUrlVars:function(hashFirst){var vars=this.getUrlVars_(),search=vars.search,hash=vars.hash,combined;if(hashFirst){combined=extend(hash,search);}else{combined=extend(search,hash);}return combined;},setSearchVars:function(map){this.anchor.search=this.setUrlVars_("search",map);return this;},setSearchVar:function(key,val){var o={};o[key]=val;return this.setSearchVars(o);},setHashVars:function(map){this.anchor.hash=this.setUrlVars_("hash",map);return this;},setHashVar:function(key,val){var o={};o[key]=val;return this.setHashVars(o);},delSearchVar:function(key){return this.setSearchVar(key);},delHashVar:function(key){return this.setHashVar(key);},toString:function(){return this.anchor.href;}};var nativeGetter=function(prop){return function(){return this.anchor[prop];};};var pathnameGetter=function(){var val=this.anchor.pathname;if(!/^\//.test(val)){val="/"+val;}return val;};var nativeMethods=(function(){var methods={},props,prop,i,l;props=["href","protocol","host","hostname","port","pathname","search","hash"];for(i=0,l=props.length;i<l;i++){prop=props[i];methods[prop]=(prop==="pathname")?pathnameGetter:nativeGetter(prop);}return methods;}());var regexP=/^(http|https|ftp):/;var regexPD=/^(http|https|ftp):\/\/([\w\-\d]+\.)+[\w\-\d]+/;var Anchor=function(href,searchEq,searchSep,hashEq,hashSep){if(typeof href==="undefined"||href===""){throw new Error("The href argument must be defined and non-empty.");}this.anchor=this.a=document.createElement("a");this.anchor.href=href;if(!regexP.test(this.anchor.protocol)){this.anchor.protocol=location.protocol;}if(!this.anchor.hostname){this.anchor.hostname=location.hostname;}this.seq=searchEq||"=";this.ssp=searchSep||"&";this.heq=hashEq||"=";this.hsp=hashSep||"&";};Anchor.prototype=extend({},nativeMethods,privateMethods,publicMethods);Anchor.factory=function(href,searchEq,searchSep,hashEq,hashSep){return new Anchor(href,searchEq,searchSep,hashEq,hashSep);};Anchor.factory.getQuery=function(key){var href=window.location.href,t=new Anchor(href),vars=t.getUrlVars(),result={},l;if(typeof key==="string"&&vars[key]){return vars[key];}if(isArray(key)){for(l=key.length;l--;){result[key[l]]=false;if(vars[key[l]]){result[key[l]]=vars[key[l]];}}return result;}if(typeof key==="undefined"){return vars;}return false;};return Anchor.factory;}(window,document));
View
13 build/js/tanchor-0.8.45.js → build/js/tanchor-0.8.46.js
@@ -255,13 +255,24 @@ var Tanchor = (function (window, document) {
};
};
+ /* fix for pathname leading slash in IE */
+ var pathnameGetter = function () {
+ var val = this.anchor.pathname;
+
+ if (!/^\//.test(val)) {
+ val = "/" + val;
+ }
+
+ return val;
+ };
+
var nativeMethods = (function () {
var methods = {}, props, prop, i, l;
props = ["href", "protocol", "host", "hostname", "port", "pathname", "search", "hash"];
for (i = 0, l = props.length; i < l; i++) {
prop = props[i];
- methods[prop] = nativeGetter(prop);
+ methods[prop] = (prop === "pathname") ? pathnameGetter : nativeGetter(prop);
}
return methods;
View
BIN dist/tanchor-0.8.46.zip
Binary file not shown.
View
13 docs/tanchor.html
@@ -254,13 +254,24 @@
<span class="p">},</span>
+</pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <h3>delHashVar</h3>
+
+<p>deletes the key parameter from the URL hash; returns this</p> </td> <td class="code"> <div class="highlight"><pre>
+ <span class="nx">delHashVar</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">setHashVar</span><span class="p">(</span><span class="nx">key</span><span class="p">);</span>
+ <span class="p">},</span>
+
+
+</pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <h3>toString</h3> </td> <td class="code"> <div class="highlight"><pre>
+ <span class="nx">toString</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">anchor</span><span class="p">.</span><span class="nx">href</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">};</span>
</pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <h2>Native Anchor properties as read-only methods</h2> </td> <td class="code"> <div class="highlight"><pre>
<span class="kd">var</span> <span class="nx">nativeGetter</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">prop</span><span class="p">)</span> <span class="p">{</span>
-
+ <span class="k">return</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">anchor</span><span class="p">[</span><span class="nx">prop</span><span class="p">];</span>
<span class="p">};</span>
<span class="p">};</span>
View
13 src/tanchor.js
@@ -255,13 +255,24 @@ var Tanchor = (function (window, document) {
};
};
+ /* fix for pathname leading slash in IE */
+ var pathnameGetter = function () {
+ var val = this.anchor.pathname;
+
+ if (!/^\//.test(val)) {
+ val = "/" + val;
+ }
+
+ return val;
+ };
+
var nativeMethods = (function () {
var methods = {}, props, prop, i, l;
props = ["href", "protocol", "host", "hostname", "port", "pathname", "search", "hash"];
for (i = 0, l = props.length; i < l; i++) {
prop = props[i];
- methods[prop] = nativeGetter(prop);
+ methods[prop] = (prop === "pathname") ? pathnameGetter : nativeGetter(prop);
}
return methods;

0 comments on commit c956cfb

Please sign in to comment.