Skip to content

Instantly share code, notes, and snippets.

@foaly-nr1
Created May 11, 2016 15:13
Show Gist options
  • Save foaly-nr1/c92e9e9ba00c3971bf5a5f4876628692 to your computer and use it in GitHub Desktop.
Save foaly-nr1/c92e9e9ba00c3971bf5a5f4876628692 to your computer and use it in GitHub Desktop.
Prevents Bootstrap modal from being opened if cmd/ctrl key is pressed when triggering link is clicked
/**
* Prevents Bootstrap modal from being opened if cmd key is pressed when triggering link is clicked.
*/
(function BS3ModalCmd() {
'use strict';
// We listen during the capture phase to always be before bootstrap's event listeners. However,
// we can't detect whether the click is relevant for us, as a child element of the triggering
// element might have been clicked. We therefore just stop propagation for all clicks #hacky
document.addEventListener('click', (e) => {
if (e.metaKey) {
e.stopPropagation();
}
}, true);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment