From 8eba18b86bba2cb4cb467685642793fd12c36fc7 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 16 Dec 2009 00:03:28 -0700 Subject: [PATCH] Add ViewPort -> onContentOffset() callback. When searching for a row on the initial display, this prevents us from having to render the viewport twice - once for the original offset, and one for the altered offset. --- imp/js/DimpBase.js | 36 ++++++++++++++++++++++-------------- imp/js/ViewPort.js | 8 ++++++++ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/imp/js/DimpBase.js b/imp/js/DimpBase.js index 36a8d1cfc..fd3acc18b 100644 --- a/imp/js/DimpBase.js +++ b/imp/js/DimpBase.js @@ -9,7 +9,7 @@ var DimpBase = { // Vars used and defaulting to null/false: - // cfolderaction, folder, folderswitch, offset, pollPE, pp, resize, + // cfolderaction, folder, folderswitch, pollPE, pp, resize, rownum, // search, splitbar, template, uid, viewport // msglist_template_horiz and msglist_template_vert set via // js/mailbox-dimp.js @@ -144,7 +144,7 @@ var DimpBase = { this.viewport.select(row, { delay: 0.3 }); } } else { - this.offset = curr; + this.rownum = curr; this.viewport.requestContentRefresh(curr - 1); } }, @@ -490,6 +490,20 @@ var DimpBase = { } return this.cacheids[id]; }.bind(this), + onContentOffset: function(offset) { + if (this.uid) { + var row = this.viewport.getSelection().search({ imapuid: { equal: [ this.uid ] }, view: { equal: [ this.folder ] } }); + if (row.size()) { + this.rownum = row.get('rownum').first(); + this.viewport.scrollTo(this.rownum, { noupdate: true, top: true }); + offset = this.viewport.currentOffset(); + } + this.uid = null; + } else if (this.rownum) { + offset = this.rownum - 1; + } + return offset; + }.bind(this), onSlide: this.setMessageListTitle.bind(this) }); @@ -503,7 +517,7 @@ var DimpBase = { }.bindAsEventListener(this)); container.observe('ViewPort:contentComplete', function(e) { - var row, ssc, tmp, + var ssc, tmp, l = this.viewport.getMetaData('label'); this.setMessageListTitle(); @@ -512,23 +526,17 @@ var DimpBase = { } this.updateTitle(); + if (this.rownum) { + this.viewport.select(this.viewport.createSelection('rownum', this.rownum)); + this.rownum = null; + } + e.memo.each(function(row) { // Add context menu this._addMouseEvents({ id: row.VP_domid, type: row.menutype }); new Drag(row.VP_domid, this._msgDragConfig); }, this); - if (this.uid) { - row = this.viewport.getSelection().search({ imapuid: { equal: [ this.uid ] }, view: { equal: [ this.folder ] } }); - if (row.size()) { - this.viewport.scrollTo(row.get('rownum').first()); - this.viewport.select(row); - } - } else if (this.offset) { - this.viewport.select(this.viewport.createSelection('rownum', this.offset)); - } - this.offset = this.uid = null; - // 'label' will not be set if there has been an error // retrieving data from the server. l = this.viewport.getMetaData('label'); diff --git a/imp/js/ViewPort.js b/imp/js/ViewPort.js index 4e087c965..9ab894b5d 100644 --- a/imp/js/ViewPort.js +++ b/imp/js/ViewPort.js @@ -45,6 +45,10 @@ * onAjaxRequest: (function) TODO * onAjaxResponse: (function) TODO * onCachedList: (function) TODO + * onContentOffset: (function) Callback function that alters the starting + * offset of the content about to be rendered. + * params: (integer) The current offset. + * return: (integer) The altered offset. * onSlide: (function) TODO * page_size: (integer) Default page size to view on load. Only used if * pane_mode is 'horiz'. @@ -871,6 +875,10 @@ var ViewPort = Class.create({ this.scrollTo(offset + 1, { noupdate: true, top: true }); offset = this.currentOffset(); + if (this.opts.onContentOffset) { + offset = this.opts.onContentOffset(offset); + } + rows = this.createSelection('rownum', $A($R(offset + 1, offset + page_size))); if (rows.size()) { -- 2.11.0