es5 -> es2015 (last stage)

Signature plugin fixes
Add view decorator
A large number of fixes
This commit is contained in:
RainLoop Team 2016-08-17 01:01:20 +03:00
parent e88c193334
commit 17669b7be0
153 changed files with 21193 additions and 21115 deletions

View file

@ -39,7 +39,6 @@ class Audio
if (this.supported)
{
$(this.player).on('ended error', () => this.stop());
Events.sub('audio.api.stop', () => this.stop());
}
}

View file

@ -1,11 +1,11 @@
/* global RL_ES6 */
import window from 'window';
import progressJs from 'progressJs';
import Promise from 'Promise';
import STYLES_CSS from 'Styles/@Boot.css';
import LAYOUT_HTML from 'Html/Layout.html';
import {jassl} from 'Common/Jassl';
import {getHash, setHash, clearHash} from 'Storage/RainLoop';
let RL_APP_DATA_STORAGE = null;
@ -64,7 +64,7 @@ class Q2 extends Q1 { constructor() { super() } }
*/
function getComputedStyle(id, name)
{
var element = window.document.getElementById(id);
const element = window.document.getElementById(id);
return element.currentStyle ? element.currentStyle[name] :
(window.getComputedStyle ? window.getComputedStyle(element, null).getPropertyValue(name) : null);
}
@ -94,14 +94,11 @@ function includeLayout()
{
const app = window.document.getElementById('rl-app');
if (STYLES_CSS)
{
includeStyle(STYLES_CSS);
}
require('style-loader!Styles/@Boot.css');
if (app && LAYOUT_HTML)
if (app)
{
app.innerHTML = LAYOUT_HTML.replace(/[\r\n\t]+/g, '');
app.innerHTML = require('Html/Layout.html').replace(/[\r\n\t]+/g, '');
return true;
}
@ -223,7 +220,7 @@ function runApp()
{
const appData = window.__rlah_data();
if (window.jassl && progressJs && appData && appData.TemplatesLink && appData.LangLink &&
if (jassl && progressJs && appData && appData.TemplatesLink && appData.LangLink &&
appData.StaticLibJsLink && appData.StaticAppJsLink && appData.StaticAppJsNextLink && appData.StaticEditorJsLink)
{
const p = progressJs;
@ -232,7 +229,7 @@ function runApp()
p.start().set(5);
const
libs = window.jassl(appData.StaticLibJsLink).then(() => {
libs = jassl(appData.StaticLibJsLink).then(() => {
if (window.$)
{
window.$('#rl-check').remove();
@ -247,18 +244,18 @@ function runApp()
}
}),
common = Promise.all([
window.jassl(appData.TemplatesLink),
window.jassl(appData.LangLink)
jassl(appData.TemplatesLink),
jassl(appData.LangLink)
]);
Promise.all([libs, common])
.then(() => {
p.set(30);
return window.jassl(useJsNextBundle ? appData.StaticAppJsNextLink : appData.StaticAppJsLink);
return jassl(useJsNextBundle ? appData.StaticAppJsNextLink : appData.StaticAppJsLink);
})
.then(() => {
p.set(50);
return appData.PluginsLink ? window.jassl(appData.PluginsLink) : window.Promise.resolve();
return appData.PluginsLink ? jassl(appData.PluginsLink) : window.Promise.resolve();
})
.then(() => {
p.set(70);
@ -268,7 +265,7 @@ function runApp()
runMainBoot(true);
throw e;
})
.then(() => window.jassl(appData.StaticEditorJsLink))
.then(() => jassl(appData.StaticEditorJsLink))
.then(() => {
if (window.CKEDITOR && window.__initEditor) {
window.__initEditor();
@ -320,7 +317,7 @@ window.__runBoot = function() {
window.document.location.replace('./?/NoCookie');
}
const root = document.documentElement;
const root = window.document.documentElement;
if ('none' !== getComputedStyle('rl-check', 'display'))
{
root.className += ' no-css';

View file

@ -1,4 +1,6 @@
/* global RL_COMMUNITY */
import window from 'window';
import _ from '_';
import $ from '$';
@ -167,9 +169,7 @@ let bAllowPdfPreview = !bMobileDevice;
if (bAllowPdfPreview && window.navigator && window.navigator.mimeTypes)
{
bAllowPdfPreview = !!_.find(window.navigator.mimeTypes, function(oType) {
return oType && 'application/pdf' === oType.type;
});
bAllowPdfPreview = !!_.find(window.navigator.mimeTypes, (type) => type && 'application/pdf' === type.type);
if (!bAllowPdfPreview)
{
@ -203,33 +203,29 @@ export const keyScopeReal = ko.observable(KeyState.All);
export const keyScopeFake = ko.observable(KeyState.All);
export const keyScope = ko.computed({
owner: this,
read: () => keyScopeFake(),
write: function(sValue) {
write: (value) => {
if (KeyState.Menu !== sValue)
if (KeyState.Menu !== value)
{
if (KeyState.Compose === sValue)
if (KeyState.Compose === value)
{
// disableKeyFilter
key.filter = function() {
return useKeyboardShortcuts();
};
key.filter = () => useKeyboardShortcuts();
}
else
{
// restoreKeyFilter
key.filter = function(event) {
key.filter = (event) => {
if (useKeyboardShortcuts())
{
var
oElement = event.target || event.srcElement,
sTagName = oElement ? oElement.tagName : '';
const
el = event.target || event.srcElement,
tagName = el ? el.tagName.toUpperCase() : '';
sTagName = sTagName.toUpperCase();
return !('INPUT' === sTagName || 'SELECT' === sTagName || 'TEXTAREA' === sTagName ||
(oElement && 'DIV' === sTagName && ('editorHtmlArea' === oElement.className || 'true' === '' + oElement.contentEditable))
return !('INPUT' === tagName || 'SELECT' === tagName || 'TEXTAREA' === tagName ||
(el && 'DIV' === tagName && ('editorHtmlArea' === el.className || 'true' === '' + el.contentEditable))
);
}
@ -237,24 +233,24 @@ export const keyScope = ko.computed({
};
}
keyScopeFake(sValue);
keyScopeFake(value);
if (dropdownVisibility())
{
sValue = KeyState.Menu;
value = KeyState.Menu;
}
}
keyScopeReal(sValue);
keyScopeReal(value);
}
});
keyScopeReal.subscribe(function(sValue) {
keyScopeReal.subscribe((value) => {
// window.console.log('keyScope=' + sValue); // DEBUG
key.setScope(sValue);
key.setScope(value);
});
dropdownVisibility.subscribe(function(bValue) {
if (bValue)
dropdownVisibility.subscribe((value) => {
if (value)
{
keyScope(KeyState.Menu);
}

View file

@ -87,20 +87,11 @@ class HtmlEditor
}
}
/**
* @param {string} text
* @returns {string}
*/
clearSignatureSigns(text) {
return text.replace(/(\u200C|\u0002)/g, '');
}
/**
* @param {boolean=} wrapIsHtml = false
* @param {boolean=} clearSignatureSigns = false
* @returns {string}
*/
getData(wrapIsHtml = false, clearSignatureSigns = false) {
getData(wrapIsHtml = false) {
let result = '';
if (this.editor)
@ -119,11 +110,6 @@ class HtmlEditor
}
}
catch (e) {} // eslint-disable-line no-empty
if (clearSignatureSigns)
{
result = this.clearSignatureSigns(result);
}
}
return result;
@ -131,11 +117,10 @@ class HtmlEditor
/**
* @param {boolean=} wrapIsHtml = false
* @param {boolean=} clearSignatureSigns = false
* @returns {string}
*/
getDataWithHtmlMark(wrapIsHtml = false, clearSignatureSigns = false) {
return (this.isHtml() ? ':HTML:' : '') + this.getData(wrapIsHtml, clearSignatureSigns);
getDataWithHtmlMark(wrapIsHtml = false) {
return (this.isHtml() ? ':HTML:' : '') + this.getData(wrapIsHtml);
}
modeToggle(plain, resize) {
@ -149,12 +134,9 @@ class HtmlEditor
this.editor.setMode('wysiwyg');
}
}
else
else if ('wysiwyg' === this.editor.mode)
{
if ('wysiwyg' === this.editor.mode)
{
this.editor.setMode('plain');
}
this.editor.setMode('plain');
}
}
catch (e) {} // eslint-disable-line no-empty
@ -302,7 +284,7 @@ class HtmlEditor
if (file && window.FileReader && event.data.dataTransfer.id &&
file.type && file.type.match(/^image/i))
{
var
const
id = event.data.dataTransfer.id,
imageId = `[img=${id}]`,
reader = new window.FileReader();

54
dev/Common/Jassl.js Normal file
View file

@ -0,0 +1,54 @@
import window from 'window';
import Promise from 'Promise';
// let rainloopCaches = window.caches && window.caches.open ? window.caches : null;
/**
* @param {src} src
* @param {boolean} async = false
* @returns {Promise}
*/
export function jassl(src, async = false) {
if (!Promise || !Promise.all)
{
throw new Error('Promises are not available your environment.');
}
if (!src)
{
throw new Error('src should not be empty.');
}
return new Promise((resolve, reject) => {
const element = window.document.createElement('script');
element.onload = () => {
resolve(src);
};
element.onerror = () => {
reject(new Error(src));
};
element.async = true === async;
element.src = src;
window.document.body.appendChild(element);
})/* .then((s) => {
const found = s && rainloopCaches ? s.match(/rainloop\/v\/([^\/]+)\/static\//) : null;
if (found && found[1])
{
rainloopCaches.open('rainloop-offline-' + found[1]).then(
(cache) => cache.add(s)
).catch(() => {
rainloopCaches = null;
});
}
return s;
})*/;
}

View file

@ -125,9 +125,10 @@ export function format(timeStampInUTC, formatStr)
*/
export function momentToNode(element)
{
var
let
key = '',
time = 0,
time = 0;
const
$el = $(element);
time = $el.data('moment-time');

View file

@ -159,14 +159,16 @@ class Selector
this.list.subscribe((aItems) => {
var
oTemp = null,
bGetNext = false,
aUids = [],
mNextFocused = mFocused,
bChecked = false,
bSelected = false,
iLen = 0;
let
temp = null,
getNext = false,
isNextFocused = mFocused,
isChecked = false,
isSelected = false,
len = 0;
const
uids = [];
this.selectedItemUseCallback = false;
@ -175,37 +177,37 @@ class Selector
if (isArray(aItems))
{
iLen = aCheckedCache.length;
len = aCheckedCache.length;
_.each(aItems, (oItem) => {
_.each(aItems, (item) => {
var sUid = this.getItemUid(oItem);
aUids.push(sUid);
const uid = this.getItemUid(item);
uids.push(uid);
if (null !== mFocused && mFocused === sUid)
if (null !== mFocused && mFocused === uid)
{
this.focusedItem(oItem);
this.focusedItem(item);
mFocused = null;
}
if (0 < iLen && -1 < inArray(sUid, aCheckedCache))
if (0 < len && -1 < inArray(uid, aCheckedCache))
{
bChecked = true;
oItem.checked(true);
iLen -= 1;
isChecked = true;
item.checked(true);
len -= 1;
}
if (!bChecked && null !== mSelected && mSelected === sUid)
if (!isChecked && null !== mSelected && mSelected === uid)
{
bSelected = true;
this.selectedItem(oItem);
isSelected = true;
this.selectedItem(item);
mSelected = null;
}
});
this.selectedItemUseCallback = true;
if (!bChecked && !bSelected && this.autoSelect())
if (!isChecked && !isSelected && this.autoSelect())
{
if (this.focusedItem())
{
@ -213,53 +215,53 @@ class Selector
}
else if (0 < aItems.length)
{
if (null !== mNextFocused)
if (null !== isNextFocused)
{
bGetNext = false;
mNextFocused = _.find(aCache, (sUid) => {
if (bGetNext && -1 < inArray(sUid, aUids))
getNext = false;
isNextFocused = _.find(aCache, (sUid) => {
if (getNext && -1 < inArray(sUid, uids))
{
return sUid;
}
else if (mNextFocused === sUid)
else if (isNextFocused === sUid)
{
bGetNext = true;
getNext = true;
}
return false;
});
if (mNextFocused)
if (isNextFocused)
{
oTemp = _.find(aItems, (oItem) => mNextFocused === this.getItemUid(oItem));
temp = _.find(aItems, (oItem) => isNextFocused === this.getItemUid(oItem));
}
}
this.selectedItem(oTemp || null);
this.selectedItem(temp || null);
this.focusedItem(this.selectedItem());
}
}
if ((0 !== this.iSelectNextHelper || 0 !== this.iFocusedNextHelper) && 0 < aItems.length && !this.focusedItem())
{
oTemp = null;
temp = null;
if (0 !== this.iFocusedNextHelper)
{
oTemp = aItems[-1 === this.iFocusedNextHelper ? aItems.length - 1 : 0] || null;
temp = aItems[-1 === this.iFocusedNextHelper ? aItems.length - 1 : 0] || null;
}
if (!oTemp && 0 !== this.iSelectNextHelper)
if (!temp && 0 !== this.iSelectNextHelper)
{
oTemp = aItems[-1 === this.iSelectNextHelper ? aItems.length - 1 : 0] || null;
temp = aItems[-1 === this.iSelectNextHelper ? aItems.length - 1 : 0] || null;
}
if (oTemp)
if (temp)
{
if (0 !== this.iSelectNextHelper)
{
this.selectedItem(oTemp || null);
this.selectedItem(temp || null);
}
this.focusedItem(oTemp || null);
this.focusedItem(temp || null);
this.scrollToFocused();
@ -288,12 +290,9 @@ class Selector
(this.oCallbacks.onItemSelect || noop)(item || null);
}
}
else
else if (item)
{
if (item)
{
(this.oCallbacks.onItemSelect || noop)(item);
}
(this.oCallbacks.onItemSelect || noop)(item);
}
}
@ -446,62 +445,64 @@ class Selector
*/
newSelectPosition(iEventKeyCode, bShiftKey, bForceSelect) {
var
iIndex = 0,
iPageStep = 10,
bNext = false,
bStop = false,
oResult = null,
aList = this.list(),
iListLen = aList ? aList.length : 0,
oFocused = this.focusedItem();
let
index = 0,
isNext = false,
isStop = false,
result = null;
if (0 < iListLen)
const
pageStep = 10,
list = this.list(),
listLen = list ? list.length : 0,
focused = this.focusedItem();
if (0 < listLen)
{
if (!oFocused)
if (!focused)
{
if (EventKeyCode.Down === iEventKeyCode || EventKeyCode.Insert === iEventKeyCode ||
EventKeyCode.Space === iEventKeyCode || EventKeyCode.Home === iEventKeyCode ||
EventKeyCode.PageUp === iEventKeyCode)
{
oResult = aList[0];
result = list[0];
}
else if (EventKeyCode.Up === iEventKeyCode || EventKeyCode.End === iEventKeyCode ||
EventKeyCode.PageDown === iEventKeyCode)
{
oResult = aList[aList.length - 1];
result = list[list.length - 1];
}
}
else if (oFocused)
else if (focused)
{
if (EventKeyCode.Down === iEventKeyCode || EventKeyCode.Up === iEventKeyCode ||
EventKeyCode.Insert === iEventKeyCode || EventKeyCode.Space === iEventKeyCode)
{
_.each(aList, (item) => {
if (!bStop)
_.each(list, (item) => {
if (!isStop)
{
switch (iEventKeyCode)
{
case EventKeyCode.Up:
if (oFocused === item)
if (focused === item)
{
bStop = true;
isStop = true;
}
else
{
oResult = item;
result = item;
}
break;
case EventKeyCode.Down:
case EventKeyCode.Insert:
if (bNext)
if (isNext)
{
oResult = item;
bStop = true;
result = item;
isStop = true;
}
else if (oFocused === item)
else if (focused === item)
{
bNext = true;
isNext = true;
}
break;
// no default
@ -509,7 +510,7 @@ class Selector
}
});
if (!oResult && (EventKeyCode.Down === iEventKeyCode || EventKeyCode.Up === iEventKeyCode))
if (!result && (EventKeyCode.Down === iEventKeyCode || EventKeyCode.Up === iEventKeyCode))
{
this.doUpUpOrDownDown(EventKeyCode.Up === iEventKeyCode);
}
@ -518,35 +519,35 @@ class Selector
{
if (EventKeyCode.Home === iEventKeyCode)
{
oResult = aList[0];
result = list[0];
}
else if (EventKeyCode.End === iEventKeyCode)
{
oResult = aList[aList.length - 1];
result = list[list.length - 1];
}
}
else if (EventKeyCode.PageDown === iEventKeyCode)
{
for (; iIndex < iListLen; iIndex++)
for (; index < listLen; index++)
{
if (oFocused === aList[iIndex])
if (focused === list[index])
{
iIndex += iPageStep;
iIndex = iListLen - 1 < iIndex ? iListLen - 1 : iIndex;
oResult = aList[iIndex];
index += pageStep;
index = listLen - 1 < index ? listLen - 1 : index;
result = list[index];
break;
}
}
}
else if (EventKeyCode.PageUp === iEventKeyCode)
{
for (iIndex = iListLen; 0 <= iIndex; iIndex--)
for (index = listLen; 0 <= index; index--)
{
if (oFocused === aList[iIndex])
if (focused === list[index])
{
iIndex -= iPageStep;
iIndex = 0 > iIndex ? 0 : iIndex;
oResult = aList[iIndex];
index -= pageStep;
index = 0 > index ? 0 : index;
result = list[index];
break;
}
}
@ -554,45 +555,45 @@ class Selector
}
}
if (oResult)
if (result)
{
this.focusedItem(oResult);
this.focusedItem(result);
if (oFocused)
if (focused)
{
if (bShiftKey)
{
if (EventKeyCode.Up === iEventKeyCode || EventKeyCode.Down === iEventKeyCode)
{
oFocused.checked(!oFocused.checked());
focused.checked(!focused.checked());
}
}
else if (EventKeyCode.Insert === iEventKeyCode || EventKeyCode.Space === iEventKeyCode)
{
oFocused.checked(!oFocused.checked());
focused.checked(!focused.checked());
}
}
if ((this.autoSelect() || !!bForceSelect) &&
!this.isListChecked() && EventKeyCode.Space !== iEventKeyCode)
{
this.selectedItem(oResult);
this.selectedItem(result);
}
this.scrollToFocused();
}
else if (oFocused)
else if (focused)
{
if (bShiftKey && (EventKeyCode.Up === iEventKeyCode || EventKeyCode.Down === iEventKeyCode))
{
oFocused.checked(!oFocused.checked());
focused.checked(!focused.checked());
}
else if (EventKeyCode.Insert === iEventKeyCode || EventKeyCode.Space === iEventKeyCode)
{
oFocused.checked(!oFocused.checked());
focused.checked(!focused.checked());
}
this.focusedItem(oFocused);
this.focusedItem(focused);
}
}

View file

@ -6,6 +6,7 @@ import ko from 'ko';
import {$win, $div, dropdownVisibility, data as GlobalsData} from 'Common/Globals';
import {ComposeType, EventKeyCode, SaveSettingsStep, FolderType} from 'Common/Enums';
import {Mime} from 'Common/Mime';
import {jassl} from 'Common/Jassl';
import Autolinker from 'Autolinker';
@ -22,7 +23,7 @@ const noop = () => {}; // eslint-disable-line no-empty-function
const noopTrue = () => true;
const noopFalse = () => false;
export {trim, inArray, isArray, isObject, isFunc, isUnd, isNull, has, bind, noop, noopTrue, noopFalse};
export {trim, inArray, isArray, isObject, isFunc, isUnd, isNull, has, bind, noop, noopTrue, noopFalse, jassl};
/**
* @param {Function} func
@ -490,7 +491,7 @@ export function killCtrlACtrlS(event)
* @param {(Function|boolean|null)=} fCanExecute = true
* @returns {Function}
*/
export function createCommand(context, fExecute, fCanExecute = true)
export function createCommandLegacy(context, fExecute, fCanExecute = true)
{
let fResult = null;
const fNonEmpty = (...args) => {
@ -516,6 +517,16 @@ export function createCommand(context, fExecute, fCanExecute = true)
return fResult;
}
/**
* @param {Function} fExecute
* @param {(Function|boolean|null)=} fCanExecute = true
* @returns {Function}
*/
export function createCommand(fExecute, fCanExecute = true)
{
return createCommandLegacy(null, fExecute, fCanExecute);
}
/**
* @param {string} theme
* @returns {string}
@ -609,12 +620,13 @@ export function clearBqSwitcher(body)
}
/**
* @param {string} title
* @param {object} messageData
* @param {Object} body
* @param {boolean} isHtml
* @param {boolean} print
* @returns {void}
*/
export function previewMessage(title, body, isHtml, print)
export function previewMessage({title, subject, date, fromCreds, toCreds, toLabel}, body, isHtml, print)
{
const
win = window.open(''),
@ -626,81 +638,16 @@ export function previewMessage(title, body, isHtml, print)
const html = bodyClone ? bodyClone.html() : '';
title = encodeHtml(title);
doc.write(`<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="robots" content="noindex, nofollow, noodp" />
<title>${title}</title>
<style>
html, body {
background-color: #fff;
font-size: 13px;
font-family: arial, sans-serif;
}
a {color: blue; text-decoration: underline}
a:visited {color: #609}
a:active {color: red}
blockquote {border-left: 2px solid black; margin: 0; padding: 0px 10px}
pre {
margin: 0px;
padding: 0px;
font-family: Monaco, Menlo, Consolas, 'Courier New', monospace;
background: #fff;
border: none;
white-space: pre-wrap;
word-wrap: break-word;
word-break: break-all;
}
body.html pre {
font-family: Monaco, Menlo, Consolas, 'Courier New', monospace;
white-space: pre-wrap;
word-wrap: break-word;
word-break: normal;
}
body.plain {
padding: 15px;
white-space: pre-wrap;
font-family: Monaco, Menlo, Consolas, 'Courier New', monospace;
}
body.plain pre {
margin: 0px;
padding: 0px;
background: #fff;
border: none;
font-family: Monaco, Menlo, Consolas, 'Courier New', monospace;
white-space: pre-wrap;
word-wrap: break-word;
word-break: normal;
}
body.plain blockquote {
border-left: 2px solid blue;
color: blue;
}
body.plain blockquote blockquote {
border-left: 2px solid green;
color: green;
}
body.plain blockquote blockquote blockquote {
border-left: 2px solid red;
color: red;
}
</style>
</head>
<body class="${bodyClass}">${html}</body>
</html>`);
doc.write(require('Html/PreviewMessage.html')
.replace('{{title}}', encodeHtml(title))
.replace('{{subject}}', encodeHtml(subject))
.replace('{{date}}', encodeHtml(date))
.replace('{{fromCreds}}', encodeHtml(fromCreds))
.replace('{{toCreds}}', encodeHtml(toCreds))
.replace('{{toLabel}}', encodeHtml(toLabel))
.replace('{{bodyClass}}', bodyClass)
.replace('{{html}}', html)
);
doc.close();
@ -851,7 +798,6 @@ export function htmlToPlain(html)
convertLinks = (...args) => (args && 1 < args.length ? trim(args[1]) : '');
text = html
.replace(/\u0002([\s\S]*)\u0002/gm, '\u200C$1\u200C')
.replace(/<p[^>]*><\/p>/gi, '')
.replace(/<pre[^>]*>([\s\S\r\n\t]*)<\/pre>/gmi, convertPre)
.replace(/[\s]+/gm, ' ')
@ -1003,7 +949,6 @@ export function plainToHtml(plain, findEmailAndLinksInText = false)
.replace(/>/g, '&gt;').replace(/</g, '&lt;')
.replace(/~~~blockquote~~~[\s]*/g, '<blockquote>')
.replace(/[\s]*~~~\/blockquote~~~/g, '</blockquote>')
.replace(/\u200C([\s\S]*)\u200C/g, '\u0002$1\u0002')
.replace(/\n/g, '<br />');
return findEmailAndLinksInText ? findEmailAndLinks(plain) : plain;
@ -1520,7 +1465,7 @@ export function mimeContentType(fileName)
*/
export function resizeAndCrop(url, value, fCallback)
{
const img = new Image();
const img = new window.Image();
img.onload = function() {
let