Advertisement
DeMorgan

Javascript hash manipulation min

Apr 9th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Javascript hash Manipulation
  3.  * Β© Copyright 2013 Peter HeleΕ‘i
  4.  *
  5.  * Peter HeleΕ‘i <http://eliteweb.eu>
  6.  * eg hash.get(key);        //returns value
  7.  * eg hash.set(key,value);      //add/edit hash properity
  8.  * eg hash.remove(key);     //remove hash properity
  9.  */
  10.  
  11.  
  12. var hash={get:function(a){var b=window.location.hash.length>0?window.location.hash.substring(1).split("&"):"";if(0==b.length)return void 0;for(var c,d=0;d<b.length;d++)if(b[d].substring(0,a.length+1)==a+"=")return c=decodeURI(b[d].substring(a.length+1)),0==c.length?void 0:c},set:function(a,b){ b=encodeURIComponent(b).replace(/%20/g, '+'); var c=window.location.hash.length>0?window.location.hash.substring(1).split("&"):"",d=a+"="+b,e="",f=1;if(c.length>0){for(var g=0;g<c.length;g++)if(c[g].substring(0,a.length+1)==a+"="){c[g]=d,f=0;break}e=c.join("&")}1==f&&(e+=(c.length>0?"&":"")+d),window.location.hash="#"+e},remove:function(a){var b=window.location.hash.length>0?window.location.hash.substring(1).split("&"):"",c="",d=1;if(b.length>0){for(var e=0;e<b.length;e++)if(b[e].substring(0,a.length+1)==a+"="){delete b[e],d=0;break}c=b.join("&").replace("&&","&"),"&"==c.substring(0,1)&&(c=c.substring(1))}0==d&&(window.location.hash="#"+c)}};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement