Upgraded some old JavaScript to ECMAScript 1.6

Removed some jQuery references
Added JavaScript Globals.$htmlCL for frequently used window.document.documentElement.classList
This commit is contained in:
djmaze 2020-07-15 14:25:51 +02:00
parent a6a337e5ce
commit 0b0747b8dc
19 changed files with 142 additions and 151 deletions

View file

@ -66,17 +66,11 @@ function getComputedStyle(id, name) {
* @returns {void}
*/
function includeStyle(styles) {
const style = window.document.createElement('style');
const doc = window.document, style = doc.createElement('style');
style.type = 'text/css';
style.text = styles;
if (style.styleSheet) {
style.styleSheet.cssText = styles;
} else {
style.appendChild(window.document.createTextNode(styles));
}
window.document.getElementsByTagName('head')[0].appendChild(style);
style.textContent = styles;
// style.appendChild(doc.createTextNode(styles));
doc.head.appendChild(style);
}
/**
@ -84,11 +78,10 @@ function includeStyle(styles) {
* @returns {void}
*/
function includeScr(src) {
const script = window.document.createElement('script');
const doc = window.document, script = doc.createElement('script');
script.type = 'text/javascript';
script.src = src;
window.document.getElementsByTagName('head')[0].appendChild(script);
doc.head.appendChild(script);
}
/**
@ -219,6 +212,7 @@ function runApp() {
jassl &&
progressJs &&
appData &&
appData.TemplatesLink &&
appData.LangLink &&
appData.StaticLibJsLink &&
appData.StaticAppJsLink &&
@ -232,15 +226,12 @@ function runApp() {
const libs = () =>
jassl(appData.StaticLibJsLink).then(() => {
if (window.$) {
window.$('#rl-check').remove();
}
window.document.getElementById('rl-check').remove();
if (appData.IncludeBackground) {
const img = appData.IncludeBackground.replace('{{USER}}', window.__rlah ? window.__rlah() || '0' : '0'),
b = window.document.body;
const img = appData.IncludeBackground.replace('{{USER}}', window.__rlah ? window.__rlah() || '0' : '0');
if (img) {
b.classList.add('UserBackground');
b.style.backgroundImage = "url("+img+")";
window.document.documentElement.classList.add('UserBackground');
window.document.body.style.backgroundImage = "url("+img+")";
}
}
});
@ -248,7 +239,7 @@ function runApp() {
libs()
.then(() => {
p.set(20);
return jassl(appData.LangLink);
return window.Promise.all([jassl(appData.TemplatesLink), jassl(appData.LangLink)]);
})
.then(() => {
p.set(30);

View file

@ -10,9 +10,8 @@ $win.__sizes = [0, 0];
export { $win };
export const $doc = $(window.document);
export const $html = $('html');
export const $htmlCL = window.document.documentElement.classList;
export const $body = $('body');
@ -71,7 +70,7 @@ export const bMobileDevice = (/android|iphone|ipod|ipad|blackberry|mobile/i).tes
* @type {boolean}
*/
export const bAnimationSupported =
!bMobileDevice && $html.hasClass('csstransitions') && $html.hasClass('cssanimations');
!bMobileDevice && $htmlCL.contains('csstransitions') && $htmlCL.contains('cssanimations');
/**
* @type {boolean}
@ -200,7 +199,7 @@ export const popupVisibilityNames = ko.observableArray([]);
export const popupVisibility = ko.computed(() => 0 < popupVisibilityNames().length);
popupVisibility.subscribe((bValue) => {
$html.toggleClass('rl-modal', bValue);
$htmlCL.toggle('rl-modal', bValue);
});
// keys

View file

@ -4,7 +4,7 @@ import $ from '$';
import ko from 'ko';
import { Notification, UploadErrorCode } from 'Common/Enums';
import { pInt, isUnd, isNull, has, microtime, inArray } from 'Common/Utils';
import { $html, bAnimationSupported } from 'Common/Globals';
import { $html, $htmlCL, bAnimationSupported } from 'Common/Globals';
import { reload as momentorReload } from 'Common/Momentor';
import { langLink } from 'Common/Links';
@ -272,7 +272,7 @@ export function getUploadErrorDescByCode(code) {
export function reload(admin, language) {
const start = microtime();
$html.addClass('rl-changing-language');
$htmlCL.add('rl-changing-language');
return new window.Promise((resolve, reject) => {
$.ajax({
@ -287,11 +287,9 @@ export function reload(admin, language) {
const isRtl = -1 < inArray((language || '').toLowerCase(), ['ar', 'ar_sa', 'he', 'he_he', 'ur', 'ur_ir']);
$html
.removeClass('rl-changing-language')
.removeClass('rl-rtl rl-ltr')
// .attr('dir', isRtl ? 'rtl' : 'ltr')
.addClass(isRtl ? 'rl-rtl' : 'rl-ltr');
$htmlCL.remove('rl-changing-language', 'rl-rtl', 'rl-ltr');
// $html.attr('dir', isRtl ? 'rtl' : 'ltr')
$htmlCL.add(isRtl ? 'rl-rtl' : 'rl-ltr');
resolve();
},
@ -299,7 +297,7 @@ export function reload(admin, language) {
);
},
() => {
$html.removeClass('rl-changing-language');
$htmlCL.remove('rl-changing-language');
window.rainloopI18N = null;
reject();
}
@ -308,4 +306,4 @@ export function reload(admin, language) {
}
// init section
$html.addClass('rl-' + ($html.attr('dir') || 'ltr'));
$htmlCL.add('rl-' + ($html.attr('dir') || 'ltr'));

View file

@ -1449,10 +1449,10 @@ export function domReady(fn) {
export const windowResize = _.debounce((timeout) => {
if (isUnd(timeout) || isNull(timeout)) {
$win.resize();
$win.trigger('resize');
} else {
window.setTimeout(() => {
$win.resize();
$win.trigger('resize');
}, timeout);
}
}, 50);