Skip to content

Instantly share code, notes, and snippets.

@avimar
Created July 13, 2016 17:55
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 avimar/aa7510afea43418dbc5eb78c5ac12ff9 to your computer and use it in GitHub Desktop.
Save avimar/aa7510afea43418dbc5eb78c5ac12ff9 to your computer and use it in GitHub Desktop.
append a value to the query string
function checkAndSetAccount(){
var q = riot.route.query();
if (Cookies.get('account')==q.account) return;//already done.
if (q.account) {
Cookies.set('account',q.account);
auth.trigger('switchAccount');
}
if (!q.account && Cookies.get('account')!==Cookies.get('accountOriginal')) {//nothing in query string: need to set it
//console.log(window.location)
var newLocation=window.location.hash;
if(!newLocation) return riot.route("account?account="+Cookies.get('account'));//if failure, just send to account page
newLocation = newLocation.substring(1);//strip the # from the start
if(newLocation.indexOf('?')!==-1) return riot.route(newLocation + "&account="+Cookies.get('account'));//already has a ?
return riot.route(newLocation + "?account="+Cookies.get('account'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment