IMPR: Ping online/offline handling

This commit is contained in:
Tony Air 2020-09-11 01:54:43 +07:00
parent 87ad23efed
commit bcc4a131ce

View File

@ -18,198 +18,199 @@ import SmoothScroll from 'smooth-scroll';
const smoothScroll = SmoothScroll(); const smoothScroll = SmoothScroll();
const MainUI = (($) => { const MainUI = (($) => {
// Constants // Constants
const W = window; const W = window;
const $W = $(W); const $W = $(W);
const D = document; const D = document;
const $Body = $('body'); const $Body = $('body');
const NAME = 'MainUI'; const NAME = 'MainUI';
console.clear(); console.clear();
console.info( console.info(
`%cUI Kit ${UINAME} ${UIVERSION}`, `%cUI Kit ${UINAME} ${UIVERSION}`,
'color:yellow;font-size:14px', 'color:yellow;font-size:14px',
); );
console.info( console.info(
`%c${UIMetaNAME} ${UIMetaVersion}`, `%c${UIMetaNAME} ${UIMetaVersion}`,
'color:yellow;font-size:12px', 'color:yellow;font-size:12px',
); );
console.info( console.info(
`%chttps://github.com/a2nt/webpack-bootstrap-ui-kit by ${UIAUTHOR}`, `%chttps://github.com/a2nt/webpack-bootstrap-ui-kit by ${UIAUTHOR}`,
'color:yellow;font-size:10px', 'color:yellow;font-size:10px',
); );
console.groupCollapsed('Events'); console.groupCollapsed('Events');
Object.keys(Events).forEach((k) => { Object.keys(Events).forEach((k) => {
console.info(`${k}: ${Events[k]}`); console.info(`${k}: ${Events[k]}`);
}); });
console.groupEnd('Events'); console.groupEnd('Events');
console.groupCollapsed('Consts'); console.groupCollapsed('Consts');
Object.keys(Consts).forEach((k) => { Object.keys(Consts).forEach((k) => {
console.info(`${k}: ${Consts[k]}`); console.info(`${k}: ${Consts[k]}`);
}); });
console.groupEnd('Events'); console.groupEnd('Events');
console.groupCollapsed('Init'); console.groupCollapsed('Init');
console.time('init'); console.time('init');
$W.on(`${Events.LODEDANDREADY}`, () => { $W.on(`${Events.LODEDANDREADY}`, () => {
console.groupEnd('Init'); console.groupEnd('Init');
console.timeEnd('init'); console.timeEnd('init');
console.time('Post-init'); console.time('Post-init');
console.groupCollapsed('Post-init'); console.groupCollapsed('Post-init');
}); });
// get browser locale // get browser locale
//const Locale = $('html').attr('lang').substring(0, 2); //const Locale = $('html').attr('lang').substring(0, 2);
const $AlertNotify = $('#AlertNotify'); const $AlertNotify = $('#AlertNotify');
const $SiteWideMessage = $('#SiteWideMessage'); const $SiteWideMessage = $('#SiteWideMessage');
// get browser window visibility preferences // get browser window visibility preferences
// Opera 12.10, Firefox >=18, Chrome >=31, IE11 // Opera 12.10, Firefox >=18, Chrome >=31, IE11
const HiddenName = 'hidden'; const HiddenName = 'hidden';
const VisibilityChangeEvent = 'visibilitychange'; const VisibilityChangeEvent = 'visibilitychange';
// update visibility state // update visibility state
D.addEventListener(VisibilityChangeEvent, () => { D.addEventListener(VisibilityChangeEvent, () => {
if (D.visibilityState === HiddenName) { if (D.visibilityState === HiddenName) {
console.log(`${NAME}: Tab: hidden`); console.log(`${NAME}: Tab: hidden`);
$Body.addClass('is-hidden'); $Body.addClass('is-hidden');
$Body.trigger(Events.TABHIDDEN); $Body.trigger(Events.TABHIDDEN);
$W.trigger(Events.TABHIDDEN); $W.trigger(Events.TABHIDDEN);
} else { } else {
console.log(`${NAME}: Tab: focused`); console.log(`${NAME}: Tab: focused`);
$Body.removeClass('is-hidden'); $Body.removeClass('is-hidden');
$Body.trigger(Events.TABFOCUSED); $Body.trigger(Events.TABFOCUSED);
$W.trigger(Events.TABFOCUSED); $W.trigger(Events.TABFOCUSED);
} }
}); });
// update online/offline state // session ping
const updateOnlineStatus = () => { const sessionPing = () => {
if (typeof navigator.onLine === 'undefined') { if ($Body.hasClass('is-offline')) {
return; return;
} }
if (!navigator.onLine) {
console.log(`${NAME}: Tab: offline`);
$Body.addClass('is-offline');
$Body.trigger(Events.OFFLINE);
$W.trigger(Events.OFFLINE);
} else {
console.log(`${NAME}: Tab: online`);
$Body.removeClass('is-offline');
$Body.trigger(Events.ONLINE);
$W.trigger(Events.ONLINE);
}
};
W.addEventListener( console.log(`${NAME}: session ping`);
`${Events.OFFLINE}`,
() => {
updateOnlineStatus();
},
false,
);
W.addEventListener( $.ajax({
`${Events.ONLINE}`, sync: false,
() => { async: true,
updateOnlineStatus(); cache: false,
}, url: '/Security/ping',
false, global: false,
); type: 'POST',
complete: (data, datastatus) => {
if (datastatus !== 'success') {
console.warn(`${NAME}: ping failed`);
clearInterval(pingInterval);
}
updateOnlineStatus();
},
});
};
W.addEventListener(`${Events.LOADED}`, () => { let pingInterval = setInterval(sessionPing, 300000); // 5 min in ms
updateOnlineStatus();
});
$W.on(`${Events.AJAX}`, () => { // update online/offline state
updateOnlineStatus(); const updateOnlineStatus = () => {
}); if (typeof navigator.onLine === 'undefined') {
return;
}
if (!navigator.onLine) {
console.log(`${NAME}: Tab: offline`);
clearInterval(pingInterval);
// scrollTo $Body.addClass('is-offline');
const ScrollTo = (trigger, selector) => { $Body.trigger(Events.OFFLINE);
smoothScroll.animateScroll(D.querySelector(selector), trigger, { $W.trigger(Events.OFFLINE);
speed: 500, } else {
offset: -20, console.log(`${NAME}: Tab: online`);
//easing: 'easeInOutCubic', pingInterval = setInterval(sessionPing, 300000); // 5 min in ms
// Callback API
//before: (anchor, toggle) => {}, // Callback to run before scroll
//`after: (anchor, toggle) => {} // Callback to run after scroll
});
};
// session ping $Body.removeClass('is-offline');
const pingInterval = setInterval(() => { $Body.trigger(Events.ONLINE);
if ($Body.hasClass('is-offline')) { $W.trigger(Events.ONLINE);
return; }
} };
$.ajax({ W.addEventListener(
sync: false, `${Events.OFFLINE}`,
async: true, () => {
cache: false, updateOnlineStatus();
url: '/Security/ping', },
global: false, false,
type: 'POST', );
complete(data, datastatus) {
if (datastatus !== 'success') {
clearInterval(pingInterval);
$Body.addClass('is-offline'); W.addEventListener(
$Body.trigger(Events.OFFLINE); `${Events.ONLINE}`,
$W.trigger(Events.OFFLINE); () => {
//W.location.reload(false); updateOnlineStatus();
} else { },
$Body.removeClass('is-offline'); false,
$Body.trigger(Events.ONLINE); );
$W.trigger(Events.ONLINE);
}
},
});
}, 300000); // 5 min in ms
W.URLDetails = { W.addEventListener(`${Events.LOADED}`, () => {
base: $('base').attr('href'), updateOnlineStatus();
relative: '/', });
hash: '',
};
let eventFired = false; $W.on(`${Events.AJAX}`, () => {
const setTouchScreen = (bool) => { updateOnlineStatus();
if (W.IsTouchScreen === bool || eventFired) { });
return;
}
eventFired = true; // scrollTo
const ScrollTo = (trigger, selector) => {
smoothScroll.animateScroll(D.querySelector(selector), trigger, {
speed: 500,
offset: -20,
//easing: 'easeInOutCubic',
// Callback API
//before: (anchor, toggle) => {}, // Callback to run before scroll
//`after: (anchor, toggle) => {} // Callback to run after scroll
});
};
W.IsTouchScreen = bool; W.URLDetails = {
$.support.touch = W.IsTouchScreen; base: $('base').attr('href'),
relative: '/',
hash: '',
};
if (bool) { let eventFired = false;
console.log(`${NAME}: Touch screen enabled`); const setTouchScreen = (bool) => {
$Body.trigger(Events.TOUCHENABLE); if (W.IsTouchScreen === bool || eventFired) {
$W.trigger(Events.TOUCHENABLE); return;
} else { }
console.log(`${NAME}: Touch screen disabled`);
$Body.trigger(Events.TOUCHDISABLED);
$W.trigger(Events.TOUCHDISABLED);
}
// prevent firing touch and mouse events together eventFired = true;
setTimeout(() => {
eventFired = false;
}, 200);
};
setTouchScreen('ontouchstart' in window || navigator.msMaxTouchPoints > 0); W.IsTouchScreen = bool;
$.support.touch = W.IsTouchScreen;
// disable touch on mouse events if (bool) {
/*D.addEventListener('mousemove', () => { console.log(`${NAME}: Touch screen enabled`);
$Body.trigger(Events.TOUCHENABLE);
$W.trigger(Events.TOUCHENABLE);
} else {
console.log(`${NAME}: Touch screen disabled`);
$Body.trigger(Events.TOUCHDISABLED);
$W.trigger(Events.TOUCHDISABLED);
}
// prevent firing touch and mouse events together
setTimeout(() => {
eventFired = false;
}, 200);
};
setTouchScreen('ontouchstart' in window || navigator.msMaxTouchPoints > 0);
// disable touch on mouse events
/*D.addEventListener('mousemove', () => {
setTouchScreen(false); setTouchScreen(false);
}); });
@ -217,41 +218,41 @@ const MainUI = (($) => {
setTouchScreen(false); setTouchScreen(false);
});*/ });*/
// enable touch screen on touch events // enable touch screen on touch events
D.addEventListener('touchmove', () => { D.addEventListener('touchmove', () => {
setTouchScreen(true); setTouchScreen(true);
}); });
D.addEventListener('touchstart', () => { D.addEventListener('touchstart', () => {
setTouchScreen(true); setTouchScreen(true);
}); });
class MainUI { class MainUI {
// Static methods // Static methods
static init() { static init() {
const ui = this; const ui = this;
ui.dispose(); ui.dispose();
console.log(`${NAME}: init`); console.log(`${NAME}: init`);
// update location details // update location details
ui.updateLocation(); ui.updateLocation();
// mark available offline areas // mark available offline areas
if ('caches' in W) { if ('caches' in W) {
$('a.offline').addClass('offline-available'); $('a.offline').addClass('offline-available');
} }
ui.loadImages(); ui.loadImages();
// detect bootstrap screen size // detect bootstrap screen size
ui.detectBootstrapScreenSize(); ui.detectBootstrapScreenSize();
// mark external links // mark external links
$('a.external,a[rel="external"]').attr('target', '_blank'); $('a.external,a[rel="external"]').attr('target', '_blank');
// show encoded emails // show encoded emails
/*$(D).find('.obm').each(() => { /*$(D).find('.obm').each(() => {
if ($(this).attr('data-val') !== undefined) { if ($(this).attr('data-val') !== undefined) {
const email = $(this).attr('data-val').split('') const email = $(this).attr('data-val').split('')
.reverse() .reverse()
@ -271,333 +272,333 @@ const MainUI = (($) => {
} }
} }
});*/ });*/
// //
// scroll links // scroll links
$('.js-scrollTo').on('click', (e) => { $('.js-scrollTo').on('click', (e) => {
console.log(`${NAME}: .js-scrollTo`); console.log(`${NAME}: .js-scrollTo`);
e.preventDefault(); e.preventDefault();
const el = e.currentTarget; const el = e.currentTarget;
const $el = $(e.currentTarget); const $el = $(e.currentTarget);
ScrollTo(el, $el.attr('data-target')); ScrollTo(el, $el.attr('data-target'));
}); });
// load external fonts // load external fonts
if ($('[data-extfont]').length) { if ($('[data-extfont]').length) {
console.log(`${NAME}: loading external fonts [data-extfont]`); console.log(`${NAME}: loading external fonts [data-extfont]`);
$.getScript( $.getScript(
'//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js', '//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js',
() => { () => {
const fonts = []; const fonts = [];
$('[data-extfont]').each((i, el) => { $('[data-extfont]').each((i, el) => {
fonts[i] = $(el).attr('data-extfont'); fonts[i] = $(el).attr('data-extfont');
}); });
W.WebFont.load({ W.WebFont.load({
google: { google: {
families: fonts, families: fonts,
}, },
}); });
}, },
); );
} }
// data-set links // data-set links
$('[data-set-target]').on('click', (e) => { $('[data-set-target]').on('click', (e) => {
console.log(`${NAME}: [data-set-target]`); console.log(`${NAME}: [data-set-target]`);
const $el = $(e.currentTarget); const $el = $(e.currentTarget);
const $target = $($el.data('set-target')); const $target = $($el.data('set-target'));
if (!$target.length) { if (!$target.length) {
return; return;
} }
$target.each((i, targetEl) => { $target.each((i, targetEl) => {
const $targetEl = $(targetEl); const $targetEl = $(targetEl);
const tag = $targetEl.prop('tagName').toLowerCase(); const tag = $targetEl.prop('tagName').toLowerCase();
if (tag === 'input' || tag === 'select') { if (tag === 'input' || tag === 'select') {
$targetEl.val($el.data('set-val')); $targetEl.val($el.data('set-val'));
} else if (!$targetEl.hasClass('field')) { } else if (!$targetEl.hasClass('field')) {
$targetEl.text($el.data('set-val')); $targetEl.text($el.data('set-val'));
} }
}); });
$el.trigger(Events.SET_TARGET_UPDATE); $el.trigger(Events.SET_TARGET_UPDATE);
$target.closest('form').trigger(Events.SET_TARGET_UPDATE); $target.closest('form').trigger(Events.SET_TARGET_UPDATE);
}); });
// emulate links // emulate links
$('.a[data-href]').on('click', (e) => { $('.a[data-href]').on('click', (e) => {
console.log(`${NAME}: js link processing .a[data-href]`); console.log(`${NAME}: js link processing .a[data-href]`);
const $el = $(e.currentTarget); const $el = $(e.currentTarget);
const href = $el.data('href'); const href = $el.data('href');
if (!href.length) { if (!href.length) {
console.warn(`${NAME}: .a[data-href] | Missing data-href`); console.warn(`${NAME}: .a[data-href] | Missing data-href`);
console.warn($el); console.warn($el);
} }
W.location.assign(href); W.location.assign(href);
}); });
// hide spinner // hide spinner
Spinner.hide(() => { Spinner.hide(() => {
$Body.addClass('loaded'); $Body.addClass('loaded');
}); });
// fire page printing // fire page printing
if (W.URLDetails['hash'].indexOf('printpage') > -1) { if (W.URLDetails['hash'].indexOf('printpage') > -1) {
W.print(); W.print();
} }
$Body.data(NAME, ui); $Body.data(NAME, ui);
$W.removeClass('lock-main-init'); $W.removeClass('lock-main-init');
} }
static detectBootstrapScreenSize() { static detectBootstrapScreenSize() {
const $el = $('<div class="env-test"></div>'); const $el = $('<div class="env-test"></div>');
let envs = [...Consts.ENVS]; let envs = [...Consts.ENVS];
$Body.append($el); $Body.append($el);
let curEnv = envs.shift(); let curEnv = envs.shift();
envs = envs.reverse(); envs = envs.reverse();
for (let i = 0; i < envs.length; ++i) { for (let i = 0; i < envs.length; ++i) {
const env = envs[i]; const env = envs[i];
$el.addClass(`d-${env}-none`); $el.addClass(`d-${env}-none`);
if ($el.is(':hidden')) { if ($el.is(':hidden')) {
curEnv = env; curEnv = env;
break; break;
} }
} }
$el.remove(); $el.remove();
$Body.removeClass(envs); $Body.removeClass(envs);
$Body.addClass(curEnv); $Body.addClass(curEnv);
let landscape = true; let landscape = true;
if ($W.width() > $W.height()) { if ($W.width() > $W.height()) {
$Body.removeClass('portrait'); $Body.removeClass('portrait');
$Body.addClass('landscape'); $Body.addClass('landscape');
} else { } else {
landscape = false; landscape = false;
$Body.removeClass('landscape'); $Body.removeClass('landscape');
$Body.addClass('portrait'); $Body.addClass('portrait');
} }
console.log( console.log(
`${NAME}: screen size detected ${curEnv} | landscape ${landscape}`, `${NAME}: screen size detected ${curEnv} | landscape ${landscape}`,
); );
return curEnv; return curEnv;
} }
static updateLocation(url) { static updateLocation(url) {
let location = url || W.location.href; let location = url || W.location.href;
location = location.replace(W.URLDetails['base'], '/'); location = location.replace(W.URLDetails['base'], '/');
const hash = location.indexOf('#'); const hash = location.indexOf('#');
W.URLDetails.relative = location.split('#')[0]; W.URLDetails.relative = location.split('#')[0];
W.URLDetails.hash = W.URLDetails.hash =
hash >= 0 ? location.substr(location.indexOf('#')) : ''; hash >= 0 ? location.substr(location.indexOf('#')) : '';
} }
// show site-wide alert // show site-wide alert
static alert(msg, cls) { static alert(msg, cls) {
$SiteWideMessage.fadeOut('fast'); $SiteWideMessage.fadeOut('fast');
$SiteWideMessage.html( $SiteWideMessage.html(
`<div class="page-alert"><div class="alert alert-${cls}"><i class="close" data-dismiss="alert">&times;</i>${msg}</div></div>`, `<div class="page-alert"><div class="alert alert-${cls}"><i class="close" data-dismiss="alert">&times;</i>${msg}</div></div>`,
); );
$SiteWideMessage.find('.page-alert').alert(); $SiteWideMessage.find('.page-alert').alert();
$SiteWideMessage.find('.close[data-dismiss="alert"]').click(() => { $SiteWideMessage.find('.close[data-dismiss="alert"]').click(() => {
$SiteWideMessage.fadeOut('slow', () => { $SiteWideMessage.fadeOut('slow', () => {
$SiteWideMessage.find('.page-alert').alert('close'); $SiteWideMessage.find('.page-alert').alert('close');
}); });
}); });
$SiteWideMessage.fadeIn('slow'); $SiteWideMessage.fadeIn('slow');
if ($AlertNotify.length) { if ($AlertNotify.length) {
$AlertNotify[0].play(); $AlertNotify[0].play();
} }
$W.trigger(`${Events.ALLERTAPPEARED}`); $W.trigger(`${Events.ALLERTAPPEARED}`);
} }
// hide site-wide alert // hide site-wide alert
static alertHide() { static alertHide() {
if ($SiteWideMessage.length !== 0) { if ($SiteWideMessage.length !== 0) {
$SiteWideMessage.fadeOut('slow', () => { $SiteWideMessage.fadeOut('slow', () => {
$SiteWideMessage.find('.alert').alert('close'); $SiteWideMessage.find('.alert').alert('close');
}); });
} }
if ( if (
$AlertNotify.length && $AlertNotify.length &&
typeof $AlertNotify[0].stop !== 'undefined' typeof $AlertNotify[0].stop !== 'undefined'
) { ) {
$AlertNotify[0].stop(); $AlertNotify[0].stop();
} }
$W.trigger(`${Events.ALLERTREMOVED}`); $W.trigger(`${Events.ALLERTREMOVED}`);
} }
// load all images // load all images
static loadImages() { static loadImages() {
const $imgs = $Body.find('img').not('.loaded'); const $imgs = $Body.find('img').not('.loaded');
const $imgUrls = []; const $imgUrls = [];
const $imgLazyUrls = []; const $imgLazyUrls = [];
// collect image details // collect image details
$imgs.each((i, el) => { $imgs.each((i, el) => {
const $el = $(el); const $el = $(el);
const src = $el.attr('src'); const src = $el.attr('src');
const lazySrc = $el.data('lazy-src'); const lazySrc = $el.data('lazy-src');
if ($el.hasClass('loaded')) { if ($el.hasClass('loaded')) {
return; return;
} }
if (src && src.length) { if (src && src.length) {
$imgUrls.push(src); $imgUrls.push(src);
} }
if (lazySrc && lazySrc.length) { if (lazySrc && lazySrc.length) {
$imgLazyUrls.push(lazySrc); $imgLazyUrls.push(lazySrc);
$el.addClass('loading'); $el.addClass('loading');
AjaxUI.preload([lazySrc]).then(() => { AjaxUI.preload([lazySrc]).then(() => {
$el.attr('src', lazySrc); $el.attr('src', lazySrc);
$el.on(`${Events.LOADED}`, () => { $el.on(`${Events.LOADED}`, () => {
$el.addClass('loaded'); $el.addClass('loaded');
$el.removeClass('loading'); $el.removeClass('loading');
$el.trigger(`${Events.LAZYIMAGEREADY}`); $el.trigger(`${Events.LAZYIMAGEREADY}`);
}); });
}); });
} }
}); });
// load lazy backgrounds // load lazy backgrounds
$Body $Body
.find('[data-lazy-bg]') .find('[data-lazy-bg]')
.not('.loaded') .not('.loaded')
.each((i, el) => { .each((i, el) => {
const $el = $(el); const $el = $(el);
const lazySrc = $el.data('lazy-bg'); const lazySrc = $el.data('lazy-bg');
if ($el.hasClass('loaded')) { if ($el.hasClass('loaded')) {
return; return;
} }
if (lazySrc && lazySrc.length) { if (lazySrc && lazySrc.length) {
$imgLazyUrls.push(lazySrc); $imgLazyUrls.push(lazySrc);
$el.addClass('loading'); $el.addClass('loading');
AjaxUI.preload([lazySrc]).then(() => { AjaxUI.preload([lazySrc]).then(() => {
$el.css({ 'background-image': `url(${lazySrc})` }); $el.css({ 'background-image': `url(${lazySrc})` });
$el.addClass('loaded'); $el.addClass('loaded');
$el.removeClass('loading'); $el.removeClass('loading');
$el.trigger(`${Events.LAZYIMAGEREADY}`); $el.trigger(`${Events.LAZYIMAGEREADY}`);
}); });
} }
}); });
// replace img src // replace img src
$Body $Body
.find('[data-src-replace]') .find('[data-src-replace]')
.not('.loaded') .not('.loaded')
.each((i, el) => { .each((i, el) => {
const $el = $(el); const $el = $(el);
const lazySrc = $el.data('src-replace'); const lazySrc = $el.data('src-replace');
if ($el.hasClass('loaded')) { if ($el.hasClass('loaded')) {
return; return;
} }
if (lazySrc && lazySrc.length) { if (lazySrc && lazySrc.length) {
$el.addClass('loaded'); $el.addClass('loaded');
$el.attr('src', lazySrc); $el.attr('src', lazySrc);
} }
}); });
// load defined images // load defined images
AjaxUI.preload($imgUrls).then(() => { AjaxUI.preload($imgUrls).then(() => {
$W.trigger('images-loaded'); $W.trigger('images-loaded');
// load lazy images // load lazy images
AjaxUI.preload($imgLazyUrls).then(() => { AjaxUI.preload($imgLazyUrls).then(() => {
console.log(`${NAME}: All images are loaded!`); console.log(`${NAME}: All images are loaded!`);
setTimeout(() => { setTimeout(() => {
$W.trigger(`${Events.LAZYIMAGESREADY}`); $W.trigger(`${Events.LAZYIMAGESREADY}`);
console.groupEnd('Post-init'); console.groupEnd('Post-init');
console.timeEnd('Post-init'); console.timeEnd('Post-init');
}, 100); }, 100);
}); });
}); });
} }
static dispose() { static dispose() {
console.log(`${NAME}: dispose`); console.log(`${NAME}: dispose`);
} }
} }
$W.on( $W.on(
`${Events.MAININIT} ${Events.AJAX} ${Events.AJAXMAIN} ${Events.LOADED}`, `${Events.MAININIT} ${Events.AJAX} ${Events.AJAXMAIN} ${Events.LOADED}`,
() => { () => {
if ($W.hasClass('lock-main-init')) { if ($W.hasClass('lock-main-init')) {
console.warn('MainUI is locked'); console.warn('MainUI is locked');
return; return;
} }
$W.addClass('lock-main-init'); $W.addClass('lock-main-init');
MainUI.init(); MainUI.init();
}, },
); );
$W.on(`${Events.RESIZE}`, () => { $W.on(`${Events.RESIZE}`, () => {
MainUI.detectBootstrapScreenSize(); MainUI.detectBootstrapScreenSize();
}); });
$W.on('beforeunload unload', () => { $W.on('beforeunload unload', () => {
Spinner.show(() => { Spinner.show(() => {
$Body.removeClass('loaded'); $Body.removeClass('loaded');
}); });
}); });
// hide spinner on target _blank // hide spinner on target _blank
$('[target="_blank"],.external').on('click submit', (e) => { $('[target="_blank"],.external').on('click submit', (e) => {
if ( if (
$(e.currentTarget).is( $(e.currentTarget).is(
'[data-toggle="lightbox"],[data-lightbox-gallery]', '[data-toggle="lightbox"],[data-lightbox-gallery]',
) )
) { ) {
return false; return false;
} }
console.log(`${NAME}: External link`); console.log(`${NAME}: External link`);
setTimeout(() => { setTimeout(() => {
Spinner.hide(() => { Spinner.hide(() => {
$Body.addClass('loaded'); $Body.addClass('loaded');
}); });
}, 1000); }, 1000);
}); });
W.MainUI = MainUI; W.MainUI = MainUI;
return MainUI; return MainUI;
})($); })($);
export default MainUI; export default MainUI;