Get rid of jQuery.wakup

Get rid of jQuery UI resizable (use HTML5 with ResizeObserver/MutationObserver, work-in-progress not as beautiful yet)
Get rid of hidden download() iframe
This commit is contained in:
djmaze 2020-07-16 19:49:56 +02:00
parent fca0bb5d56
commit e3aaea8035
9 changed files with 121 additions and 1483 deletions

View file

@ -1,5 +1,4 @@
import window from 'window'; import window from 'window';
import $ from '$';
import _ from '_'; import _ from '_';
import ko from 'ko'; import ko from 'ko';
import key from 'key'; import key from 'key';
@ -10,7 +9,6 @@ import {
$htmlCL, $htmlCL,
leftPanelDisabled, leftPanelDisabled,
leftPanelType, leftPanelType,
sUserAgent,
bMobileDevice, bMobileDevice,
bAnimationSupported bAnimationSupported
} from 'Common/Globals'; } from 'Common/Globals';
@ -37,11 +35,8 @@ class AbstractApp extends AbstractBoot {
super(); super();
this.isLocalAutocomplete = true; this.isLocalAutocomplete = true;
this.iframe = null;
this.lastErrorTime = 0; this.lastErrorTime = 0;
this.iframe = $('<iframe class="internal-hiddden" />').appendTo('body');
window.addEventListener('resize', () => { window.addEventListener('resize', () => {
Events.pub('window.resize'); Events.pub('window.resize');
}); });
@ -71,21 +66,23 @@ class AbstractApp extends AbstractBoot {
// } // }
// }); // });
const $doc = $(window.document); const $doc = window.document;
$doc $doc.addEventListener('keydown', (event) => {
.on('keydown', (event) => { if (event && event.ctrlKey) {
if (event && event.ctrlKey) { $htmlCL.add('rl-ctrl-key-pressed');
$htmlCL.add('rl-ctrl-key-pressed'); }
} });
}) $doc.addEventListener('keyup', (event) => {
.on('keyup', (event) => { if (event && !event.ctrlKey) {
if (event && !event.ctrlKey) { $htmlCL.remove('rl-ctrl-key-pressed');
$htmlCL.remove('rl-ctrl-key-pressed'); }
} });
}) const fn = _.debounce(() => {
.on('mousemove keypress click', _.debounce(() => { Events.pub('rl.auto-logout-refresh');
Events.pub('rl.auto-logout-refresh'); }, Magics.Time5s);
}, Magics.Time5s)); $doc.addEventListener('mousemove', fn);
$doc.addEventListener('keypress', fn);
$doc.addEventListener('click', fn);
key('esc, enter', KeyState.All, () => { key('esc, enter', KeyState.All, () => {
detectDropdownVisibility(); detectDropdownVisibility();
@ -109,28 +106,16 @@ class AbstractApp extends AbstractBoot {
* @returns {boolean} * @returns {boolean}
*/ */
download(link) { download(link) {
if (sUserAgent && (-1 < sUserAgent.indexOf('chrome') || -1 < sUserAgent.indexOf('chrome'))) {
const oLink = window.document.createElement('a');
oLink.href = link;
if (window.document && window.document.createEvent) {
const oE = window.document.createEvent.MouseEvents;
if (oE && oE.initEvent && oLink.dispatchEvent) {
oE.initEvent('click', true, true);
oLink.dispatchEvent(oE);
return true;
}
}
}
if (bMobileDevice) { if (bMobileDevice) {
window.open(link, '_self'); window.open(link, '_self');
window.focus(); window.focus();
} else { } else {
this.iframe.attr('src', link); const oLink = window.document.createElement('a');
// window.document.location.href = link; oLink.href = link;
window.document.body.appendChild(oLink).click();
oLink.remove();
// window.open(link, '_self');
} }
return true; return true;
} }
@ -143,7 +128,6 @@ class AbstractApp extends AbstractBoot {
title += (title ? ' - ' : '') + Settings.settingsGet('Title'); title += (title ? ' - ' : '') + Settings.settingsGet('Title');
} }
window.document.title = title + ' ...';
window.document.title = title; window.document.title = title;
} }

View file

@ -1,6 +1,5 @@
import window from 'window'; import window from 'window';
import _ from '_'; import _ from '_';
import $ from '$';
import progressJs from 'progressJs'; import progressJs from 'progressJs';
import { import {
@ -18,7 +17,6 @@ import {
pString, pString,
delegateRunOnDestroy, delegateRunOnDestroy,
mailToHelper, mailToHelper,
windowResize,
jassl jassl
} from 'Common/Utils'; } from 'Common/Utils';
@ -34,7 +32,7 @@ import {
Magics Magics
} from 'Common/Enums'; } from 'Common/Enums';
import { $htmlCL, leftPanelWidth, leftPanelDisabled, bMobileDevice } from 'Common/Globals'; import { $htmlCL, leftPanelDisabled, bMobileDevice } from 'Common/Globals';
import { UNUSED_OPTION_VALUE } from 'Common/Consts'; import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { runHook } from 'Common/Plugins'; import { runHook } from 'Common/Plugins';
@ -124,21 +122,23 @@ class AppUser extends AbstractApp {
Magics.Time5m Magics.Time5m
); );
$.wakeUp( // wakeUp
() => { const interval = Magics.Time60m;
var lastTime = (new Date()).getTime();
setInterval(() => {
const currentTime = (new Date()).getTime();
if (currentTime > (lastTime + interval + 1000)) {
if (checkTimestamp()) { if (checkTimestamp()) {
this.reload(); this.reload();
} }
Remote.jsVersion((sResult, oData) => { Remote.jsVersion((sResult, oData) => {
if (StorageResultType.Success === sResult && oData && !oData.Result) { if (StorageResultType.Success === sResult && oData && !oData.Result) {
this.reload(); this.reload();
} }
}, Settings.appSettingsGet('version')); }, Settings.appSettingsGet('version'));
}, }
{}, lastTime = currentTime;
Magics.Time60m }, interval);
);
if (checkTimestamp()) { if (checkTimestamp()) {
this.reload(); this.reload();
@ -881,84 +881,49 @@ class AppUser extends AbstractApp {
Local.set(ClientSideKeyName.ExpandedFolders, aExpandedList); Local.set(ClientSideKeyName.ExpandedFolders, aExpandedList);
} }
initHorizontalLayoutResizer(sClientSideKeyName) { initHorizontalLayoutResizer() {
let top = null, let top = null,
bottom = null; bottom = null,
observer = null;
const minHeight = 200, const
maxHeight = 500,
fSetHeight = (height) => {
if (height) {
if (top) {
top.attr('style', 'height:' + height + 'px');
}
if (bottom) {
bottom.attr('style', 'top:' + (55 /* top toolbar */ + height) + 'px');
}
}
},
fResizeCreateFunction = (event) => {
if (event && event.target) {
$(event.target)
.find('.ui-resizable-handle')
.on('mousedown', () => {
$htmlCL.add('rl-resizer');
})
.on('mouseup', () => {
$htmlCL.remove('rl-resizer');
});
}
},
fResizeStartFunction = () => {
$htmlCL.add('rl-resizer');
},
fResizeResizeFunction = _.debounce(
() => {
$htmlCL.add('rl-resizer');
},
500,
true
),
fResizeStopFunction = (oEvent, oObject) => {
$htmlCL.remove('rl-resizer');
if (oObject && oObject.size && oObject.size.height) {
Local.set(sClientSideKeyName, oObject.size.height);
fSetHeight(oObject.size.height);
windowResize();
}
},
oOptions = {
helper: 'ui-resizable-helper-h',
minHeight: minHeight,
maxHeight: maxHeight,
handles: 's',
create: fResizeCreateFunction,
resize: fResizeResizeFunction,
start: fResizeStartFunction,
stop: fResizeStopFunction
},
fDisable = (bDisable) => { fDisable = (bDisable) => {
if (bDisable) { if (bDisable) {
if (top && top.hasClass('ui-resizable')) { if (observer) {
top.resizable('destroy').removeAttr('style'); observer.disconnect();
} top.removeAttribute('style');
top.classList.remove('resizable');
if (bottom) { bottom.removeAttribute('style');
bottom.removeAttr('style');
} }
} else if ($htmlCL.contains('rl-bottom-preview-pane')) { } else if ($htmlCL.contains('rl-bottom-preview-pane')) {
top = $('.b-message-list-wrapper'); top = window.document.querySelector('.b-message-list-wrapper');
bottom = $('.b-message-view-wrapper'); bottom = window.document.querySelector('.b-message-view-wrapper');
if (top && bottom) {
if (!top.hasClass('ui-resizable')) { top.classList.add('resizable');
top.resizable(oOptions); if (window.ResizeObserver) {
if (!observer) {
observer = new window.ResizeObserver(entries => {
entries.forEach(entry => {
if (entry.target === top) {
bottom.style.top = (56 + entry.borderBoxSize.blockSize) + 'px';
}
});
});
}
observer.observe(top);
} else {
if (!observer) {
observer = new window.MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.target === top && 'style' == mutation.attributeName) {
bottom.style.top = (56 + top.offsetHeight) + 'px';
}
});
});
}
observer.observe(top, { attributes: true });
}
} }
const iHeight = pInt(Local.get(sClientSideKeyName)) || 300;
fSetHeight(iHeight > minHeight ? iHeight : minHeight);
} }
}; };
@ -969,93 +934,51 @@ class AppUser extends AbstractApp {
}); });
} }
initVerticalLayoutResizer(sClientSideKeyName) { initVerticalLayoutResizer() {
const disabledWidth = 60, let rlLeft = null,
minWidth = 155, rlRight = null,
lLeft = $('#rl-left'), observer = null;
right = $('#rl-right'),
mLeftWidth = Local.get(sClientSideKeyName) || null,
fSetWidth = (iWidth) => {
if (iWidth) {
leftPanelWidth(iWidth);
$htmlCL.remove('rl-resizer'); const
lLeft.css({
width: '' + iWidth + 'px'
});
right.css({
left: '' + iWidth + 'px'
});
}
},
fDisable = (bDisable) => { fDisable = (bDisable) => {
if (bDisable) { if (bDisable) {
lLeft.resizable('disable'); if (observer) {
fSetWidth(disabledWidth); observer.disconnect();
}
rlLeft.classList.remove('resizable');
rlLeft.removeAttribute('style');
rlRight.removeAttribute('style');
} else { } else {
lLeft.resizable('enable'); rlLeft = window.document.getElementById('rl-left');
const width = pInt(Local.get(sClientSideKeyName)) || minWidth; rlRight = window.document.getElementById('rl-right');
fSetWidth(width > minWidth ? width : minWidth); if (rlLeft && rlRight) {
} rlLeft.classList.add('resizable');
}, rlLeft.removeAttribute('style');
fResizeCreateFunction = (event) => { rlRight.removeAttribute('style');
if (event && event.target) { if (window.ResizeObserver) {
$(event.target) let observer = new window.ResizeObserver(entries => {
.find('.ui-resizable-handle') entries.forEach(entry => {
.on('mousedown', () => { if (entry.target === rlLeft) {
$htmlCL.add('rl-resizer'); rlRight.style.left = entry.borderBoxSize.inlineSize + 'px';
}) }
.on('mouseup', () => { });
$htmlCL.remove('rl-resizer'); });
}); observer.observe(rlLeft);
} } else {
}, let observer = new window.MutationObserver(mutations => {
fResizeResizeFunction = _.debounce( mutations.forEach(mutation => {
() => { if (mutation.target === rlLeft && 'style' == mutation.attributeName) {
$htmlCL.add('rl-resizer'); rlRight.style.left = rlLeft.offsetWidth + 'px';
}, }
500, });
true });
), observer.observe(rlLeft, { attributes: true });
fResizeStartFunction = () => { }
$htmlCL.add('rl-resizer'); }
},
fResizeStopFunction = (event, obj) => {
$htmlCL.remove('rl-resizer');
if (obj && obj.size && obj.size.width) {
Local.set(sClientSideKeyName, obj.size.width);
leftPanelWidth(obj.size.width);
right.css({
left: '' + obj.size.width + 'px'
});
lLeft.css({
position: '',
top: '',
left: '',
height: ''
});
} }
}; };
if (null !== mLeftWidth) { fDisable(false);
fSetWidth(mLeftWidth > minWidth ? mLeftWidth : minWidth);
}
lLeft.resizable({
helper: 'ui-resizable-helper-w',
minWidth: minWidth,
maxWidth: Magics.Size350px,
handles: 'e',
create: fResizeCreateFunction,
resize: fResizeResizeFunction,
start: fResizeStartFunction,
stop: fResizeStopFunction
});
Events.sub('left-panel.off', () => { Events.sub('left-panel.off', () => {
fDisable(true); fDisable(true);

View file

@ -53,6 +53,19 @@ html.rl-mobile {
min-width: 60px; min-width: 60px;
} }
html:not(.rl-left-panel-disabled) #rl-left.resizable {
resize: horizontal;
overflow: hidden;
min-width: 155px;
max-width: 350px;
}
.b-message-list-wrapper.resizable {
resize: vertical;
overflow: hidden;
min-height: 200px;
max-height: 500px;
}
#rl-right { #rl-right {
.g-ui-absolute-reset; .g-ui-absolute-reset;
@ -271,21 +284,6 @@ html.rl-left-panel-none {
} }
} }
.ui-resizable-helper-w {
border-right: 5px solid #777;
border-right-color: rgba(255,255,255,0.7);
}
.ui-resizable-helper-h {
border-bottom: 5px solid #ccc;
border-bottom-color: rgba(0,0,0,0.3);
}
.ui-resizable-handle:hover {
background: #aaa;
background: rgba(255,255,255,0.5);
}
html.rl-no-preview-pane { html.rl-no-preview-pane {
#rl-sub-left { #rl-sub-left {
@ -300,10 +298,6 @@ html.rl-no-preview-pane {
#rl-sub-right { #rl-sub-right {
left: 0 !important; left: 0 !important;
} }
#rl-right .ui-resizable-handle {
display: none !important;
}
} }
html.rl-side-preview-pane #rl-right .ui-resizable-handle { html.rl-side-preview-pane #rl-right .ui-resizable-handle {

