Skip to content

Instantly share code, notes, and snippets.

@AllieRays
Created June 8, 2015 17:30
Show Gist options
  • Save AllieRays/cf1b90e9b85ce5c53c94 to your computer and use it in GitHub Desktop.
Save AllieRays/cf1b90e9b85ce5c53c94 to your computer and use it in GitHub Desktop.
js pop up interstitial for drupal custom module. See rest of module here, https://github.com/devupable/popup-interstitial-drupal
(function ($) {
Drupal.behaviors.idi_interstitial = {
attach: function (context, settings) {
$('.block--bean-interstitial a.external, .block--bean-interstitial-iframe a.external ').click(function () {
$.colorbox.close();
return true;
});
$('.block--bean-interstitial .internal, .block--bean-interstitial-iframe .internal').click(function () {
$.colorbox.close();
return false;
});
var external = RegExp('^((f|ht)tps?:)?//(?!' + location.host + ')');
$('a:not(.external, .internal, .interstitial-exception)').click(function () {
var $txt = $(this).attr('href');
if (external.test($(this).attr('href')) == true) {
//alert('this is an external link');
//console.log("text equals " + txt);
//--if client requests external links that exception to the colorbox rule--//
//if (txt.indexOf('http://www.placeholder.com') == -1
// && txt.indexOf('http://www.placeholder2.com') == -1
// )
{
colorboxInterstitial('.block--bean-interstitial', $txt);
}
trackOutboundLink(this, 'Outbound links', 'click');
return false;
}
else if ($(this).hasClass('interstitial-iframe')) {
$('.block--bean-interstitial-iframe').find('a.external').removeAttr('target');
colorboxInterstitial('.block--bean-interstitial-iframe', $txt);
return false;
}
return true;
});
function colorboxInterstitial($beanSelector, $href) {
$($beanSelector).find('a.external').attr('href', $href);
//evt.preventDefault();
//alert('TEST EXTERNAL LINK');
//trackOutboundLink(this, 'Outbound links', 'click');
$.colorbox({
width: "100%",
height: "40%",
inline: true,
ajax: true,
scrolling: false,
closeButton: false,
top: 0,
href: $beanSelector
});
}
}
};
//change colorbox size on resize
var cboxOptions = {
width: '100%',
// height: '95%',
maxWidth: '1200px',
maxHeight: '1200px'
}
$('.cbox-link').colorbox(cboxOptions);
$(window).resize(function(){
$.colorbox.resize({
width: window.innerWidth > parseInt(cboxOptions.maxWidth) ? cboxOptions.maxWidth : cboxOptions.width,
height: window.innerHeight > parseInt(cboxOptions.maxHeight) ? cboxOptions.maxHeight : cboxOptions.height
});
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment