Made eslint using 'browser' environment and added globals, because RainLoop is used in browsers.

This also allowed to remove all webpack 'externals' overhead.
This commit is contained in:
djmaze 2020-08-12 00:25:36 +02:00
parent c3a213802d
commit e7180a86ce
81 changed files with 1857 additions and 1259 deletions

View file

@ -1,4 +1,3 @@
import window from 'window';
import * as Links from 'Common/Links';
import * as Events from 'Common/Events';
@ -44,7 +43,7 @@ class Audio {
createNewObject() {
try {
const player = window.Audio ? new window.Audio() : null;
const player = window.Audio ? new Audio() : null;
if (player && player.canPlayType && player.pause && player.play) {
player.preload = 'none';
player.loop = false;

View file

@ -1,10 +1,8 @@
/* eslint-env browser */
import { getHash, setHash, clearHash } from 'Storage/RainLoop';
let RL_APP_DATA_STORAGE = null;
const doc = window.document;
const doc = document;
/* eslint-disable camelcase,spaced-comment */
window.__rlah_set = () => setHash();
@ -27,7 +25,7 @@ function showError() {
}
if (window.progressJs) {
window.progressJs.set(100).end();
progressJs.set(100).end();
}
}
@ -55,7 +53,7 @@ function loadScript(src) {
if (!src) {
throw new Error('src should not be empty.');
}
return new window.Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
const script = doc.createElement('script');
script.onload = () => resolve();
script.onerror = () => reject(new Error(src));
@ -93,11 +91,11 @@ window.__initAppData = data => {
}
if (oE && oE.style) {
oE.style.opacity = 0;
window.setTimeout(() => oE.style.opacity = 1, 300);
setTimeout(() => oE.style.opacity = 1, 300);
}
}
const appData = window.__rlah_data(), p = window.progressJs;
const appData = window.__rlah_data(), p = progressJs;
if (
p &&
@ -125,7 +123,7 @@ window.__initAppData = data => {
libs()
.then(() => {
p.set(20);
return window.Promise.all([loadScript(appData.TemplatesLink), loadScript(appData.LangLink)]);
return Promise.all([loadScript(appData.TemplatesLink), loadScript(appData.LangLink)]);
})
.then(() => {
p.set(30);
@ -133,7 +131,7 @@ window.__initAppData = data => {
})
.then(() => {
p.set(50);
return appData.PluginsLink ? loadScript(appData.PluginsLink) : window.Promise.resolve();
return appData.PluginsLink ? loadScript(appData.PluginsLink) : Promise.resolve();
})
.then(() => {
p.set(70);
@ -161,7 +159,7 @@ window.__initAppData = data => {
window.__runBoot = () => {
const app = doc.getElementById('rl-app');
if (!window.navigator || !window.navigator.cookieEnabled) {
if (!navigator || !navigator.cookieEnabled) {
doc.location.replace('./?/NoCookie');
}
@ -183,7 +181,7 @@ window.__runBoot = () => {
+ '/'
+ (getHash() || '0')
+ '/'
+ window.Math.random().toString().substr(2)
+ Math.random().toString().substr(2)
+ '/').then(() => {});
}
};

View file

@ -1,4 +1,3 @@
import window from 'window';
import Cookies from 'js-cookie';
import { CLIENT_SIDE_STORAGE_INDEX_NAME } from 'Common/Consts';
@ -48,7 +47,7 @@ class CookieDriver {
* @returns {boolean}
*/
static supported() {
return !!(window.navigator && window.navigator.cookieEnabled);
return !!(navigator && navigator.cookieEnabled);
}
}

View file

@ -1,4 +1,3 @@
import window from 'window';
import { isStorageSupported } from 'Storage/RainLoop';
import { CLIENT_SIDE_STORAGE_INDEX_NAME } from 'Common/Consts';
@ -22,13 +21,13 @@ class LocalStorageDriver {
let storageResult = null;
try {
const storageValue = this.s.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null;
storageResult = null === storageValue ? null : window.JSON.parse(storageValue);
storageResult = null === storageValue ? null : JSON.parse(storageValue);
} catch (e) {} // eslint-disable-line no-empty
(storageResult || (storageResult = {}))[key] = data;
try {
this.s.setItem(CLIENT_SIDE_STORAGE_INDEX_NAME, window.JSON.stringify(storageResult));
this.s.setItem(CLIENT_SIDE_STORAGE_INDEX_NAME, JSON.stringify(storageResult));
return true;
} catch (e) {} // eslint-disable-line no-empty
@ -46,7 +45,7 @@ class LocalStorageDriver {
try {
const storageValue = this.s.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null,
storageResult = null === storageValue ? null : window.JSON.parse(storageValue);
storageResult = null === storageValue ? null : JSON.parse(storageValue);
return storageResult && undefined !== storageResult[key] ? storageResult[key] : null;
} catch (e) {} // eslint-disable-line no-empty

View file

@ -1,16 +1,13 @@
import window from 'window';
import $ from '$';
import key from 'key';
import ko from 'ko';
import { KeyState } from 'Common/Enums';
const $win = $(window);
const $win = jQuery(window);
$win.__sizes = [0, 0];
export { $win };
export const $html = $('html');
export const $htmlCL = window.document.documentElement.classList;
export const $html = jQuery('html');
export const $htmlCL = document.documentElement.classList;
/**
* @type {boolean}
@ -31,7 +28,7 @@ export const useKeyboardShortcuts = ko.observable(true);
* @type {string}
*/
const sUserAgent =
('navigator' in window && 'userAgent' in window.navigator && window.navigator.userAgent.toLowerCase()) || '';
('navigator' in window && 'userAgent' in navigator && navigator.userAgent.toLowerCase()) || '';
/**
* @type {boolean}
@ -189,7 +186,7 @@ export const keyScope = ko.computed({
});
keyScopeReal.subscribe((value) => {
// window.console.log('keyScope=' + sValue); // DEBUG
// console.log('keyScope=' + sValue); // DEBUG
key.setScope(value);
});

View file

@ -1,5 +1,3 @@
import window from 'window';
import $ from '$';
import { htmlEditorDefaultConfig, htmlEditorLangsMap } from 'Common/Globals';
import { EventKeyCode, Magics } from 'Common/Enums';
import * as Settings from 'Storage/Settings';
@ -32,7 +30,7 @@ class HtmlEditor {
this.onModeChange = onModeChange;
this.element = element;
this.$element = $(element);
this.$element = jQuery(element);
// throttle
var t, o = this;
@ -56,8 +54,8 @@ class HtmlEditor {
blurTrigger() {
if (this.onBlur) {
window.clearTimeout(this.blurTimer);
this.blurTimer = window.setTimeout(() => {
clearTimeout(this.blurTimer);
this.blurTimer = setTimeout(() => {
this.runOnBlur();
}, Magics.Time200ms);
}
@ -65,7 +63,7 @@ class HtmlEditor {
focusTrigger() {
if (this.onBlur) {
window.clearTimeout(this.blurTimer);
clearTimeout(this.blurTimer);
}
}
@ -275,10 +273,10 @@ class HtmlEditor {
this.editor.on('drop', (event) => {
if (0 < event.data.dataTransfer.getFilesCount()) {
const file = event.data.dataTransfer.getFile(0);
if (file && window.FileReader && event.data.dataTransfer.id && file.type && file.type.match(/^image/i)) {
if (file && event.data.dataTransfer.id && file.type && file.type.match(/^image/i)) {
const id = event.data.dataTransfer.id,
imageId = `[img=${id}]`,
reader = new window.FileReader();
reader = new FileReader();
reader.onloadend = () => {
if (reader.result) {

View file

@ -1,4 +1,3 @@
import window from 'window';
// let rainloopCaches = window.caches && window.caches.open ? window.caches : null;
@ -12,9 +11,8 @@ export function jassl(src, async = false) {
throw new Error('src should not be empty.');
}
return new window.Promise((resolve, reject) => {
const doc = window.document,
element = doc.createElement('script');
return new Promise((resolve, reject) => {
const element = document.createElement('script');
element.onload = () => {
resolve(src);
@ -27,7 +25,7 @@ export function jassl(src, async = false) {
element.async = !!async;
element.src = src;
doc.body.appendChild(element);
document.body.appendChild(element);
}) /* .then((s) => {
const found = s && rainloopCaches ? s.match(/rainloop\/v\/([^\/]+)\/static\//) : null;

View file

@ -1,4 +1,3 @@
import window from 'window';
import { pString, pInt, isNormal } from 'Common/Utils';
import * as Settings from 'Storage/Settings';
@ -160,7 +159,7 @@ export function append() {
* @returns {string}
*/
export function change(email) {
return serverRequest('Change') + window.encodeURIComponent(email) + '/';
return serverRequest('Change') + encodeURIComponent(email) + '/';
}
/**
@ -204,7 +203,7 @@ export function messageDownloadLink(requestHash) {
* @returns {string}
*/
export function avatarLink(email) {
return SERVER_PREFIX + '/Raw/0/Avatar/' + window.encodeURIComponent(email) + '/';
return SERVER_PREFIX + '/Raw/0/Avatar/' + encodeURIComponent(email) + '/';
}
/**
@ -231,7 +230,7 @@ export function userBackground(hash) {
* @returns {string}
*/
export function langLink(lang, isAdmin) {
return SERVER_PREFIX + '/Lang/0/' + (isAdmin ? 'Admin' : 'App') + '/' + window.encodeURI(lang) + '/' + VERSION + '/';
return SERVER_PREFIX + '/Lang/0/' + (isAdmin ? 'Admin' : 'App') + '/' + encodeURI(lang) + '/' + VERSION + '/';
}
/**
@ -310,7 +309,7 @@ export function themePreviewLink(theme) {
prefix = WEB_PREFIX;
}
return prefix + 'themes/' + window.encodeURI(theme) + '/images/preview.png';
return prefix + 'themes/' + encodeURI(theme) + '/images/preview.png';
}
/**
@ -373,7 +372,7 @@ export function mailBox(folder, page = 1, search = '', threadUid = '') {
if (folder) {
const resultThreadUid = pInt(threadUid);
result += window.encodeURI(folder) + (0 < resultThreadUid ? '~' + resultThreadUid : '');
result += encodeURI(folder) + (0 < resultThreadUid ? '~' + resultThreadUid : '');
}
if (1 < page) {
@ -383,7 +382,7 @@ export function mailBox(folder, page = 1, search = '', threadUid = '') {
if (search) {
result = result.replace(/[/]+$/, '');
result += '/' + window.encodeURI(search);
result += '/' + encodeURI(search);
}
return result;

View file

@ -1,5 +1,3 @@
import window from 'window';
import $ from '$';
import { i18n } from 'Common/Translator';
let _moment = null;
@ -98,7 +96,7 @@ export function format(timeStampInUTC, formatStr) {
export function momentToNode(element) {
let key = '',
time = 0;
const $el = $(element);
const $el = jQuery(element);
time = $el.data('moment-time');
if (time) {
@ -119,7 +117,7 @@ export function momentToNode(element) {
*/
export function reload() {
setTimeout(() =>
$('.moment', window.document).each((index, item) => {
jQuery('.moment', document).each((index, item) => {
momentToNode(item);
})
, 1);

View file

@ -1,5 +1,3 @@
import $ from '$';
import key from 'key';
import ko from 'ko';
import { EventKeyCode } from 'Common/Enums';
@ -274,7 +272,7 @@ class Selector {
this.oContentScrollable = contentScrollable ? contentScrollable[0] : null;
if (this.oContentVisible && this.oContentScrollable) {
$(this.oContentVisible)
jQuery(this.oContentVisible)
.on('selectstart', (event) => {
if (event && event.preventDefault) {
event.preventDefault();
@ -513,7 +511,7 @@ class Selector {
const offset = 20,
list = this.list(),
$focused = $(this.sItemFocusedSelector, this.oContentScrollable),
$focused = jQuery(this.sItemFocusedSelector, this.oContentScrollable),
pos = $focused.position(),
visibleHeight = this.oContentVisible.height(),
focusedHeight = $focused.outerHeight();

View file

@ -1,5 +1,3 @@
import window from 'window';
import $ from '$';
import ko from 'ko';
import { Notification, UploadErrorCode } from 'Common/Enums';
import { pInt } from 'Common/Utils';
@ -109,7 +107,7 @@ export function i18n(key, valueList, defaulValue) {
}
const i18nToNode = (element) => {
const $el = $(element),
const $el = jQuery(element),
key = $el.data('i18n');
if (key) {
@ -138,7 +136,7 @@ const i18nToNode = (element) => {
*/
export function i18nToNodes(elements) {
setTimeout(() =>
$('[data-i18n]', elements).each((index, item) => {
jQuery('[data-i18n]', elements).each((index, item) => {
i18nToNode(item);
})
, 1);
@ -148,7 +146,7 @@ const reloadData = () => {
if (window.rainloopI18N) {
I18N_DATA = window.rainloopI18N || {};
i18nToNodes(window.document);
i18nToNodes(document);
momentorReload();
trigger(!trigger());
@ -196,12 +194,12 @@ export function initOnStartOrLangChange(startCallback, langCallback = null) {
* @returns {string}
*/
export function getNotification(code, message = '', defCode = null) {
code = window.parseInt(code, 10) || 0;
code = parseInt(code, 10) || 0;
if (Notification.ClientViewError === code && message) {
return message;
}
defCode = defCode ? window.parseInt(defCode, 10) || 0 : 0;
defCode = defCode ? parseInt(defCode, 10) || 0 : 0;
return undefined === I18N_NOTIFICATION_DATA[code]
? defCode && undefined === I18N_NOTIFICATION_DATA[defCode]
? I18N_NOTIFICATION_DATA[defCode]
@ -226,7 +224,7 @@ export function getNotificationFromResponse(response, defCode = Notification.Unk
*/
export function getUploadErrorDescByCode(code) {
let result = '';
switch (window.parseInt(code, 10) || 0) {
switch (parseInt(code, 10) || 0) {
case UploadErrorCode.FileIsTooBig:
result = i18n('UPLOAD/ERROR_FILE_IS_TOO_BIG');
break;
@ -263,7 +261,7 @@ export function reload(admin, language) {
$htmlCL.add('rl-changing-language');
return new Promise((resolve, reject) => {
return window.fetch(langLink(language, admin), {cache: 'reload'})
return fetch(langLink(language, admin), {cache: 'reload'})
.then(response => {
if (response.ok) {
const type = response.headers.get('Content-Type');
@ -276,9 +274,9 @@ export function reload(admin, language) {
reject(new Error(error.message))
})
.then(data => {
var doc = window.document, script = doc.createElement('script');
var script = document.createElement('script');
script.text = data;
doc.head.appendChild(script).parentNode.removeChild(script);
document.head.appendChild(script).parentNode.removeChild(script);
setTimeout(
() => {
reloadData();

View file

@ -1,5 +1,3 @@
import window from 'window';
import $ from '$';
import ko from 'ko';
import { $win, dropdownVisibility, data as GlobalsData } from 'Common/Globals';
@ -7,9 +5,9 @@ import { ComposeType, SaveSettingsStep, FolderType } from 'Common/Enums';
import { Mime } from 'Common/Mime';
const
$ = jQuery,
$div = $('<div></div>'),
isArray = Array.isArray,
decodeURIComponent = component => window.decodeURIComponent(component);
isArray = Array.isArray;
var htmlspecialchars = ((de,se,gt,lt,sq,dq,bt) => {
return (str, quote_style = 3, double_encode = true) => {
@ -50,8 +48,8 @@ export function isPosNumeric(value, includeZero = true) {
* @returns {number}
*/
export function pInt(value, defaultValur = 0) {
const result = isNormal(value) && value ? window.parseInt(value, 10) : defaultValur;
return window.isNaN(result) ? defaultValur : result;
const result = isNormal(value) && value ? parseInt(value, 10) : defaultValur;
return isNaN(result) ? defaultValur : result;
}
/**
@ -98,7 +96,7 @@ export function fakeMd5(len = 32) {
let result = '';
while (result.length < len) {
result += line.substr(window.Math.round(window.Math.random() * lineLen), 1);
result += line.substr(Math.round(Math.random() * lineLen), 1);
}
return result;
@ -148,8 +146,8 @@ const timeOutAction = (() => {
const timeOuts = {};
return (action, fFunction, timeOut) => {
timeOuts[action] = undefined === timeOuts[action] ? 0 : timeOuts[action];
window.clearTimeout(timeOuts[action]);
timeOuts[action] = window.setTimeout(fFunction, timeOut);
clearTimeout(timeOuts[action]);
timeOuts[action] = setTimeout(fFunction, timeOut);
};
})();
@ -168,14 +166,14 @@ export function deModule(m) {
*/
export function inFocus() {
try {
if (window.document.activeElement) {
if (undefined === window.document.activeElement.__inFocusCache) {
window.document.activeElement.__inFocusCache = $(window.document.activeElement).is(
if (document.activeElement) {
if (undefined === document.activeElement.__inFocusCache) {
document.activeElement.__inFocusCache = $(document.activeElement).is(
'input,textarea,iframe,.cke_editable'
);
}
return !!window.document.activeElement.__inFocusCache;
return !!document.activeElement.__inFocusCache;
}
} catch (e) {} // eslint-disable-line no-empty
@ -187,13 +185,11 @@ export function inFocus() {
* @returns {void}
*/
export function removeInFocus(force) {
if (window.document && window.document.activeElement && window.document.activeElement.blur) {
if (document.activeElement && document.activeElement.blur) {
try {
const activeEl = $(window.document.activeElement);
if (activeEl && activeEl.is('input,textarea')) {
window.document.activeElement.blur();
} else if (force) {
window.document.activeElement.blur();
const activeEl = $(document.activeElement);
if (force || (activeEl && activeEl.is('input,textarea'))) {
document.activeElement.blur();
}
} catch (e) {} // eslint-disable-line no-empty
}
@ -204,14 +200,7 @@ export function removeInFocus(force) {
*/
export function removeSelection() {
try {
if (window && window.getSelection) {
const sel = window.getSelection();
if (sel && sel.removeAllRanges) {
sel.removeAllRanges();
}
} else if (window.document && window.document.selection && window.document.selection.empty) {
window.document.selection.empty();
}
getSelection().removeAllRanges();
} catch (e) {} // eslint-disable-line no-empty
}
@ -264,7 +253,7 @@ export function replySubjectAdd(prefix, subject) {
* @returns {number}
*/
export function roundNumber(num, dec) {
return window.Math.round(num * window.Math.pow(10, dec)) / window.Math.pow(10, dec);
return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
}
/**
@ -287,15 +276,6 @@ export function friendlySize(sizeInBytes) {
return sizeInBytes + 'B';
}
/**
* @param {string} desc
*/
export function log(desc) {
if (window.console && window.console.log) {
window.console.log(desc);
}
}
/**
* @param {?} object
* @param {string} methodName
@ -429,7 +409,7 @@ export function previewMessage(
isHtml,
print
) {
const win = window.open(''),
const win = open(''),
doc = win.document,
bodyClone = body.clone(),
bodyClass = isHtml ? 'html' : 'plain';
@ -456,7 +436,7 @@ export function previewMessage(
doc.close();
if (print) {
window.setTimeout(() => win.print(), 100);
setTimeout(() => win.print(), 100);
}
}
@ -830,7 +810,7 @@ export function folderListOptionsBuilder(
aResult.push({
id: oItem.fullNameRaw,
name:
new window.Array(oItem.deep + 1 - iUnDeep).join(sDeepPrefix) +
new Array(oItem.deep + 1 - iUnDeep).join(sDeepPrefix) +
(fRenameCallback ? fRenameCallback(oItem) : oItem.name()),
system: false,
seporator: false,
@ -869,20 +849,11 @@ export function folderListOptionsBuilder(
* @returns {void}
*/
export function selectElement(element) {
let sel = null,
range = null;
if (window.getSelection) {
sel = window.getSelection();
sel.removeAllRanges();
range = window.document.createRange();
range.selectNodeContents(element);
sel.addRange(range);
} else if (window.document.selection) {
range = window.document.body.createTextRange();
range.moveToElementText(element);
range.select();
}
let sel = getSelection(),
range = document.createRange();
sel.removeAllRanges();
range.selectNodeContents(element);
sel.addRange(range);
}
var dv;
@ -975,7 +946,7 @@ let __themeTimer = 0,
export function changeTheme(value, themeTrigger = ()=>{}) {
const themeLink = $('#app-theme-link'),
clearTimer = () => {
__themeTimer = window.setTimeout(() => themeTrigger(SaveSettingsStep.Idle), 1000);
__themeTimer = setTimeout(() => themeTrigger(SaveSettingsStep.Idle), 1000);
__themeAjax = null;
};
@ -995,7 +966,7 @@ export function changeTheme(value, themeTrigger = ()=>{}) {
url += 'Json/';
}
window.clearTimeout(__themeTimer);
clearTimeout(__themeTimer);
themeTrigger(SaveSettingsStep.Animate);
@ -1004,10 +975,10 @@ export function changeTheme(value, themeTrigger = ()=>{}) {
}
let init = {};
if (window.AbortController) {
__themeAjax = new window.AbortController();
__themeAjax = new AbortController();
init.signal = __themeAjax.signal;
}
window.fetch(url, init)
fetch(url, init)
.then(response => response.json())
.then(data => {
if (data && isArray(data) && 2 === data.length) {
@ -1163,11 +1134,11 @@ export function isTransparent(color) {
* @param {Function} fCallback
*/
export function resizeAndCrop(url, value, fCallback) {
const img = new window.Image();
const img = new Image();
img.onload = function() {
let diff = [0, 0];
const canvas = window.document.createElement('canvas'),
const canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d');
canvas.width = value;
@ -1264,23 +1235,6 @@ export function mailToHelper(mailToUrl, PopupComposeViewModel) {
return false;
}
/**
* @param {Function} fn
* @returns {void}
*/
export function domReady(fn) {
$(() => fn());
//
// if ('loading' !== window.document.readyState)
// {
// fn();
// }
// else
// {
// window.document.addEventListener('DOMContentLoaded', fn);
// }
}
var wr;
export const windowResize = timeout => {
wr && clearTimeout(wr);
@ -1298,12 +1252,12 @@ export function windowResizeCallback() {
windowResize();
}
let substr = window.String.substr;
let substr = String.substr;
if ('b' !== 'ab'.substr(-1)) {
substr = (str, start, length) => {
start = 0 > start ? str.length + start : start;
return str.substr(start, length);
};
window.String.substr = substr;
String.substr = substr;
}