Simple prefetch functionality (ifvisible.js)

config:
[labs]
allow_prefetch
This commit is contained in:
RainLoop Team 2014-01-26 18:23:37 +04:00
parent b7e135a553
commit 38672e1672
18 changed files with 988 additions and 28 deletions

View file

@ -909,6 +909,7 @@ class Actions
'AllowAdditionalAccounts' => (bool) $oConfig->Get('webmail', 'allow_additional_accounts', true),
'AllowIdentities' => (bool) $oConfig->Get('webmail', 'allow_identities', true),
'DetermineUserLanguage' => (bool) $oConfig->Get('labs', 'determine_user_language', false),
'AllowPrefetch' => (bool) $oConfig->Get('labs', 'allow_prefetch', true),
'AllowCustomLogin' => (bool) $oConfig->Get('login', 'allow_custom_login', false),
'LoginDefaultDomain' => $oConfig->Get('login', 'default_domain', ''),
'AllowThemes' => (bool) $oConfig->Get('webmail', 'allow_themes', true),

View file

@ -229,6 +229,7 @@ Enables caching in the system'),
'imap_forwarded_flag' => array('$Forwarded'),
'imap_read_receipt_flag' => array('$ReadReceipt'),
'smtp_show_server_errors' => array(false),
'allow_prefetch' => array(true),
'autocreate_system_folders' => array(true),
'repo_type' => array('stable'),
'custom_repo' => array(''),

View file

@ -1153,7 +1153,7 @@ Utils.log = function (sDesc)
/**
* @param {number} iCode
* @param {ыекштп=} mMessage = ''
* @param {*=} mMessage = ''
* @return {string}
*/
Utils.getNotification = function (iCode, mMessage)
@ -5139,7 +5139,7 @@ function AdminLoginViewModel()
RL.remote().adminLogin(_.bind(function (sResult, oData) {
if (Enums.StorageResultType.Success === sResult && oData&& 'AdminLogin' === oData.Action)
if (Enums.StorageResultType.Success === sResult && oData && 'AdminLogin' === oData.Action)
{
if (oData.Result)
{

View file

@ -1,5 +1,5 @@
/*! RainLoop Webmail Main Module (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
(function (window, $, ko, crossroads, hasher, moment, Jua, _) {
(function (window, $, ko, crossroads, hasher, moment, Jua, _, ifvisible) {
'use strict';
@ -1153,7 +1153,7 @@ Utils.log = function (sDesc)
/**
* @param {number} iCode
* @param {ыекштп=} mMessage = ''
* @param {*=} mMessage = ''
* @return {string}
*/
Utils.getNotification = function (iCode, mMessage)
@ -6328,8 +6328,6 @@ function MessageModel()
this.toEmailsString = ko.observable('');
this.senderEmailsString = ko.observable('');
this.prefetched = false;
this.emails = [];
this.from = [];
@ -6539,8 +6537,6 @@ MessageModel.prototype.clear = function ()
this.toEmailsString('');
this.senderEmailsString('');
this.prefetched = false;
this.emails = [];
this.from = [];
@ -6610,8 +6606,6 @@ MessageModel.prototype.initByJson = function (oJsonMessage)
this.uid = oJsonMessage.Uid;
this.requestHash = oJsonMessage.RequestHash;
this.prefetched = false;
this.size(Utils.pInt(oJsonMessage.Size));
this.from = MessageModel.initEmailsFromJson(oJsonMessage.From);
@ -11220,6 +11214,7 @@ function MailBoxMessageListViewModel()
KnoinAbstractViewModel.call(this, 'Right', 'MailMessageList');
this.sLastUid = null;
this.bPrefetch = false;
this.emptySubjectValue = '';
var oData = RL.data();
@ -12007,6 +12002,51 @@ MailBoxMessageListViewModel.prototype.onBuild = function (oDom)
}, this).extend({'notify': 'always'});
this.initUploaderForAppend();
if (!Globals.bMobileDevice && !!RL.settingsGet('AllowPrefetch') && ifvisible)
{
ifvisible.setIdleDuration(10);
ifvisible.idle(function () {
self.prefetchNextTick();
});
}
};
MailBoxMessageListViewModel.prototype.prefetchNextTick = function ()
{
if (!this.bPrefetch && !ifvisible.now() && this.viewModelVisibility())
{
var
self = this,
oCache = RL.cache(),
oMessage = _.find(this.messageList(), function (oMessage) {
return oMessage &&
!oCache.hasRequestedMessage(oMessage.folderFullNameRaw, oMessage.uid);
})
;
if (oMessage)
{
this.bPrefetch = true;
RL.cache().addRequestedMessage(oMessage.folderFullNameRaw, oMessage.uid);
RL.remote().message(function (sResult, oData) {
var bNext = !!(Enums.StorageResultType.Success === sResult && oData && oData.Result);
_.delay(function () {
self.bPrefetch = false;
if (bNext)
{
self.prefetchNextTick();
}
}, 1000);
}, oMessage.folderFullNameRaw, oMessage.uid);
}
}
};
MailBoxMessageListViewModel.prototype.composeClick = function ()
@ -17509,4 +17549,4 @@ if (window.SimplePace) {
window.SimplePace.add(10);
}
}(window, jQuery, ko, crossroads, hasher, moment, Jua, _));
}(window, jQuery, ko, crossroads, hasher, moment, Jua, _, ifvisible));

File diff suppressed because one or more lines are too long

View file

@ -224,6 +224,9 @@ this.j[c]=i,g.on("click",function(){var a=b.b.d("onDialog");a&&a()}).on("change"
j.c=e;j.h=0;j.a={};j.m={};j.q=f;j.e=f;j.on=function(a,b){this.m[a]=b;return this};j.g=function(a,b){this.m[a]&&this.m[a].apply(f,b||[])};j.d=function(a){return this.m[a]||f};j.cancel=function(a){this.e.cancel(a)};j.p=function(){return B.p};j.v=function(a){this.c=!!a};j.k=function(){return this.e.k()};j.s=function(a){this.r(w(),a)};
j.r=function(a,b){var c=this.d("onSelect");if(b&&(!c||h!==c(a,b))){this.e.t(a);var g=this.e.u,d=this.e;this.q.defer(function(){return g.apply(q(d)?f:d,Array.prototype.slice.call(arguments))},a,b)}else this.e.cancel(a)};l.Jua=B;
/*!ifvisible.js v1.0.0 (c) 2013 Serkan Yersen | MIT */
(function(){"use strict";var a,b,c,d,e,f,g,h,i,j,k,l,m,n;i={},c=document,k=!1,l="active",g=6e4,f=!1,b=function(){var a,b,c,d,e,f;return a=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)},e=function(){return a()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a()},f={},c="__ceGUID",b=function(a,b,d){return a[c]=void 0,a[c]||(a[c]="ifvisible.object.event.identifier"),f[a[c]]||(f[a[c]]={}),f[a[c]][b]||(f[a[c]][b]=[]),f[a[c]][b].push(d)},d=function(a,b,d){var e,g,h,i,j;if(a[c]&&f[a[c]]&&f[a[c]][b]){for(i=f[a[c]][b],j=[],g=0,h=i.length;h>g;g++)e=i[g],j.push(e(d||{}));return j}},{add:b,fire:d}}(),a=function(){var a;return a=!1,function(b,c,d){return a||(a=b.addEventListener?function(a,b,c){return a.addEventListener(b,c,!1)}:b.attachEvent?function(a,b,c){return a.attachEvent("on"+b,c,!1)}:function(a,b,c){return a["on"+b]=c}),a(b,c,d)}}(),d=function(a,b){var d;return c.createEventObject?a.fireEvent("on"+b,d):(d=c.createEvent("HTMLEvents"),d.initEvent(b,!0,!0),!a.dispatchEvent(d))},h=function(){var a,b,d,e,f;for(e=void 0,f=3,d=c.createElement("div"),a=d.getElementsByTagName("i"),b=function(){return d.innerHTML="<!--[if gt IE "+ ++f+"]><i></i><![endif]-->",a[0]};b(););return f>4?f:e}(),e=!1,n=void 0,"undefined"!=typeof c.hidden?(e="hidden",n="visibilitychange"):"undefined"!=typeof c.mozHidden?(e="mozHidden",n="mozvisibilitychange"):"undefined"!=typeof c.msHidden?(e="msHidden",n="msvisibilitychange"):"undefined"!=typeof c.webkitHidden&&(e="webkitHidden",n="webkitvisibilitychange"),m=function(){var b,d;return b=!1,d=function(){return clearTimeout(b),"active"!==l&&i.wakeup(),f=+new Date,b=setTimeout(function(){return"active"===l?i.idle():void 0},g)},d(),a(c,"mousemove",d),a(c,"keyup",d),a(window,"scroll",d),i.focus(d)},j=function(){var b;return k?!0:(e===!1?(b="blur",9>h&&(b="focusout"),a(window,b,function(){return i.blur()}),a(window,"focus",function(){return i.focus()})):a(c,n,function(){return c[e]?i.blur():i.focus()},!1),k=!0,m())},i={setIdleDuration:function(a){return g=1e3*a},getIdleDuration:function(){return g},getIdleInfo:function(){var a,b;return a=+new Date,b={},"idle"===l?(b.isIdle=!0,b.idleFor=a-f,b.timeLeft=0,b.timeLeftPer=100):(b.isIdle=!1,b.idleFor=a-f,b.timeLeft=f+g-a,b.timeLeftPer=(100-100*b.timeLeft/g).toFixed(2)),b},focus:function(a){return"function"==typeof a?this.on("focus",a):(l="active",b.fire(this,"focus"),b.fire(this,"wakeup"),b.fire(this,"statusChanged",{status:l}))},blur:function(a){return"function"==typeof a?this.on("blur",a):(l="hidden",b.fire(this,"blur"),b.fire(this,"idle"),b.fire(this,"statusChanged",{status:l}))},idle:function(a){return"function"==typeof a?this.on("idle",a):(l="idle",b.fire(this,"idle"),b.fire(this,"statusChanged",{status:l}))},wakeup:function(a){return"function"==typeof a?this.on("wakeup",a):(l="active",b.fire(this,"wakeup"),b.fire(this,"statusChanged",{status:l}))},on:function(a,c){return j(),b.add(this,a,c)},onEvery:function(a,b){var c;return j(),c=setInterval(function(){return"active"===l?b():void 0},1e3*a),{stop:function(){return clearInterval(c)},code:c,callback:b}},now:function(){return j(),"active"===l}},"function"==typeof define&&define.amd?define(function(){return i}):window.ifvisible=i}).call(this);
/*! Magnific Popup - v0.9.8 - 2013-10-26
* http://dimsemenov.com/plugins/magnific-popup/
* Copyright (c) 2013 Dmitry Semenov; MIT */