View file

@ -103,11 +103,6 @@
height: 100%; height: 100%;
} }
.g-ui-resizable-delimiter-highlight {
border: none;
border-right: 6px solid #aaa;
}
.e-pagenator { .e-pagenator {
.e-page { .e-page {
@ -131,10 +126,6 @@
} }
} }
html.rgba .g-ui-resizable-delimiter-highlight {
border-right-color: rgba(0, 0, 0, 0.2);
}
.settings-saved-trigger { .settings-saved-trigger {
display: inline-block; display: inline-block;

View file

@ -12,11 +12,6 @@
min-width: 300px; min-width: 300px;
} }
.ui-resizable-e {
right: -1px;
width: 5px;
}
.pswp__error-msg { .pswp__error-msg {
color: #ccc; color: #ccc;
a, a:hover { a, a:hover {

View file

@ -75,7 +75,6 @@ config.paths.js = {
src: [ src: [
'node_modules/jquery/dist/jquery.min.js', 'node_modules/jquery/dist/jquery.min.js',
'vendors/jquery-ui/js/jquery-ui-1.12.1.custom.min.js', // custom 'vendors/jquery-ui/js/jquery-ui-1.12.1.custom.min.js', // custom
'vendors/jquery-wakeup/jquery.wakeup.js', // no-npm
'vendors/jquery-letterfx/jquery-letterfx.min.js', // no-npm 'vendors/jquery-letterfx/jquery-letterfx.min.js', // no-npm
'vendors/inputosaurus/inputosaurus.js', // custom (modified) 'vendors/inputosaurus/inputosaurus.js', // custom (modified)
'vendors/routes/signals.min.js', // fixed 'vendors/routes/signals.min.js', // fixed

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -1,70 +0,0 @@
/*!
* jQuery WakeUp plugin
*
* A JQuery plugin that will help detecting waking up from sleep and/or
* hibernation and executing assigned functions.
*
* Based on code provided by Andrew Mu:
* http://stackoverflow.com/questions/4079115
*
* Copyright (c) 2013, Paul Okopny <paul.okopny@gmail.com>
* https://bitbucket.org/paul.okopny/jquery.wakeup-plugin
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
(function ($, document, undefined) {
var default_wakeup_interval = 1000;
var wake_up_ids = new Array();
// returns intervalId, which can be used to cancel future waking
$.wakeUp = function (on_wakeup, params, interval) {
if ((!interval) || typeof(interval) !== 'number' ){
interval = default_wakeup_interval;
};
// on_wakeup should be a function
if (typeof(on_wakeup) !== "function") {
return null;
}
var lastTime = (new Date()).getTime();
var intervalId = setInterval(function() {
var currentTime = (new Date()).getTime();
if (currentTime > (lastTime + interval + 1000)) { //
var sleepTime = currentTime - lastTime;
lastTime = currentTime;
if (params) {
on_wakeup(sleepTime, params);} else {on_wakeup(sleepTime); }
} else {lastTime = currentTime;}
}, interval);
//add interval id to wake_up_ids array
wake_up_ids.push(intervalId);
return intervalId;
};
$.ignoreBell = function(interval_id) {
if (interval_id) {
// delete only one wakeUp call
wake_up_ids.splice($.inArray(interval_id, wake_up_ids),1);
clearInterval(interval_id);
};
};
$.dreamOn = function() {
// delete all current wake Up calls
$.each(wake_up_ids, function(index_of, interval_id) {
clearInterval(interval_id)
});
wake_up_ids = new Array();
};
})(jQuery, document);