Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Last active February 12, 2019 20:58
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tomhodgins/10414454 to your computer and use it in GitHub Desktop.
Save tomhodgins/10414454 to your computer and use it in GitHub Desktop.
Deeplink to bootstrap modals, tooltips, popovers, and tabs
$(document).ready(function(){
// queryStrip
function queryStrip(string) {
string = string.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + string + '=([^&#]*)'),
results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ''));
}
// Show bootstrap modal on load
// If the modal id="terms", you can show it on page load by appending `?modal=terms` to the URL
var modalString = queryStrip('modal'),
modalToShow = '#' + modalString;
if (modalString !== '') {
$(modalToShow).modal('show');
}
// Show bootstrap tooltip on load
// If the tooltip id="artistName", you can show it on page load by appending `?tooltip=artistName to the URL
var tooltipString = queryStrip('tooltip'),
tooltipToShow = '#' + tooltipString;
if (tooltipString !== '') {
$(tooltipToShow).tooltip('show');
}
// Show bootstrap popover on load
// If the popover id="moreInfo", you can show it on page load by appending `?popover=moreInfo` to the URL
var popoverString = queryStrip('popover'),
popoverToShow = '#' + popoverString;
if (popoverString !== '') {
$(popoverToShow).popover('show');
}
// Show bootstrap tab on load
// If the tab id="friendRequests", you can show it on page load by appending `?tab=friendRequests` to the URL
var tabString = queryStrip('tab');
if (tabString !== '') {
$('.nav-tabs a[href=#' + tabString + ']').tab('show');
}
});
@christiangehrke
Copy link

This just saved me so much time. Thanks so much!

@erezLieberman
Copy link

Work great!
thank you very much!

@flxcode
Copy link

flxcode commented Jan 28, 2015

this is working perfect, thank you!
i’m kinda new, so i got one qustion: how is it possible to remove the deeplink after closing the modal?
would appreciate any help.

@iampeterbanjo
Copy link

+1 Thanks

@BlueSky1021
Copy link

+1 like
nice work btw, I real love it. But my question is can I use it to foundation zurb?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment