Keeping Drupal's contextual links working even when the whole content item is linked offsite or triggering a lightbox
We have a site where one content type (publicity, for news items and awards) are listed, but the whole thing is wrapped in an anchor tag and linked to outside content. To prevent leaving the site before the contextual edit link is shown, i did this:
{syntaxhighlighter brush:js}
/**
* Allow content editors to reach contextual links without being taken away
* to a publicity outbound link first.
*/
$('.grid__item a').on("click tap", function(e) {
var origtarget = e.originalEvent.originalTarget;
if (!origtarget) {
origtarget = e.originalEvent.currentTarget;
}
if (origtarget.type === 'button') {
e.preventDefault();
}
});
{/syntaxhighlighter}
For another content type on the same site that also never links to its own page, but instead opens in a lightbox if any part of it is clicked, and further had additional effects making it probably impossible to get the contextual links outside of the element triggering the lightbox, i did this:
{syntaxhighlighter brush:js}
$('.lightbox').on("click tap", function(e) {
var origtarget = e.originalEvent.originalTarget;
if (!origtarget) {
origtarget = e.originalEvent.currentTarget;
}
if (origtarget.className !== 'trigger focusable'
&& origtarget.innerText !== 'Edit'
&& origtarget.innerText !== 'Delete'
) {
$.featherlight($(this).attr('data-img'));
e.stopPropagation();
return false;
}
});
{/syntaxhighlighter}
There must be a better way, right?
Comments
Post new comment