', {
class: 'meta-lightbox-content',
});
const nav = $(
'
', {
class: 'meta-lightbox-title-wrap',
});
if (ui.$overlay) return ui.$overlay;
if (ui.isMSIE) overlay.addClass('meta-lightbox-ie');
wrap.append(content);
wrap.append(title);
overlay.append(wrap);
overlay.append(nav);
overlay.append(close);
$Body.append(overlay);
overlay.on('click', (e) => {
e.preventDefault();
ui.hide();
});
close.on('click', (e) => {
e.preventDefault();
ui.hide();
});
ui.$overlay = overlay;
ui.$content = content;
ui.$title = title;
return ui.$overlay;
}
static setTitle(str) {
const ui = this;
ui.$title.html(str);
}
static process($content, $link) {
console.log(`${NAME}: process`);
const ui = this;
const href =
$link.attr('href') && $link.attr('href').length
? $link.attr('href')
: $link.data('href');
// add custom link specific class
ui.$content.attr('class', 'meta-lightbox-content');
ui.$content.addClass($link.data('lightbox-class'));
if (!href.length) {
console.log($link);
console.error(`${NAME}: href(attr/data) is missing`);
}
const $pageSpinner = $('#PageLoading .loading-spinner');
const loadingContent = $pageSpinner.length ? $pageSpinner.clone() : '';
ui.$content.append(loadingContent).addClass('meta-lightbox-loading');
// Image
if (
href.match(/\.(jpeg|jpg|gif|png|svg)$/i) ||
$link.data('force') === 'image'
) {
$.ajax({
url: href,
success: () => {
const img = $('
', { src: href });
const wrap = $('
');
const imgwrapper = $(
'
',
);
imgwrapper.append(img);
wrap.append(imgwrapper);
// Vertically center images
wrap.css({
'line-height': `${$content.height()}px`,
height: `${$content.height()}px`, // For Firefox
});
$W.resize(() => {
wrap.css({
'line-height': `${$content.height()}px`,
height: `${$content.height()}px`, // For Firefox
});
});
if (typeof imgwrapper['zoom'] !== 'undefined') {
imgwrapper.zoom();
} else {
imgwrapper.addClass('no-zoom');
}
ui.$content.html(wrap);
ui.contentLoaded();
},
error: (jqXHR, status) => {
const wrap = $(NETWORK_ERROR);
ui.$content.html(wrap);
ui.contentLoaded();
},
});
// Set the title
const title = $link.data('title')
? $link.data('title')
: $link.attr('title');
ui.setTitle(title);
// google analytics
if (typeof ga === 'function') {
ga('send', 'event', 'meta', 'Image Click', href);
}
}
// Video (Youtube/Vimeo)
else if (
href.match(
/(youtube|youtube-nocookie|youtu|vimeo)\.(com|be)\/(watch\?v=([\w-]+)|([\w-]+))/,
) ||
$link.data('force') === 'youtube' ||
$link.data('force') === 'vimeo'
) {
const video = href.match(
/(youtube|youtube-nocookie|youtu|vimeo)\.(com|be)\/(watch\?v=([\w-]+)|([\w-]+))/,
);
let classTerm = 'meta-lightbox-video';
let src;
if (video[1] == 'youtube') {
src = `https://www.youtube.com/embed/${video[4]}`;
classTerm = `${classTerm} meta-lightbox-youtube`;
}
if (video[1] == 'youtu') {
src = `https://www.youtube.com/embed/${video[3]}`;
classTerm = `${classTerm} meta-lightbox-youtube`;
}
if (video[1] == 'youtube-nocookie') {
src = `https://www.youtube-nocookie.com/embed/${video[4]}`;
classTerm = `${classTerm} meta-lightbox-youtube`;
}
if (video[1] == 'vimeo') {
src = `https://player.vimeo.com/video/${video[3]}`;
classTerm = `${classTerm} meta-lightbox-vimeo`;
}
if (!src) {
console.warn(`${NAME}: Video loading bad URL`);
return false;
}
const $iframe = ui.loadIframe(src, classTerm);
if (!$iframe) {
$link.addClass('meta-offline');
return false;
}
$link.removeClass('meta-offline');
// Set the title
const title = $link.data('title')
? $link.data('title')
: $link.attr('title');
ui.setTitle(title);
// google analytics
if (typeof ga === 'function') {
ga('send', 'event', 'meta', 'Video Click', video);
}
}
// Inline HTML
else if (
href.substring(0, 1) == '#' ||
$link.data('force') === 'inline'
) {
if ($(href).length) {
wrap = $('
');
wrap.append($(href).clone().show());
// Vertically center html
if (wrap.outerHeight() < ui.$content.height()) {
wrap.css({
position: 'relative',
top: '50%',
'margin-top': `${-(wrap.outerHeight() / 2)}px`,
});
}
$W.resize(() => {
if (wrap.outerHeight() < ui.$content.height()) {
wrap.css({
position: 'relative',
top: '50%',
'margin-top': `${-(wrap.outerHeight() / 2)}px`,
});
}
});
ui.$content.html(wrap);
ui.contentLoaded();
} else {
wrap = $(NETWORK_ERROR);
ui.$content.html(wrap);
ui.contentLoaded();
}
$('.meta-lightbox-title-wrap').html('');
// google analytics
if (typeof ga === 'function') {
ga('send', 'event', 'meta', 'inline HTML click', href);
}
}
// AJAX/iFrame (default)
else {
if ($link.data('force-iframe') || $link.data('force') === 'iframe') {
console.log(`${NAME}: IFrame forced`);
const $iframe = ui.loadIframe(href, 'meta-lightbox-iframe-content');
if (!$iframe) {
$link.addClass('meta-offline');
return false;
}
$link.removeClass('meta-offline');
return true;
}
console.log(`${NAME}: loading AJAX`);
$.ajax({
sync: false,
async: true,
url: href,
dataType: 'html',
method: 'GET',
cache: false,
statusCode: {
404: function () {
console.log(`${NAME}: page not found`);
W.location.href = url;
},
302: function () {
console.log(`${NAME}: redirect 302`);
W.location.href = url;
},
},
error: function (jqXHR, status) {
console.log(`${NAME}: AJAX request failure.${jqXHR.statusText}`);
var wrap = $(NETWORK_ERROR);
ui.$content.html(wrap);
ui.contentLoaded();
// google analytics
if (typeof ga === 'function') {
ga('send', 'event', 'error', 'AJAX ERROR', jqXHR.statusText);
}
},
success: function (data, status, jqXHR) {
console.log(`${NAME}: AJAX success`);
try {
const dataJson = $.parseJSON(data);
if (typeof dataJson === 'object') {
console.log(`${NAME}: AJAX JSON`);
// Replace regions
if (
typeof dataJson['regions'] === 'object' &&
typeof dataJson['regions']['LayoutAjax'] !== 'undefinded'
) {
var wrap = $('
');
wrap.html(dataJson['regions']['LayoutAjax']);
ui.$content.html(wrap);
ui.contentLoaded();
}
// trigger events
/*if (typeof (data['events']) === 'object') {
for (var eventName in data.events) {
$(D).trigger(eventName, [data['events'][eventName]]);
}
}*/
var title = jqXHR.getResponseHeader('X-Title'),
link = jqXHR.getResponseHeader('X-Link');
if (
title &&
title.length &&
link &&
link.length &&
link !== W.location.href &&
link.substring(0, link.indexOf('#')) !==
W.location.href.replace($('base').attr('href'), '/')
) {
$('.meta-lightbox-ajax').data('curr-title', D.title);
$('.meta-lightbox-ajax').data('curr-link', W.location.href);
if (typeof W.localStorage !== 'undefined' && link !== '/') {
W.localStorage.setItem('current-page', link);
}
if (
D.URL !== link &&
D.URL !== $('base').attr('href') + link &&
D.URL !== `${$('base').attr('href')}/${link}`
) {
W.history.pushState(
{
title,
page: link,
ajax: 'true',
},
title,
link,
);
}
$('.meta-lightbox-title-wrap').html('');
// google analytics
if (typeof ga === 'function') {
ga('set', {
page: link.replace($('base').attr('href'), ''),
title,
});
ga('send', 'pageview');
}
}
}
} catch (e) {
console.log(`${NAME}: AJAX HTML`);
const $wrap = $('
');
$wrap.append(data);
ui.$content.html($wrap);
ui.contentLoaded();
}
// Vertically center html
/*if (wrap.outerHeight() < ui.$content.height()) {
wrap.css({
position: 'relative',
top: '50%',
'margin-top': `${-(wrap.outerHeight() / 2)}px`,
});
}
$W.resize(() => {
if (wrap.outerHeight() < ui.$content.height()) {
wrap.css({
position: 'relative',
top: '50%',
'margin-top': `${-(wrap.outerHeight() / 2)}px`,
});
}
});*/
/*setTimeout(() => {
$W.resize();
if (typeof W.imagesLoaded === 'function') {
W.imagesLoaded().then(() => {
$W.resize();
});
}
}, 500);*/
ui.contentLoaded();
},
});
}
}
static loadIframe(href, classTerm) {
const ui = this;
const $iframe = $('