mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
changeTheme() to ES2015
removed ancient String.substr
This commit is contained in:
parent
53451a1236
commit
578925c904
3 changed files with 34 additions and 69 deletions
16
README.md
16
README.md
|
|
@ -80,23 +80,23 @@ Things might work in Edge 18, Firefox 50-62 and Chrome 54-68 due to one polyfill
|
||||||
|
|
||||||
|js/* |1.14.0 |native |
|
|js/* |1.14.0 |native |
|
||||||
|----------- |--------: |--------: |
|
|----------- |--------: |--------: |
|
||||||
|admin.js |2.130.942 |1.061.841 |
|
|admin.js |2.130.942 |1.056.416 |
|
||||||
|app.js |4.184.455 |2.732.920 |
|
|app.js |4.184.455 |2.727.475 |
|
||||||
|boot.js | 671.522 | 43.995 |
|
|boot.js | 671.522 | 43.856 |
|
||||||
|libs.js | 647.614 | 317.218 |
|
|libs.js | 647.614 | 317.218 |
|
||||||
|polyfills.js | 325.834 | 0 |
|
|polyfills.js | 325.834 | 0 |
|
||||||
|TOTAL |7.960.367 |4.155.974 |
|
|TOTAL |7.960.367 |4.144.965 |
|
||||||
|
|
||||||
|js/min/* |1.14.0 |native |gzip 1.14 |gzip |
|
|js/min/* |1.14.0 |native |gzip 1.14 |gzip |
|
||||||
|--------------- |--------: |--------: |--------: |--------: |
|
|--------------- |--------: |--------: |--------: |--------: |
|
||||||
|admin.min.js | 252.147 | 144.802 | 73.657 | 41.416 |
|
|admin.min.js | 252.147 | 144.091 | 73.657 | 41.256 |
|
||||||
|app.min.js | 511.202 | 366.677 |140.462 | 96.593 |
|
|app.min.js | 511.202 | 365.966 |140.462 | 96.362 |
|
||||||
|boot.min.js | 66.007 | 5.579 | 22.567 | 2.328 |
|
|boot.min.js | 66.007 | 5.579 | 22.567 | 2.328 |
|
||||||
|libs.min.js | 572.545 | 300.771 |176.720 | 92.928 |
|
|libs.min.js | 572.545 | 300.771 |176.720 | 92.928 |
|
||||||
|polyfills.min.js | 32.452 | 0 | 11.312 | 0 |
|
|polyfills.min.js | 32.452 | 0 | 11.312 | 0 |
|
||||||
|TOTAL |1.434.353 | 817.829 |424.718 |233.265 |
|
|TOTAL |1.434.353 | 816.407 |424.718 |232.874 |
|
||||||
|
|
||||||
614.743 bytes (191.108 gzip) is not much, but it feels faster.
|
617.946 bytes (191.844 gzip) is not much, but it feels faster.
|
||||||
|
|
||||||
|
|
||||||
|css/* |1.14.0 |native |
|
|css/* |1.14.0 |native |
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { ComposeType, SaveSettingsStep, FolderType } from 'Common/Enums';
|
||||||
import { Mime } from 'Common/Mime';
|
import { Mime } from 'Common/Mime';
|
||||||
|
|
||||||
const
|
const
|
||||||
|
doc = document,
|
||||||
$ = jQuery,
|
$ = jQuery,
|
||||||
$div = $('<div></div>'),
|
$div = $('<div></div>'),
|
||||||
isArray = Array.isArray,
|
isArray = Array.isArray,
|
||||||
|
|
@ -137,14 +138,14 @@ export function deModule(m) {
|
||||||
*/
|
*/
|
||||||
export function inFocus() {
|
export function inFocus() {
|
||||||
try {
|
try {
|
||||||
if (document.activeElement) {
|
if (doc.activeElement) {
|
||||||
if (undefined === document.activeElement.__inFocusCache) {
|
if (undefined === doc.activeElement.__inFocusCache) {
|
||||||
document.activeElement.__inFocusCache = $(document.activeElement).is(
|
doc.activeElement.__inFocusCache = $(doc.activeElement).is(
|
||||||
'input,textarea,iframe,.cke_editable'
|
'input,textarea,iframe,.cke_editable'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return !!document.activeElement.__inFocusCache;
|
return !!doc.activeElement.__inFocusCache;
|
||||||
}
|
}
|
||||||
} catch (e) {} // eslint-disable-line no-empty
|
} catch (e) {} // eslint-disable-line no-empty
|
||||||
|
|
||||||
|
|
@ -156,11 +157,11 @@ export function inFocus() {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
export function removeInFocus(force) {
|
export function removeInFocus(force) {
|
||||||
if (document.activeElement && document.activeElement.blur) {
|
if (doc.activeElement && doc.activeElement.blur) {
|
||||||
try {
|
try {
|
||||||
const activeEl = $(document.activeElement);
|
const activeEl = $(doc.activeElement);
|
||||||
if (force || (activeEl && activeEl.is('input,textarea'))) {
|
if (force || (activeEl && activeEl.is('input,textarea'))) {
|
||||||
document.activeElement.blur();
|
doc.activeElement.blur();
|
||||||
}
|
}
|
||||||
} catch (e) {} // eslint-disable-line no-empty
|
} catch (e) {} // eslint-disable-line no-empty
|
||||||
}
|
}
|
||||||
|
|
@ -325,9 +326,7 @@ export function draggablePlace() {
|
||||||
*/
|
*/
|
||||||
export function defautOptionsAfterRender(domItem, item) {
|
export function defautOptionsAfterRender(domItem, item) {
|
||||||
if (item && undefined !== item.disabled && domItem) {
|
if (item && undefined !== item.disabled && domItem) {
|
||||||
$(domItem)
|
domItem.classList.toggle('disabled', domItem.disabled = item.disabled);
|
||||||
.toggleClass('disabled', item.disabled)
|
|
||||||
.prop('disabled', item.disabled);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -792,7 +791,7 @@ export function folderListOptionsBuilder(
|
||||||
*/
|
*/
|
||||||
export function selectElement(element) {
|
export function selectElement(element) {
|
||||||
let sel = getSelection(),
|
let sel = getSelection(),
|
||||||
range = document.createRange();
|
range = doc.createRange();
|
||||||
sel.removeAllRanges();
|
sel.removeAllRanges();
|
||||||
range.selectNodeContents(element);
|
range.selectNodeContents(element);
|
||||||
sel.addRange(range);
|
sel.addRange(range);
|
||||||
|
|
@ -806,9 +805,7 @@ export const detectDropdownVisibility = (()=>
|
||||||
* @param {boolean=} delay = false
|
* @param {boolean=} delay = false
|
||||||
*/
|
*/
|
||||||
export function triggerAutocompleteInputChange(delay = false) {
|
export function triggerAutocompleteInputChange(delay = false) {
|
||||||
const fFunc = () => {
|
const fFunc = () => $('.checkAutocomplete').trigger('change');
|
||||||
$('.checkAutocomplete').trigger('change');
|
|
||||||
};
|
|
||||||
|
|
||||||
if (delay) {
|
if (delay) {
|
||||||
setTimeout(fFunc, 100);
|
setTimeout(fFunc, 100);
|
||||||
|
|
@ -851,25 +848,6 @@ export function delegateRunOnDestroy(objectOrObjects) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {object} $styleTag
|
|
||||||
* @param {string} css
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
export function appendStyles($styleTag, css) {
|
|
||||||
if ($styleTag && $styleTag[0]) {
|
|
||||||
if ($styleTag[0].styleSheet && undefined !== $styleTag[0].styleSheet.cssText) {
|
|
||||||
$styleTag[0].styleSheet.cssText = css;
|
|
||||||
} else {
|
|
||||||
$styleTag.text(css);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let __themeTimer = 0,
|
let __themeTimer = 0,
|
||||||
__themeAjax = null;
|
__themeAjax = null;
|
||||||
|
|
||||||
|
|
@ -879,23 +857,20 @@ let __themeTimer = 0,
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
export function changeTheme(value, themeTrigger = ()=>{}) {
|
export function changeTheme(value, themeTrigger = ()=>{}) {
|
||||||
const themeLink = $('#app-theme-link'),
|
const themeLink = doc.getElementById('app-theme-link'),
|
||||||
clearTimer = () => {
|
clearTimer = () => {
|
||||||
__themeTimer = setTimeout(() => themeTrigger(SaveSettingsStep.Idle), 1000);
|
__themeTimer = setTimeout(() => themeTrigger(SaveSettingsStep.Idle), 1000);
|
||||||
__themeAjax = null;
|
__themeAjax = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
let themeStyle = $('#app-theme-style'),
|
let themeStyle = doc.getElementById('app-theme-style'),
|
||||||
url = themeLink.attr('href');
|
url = (themeLink && themeLink.href) || (themeStyle && themeStyle.dataset.href);
|
||||||
|
|
||||||
if (!url) {
|
|
||||||
url = themeStyle.attr('data-href');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
url = url.toString().replace(/\/-\/[^/]+\/-\//, '/-/' + value + '/-/');
|
url = url.toString()
|
||||||
url = url.replace(/\/Css\/[^/]+\/User\//, '/Css/0/User/');
|
.replace(/\/-\/[^/]+\/-\//, '/-/' + value + '/-/')
|
||||||
url = url.replace(/\/Hash\/[^/]+\//, '/Hash/-/');
|
.replace(/\/Css\/[^/]+\/User\//, '/Css/0/User/')
|
||||||
|
.replace(/\/Hash\/[^/]+\//, '/Hash/-/');
|
||||||
|
|
||||||
if ('Json/' !== url.substring(url.length - 5, url.length)) {
|
if ('Json/' !== url.substring(url.length - 5, url.length)) {
|
||||||
url += 'Json/';
|
url += 'Json/';
|
||||||
|
|
@ -917,16 +892,17 @@ export function changeTheme(value, themeTrigger = ()=>{}) {
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data && isArray(data) && 2 === data.length) {
|
if (data && isArray(data) && 2 === data.length) {
|
||||||
if (themeLink && themeLink[0] && (!themeStyle || !themeStyle[0])) {
|
if (themeLink && !themeStyle) {
|
||||||
themeStyle = $('<style id="app-theme-style"></style>');
|
themeStyle = doc.createElement('style');
|
||||||
|
themeStyle.id = 'app-theme-style';
|
||||||
themeLink.after(themeStyle);
|
themeLink.after(themeStyle);
|
||||||
themeLink.remove();
|
themeLink.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (themeStyle && themeStyle[0]) {
|
if (themeStyle) {
|
||||||
if (appendStyles(themeStyle, data[1])) {
|
themeStyle.textContent = data[1];
|
||||||
themeStyle.attr('data-href', url).attr('data-theme', data[0]);
|
themeStyle.dataset.href = url;
|
||||||
}
|
themeStyle.dataset.theme = data[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
themeTrigger(SaveSettingsStep.TrueResult);
|
themeTrigger(SaveSettingsStep.TrueResult);
|
||||||
|
|
@ -1073,7 +1049,7 @@ export function resizeAndCrop(url, value, fCallback) {
|
||||||
img.onload = function() {
|
img.onload = function() {
|
||||||
let diff = [0, 0];
|
let diff = [0, 0];
|
||||||
|
|
||||||
const canvas = document.createElement('canvas'),
|
const canvas = doc.createElement('canvas'),
|
||||||
ctx = canvas.getContext('2d');
|
ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
canvas.width = value;
|
canvas.width = value;
|
||||||
|
|
@ -1169,13 +1145,3 @@ export function mailToHelper(mailToUrl, PopupComposeViewModel) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
};
|
|
||||||
|
|
||||||
String.substr = substr;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,6 @@ function writeCSS(css) {
|
||||||
const style = doc.createElement('style');
|
const style = doc.createElement('style');
|
||||||
style.type = 'text/css';
|
style.type = 'text/css';
|
||||||
style.textContent = css;
|
style.textContent = css;
|
||||||
// style.appendChild(doc.createTextNode(styles));
|
|
||||||
doc.head.appendChild(style);
|
doc.head.appendChild(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue