Code refactoring

Fixed languages popup
Release commit
This commit is contained in:
RainLoop Team 2014-09-02 04:15:31 +04:00
parent fa795947cf
commit ccbf04cb67
123 changed files with 1375 additions and 5128 deletions

View file

@ -2,7 +2,7 @@
// http://www.webtoolkit.info/
(function (module) {
'use strict';
/*jslint bitwise: true*/

View file

@ -1,4 +1,3 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
@ -126,4 +125,4 @@
module.exports = Consts;
}(module, require));
}(module));

View file

@ -1,4 +1,3 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module) {
@ -248,15 +247,6 @@
'Month': 30
};
/**
* @enum {number}
*/
Enums.EmailType = {
'Defailt': 0,
'Facebook': 1,
'Google': 2
};
/**
* @enum {number}
*/

View file

@ -1,9 +1,8 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module, require) {
'use strict';
var
_ = require('_'),

View file

@ -1,4 +1,3 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module, require) {
@ -6,7 +5,9 @@
var
Globals = {},
window = require('window'),
_ = require('_'),
$ = require('$'),
ko = require('ko'),
key = require('key'),

View file

@ -1,4 +1,3 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module, require) {
@ -7,6 +6,7 @@
var
window = require('window'),
_ = require('_'),
Globals = require('Globals'),
Settings = require('Storage:Settings')
;

View file

@ -1,7 +1,6 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module, require) {
'use strict';
var
@ -133,7 +132,6 @@
LinkBuilder.prototype.avatarLink = function (sEmail)
{
return this.sServer + '/Raw/0/Avatar/' + window.encodeURIComponent(sEmail) + '/';
// return '//secure.gravatar.com/avatar/' + Utils.md5(sEmail.toLowerCase()) + '.jpg?s=80&d=mm';
};
/**

View file

@ -1,56 +1,57 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module, require) {
'use strict';
var
Plugins = {
__boot: null,
__remote: null,
__data: null
},
_ = require('_'),
Utils = require('Utils'),
Settings = require('Storage:Settings')
Utils = require('Utils')
;
/**
* @type {Object}
* @constructor
*/
Plugins.oViewModelsHooks = {};
/**
* @type {Object}
*/
Plugins.oSimpleHooks = {};
/**
* @param {string} sName
* @param {Function} ViewModel
*/
Plugins.regViewModelHook = function (sName, ViewModel)
function Plugins()
{
if (ViewModel)
{
ViewModel.__hookName = sName;
}
};
this.__boot = null;
this.__data = null;
this.__remote = null;
this.oSettings = require('Storage:Settings');
this.oViewModelsHooks = {};
this.oSimpleHooks = {};
}
Plugins.prototype.__boot = null;
Plugins.prototype.__data = null;
Plugins.prototype.__remote = null;
/**
* @type {Object}
*/
Plugins.prototype.oViewModelsHooks = {};
/**
* @type {Object}
*/
Plugins.prototype.oSimpleHooks = {};
/**
* @param {string} sName
* @param {Function} fCallback
*/
Plugins.addHook = function (sName, fCallback)
Plugins.prototype.addHook = function (sName, fCallback)
{
if (Utils.isFunc(fCallback))
{
if (!Utils.isArray(Plugins.oSimpleHooks[sName]))
if (!Utils.isArray(this.oSimpleHooks[sName]))
{
Plugins.oSimpleHooks[sName] = [];
this.oSimpleHooks[sName] = [];
}
Plugins.oSimpleHooks[sName].push(fCallback);
this.oSimpleHooks[sName].push(fCallback);
}
};
@ -58,13 +59,13 @@
* @param {string} sName
* @param {Array=} aArguments
*/
Plugins.runHook = function (sName, aArguments)
Plugins.prototype.runHook = function (sName, aArguments)
{
if (Utils.isArray(Plugins.oSimpleHooks[sName]))
if (Utils.isArray(this.oSimpleHooks[sName]))
{
aArguments = aArguments || [];
_.each(Plugins.oSimpleHooks[sName], function (fCallback) {
_.each(this.oSimpleHooks[sName], function (fCallback) {
fCallback.apply(null, aArguments);
});
}
@ -74,9 +75,9 @@
* @param {string} sName
* @return {?}
*/
Plugins.mainSettingsGet = function (sName)
Plugins.prototype.mainSettingsGet = function (sName)
{
return Settings.settingsGet(sName);
return this.oSettings.settingsGet(sName);
};
/**
@ -87,11 +88,11 @@
* @param {string=} sGetAdd = ''
* @param {Array=} aAbortActions = []
*/
Plugins.remoteRequest = function (fCallback, sAction, oParameters, iTimeout, sGetAdd, aAbortActions)
Plugins.prototype.remoteRequest = function (fCallback, sAction, oParameters, iTimeout, sGetAdd, aAbortActions)
{
if (Plugins.__remote)
if (this.__remote)
{
Plugins.__remote.defaultRequest(fCallback, sAction, oParameters, iTimeout, sGetAdd, aAbortActions);
this.__remote.defaultRequest(fCallback, sAction, oParameters, iTimeout, sGetAdd, aAbortActions);
}
};
@ -100,13 +101,13 @@
* @param {string} sName
* @return {?}
*/
Plugins.settingsGet = function (sPluginSection, sName)
Plugins.prototype.settingsGet = function (sPluginSection, sName)
{
var oPlugin = Settings.settingsGet('Plugins');
var oPlugin = this.oSettings.settingsGet('Plugins');
oPlugin = oPlugin && !Utils.isUnd(oPlugin[sPluginSection]) ? oPlugin[sPluginSection] : null;
return oPlugin ? (Utils.isUnd(oPlugin[sName]) ? null : oPlugin[sName]) : null;
};
module.exports = Plugins;
module.exports = new Plugins();
}(module, require));

View file

@ -1,12 +1,11 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module, require) {
'use strict';
var
$ = require('$'),
_ = require('_'),
$ = require('$'),
ko = require('ko'),
key = require('key'),

View file

@ -1,16 +1,15 @@
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (module, require) {
'use strict';
var
Utils = {},
$ = require('$'),
_ = require('_'),
ko = require('ko'),
window = require('window'),
_ = require('_'),
$ = require('$'),
ko = require('ko'),
Enums = require('Enums'),
Consts = require('Consts'),
@ -123,7 +122,46 @@
};
/**
* @param {string} aValue
* @param {string} sMailToUrl
* @param {Function} PopupComposeVoreModel
* @returns {boolean}
*/
Utils.mailToHelper = function (sMailToUrl, PopupComposeVoreModel)
{
if (sMailToUrl && 'mailto:' === sMailToUrl.toString().substr(0, 7).toLowerCase())
{
sMailToUrl = sMailToUrl.toString().substr(7);
var
oParams = {},
oEmailModel = null,
sEmail = sMailToUrl.replace(/\?.+$/, ''),
sQueryString = sMailToUrl.replace(/^[^\?]*\?/, ''),
EmailModel = require('Model:Email')
;
oEmailModel = new EmailModel();
oEmailModel.parse(window.decodeURIComponent(sEmail));
if (oEmailModel && oEmailModel.email)
{
oParams = Utils.simpleQueryParser(sQueryString);
require('App:Knoin').showScreenPopup(PopupComposeVoreModel, [Enums.ComposeType.Empty, null, [oEmailModel],
Utils.isUnd(oParams.subject) ? null : Utils.pString(oParams.subject),
Utils.isUnd(oParams.body) ? null : Utils.plainToHtml(Utils.pString(oParams.body))
]);
}
return true;
}
return false;
};
/**
* @param {string} sValue
* @param {string} sHash
* @param {string} sKey
* @param {string} sLongKey
* @return {string|boolean}
@ -892,7 +930,7 @@
NotificationClass = Utils.notificationClass(),
iResult = Enums.DesktopNotifications.NotSupported
;
if (NotificationClass && NotificationClass.permission)
{
switch (NotificationClass.permission.toLowerCase())
@ -928,7 +966,7 @@
NotificationClass = Utils.notificationClass(),
iPermission = oData.desktopNotificationsPermisions()
;
if (NotificationClass && Enums.DesktopNotifications.Allowed === iPermission)
{
oData.desktopNotifications(true);
@ -1134,66 +1172,9 @@
};
/**
* @param {Object} oMessageTextBody
* @param {string} sTheme
* @return {string}
*/
Utils.initBlockquoteSwitcher = function (oMessageTextBody)
{
if (oMessageTextBody)
{
var $oList = $('blockquote:not(.rl-bq-switcher)', oMessageTextBody).filter(function () {
return 0 === $(this).parent().closest('blockquote', oMessageTextBody).length;
});
if ($oList && 0 < $oList.length)
{
$oList.each(function () {
var $self = $(this), iH = $self.height();
if (0 === iH || 100 < iH)
{
$self.addClass('rl-bq-switcher hidden-bq');
$('<span class="rlBlockquoteSwitcher"><i class="icon-ellipsis" /></span>')
.insertBefore($self)
.click(function () {
$self.toggleClass('hidden-bq');
Utils.windowResize();
})
.after('<br />')
.before('<br />')
;
}
});
}
}
};
/**
* @param {Object} oMessageTextBody
*/
Utils.removeBlockquoteSwitcher = function (oMessageTextBody)
{
if (oMessageTextBody)
{
$(oMessageTextBody).find('blockquote.rl-bq-switcher').each(function () {
$(this).removeClass('rl-bq-switcher hidden-bq');
});
$(oMessageTextBody).find('.rlBlockquoteSwitcher').each(function () {
$(this).remove();
});
}
};
/**
* @param {Object} oMessageTextBody
*/
Utils.toggleMessageBlockquote = function (oMessageTextBody)
{
if (oMessageTextBody)
{
oMessageTextBody.find('.rlBlockquoteSwitcher').click();
}
};
Utils.convertThemeName = function (sTheme)
{
if ('@custom' === sTheme.substr(-7))
@ -1201,7 +1182,7 @@
sTheme = Utils.trim(sTheme.substring(0, sTheme.length - 7));
}
return Utils.trim(sTheme.replace(/[^a-zA-Z]+/g, ' ').replace(/([A-Z])/g, ' $1').replace(/[\s]+/g, ' '));
return Utils.trim(sTheme.replace(/[^a-zA-Z0-9]+/g, ' ').replace(/([A-Z])/g, ' $1').replace(/[\s]+/g, ' '));
};
/**
@ -1254,14 +1235,10 @@
return sResult;
};
/* jshint ignore:start */
/**
* @param {string} s
* @param {string} sPlain
* @return {string}
*/
Utils.md5 = function(s){function L(k,d){return(k<<d)|(k>>>(32-d))}function K(G,k){var I,d,F,H,x;F=(G&2147483648);H=(k&2147483648);I=(G&1073741824);d=(k&1073741824);x=(G&1073741823)+(k&1073741823);if(I&d){return(x^2147483648^F^H)}if(I|d){if(x&1073741824){return(x^3221225472^F^H)}else{return(x^1073741824^F^H)}}else{return(x^F^H)}}function r(d,F,k){return(d&F)|((~d)&k)}function q(d,F,k){return(d&k)|(F&(~k))}function p(d,F,k){return(d^F^k)}function n(d,F,k){return(F^(d|(~k)))}function u(G,F,aa,Z,k,H,I){G=K(G,K(K(r(F,aa,Z),k),I));return K(L(G,H),F)}function f(G,F,aa,Z,k,H,I){G=K(G,K(K(q(F,aa,Z),k),I));return K(L(G,H),F)}function D(G,F,aa,Z,k,H,I){G=K(G,K(K(p(F,aa,Z),k),I));return K(L(G,H),F)}function t(G,F,aa,Z,k,H,I){G=K(G,K(K(n(F,aa,Z),k),I));return K(L(G,H),F)}function e(G){var Z;var F=G.length;var x=F+8;var k=(x-(x%64))/64;var I=(k+1)*16;var aa=Array(I-1);var d=0;var H=0;while(H<F){Z=(H-(H%4))/4;d=(H%4)*8;aa[Z]=(aa[Z]|(G.charCodeAt(H)<<d));H++}Z=(H-(H%4))/4;d=(H%4)*8;aa[Z]=aa[Z]|(128<<d);aa[I-2]=F<<3;aa[I-1]=F>>>29;return aa}function B(x){var k="",F="",G,d;for(d=0;d<=3;d++){G=(x>>>(d*8))&255;F="0"+G.toString(16);k=k+F.substr(F.length-2,2)}return k}function J(k){k=k.replace(/rn/g,"n");var d="";for(var F=0;F<k.length;F++){var x=k.charCodeAt(F);if(x<128){d+=String.fromCharCode(x)}else{if((x>127)&&(x<2048)){d+=String.fromCharCode((x>>6)|192);d+=String.fromCharCode((x&63)|128)}else{d+=String.fromCharCode((x>>12)|224);d+=String.fromCharCode(((x>>6)&63)|128);d+=String.fromCharCode((x&63)|128)}}}return d}var C=Array();var P,h,E,v,g,Y,X,W,V;var S=7,Q=12,N=17,M=22;var A=5,z=9,y=14,w=20;var o=4,m=11,l=16,j=23;var U=6,T=10,R=15,O=21;s=J(s);C=e(s);Y=1732584193;X=4023233417;W=2562383102;V=271733878;for(P=0;P<C.length;P+=16){h=Y;E=X;v=W;g=V;Y=u(Y,X,W,V,C[P+0],S,3614090360);V=u(V,Y,X,W,C[P+1],Q,3905402710);W=u(W,V,Y,X,C[P+2],N,606105819);X=u(X,W,V,Y,C[P+3],M,3250441966);Y=u(Y,X,W,V,C[P+4],S,4118548399);V=u(V,Y,X,W,C[P+5],Q,1200080426);W=u(W,V,Y,X,C[P+6],N,2821735955);X=u(X,W,V,Y,C[P+7],M,4249261313);Y=u(Y,X,W,V,C[P+8],S,1770035416);V=u(V,Y,X,W,C[P+9],Q,2336552879);W=u(W,V,Y,X,C[P+10],N,4294925233);X=u(X,W,V,Y,C[P+11],M,2304563134);Y=u(Y,X,W,V,C[P+12],S,1804603682);V=u(V,Y,X,W,C[P+13],Q,4254626195);W=u(W,V,Y,X,C[P+14],N,2792965006);X=u(X,W,V,Y,C[P+15],M,1236535329);Y=f(Y,X,W,V,C[P+1],A,4129170786);V=f(V,Y,X,W,C[P+6],z,3225465664);W=f(W,V,Y,X,C[P+11],y,643717713);X=f(X,W,V,Y,C[P+0],w,3921069994);Y=f(Y,X,W,V,C[P+5],A,3593408605);V=f(V,Y,X,W,C[P+10],z,38016083);W=f(W,V,Y,X,C[P+15],y,3634488961);X=f(X,W,V,Y,C[P+4],w,3889429448);Y=f(Y,X,W,V,C[P+9],A,568446438);V=f(V,Y,X,W,C[P+14],z,3275163606);W=f(W,V,Y,X,C[P+3],y,4107603335);X=f(X,W,V,Y,C[P+8],w,1163531501);Y=f(Y,X,W,V,C[P+13],A,2850285829);V=f(V,Y,X,W,C[P+2],z,4243563512);W=f(W,V,Y,X,C[P+7],y,1735328473);X=f(X,W,V,Y,C[P+12],w,2368359562);Y=D(Y,X,W,V,C[P+5],o,4294588738);V=D(V,Y,X,W,C[P+8],m,2272392833);W=D(W,V,Y,X,C[P+11],l,1839030562);X=D(X,W,V,Y,C[P+14],j,4259657740);Y=D(Y,X,W,V,C[P+1],o,2763975236);V=D(V,Y,X,W,C[P+4],m,1272893353);W=D(W,V,Y,X,C[P+7],l,4139469664);X=D(X,W,V,Y,C[P+10],j,3200236656);Y=D(Y,X,W,V,C[P+13],o,681279174);V=D(V,Y,X,W,C[P+0],m,3936430074);W=D(W,V,Y,X,C[P+3],l,3572445317);X=D(X,W,V,Y,C[P+6],j,76029189);Y=D(Y,X,W,V,C[P+9],o,3654602809);V=D(V,Y,X,W,C[P+12],m,3873151461);W=D(W,V,Y,X,C[P+15],l,530742520);X=D(X,W,V,Y,C[P+2],j,3299628645);Y=t(Y,X,W,V,C[P+0],U,4096336452);V=t(V,Y,X,W,C[P+7],T,1126891415);W=t(W,V,Y,X,C[P+14],R,2878612391);X=t(X,W,V,Y,C[P+5],O,4237533241);Y=t(Y,X,W,V,C[P+12],U,1700485571);V=t(V,Y,X,W,C[P+3],T,2399980690);W=t(W,V,Y,X,C[P+10],R,4293915773);X=t(X,W,V,Y,C[P+1],O,2240044497);Y=t(Y,X,W,V,C[P+8],U,1873313359);V=t(V,Y,X,W,C[P+15],T,4264355552);W=t(W,V,Y,X,C[P+6],R,2734768916);X=t(X,W,V,Y,C[P+13],O,1309151649);Y=t(Y,X,W,V,C[P+4],U,4149444226);V=t(V,Y,X,W,C[P+11],T,3174756917);W=t(W,V,Y,X,C[P+2],R,718787259);X=t(X,W,V,Y,C[P+9],O,3951481745);Y=K(Y,h);X=K(X,E);W=K(W,v);V=K(V,g)}var i=B(Y)+B(X)+B(W)+B(V);return i.toLowerCase()};
/* jshint ignore:end */
Utils.convertPlainTextToHtml = function (sPlain)
{
return sPlain.toString()
@ -1274,11 +1251,11 @@
return $('<div class="draggablePlace"><span class="text"></span>&nbsp;<i class="icon-copy icon-white visible-on-ctrl"></i><i class="icon-mail icon-white hidden-on-ctrl"></i></div>').appendTo('#rl-hidden');
};
Utils.defautOptionsAfterRender = function (oOption, oItem)
Utils.defautOptionsAfterRender = function (oDomOption, oItem)
{
if (oItem && !Utils.isUnd(oItem.disabled) && oOption)
if (oItem && !Utils.isUnd(oItem.disabled) && oDomOption)
{
$(oOption)
$(oDomOption)
.toggleClass('disabled', oItem.disabled)
.prop('disabled', oItem.disabled)
;
@ -1339,10 +1316,18 @@
oWin.document.getElementsByTagName('head')[0].appendChild(oScript);
};
/**
* @param {Function} fCallback
* @param {?} koTrigger
* @param {?} oContext = null
* @param {number=} iTimer = 1000
* @return {Function}
*/
Utils.settingsSaveHelperFunction = function (fCallback, koTrigger, oContext, iTimer)
{
oContext = oContext || null;
iTimer = Utils.isUnd(iTimer) ? 1000 : Utils.pInt(iTimer);
return function (sType, mData, bCached, sRequestAction, oRequestParameters) {
koTrigger.call(oContext, mData && mData['Result'] ? Enums.SaveSettingsStep.TrueResult : Enums.SaveSettingsStep.FalseResult);
if (fCallback)
@ -1616,6 +1601,11 @@
return sHtml;
};
/**
* @param {string} sUrl
* @param {number} iValue
* @param {Function} fCallback
*/
Utils.resizeAndCrop = function (sUrl, iValue, fCallback)
{
var oTempImg = new window.Image();
@ -1781,6 +1771,7 @@
Utils.computedPagenatorHelper = function (koCurrentPage, koPageCount)
{
return function() {
var
iPrev = 0,
iNext = 0,
@ -1791,8 +1782,8 @@
/**
* @param {number} iIndex
* @param {boolean=} bPush
* @param {string=} sCustomName
* @param {boolean=} bPush = true
* @param {string=} sCustomName = ''
*/
fAdd = function (iIndex, bPush, sCustomName) {
@ -1894,22 +1885,21 @@
Utils.selectElement = function (element)
{
/* jshint onevar: false */
var sel, range;
if (window.getSelection)
{
var sel = window.getSelection();
sel = window.getSelection();
sel.removeAllRanges();
var range = window.document.createRange();
range = window.document.createRange();
range.selectNodeContents(element);
sel.addRange(range);
}
else if (window.document.selection)
{
var textRange = window.document.body.createTextRange();
textRange.moveToElementText(element);
textRange.select();
range = window.document.body.createTextRange();
range.moveToElementText(element);
range.select();
}
/* jshint onevar: true */
};
Utils.detectDropdownVisibility = _.debounce(function () {
@ -1918,13 +1908,16 @@
}));
}, 50);
/**
* @param {boolean=} bDelay = false
*/
Utils.triggerAutocompleteInputChange = function (bDelay) {
var fFunc = function () {
$('.checkAutocomplete').trigger('change');
};
if (bDelay)
if (Utils.isUnd(bDelay) ? false : !!bDelay)
{
_.delay(fFunc, 100);
}