2016-06-07 05:57:52 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/* global RL_COMMUNITY */
|
|
|
|
|
2016-07-02 06:49:59 +08:00
|
|
|
import window from 'window';
|
|
|
|
import _ from '_';
|
|
|
|
import $ from '$';
|
|
|
|
import key from 'key';
|
2016-06-07 05:57:52 +08:00
|
|
|
import ko from 'ko';
|
|
|
|
import {KeyState} from 'Common/Enums';
|
|
|
|
|
|
|
|
const $win = $(window);
|
|
|
|
$win.__sizes = [0, 0];
|
|
|
|
|
|
|
|
export {$win};
|
|
|
|
|
|
|
|
export const $doc = $(window.document);
|
|
|
|
|
|
|
|
export const $html = $('html');
|
|
|
|
|
|
|
|
export const $body = $('body');
|
|
|
|
|
|
|
|
export const $div = $('<div></div>');
|
|
|
|
|
2016-10-26 06:10:36 +08:00
|
|
|
export const $hcont = $('<div></div>');
|
|
|
|
$hcont.attr('area', 'hidden').css({position: 'absolute', left: -5000}).appendTo($body);
|
|
|
|
|
2016-06-07 05:57:52 +08:00
|
|
|
export const startMicrotime = (new window.Date()).getTime();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
export const community = RL_COMMUNITY;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {?}
|
|
|
|
*/
|
|
|
|
export const dropdownVisibility = ko.observable(false).extend({rateLimit: 0});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
export const useKeyboardShortcuts = ko.observable(true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
export const sUserAgent = 'navigator' in window && 'userAgent' in window.navigator &&
|
|
|
|
window.navigator.userAgent.toLowerCase() || '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2016-06-30 08:02:45 +08:00
|
|
|
export const bIE = -1 < sUserAgent.indexOf('msie');
|
2016-06-07 05:57:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2016-06-30 08:02:45 +08:00
|
|
|
export const bChrome = -1 < sUserAgent.indexOf('chrome');
|
2016-06-07 05:57:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2016-06-30 08:02:45 +08:00
|
|
|
export const bSafari = !bChrome && -1 < sUserAgent.indexOf('safari');
|
2016-06-07 05:57:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
export const bMobileDevice =
|
2016-06-30 08:02:45 +08:00
|
|
|
(/android/i).test(sUserAgent) ||
|
|
|
|
(/iphone/i).test(sUserAgent) ||
|
|
|
|
(/ipod/i).test(sUserAgent) ||
|
|
|
|
(/ipad/i).test(sUserAgent) ||
|
|
|
|
(/blackberry/i).test(sUserAgent);
|
2016-06-07 05:57:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2016-06-30 08:02:45 +08:00
|
|
|
export const bDisableNanoScroll = bMobileDevice;
|
2016-06-07 05:57:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2016-06-30 08:02:45 +08:00
|
|
|
export const bAnimationSupported = !bMobileDevice && $html.hasClass('csstransitions') && $html.hasClass('cssanimations');
|
2016-06-07 05:57:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
export const bXMLHttpRequestSupported = !!window.XMLHttpRequest;
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
export const bIsHttps = window.document && window.document.location ? 'https:' === window.document.location.protocol : false;
|
|
|
|
|
2016-06-07 05:57:52 +08:00
|
|
|
/**
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
2016-08-09 02:58:06 +08:00
|
|
|
export const htmlEditorDefaultConfig = {
|
2016-07-16 05:29:42 +08:00
|
|
|
'title': false,
|
|
|
|
'stylesSet': false,
|
|
|
|
'customConfig': '',
|
|
|
|
'contentsCss': '',
|
|
|
|
'toolbarGroups': [
|
2016-06-07 05:57:52 +08:00
|
|
|
{name: 'spec'},
|
|
|
|
{name: 'styles'},
|
|
|
|
{name: 'basicstyles', groups: ['basicstyles', 'cleanup', 'bidi']},
|
|
|
|
{name: 'colors'},
|
|
|
|
bMobileDevice ? {} : {name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align']},
|
|
|
|
{name: 'links'},
|
|
|
|
{name: 'insert'},
|
|
|
|
{name: 'document', groups: ['mode', 'document', 'doctools']},
|
|
|
|
{name: 'others'}
|
|
|
|
],
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
'removePlugins': 'liststyle',
|
|
|
|
'removeButtons': 'Format,Undo,Redo,Cut,Copy,Paste,Anchor,Strike,Subscript,Superscript,Image,SelectAll,Source',
|
|
|
|
'removeDialogTabs': 'link:advanced;link:target;image:advanced;images:advanced',
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
'extraPlugins': 'plain,signature',
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
'allowedContent': true,
|
|
|
|
'extraAllowedContent': true,
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
'fillEmptyBlocks': false,
|
|
|
|
'ignoreEmptyParagraph': true,
|
|
|
|
'disableNativeSpellChecker': false,
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2017-01-19 23:50:00 +08:00
|
|
|
'colorButton_enableAutomatic': false,
|
|
|
|
'colorButton_enableMore': true,
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
'font_defaultLabel': 'Arial',
|
|
|
|
'fontSize_defaultLabel': '13',
|
|
|
|
'fontSize_sizes': '10/10px;12/12px;13/13px;14/14px;16/16px;18/18px;20/20px;24/24px;28/28px;36/36px;48/48px'
|
2016-06-07 05:57:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
2016-08-09 02:58:06 +08:00
|
|
|
export const htmlEditorLangsMap = {
|
|
|
|
'ar_sa': 'ar-sa',
|
2016-07-16 05:29:42 +08:00
|
|
|
'bg_bg': 'bg',
|
2016-08-09 02:58:06 +08:00
|
|
|
'cs_CZ': 'cs',
|
2016-07-16 05:29:42 +08:00
|
|
|
'de_de': 'de',
|
|
|
|
'el_gr': 'el',
|
|
|
|
'es_es': 'es',
|
2016-08-09 02:58:06 +08:00
|
|
|
'et_ee': 'et',
|
2016-07-16 05:29:42 +08:00
|
|
|
'fr_fr': 'fr',
|
|
|
|
'hu_hu': 'hu',
|
|
|
|
'is_is': 'is',
|
|
|
|
'it_it': 'it',
|
|
|
|
'ja_jp': 'ja',
|
|
|
|
'ko_kr': 'ko',
|
|
|
|
'lt_lt': 'lt',
|
|
|
|
'lv_lv': 'lv',
|
2016-09-07 05:46:23 +08:00
|
|
|
'fa_ir': 'fa',
|
2016-08-09 02:58:06 +08:00
|
|
|
'nb_no': 'nb',
|
2016-07-16 05:29:42 +08:00
|
|
|
'nl_nl': 'nl',
|
|
|
|
'pl_pl': 'pl',
|
|
|
|
'pt_br': 'pt-br',
|
2016-08-09 02:58:06 +08:00
|
|
|
'pt_pt': 'pt',
|
2016-07-16 05:29:42 +08:00
|
|
|
'ro_ro': 'ro',
|
|
|
|
'ru_ru': 'ru',
|
|
|
|
'sk_sk': 'sk',
|
|
|
|
'sl_si': 'sl',
|
|
|
|
'sv_se': 'sv',
|
|
|
|
'tr_tr': 'tr',
|
2016-08-09 02:58:06 +08:00
|
|
|
'uk_ua': 'uk',
|
|
|
|
'zh_cn': 'zh-cn',
|
|
|
|
'zh_tw': 'zh'
|
2016-06-07 05:57:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
let bAllowPdfPreview = !bMobileDevice;
|
|
|
|
|
|
|
|
if (bAllowPdfPreview && window.navigator && window.navigator.mimeTypes)
|
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
bAllowPdfPreview = !!_.find(window.navigator.mimeTypes, (type) => type && 'application/pdf' === type.type);
|
2016-06-07 05:57:52 +08:00
|
|
|
|
|
|
|
if (!bAllowPdfPreview)
|
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
bAllowPdfPreview = 'undefined' !== typeof window.navigator.mimeTypes['application/pdf'];
|
2016-06-07 05:57:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export {bAllowPdfPreview};
|
|
|
|
|
2016-10-19 01:52:43 +08:00
|
|
|
export const VIEW_MODELS = {
|
2016-06-07 05:57:52 +08:00
|
|
|
settings: [],
|
|
|
|
'settings-removed': [],
|
|
|
|
'settings-disabled': []
|
|
|
|
};
|
|
|
|
|
2017-02-09 01:48:53 +08:00
|
|
|
export const moveAction = ko.observable(false);
|
2016-06-07 05:57:52 +08:00
|
|
|
export const leftPanelDisabled = ko.observable(false);
|
|
|
|
export const leftPanelType = ko.observable('');
|
|
|
|
export const leftPanelWidth = ko.observable(0);
|
|
|
|
|
2017-02-09 01:48:53 +08:00
|
|
|
leftPanelDisabled.subscribe((value) => {
|
|
|
|
if (value && moveAction()) {
|
|
|
|
moveAction(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
moveAction.subscribe((value) => {
|
|
|
|
if (value && leftPanelDisabled()) {
|
|
|
|
leftPanelDisabled(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-07 05:57:52 +08:00
|
|
|
// popups
|
|
|
|
export const popupVisibilityNames = ko.observableArray([]);
|
|
|
|
|
2016-07-02 06:49:59 +08:00
|
|
|
export const popupVisibility = ko.computed(() => 0 < popupVisibilityNames().length);
|
2016-06-07 05:57:52 +08:00
|
|
|
|
|
|
|
popupVisibility.subscribe((bValue) => {
|
|
|
|
$html.toggleClass('rl-modal', bValue);
|
|
|
|
});
|
|
|
|
|
|
|
|
// keys
|
|
|
|
export const keyScopeReal = ko.observable(KeyState.All);
|
|
|
|
export const keyScopeFake = ko.observable(KeyState.All);
|
|
|
|
|
|
|
|
export const keyScope = ko.computed({
|
2016-07-02 06:49:59 +08:00
|
|
|
read: () => keyScopeFake(),
|
2016-08-17 06:01:20 +08:00
|
|
|
write: (value) => {
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
if (KeyState.Menu !== value)
|
2016-06-07 05:57:52 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
if (KeyState.Compose === value)
|
2016-06-07 05:57:52 +08:00
|
|
|
{
|
|
|
|
// disableKeyFilter
|
2016-08-17 06:01:20 +08:00
|
|
|
key.filter = () => useKeyboardShortcuts();
|
2016-06-07 05:57:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// restoreKeyFilter
|
2016-08-17 06:01:20 +08:00
|
|
|
key.filter = (event) => {
|
2016-06-07 05:57:52 +08:00
|
|
|
|
|
|
|
if (useKeyboardShortcuts())
|
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
const
|
|
|
|
el = event.target || event.srcElement,
|
|
|
|
tagName = el ? el.tagName.toUpperCase() : '';
|
2016-06-07 05:57:52 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
return !('INPUT' === tagName || 'SELECT' === tagName || 'TEXTAREA' === tagName ||
|
|
|
|
(el && 'DIV' === tagName && ('editorHtmlArea' === el.className || 'true' === '' + el.contentEditable))
|
2016-06-07 05:57:52 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
keyScopeFake(value);
|
2016-06-07 05:57:52 +08:00
|
|
|
if (dropdownVisibility())
|
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
value = KeyState.Menu;
|
2016-06-07 05:57:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
keyScopeReal(value);
|
2016-06-07 05:57:52 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
keyScopeReal.subscribe((value) => {
|
2016-06-07 05:57:52 +08:00
|
|
|
// window.console.log('keyScope=' + sValue); // DEBUG
|
2016-08-17 06:01:20 +08:00
|
|
|
key.setScope(value);
|
2016-06-07 05:57:52 +08:00
|
|
|
});
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
dropdownVisibility.subscribe((value) => {
|
|
|
|
if (value)
|
2016-06-07 05:57:52 +08:00
|
|
|
{
|
|
|
|
keyScope(KeyState.Menu);
|
|
|
|
}
|
|
|
|
else if (KeyState.Menu === key.getScope())
|
|
|
|
{
|
|
|
|
keyScope(keyScopeFake());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {*}
|
|
|
|
*/
|
|
|
|
export const data = {
|
|
|
|
__APP__: null,
|
|
|
|
iAjaxErrorCount: 0,
|
|
|
|
iTokenErrorCount: 0,
|
|
|
|
aBootstrapDropdowns: [],
|
|
|
|
iMessageBodyCacheCount: 0,
|
|
|
|
bUnload: false
|
|
|
|
};
|