Skip to content

Instantly share code, notes, and snippets.

@iampeterbanjo
Last active October 2, 2015 11:29
Show Gist options
  • Save iampeterbanjo/81897f03c0810218c326 to your computer and use it in GitHub Desktop.
Save iampeterbanjo/81897f03c0810218c326 to your computer and use it in GitHub Desktop.
// i can't remember where I found this
// deep link to modal items
function deepLinkIntoModals() {
// 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.replace(/\/$/gi, '');
if (modalString !== '') {
$('[data-target="' + modalToShow + '"]').click();
}
// 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');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment