Skip to content

Instantly share code, notes, and snippets.

@thysultan
Last active August 26, 2016 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thysultan/f733ab8e22b776c8580cc54d87376b08 to your computer and use it in GitHub Desktop.
Save thysultan/f733ab8e22b776c8580cc54d87376b08 to your computer and use it in GitHub Desktop.
urlstore.js
param: function (obj, prefix) {
var arr = [];
for (var key in obj) {
var __prefix = prefix ? prefix + '[' + key + ']' : key,
value = obj[key];
arr.push(typeof value == 'object' ?
param(value, __prefix) :
encodeURIComponent(__prefix) + '=' + encodeURIComponent(value));
}
return arr.join('&');
}
setUrl: function () {
history.pushState(null, null, '?state='+this.param(this.state));
}
getUrl: function () {
return JSON.parse('{"' + decodeURI(history.location.search.substr(1)).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"').replace(/\s/g,'') + '"}')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment