Last active
December 19, 2023 16:00
-
-
Save zackpyle/dcb8c84c043085f80c6a25b85f1af270 to your computer and use it in GitHub Desktop.
Makes a Beaver Builder Column Clickable #beaverbuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Makes a BB Column clickable. | |
* Pre-requisite: There must be an A Tag contained within the column element and a class of clickable-col for the column | |
*/ | |
jQuery(document).ready(function($) { | |
// Exit if BB layout is in edit mode. | |
if (typeof window.FLBuilderConfig !== 'undefined') { | |
return; | |
} | |
$('.clickable-col').css('cursor', 'pointer'); | |
$('.clickable-col').on('click', function(event) { | |
const link = $(this).find('a')[0]; | |
// Prevent link being clicked since we will handle that below | |
if (event.target === link) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
} | |
// Make sure the event target is not a button | |
if (!$(event.target).is('button')) { | |
// Then handle ctrl/cmd click for opening in a new tab | |
if (event.ctrlKey || event.metaKey) { | |
const newTab = window.open(link.href, '_blank'); | |
newTab.focus(); | |
} else { | |
window.location.href = link.href; | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment