Repository URL to install this package:
|
Version:
1.2.0 ▾
|
/**
* Job of this function is to check all valid urls and determine
* if we need to add `data-izimodal-open` to them
*/
(function($, drupalSettings, window){
var modalId = drupalSettings.meltModal.modalId;
var continueId = drupalSettings.meltModal.continueId;
// Set defaults if no id exists
modalId = modalId || '#external-link-modal';
continueId = continueId || '.external-link-modal--continue';
// Loop through each link and add a `data-external` attribute
// so we can add click event listeners after we loop
$('a[href^="http"]').each(function(){
var isExternalLink = window.location.hostname !== this.hostname;
if(isExternalLink && !inWhitelist(this.href)) {
$(this).attr('data-izimodal-open', modalId);
$(this).attr('data-externallink-continue', continueId);
}
});
/*********************************************************************************
* Function Declarations
**********************************************************************************/
/**
* Checks to see if url given is in the melt Modal's whitelist.
*
* @param {string} url
*
* @returns {boolean} true/false
*/
function inWhitelist(url){
var whiteList = drupalSettings.meltModal.whitelist;
whiteList = whiteList ? whiteList.split('\n') : [];
return whiteList.some(function(item){
return url.indexOf(item.trim()) !== -1;
});
}
})(jQuery, drupalSettings, window)