Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
init() {
const app = this;
const classNames = [];
const html = document.querySelector('html');
const metaStatusbar = document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]');
if (!html) return;
if (Device.standalone && Device.ios && metaStatusbar && metaStatusbar.content === 'black-translucent') {
classNames.push('device-full-viewport');
}
// Pixel Ratio
classNames.push(`device-pixel-ratio-${Math.floor(Device.pixelRatio)}`);
if (Device.pixelRatio >= 2) {
classNames.push('device-retina');
}
// OS classes
if (Device.os) {
classNames.push(
`device-${Device.os}`,
`device-${Device.os}-${Device.osVersion.split('.')[0]}`,
`device-${Device.os}-${Device.osVersion.replace(/\./g, '-')}`
init() {
const html = document.querySelector('html');
if (!html) return;
const classNames = [];
if (Support.positionSticky) {
classNames.push('support-position-sticky');
}
// Add html classes
classNames.forEach((className) => {
html.classList.add(className);
});
},
},
init() {
const app = this;
const classNames = [];
const html = document.querySelector('html');
const metaStatusbar = document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]');
if (!html) return;
if (Device.standalone && Device.ios && metaStatusbar && metaStatusbar.content === 'black-translucent') {
classNames.push('device-full-viewport');
}
// Pixel Ratio
classNames.push(`device-pixel-ratio-${Math.floor(Device.pixelRatio)}`);
if (Device.pixelRatio >= 2) {
classNames.push('device-retina');
}
// OS classes
if (Device.os) {
classNames.push(
`device-${Device.os}`,
`device-${Device.os}-${Device.osVersion.split('.')[0]}`,
init() {
const classNames = [];
const html = document.querySelector('html');
const metaStatusbar = document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]');
if (!html) return;
if (Device.standalone && Device.ios && metaStatusbar && metaStatusbar.content === 'black-translucent') {
classNames.push('device-full-viewport');
}
// Pixel Ratio
classNames.push(`device-pixel-ratio-${Math.floor(Device.pixelRatio)}`);
if (Device.pixelRatio >= 2) {
classNames.push('device-retina');
}
// OS classes
if (Device.os && !Device.desktop) {
classNames.push(
`device-${Device.os}`,
`device-${Device.os}-${Device.osVersion.split('.')[0]}`,
init() {
const classNames = [];
const html = document.querySelector('html');
if (!html) return;
// Pixel Ratio
classNames.push(`device-pixel-ratio-${Math.floor(Device.pixelRatio)}`);
if (Device.pixelRatio >= 2) {
classNames.push('device-retina');
}
// OS classes
if (Device.os) {
classNames.push(
`device-${Device.os}`,
`device-${Device.os}-${Device.osVersion.split('.')[0]}`,
`device-${Device.os}-${Device.osVersion.replace(/\./g, '-')}`
);
if (Device.os === 'ios') {
const major = parseInt(Device.osVersion.split('.')[0], 10);
for (let i = major - 1; i >= 6; i -= 1) {
script.onerror = function onerror() {
clearTimeout(abortTimeout);
fireCallback('error', null, 'scripterror');
fireCallback('complete', null, 'scripterror');
};
script.src = requestUrl;
// Handler
window[callbackName] = function jsonpCallback(data) {
clearTimeout(abortTimeout);
fireCallback('success', data);
script.parentNode.removeChild(script);
script = null;
delete window[callbackName];
};
document.querySelector('head').appendChild(script);
if (options.timeout > 0) {
abortTimeout = setTimeout(() => {
script.parentNode.removeChild(script);
script = null;
fireCallback('error', null, 'timeout');
}, options.timeout);
}
return undefined;
}
// Cache for GET/HEAD requests
if (method === 'GET' || method === 'HEAD' || method === 'OPTIONS' || method === 'DELETE') {
if (options.cache === false) {
options.url += `${paramsPrefix}_nocache${Date.now()}`;
app.colorSchemeListener = function colorSchemeListener({ matches, media }) {
if (!matches) {
return;
}
const html = document.querySelector('html');
if (media === DARK) {
html.classList.add('theme-dark');
} else if (media === LIGHT) {
html.classList.remove('theme-dark');
}
};
// Init
script.onerror = function onerror() {
clearTimeout(abortTimeout);
fireCallback('error', null, 'scripterror', 'scripterror');
fireCallback('complete', null, 'scripterror');
};
script.src = requestUrl;
// Handler
window[callbackName] = function jsonpCallback(data) {
clearTimeout(abortTimeout);
fireCallback('success', data);
script.parentNode.removeChild(script);
script = null;
delete window[callbackName];
};
document.querySelector('head').appendChild(script);
if (options.timeout > 0) {
abortTimeout = setTimeout(() => {
script.parentNode.removeChild(script);
script = null;
fireCallback('error', null, 'timeout', 'timeout');
}, options.timeout);
}
return undefined;
}
// Cache for GET/HEAD requests
if (method === 'GET' || method === 'HEAD' || method === 'OPTIONS' || method === 'DELETE') {
if (options.cache === false) {
options.url += `${paramsPrefix}_nocache${Date.now()}`;
enableAutoDarkTheme() {
if (!window.matchMedia) return;
const app = this;
const html = document.querySelector('html');
if (app.mq.dark && app.mq.light) {
app.mq.dark.addListener(app.colorSchemeListener);
app.mq.light.addListener(app.colorSchemeListener);
}
if (app.mq.dark && app.mq.dark.matches) {
html.classList.add('theme-dark');
} else if (app.mq.light && app.mq.light.matches) {
html.classList.remove('theme-dark');
}
}