Skip to content

Instantly share code, notes, and snippets.

@vrinek
Created June 24, 2010 14:25
Show Gist options
  • Save vrinek/451508 to your computer and use it in GitHub Desktop.
Save vrinek/451508 to your computer and use it in GitHub Desktop.
$$('a[data-remote=true]').each(function(a){
a.onclick = function(){
href = a.getAttribute('href');
url = href.split('?')[0];
params = href.split('?')[1];
newParam = encodeURI(eval(a.getAttribute('data-with')));
if(params){
params = params.split('&');
params.each(function(p){
if(p.match(new RegExp('^'+newParam.split('=')[0]+'='))){
oldParam = p;
};
});
params = params.without(oldParam);
}else{
params = [];
};
params.push(newParam);
a.setAttribute('href', url + '?' + params.join('&'));
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment