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

@ -7,8 +7,7 @@ import ssm from 'ssm';
import {
$win,
$html,
$doc,
$htmlCL,
leftPanelDisabled,
leftPanelType,
sUserAgent,
@ -43,7 +42,7 @@ class AbstractApp extends AbstractBoot {
this.iframe = $('<iframe class="internal-hiddden" />').appendTo('body');
$win.on('resize', () => {
window.addEventListener('resize', () => {
Events.pub('window.resize');
});
@ -72,24 +71,21 @@ class AbstractApp extends AbstractBoot {
// }
// });
const $doc = $(window.document);
$doc
.on('keydown', (event) => {
if (event && event.ctrlKey) {
$html.addClass('rl-ctrl-key-pressed');
$htmlCL.add('rl-ctrl-key-pressed');
}
})
.on('keyup', (event) => {
if (event && !event.ctrlKey) {
$html.removeClass('rl-ctrl-key-pressed');
$htmlCL.remove('rl-ctrl-key-pressed');
}
});
$doc.on(
'mousemove keypress click',
_.debounce(() => {
})
.on('mousemove keypress click', _.debounce(() => {
Events.pub('rl.auto-logout-refresh');
}, Magics.Time5s)
);
}, Magics.Time5s));
key('esc, enter', KeyState.All, () => {
detectDropdownVisibility();
@ -265,17 +261,17 @@ class AbstractApp extends AbstractBoot {
});
if (!mobile) {
$html.addClass('rl-desktop');
$htmlCL.add('rl-desktop');
ssm.addState({
id: 'mobile',
query: '(max-width: 767px)',
onEnter: () => {
$html.addClass('ssm-state-mobile');
$htmlCL.add('ssm-state-mobile');
Events.pub('ssm.mobile-enter');
},
onLeave: () => {
$html.removeClass('ssm-state-mobile');
$htmlCL.remove('ssm-state-mobile');
Events.pub('ssm.mobile-leave');
}
});
@ -284,10 +280,10 @@ class AbstractApp extends AbstractBoot {
id: 'tablet',
query: '(min-width: 768px) and (max-width: 999px)',
onEnter: () => {
$html.addClass('ssm-state-tablet');
$htmlCL.add('ssm-state-tablet');
},
onLeave: () => {
$html.removeClass('ssm-state-tablet');
$htmlCL.remove('ssm-state-tablet');
}
});
@ -295,10 +291,10 @@ class AbstractApp extends AbstractBoot {
id: 'desktop',
query: '(min-width: 1000px) and (max-width: 1400px)',
onEnter: () => {
$html.addClass('ssm-state-desktop');
$htmlCL.add('ssm-state-desktop');
},
onLeave: () => {
$html.removeClass('ssm-state-desktop');
$htmlCL.remove('ssm-state-desktop');
}
});
@ -306,25 +302,25 @@ class AbstractApp extends AbstractBoot {
id: 'desktop-large',
query: '(min-width: 1401px)',
onEnter: () => {
$html.addClass('ssm-state-desktop-large');
$htmlCL.add('ssm-state-desktop-large');
},
onLeave: () => {
$html.removeClass('ssm-state-desktop-large');
$htmlCL.remove('ssm-state-desktop-large');
}
});
} else {
$html.addClass('ssm-state-mobile').addClass('rl-mobile');
$htmlCL.add('ssm-state-mobile', 'rl-mobile');
Events.pub('ssm.mobile-enter');
}
leftPanelDisabled.subscribe((bValue) => {
$html.toggleClass('rl-left-panel-disabled', bValue);
$html.toggleClass('rl-left-panel-enabled', !bValue);
$htmlCL.toggle('rl-left-panel-disabled', bValue);
$htmlCL.toggle('rl-left-panel-enabled', !bValue);
});
leftPanelType.subscribe((sValue) => {
$html.toggleClass('rl-left-panel-none', 'none' === sValue);
$html.toggleClass('rl-left-panel-short', 'short' === sValue);
$htmlCL.toggle('rl-left-panel-none', 'none' === sValue);
$htmlCL.toggle('rl-left-panel-short', 'short' === sValue);
});
leftPanelDisabled.valueHasMutated();

View file

@ -34,7 +34,7 @@ import {
Magics
} from 'Common/Enums';
import { $html, leftPanelWidth, leftPanelDisabled, bMobileDevice } from 'Common/Globals';
import { $htmlCL, leftPanelWidth, leftPanelDisabled, bMobileDevice } from 'Common/Globals';
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { runHook } from 'Common/Plugins';
@ -146,11 +146,10 @@ class AppUser extends AbstractApp {
if (Settings.settingsGet('UserBackgroundHash')) {
_.delay(() => {
const img = userBackground(Settings.settingsGet('UserBackgroundHash')),
b = window.document.body;
const img = userBackground(Settings.settingsGet('UserBackgroundHash'));
if (img) {
b.classList.add('UserBackground');
b.style.backgroundImage = "url("+img+")";
$htmlCL.add('UserBackground');
window.document.body.style.backgroundImage = "url("+img+")";
}
}, Magics.Time1s);
}
@ -904,25 +903,25 @@ class AppUser extends AbstractApp {
$(event.target)
.find('.ui-resizable-handle')
.on('mousedown', () => {
$html.addClass('rl-resizer');
$htmlCL.add('rl-resizer');
})
.on('mouseup', () => {
$html.removeClass('rl-resizer');
$htmlCL.remove('rl-resizer');
});
}
},
fResizeStartFunction = () => {
$html.addClass('rl-resizer');
$htmlCL.add('rl-resizer');
},
fResizeResizeFunction = _.debounce(
() => {
$html.addClass('rl-resizer');
$htmlCL.add('rl-resizer');
},
500,
true
),
fResizeStopFunction = (oEvent, oObject) => {
$html.removeClass('rl-resizer');
$htmlCL.remove('rl-resizer');
if (oObject && oObject.size && oObject.size.height) {
Local.set(sClientSideKeyName, oObject.size.height);
@ -950,7 +949,7 @@ class AppUser extends AbstractApp {
if (bottom) {
bottom.removeAttr('style');
}
} else if ($html.hasClass('rl-bottom-preview-pane')) {
} else if ($htmlCL.contains('rl-bottom-preview-pane')) {
top = $('.b-message-list-wrapper');
bottom = $('.b-message-view-wrapper');
@ -980,7 +979,7 @@ class AppUser extends AbstractApp {
if (iWidth) {
leftPanelWidth(iWidth);
$html.removeClass('rl-resizer');
$htmlCL.remove('rl-resizer');
lLeft.css({
width: '' + iWidth + 'px'
@ -1006,25 +1005,25 @@ class AppUser extends AbstractApp {
$(event.target)
.find('.ui-resizable-handle')
.on('mousedown', () => {
$html.addClass('rl-resizer');
$htmlCL.add('rl-resizer');
})
.on('mouseup', () => {
$html.removeClass('rl-resizer');
$htmlCL.remove('rl-resizer');
});
}
},
fResizeResizeFunction = _.debounce(
() => {
$html.addClass('rl-resizer');
$htmlCL.add('rl-resizer');
},
500,
true
),
fResizeStartFunction = () => {
$html.addClass('rl-resizer');
$htmlCL.add('rl-resizer');
},
fResizeStopFunction = (event, obj) => {
$html.removeClass('rl-resizer');
$htmlCL.remove('rl-resizer');
if (obj && obj.size && obj.size.width) {
Local.set(sClientSideKeyName, obj.size.width);
@ -1086,7 +1085,8 @@ class AppUser extends AbstractApp {
}
bootstartLoginScreen() {
$html.removeClass('rl-user-auth').addClass('rl-user-no-auth');
$htmlCL.remove('rl-user-auth');
$htmlCL.add('rl-user-no-auth');
const customLoginLink = pString(Settings.appSettingsGet('customLoginLink'));
if (!customLoginLink) {
@ -1135,7 +1135,7 @@ class AppUser extends AbstractApp {
this.setWindowTitle('');
if (Settings.settingsGet('Auth')) {
$html.addClass('rl-user-auth');
$htmlCL.add('rl-user-auth');
if (
Settings.capa(Capa.TwoFactor) &&