snappymail/dev/Common/Globals.js

295 lines
6 KiB
JavaScript
Raw Normal View History

2015-07-30 01:21:24 +08:00
/* global RL_COMMUNITY */
2014-09-05 06:49:03 +08:00
(function () {
2014-08-25 23:49:01 +08:00
'use strict';
2014-08-20 23:03:12 +08:00
var
Globals = {},
2014-08-25 23:49:01 +08:00
window = require('window'),
_ = require('_'),
2014-09-02 00:05:32 +08:00
$ = require('$'),
2014-08-25 23:49:01 +08:00
ko = require('ko'),
key = require('key'),
2014-08-25 15:10:51 +08:00
2014-09-05 06:49:03 +08:00
Enums = require('Common/Enums')
2014-08-20 23:03:12 +08:00
;
2014-09-02 00:05:32 +08:00
Globals.$win = $(window);
Globals.$doc = $(window.document);
Globals.$html = $('html');
2015-04-14 02:45:09 +08:00
Globals.$body = $('body');
2014-09-02 00:05:32 +08:00
Globals.$div = $('<div></div>');
Globals.$win.__sizes = [0, 0];
2014-08-20 23:03:12 +08:00
/**
* @type {?}
*/
Globals.startMicrotime = (new window.Date()).getTime();
2014-08-20 23:03:12 +08:00
2015-05-03 04:22:32 +08:00
/**
* @type {boolean}
*/
Globals.community = RL_COMMUNITY;
2014-08-20 23:03:12 +08:00
/**
* @type {?}
*/
Globals.dropdownVisibility = ko.observable(false).extend({'rateLimit': 0});
2014-08-22 23:08:56 +08:00
/**
* @type {boolean}
*/
Globals.useKeyboardShortcuts = ko.observable(true);
2014-08-20 23:03:12 +08:00
/**
* @type {number}
*/
Globals.iAjaxErrorCount = 0;
/**
* @type {number}
*/
Globals.iTokenErrorCount = 0;
/**
* @type {number}
*/
Globals.iMessageBodyCacheCount = 0;
/**
* @type {boolean}
*/
Globals.bUnload = false;
/**
* @type {string}
2014-08-20 23:03:12 +08:00
*/
Globals.sUserAgent = 'navigator' in window && 'userAgent' in window.navigator &&
window.navigator.userAgent.toLowerCase() || '';
2014-08-20 23:03:12 +08:00
2015-04-11 06:45:30 +08:00
/**
* @type {boolean}
*/
Globals.bIE = Globals.sUserAgent.indexOf('msie') > -1;
/**
* @type {boolean}
*/
Globals.bChrome = Globals.sUserAgent.indexOf('chrome') > -1;
/**
* @type {boolean}
*/
Globals.bSafari = !Globals.bChrome && Globals.sUserAgent.indexOf('safari') > -1;
2014-08-20 23:03:12 +08:00
/**
* @type {boolean}
*/
Globals.bMobileDevice =
/android/i.test(Globals.sUserAgent) ||
/iphone/i.test(Globals.sUserAgent) ||
/ipod/i.test(Globals.sUserAgent) ||
/ipad/i.test(Globals.sUserAgent) ||
/blackberry/i.test(Globals.sUserAgent)
;
2014-08-20 23:03:12 +08:00
/**
* @type {boolean}
*/
Globals.bDisableNanoScroll = Globals.bMobileDevice;
/**
* @type {boolean}
*/
Globals.bAllowPdfPreview = !Globals.bMobileDevice;
/**
* @type {boolean}
*/
2015-11-15 08:23:16 +08:00
Globals.bAnimationSupported = !Globals.bMobileDevice &&
Globals.$html.hasClass('csstransitions') &&
Globals.$html.hasClass('cssanimations');
2014-08-20 23:03:12 +08:00
/**
* @type {boolean}
*/
Globals.bXMLHttpRequestSupported = !!window.XMLHttpRequest;
2014-08-22 23:08:56 +08:00
/**
* @type {*}
*/
Globals.__APP__ = null;
2014-08-20 23:03:12 +08:00
/**
* @type {Object}
*/
Globals.oHtmlEditorDefaultConfig = {
'title': false,
'stylesSet': false,
'customConfig': '',
'contentsCss': '',
'toolbarGroups': [
{name: 'spec'},
{name: 'styles'},
{name: 'basicstyles', groups: ['basicstyles', 'cleanup', 'bidi']},
2014-08-20 23:03:12 +08:00
{name: 'colors'},
{name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align']},
{name: 'links'},
{name: 'insert'},
{name: 'document', groups: ['mode', 'document', 'doctools']},
2014-08-20 23:03:12 +08:00
{name: 'others'}
],
'removePlugins': 'liststyle',
'removeButtons': 'Format,Undo,Redo,Cut,Copy,Paste,Anchor,Strike,Subscript,Superscript,Image,SelectAll,Source',
2014-08-20 23:03:12 +08:00
'removeDialogTabs': 'link:advanced;link:target;image:advanced;images:advanced',
'extraPlugins': 'plain,signature',
2015-02-21 07:56:39 +08:00
2014-08-20 23:03:12 +08:00
'allowedContent': true,
2015-02-21 07:56:39 +08:00
'extraAllowedContent': true,
'fillEmptyBlocks': false,
'ignoreEmptyParagraph': true,
2016-01-05 00:47:02 +08:00
'disableNativeSpellChecker': false,
2014-08-20 23:03:12 +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'
};
/**
* @type {Object}
*/
Globals.oHtmlEditorLangsMap = {
2015-11-15 08:23:16 +08:00
'bg_bg': 'bg',
'de_de': 'de',
'es_es': 'es',
'fr_fr': 'fr',
'hu_hu': 'hu',
'is_is': 'is',
'it_it': 'it',
'ja_jp': 'ja',
'ko_kr': 'ko',
'lt_lt': 'lt',
'lv_lv': 'lv',
'nl_nl': 'nl',
'bg_no': 'no',
'pl_pl': 'pl',
'pt_pt': 'pt',
'pt_br': 'pt-br',
'ro_ro': 'ro',
'ru_ru': 'ru',
'sk_sk': 'sk',
'sv_se': 'sv',
'tr_tr': 'tr',
'uk_ua': 'ru',
'zh_tw': 'zh',
'zh_cn': 'zh-cn'
2014-08-20 23:03:12 +08:00
};
if (Globals.bAllowPdfPreview && window.navigator && window.navigator.mimeTypes)
{
Globals.bAllowPdfPreview = !!_.find(window.navigator.mimeTypes, function (oType) {
return oType && 'application/pdf' === oType.type;
});
}
2014-08-22 23:08:56 +08:00
Globals.aBootstrapDropdowns = [];
2014-08-25 15:10:51 +08:00
2014-08-20 23:03:12 +08:00
Globals.aViewModels = {
'settings': [],
'settings-removed': [],
'settings-disabled': []
};
2014-08-22 23:08:56 +08:00
Globals.leftPanelDisabled = ko.observable(false);
Globals.leftPanelType = ko.observable('');
2014-08-22 23:08:56 +08:00
// popups
Globals.popupVisibilityNames = ko.observableArray([]);
Globals.popupVisibility = ko.computed(function () {
return 0 < Globals.popupVisibilityNames().length;
}, this);
2015-02-15 08:30:21 +08:00
Globals.popupVisibility.subscribe(function (bValue) {
Globals.$html.toggleClass('rl-modal', bValue);
});
2014-08-22 23:08:56 +08:00
// keys
Globals.keyScopeReal = ko.observable(Enums.KeyState.All);
Globals.keyScopeFake = ko.observable(Enums.KeyState.All);
Globals.keyScope = ko.computed({
'owner': this,
'read': function () {
return Globals.keyScopeFake();
},
'write': function (sValue) {
if (Enums.KeyState.Menu !== sValue)
{
if (Enums.KeyState.Compose === sValue)
{
// disableKeyFilter
key.filter = function () {
return Globals.useKeyboardShortcuts();
};
}
else
{
// restoreKeyFilter
key.filter = function (event) {
if (Globals.useKeyboardShortcuts())
{
var
oElement = event.target || event.srcElement,
sTagName = oElement ? oElement.tagName : ''
;
sTagName = sTagName.toUpperCase();
return !(sTagName === 'INPUT' || sTagName === 'SELECT' || sTagName === 'TEXTAREA' ||
2015-05-15 04:10:58 +08:00
(oElement && sTagName === 'DIV' && ('editorHtmlArea' === oElement.className || 'true' === '' + oElement.contentEditable))
2014-08-22 23:08:56 +08:00
);
}
return false;
};
}
Globals.keyScopeFake(sValue);
if (Globals.dropdownVisibility())
{
sValue = Enums.KeyState.Menu;
}
}
Globals.keyScopeReal(sValue);
}
});
Globals.keyScopeReal.subscribe(function (sValue) {
2015-04-14 02:45:09 +08:00
// window.console.log('keyScope=' + sValue); // DEBUG
2014-08-22 23:08:56 +08:00
key.setScope(sValue);
});
Globals.dropdownVisibility.subscribe(function (bValue) {
if (bValue)
{
Globals.keyScope(Enums.KeyState.Menu);
}
else if (Enums.KeyState.Menu === key.getScope())
{
Globals.keyScope(Globals.keyScopeFake());
}
});
2014-08-25 15:10:51 +08:00
2014-08-20 23:03:12 +08:00
module.exports = Globals;
2014-09-05 06:49:03 +08:00
}());