From 31329fa7ea6b43aa3af04296f199c6d212490cd2 Mon Sep 17 00:00:00 2001 From: John Chen Date: Thu, 9 Aug 2012 14:17:36 +0800 Subject: [PATCH] [Layout View] Fix unnecessary scrolling when model update Now there's no position change when propertyChanged and no fliker when nodeAdded/nodeRemoved --- src/js/composer.js | 7 ------- src/js/views/layout.js | 8 +++++++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/js/composer.js b/src/js/composer.js index 73329545..99ada8bf 100644 --- a/src/js/composer.js +++ b/src/js/composer.js @@ -804,13 +804,6 @@ $(function() { $(inputs).disableSelection(); }); - $('div:jqmData(role="page")').live('pageshow', function(e) { - // Make sure selected node is visible on pageinit - $('.ui-selected:first').each(function () { - $.mobile.silentScroll($(this).offset().top); - }); - }); - function messageHandler(e) { switch (e.data) { case 'reload': diff --git a/src/js/views/layout.js b/src/js/views/layout.js index d08d1b74..f7fec2f3 100644 --- a/src/js/views/layout.js +++ b/src/js/views/layout.js @@ -258,7 +258,8 @@ }, _modelUpdatedHandler: function (event, widget) { - var win, aPage, pageNode; + var win, aPage, pageNode, + oldScrollTop = (widget.options.contentDocument.scrollTop()); widget = widget || this; @@ -283,6 +284,11 @@ } else { console.error(widget.widgetName, ':: Missing contentDocument'); } + widget.options.contentDocument.scrollTop(oldScrollTop); + // Make sure Make sure selected node is visible + widget.options.contentDocument.find('.ui-selected').first().each(function () { + this.scrollIntoViewIfNeeded() + }); }, _createDocument: function () {