openSNP / snpr

The sources of the openSNP website
http://opensnp.org
MIT License
174 stars 46 forks source link

Links to tabs don't work #406

Closed gedankenstuecke closed 7 years ago

gedankenstuecke commented 7 years ago

Linking to specific tabs doesn't work right now. E.g. https://opensnp.org/snps/rs7903146#plos should take you to the PLOS-paper tab, but that doesn't work.

Same is true for linking to a users personal message page: We're trying to link back to a user's inbox at https://opensnp.org/users/1#messages after sending a message in the message_controller but that fails right now. Seems some JS there isn't working as it's supposed to.

philippbayer commented 7 years ago

This piece of JavaScript can do it:

$(function(){
   var hash = window.location.hash;
   var anchor = $('a[href$="'+hash+'"]');
   if (anchor.length > 0){
      anchor.click();
   }
});

Source

Essentially it checks whether there's a hash in the URL and then 'clicks' the tab for the user. With Firefox's JavaScript Scratchpad it works, will send a PR later

gedankenstuecke commented 7 years ago

Ok, looking forward to see that PR! (Tried briefly on my end and it seems to get stuck in an endless loop on Chrome when I just c&p it into application.js).

philippbayer commented 7 years ago

Done with latest PR