snappymail/dev/Common/Globals.js

272 lines
5.4 KiB
JavaScript
Raw Normal View History

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'),
2015-02-18 01:44:11 +08:00
is = require('is'),
_ = 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');
Globals.$div = $('<div></div>');
Globals.$win.__sizes = [0, 0];
2014-08-20 23:03:12 +08:00
/**
* @type {?}
*/
Globals.now = (new window.Date()).getTime();
/**
* @type {?}
*/
Globals.momentTrigger = ko.observable(true);
/**
* @type {?}
*/
Globals.dropdownVisibility = ko.observable(false).extend({'rateLimit': 0});
/**
* @type {?}
*/
Globals.tooltipTrigger = 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 {boolean}
*/
2015-02-18 01:44:11 +08:00
Globals.bTabletDevice = is.tablet();
2014-08-20 23:03:12 +08:00
/**
* @type {boolean}
*/
2015-02-18 01:44:11 +08:00
Globals.bMobileDevice = is.mobile() || is.tablet();
2014-08-20 23:03:12 +08:00
/**
* @type {boolean}
*/
Globals.bDisableNanoScroll = Globals.bMobileDevice;
/**
* @type {boolean}
*/
Globals.bAllowPdfPreview = !Globals.bMobileDevice;
/**
* @type {boolean}
*/
2014-11-01 01:25:02 +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',
2014-08-20 23:03:12 +08:00
'allowedContent': true,
'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 = {
2014-11-01 01:25:02 +08:00
'bg': 'bg',
2014-08-20 23:03:12 +08:00
'de': 'de',
'es': 'es',
'fr': 'fr',
'hu': 'hu',
'is': 'is',
'it': 'it',
2014-08-31 04:37:36 +08:00
'ja': 'ja',
'ja-jp': 'ja',
2014-08-20 23:03:12 +08:00
'ko': 'ko',
'ko-kr': 'ko',
2014-11-01 01:25:02 +08:00
'lt': 'lt',
2014-08-20 23:03:12 +08:00
'lv': 'lv',
'nl': 'nl',
'no': 'no',
'pl': 'pl',
'pt': 'pt',
'pt-pt': 'pt',
'pt-br': 'pt-br',
'ro': 'ro',
2014-08-31 04:37:36 +08:00
'ru': 'ru',
'sk': 'sk',
2014-11-01 01:25:02 +08:00
'sv': 'sv',
2014-08-31 04:37:36 +08:00
'tr': 'tr',
'ua': 'ru',
2014-08-20 23:03:12 +08:00
'zh': 'zh',
2014-11-01 01:25:02 +08:00
'zh-tw': 'zh',
2014-08-20 23:03:12 +08:00
'zh-cn': 'zh-cn'
};
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);
// 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' ||
(oElement && sTagName === 'DIV' && 'editorHtmlArea' === oElement.className && oElement.contentEditable)
);
}
return false;
};
}
Globals.keyScopeFake(sValue);
if (Globals.dropdownVisibility())
{
sValue = Enums.KeyState.Menu;
}
}
Globals.keyScopeReal(sValue);
}
});
Globals.keyScopeReal.subscribe(function (sValue) {
key.setScope(sValue);
});
Globals.dropdownVisibility.subscribe(function (bValue) {
if (bValue)
{
Globals.tooltipTrigger(!Globals.tooltipTrigger());
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
}());