From 776995582d93fc25e5c9e8b9909f851c56d63fcf Mon Sep 17 00:00:00 2001 From: stephaneDiot Date: Wed, 15 Feb 2017 14:50:48 +0100 Subject: [PATCH 1/2] EZP-26044: Handle scroll on navigation --- Resources/public/js/apps/ez-platformuiapp.js | 10 ++++++ .../js/apps/assets/ez-platformuiapp-tests.js | 34 ++++++++++++++++++- .../views/assets/ez-locationviewview-tests.js | 1 - .../assets/ez-navigationhubview-tests.js | 2 +- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Resources/public/js/apps/ez-platformuiapp.js b/Resources/public/js/apps/ez-platformuiapp.js index 3e728fc13..b74a26c83 100644 --- a/Resources/public/js/apps/ez-platformuiapp.js +++ b/Resources/public/js/apps/ez-platformuiapp.js @@ -736,6 +736,16 @@ YUI.add('ez-platformuiapp', function (Y) { update: true, render: true }); + + if (window && app.get('scrollToTop')) { + // Scroll to the top of the page. The timeout ensures that the + // scroll happens after navigation begins, so that the current + // scroll position will be restored if the user clicks the back + // button. + setTimeout(function () { + window.scroll(0, 0); + }, 1); + } }; if ( this.get('activeView') ) { diff --git a/Tests/js/apps/assets/ez-platformuiapp-tests.js b/Tests/js/apps/assets/ez-platformuiapp-tests.js index 7f6fbd77e..e22b44ab8 100644 --- a/Tests/js/apps/assets/ez-platformuiapp-tests.js +++ b/Tests/js/apps/assets/ez-platformuiapp-tests.js @@ -8,7 +8,7 @@ YUI.add('ez-platformuiapp-tests', function (Y) { showSideViewTest, hideSideViewTest, enablingRoutingTest, hashChangeTest, handleMainViewTest, titleTest, configRouteTest, dispatchConfigTest, getLanguageNameTest, refreshViewTest, - navigateToTest, + navigateToTest, scrollTest, Assert = Y.Assert, Mock = Y.Mock; appTest = new Y.Test.Case({ @@ -199,6 +199,37 @@ YUI.add('ez-platformuiapp-tests', function (Y) { }, }); + scrollTest = new Y.Test.Case({ + name: "Scroll tests", + + setUp: function () { + this.app = new Y.eZ.PlatformUIApp({ + container: '.app', + viewContainer: '.view-container' + }); + }, + + tearDown: function () { + + this.app.destroy(); + delete this.app; + }, + + "Should scroll to top and left of the window when showing main view": function () { + var that = this; + + window.scroll(800, 800); + + this.app.showView('view', {}, function () { + that.resume(function () { + Assert.areSame(window.pageXOffset, 0 ,"window should be scrolled to left"); + Assert.areSame(window.pageYOffset, 0 ,"window should be scrolled to top"); + }); + }); + this.wait(); + }, + }); + handleMainViewTest = new Y.Test.Case({ name: "handleMainView app tests", @@ -2443,4 +2474,5 @@ YUI.add('ez-platformuiapp-tests', function (Y) { Y.Test.Runner.add(enablingRoutingTest); Y.Test.Runner.add(hashChangeTest); Y.Test.Runner.add(navigateToTest); + Y.Test.Runner.add(scrollTest); }, '', {requires: ['test', 'ez-platformuiapp', 'ez-viewservice', 'ez-viewservicebaseplugin', 'history-hash']}); diff --git a/Tests/js/views/assets/ez-locationviewview-tests.js b/Tests/js/views/assets/ez-locationviewview-tests.js index 8fd82ad28..8ba6aec2f 100644 --- a/Tests/js/views/assets/ez-locationviewview-tests.js +++ b/Tests/js/views/assets/ez-locationviewview-tests.js @@ -1093,7 +1093,6 @@ YUI.add('ez-locationviewview-tests', function (Y) { }, }); - Y.Test.Runner.setName("eZ Location View view tests"); Y.Test.Runner.add(test); Y.Test.Runner.add(tabsTest); diff --git a/Tests/js/views/assets/ez-navigationhubview-tests.js b/Tests/js/views/assets/ez-navigationhubview-tests.js index 92f65f771..c40d1f35e 100644 --- a/Tests/js/views/assets/ez-navigationhubview-tests.js +++ b/Tests/js/views/assets/ez-navigationhubview-tests.js @@ -537,7 +537,7 @@ YUI.add('ez-navigationhubview-tests', function (Y) { Y.Assert.areEqual(2, eventFired, "The 'navigationModeChange' event should be been fire twice"); }, - + "Should fire the heightChange event when getting fixed": function () { var heightChange = false; From beb539cf50d30b4c1057602b7bf17966254f946e Mon Sep 17 00:00:00 2001 From: stephaneDiot Date: Thu, 23 Feb 2017 11:33:56 +0100 Subject: [PATCH 2/2] Fix-EZP-26044: Fixed NavigationHub positionning --- Resources/public/js/apps/ez-platformuiapp.js | 2 +- Resources/public/js/views/ez-navigationhubview.js | 1 + Tests/js/apps/assets/ez-platformuiapp-tests.js | 9 +++------ Tests/js/views/assets/ez-navigationhubview-tests.js | 12 +++++++++++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Resources/public/js/apps/ez-platformuiapp.js b/Resources/public/js/apps/ez-platformuiapp.js index b74a26c83..8ba083a59 100644 --- a/Resources/public/js/apps/ez-platformuiapp.js +++ b/Resources/public/js/apps/ez-platformuiapp.js @@ -737,7 +737,7 @@ YUI.add('ez-platformuiapp', function (Y) { render: true }); - if (window && app.get('scrollToTop')) { + if (app.get('scrollToTop')) { // Scroll to the top of the page. The timeout ensures that the // scroll happens after navigation begins, so that the current // scroll position will be restored if the user clicks the back diff --git a/Resources/public/js/views/ez-navigationhubview.js b/Resources/public/js/views/ez-navigationhubview.js index 4a5d77eff..91f8930f3 100644 --- a/Resources/public/js/views/ez-navigationhubview.js +++ b/Resources/public/js/views/ez-navigationhubview.js @@ -85,6 +85,7 @@ YUI.add('ez-navigationhubview', function (Y) { var oldHeight; if ( this.get('active') ) { + this.set('navigationFixed', false); oldHeight = this._getContainerHeight(); this._uiSetActiveNavigation(e.prevVal); this._navigateToZone(e.newVal); diff --git a/Tests/js/apps/assets/ez-platformuiapp-tests.js b/Tests/js/apps/assets/ez-platformuiapp-tests.js index e22b44ab8..dcbb8cd27 100644 --- a/Tests/js/apps/assets/ez-platformuiapp-tests.js +++ b/Tests/js/apps/assets/ez-platformuiapp-tests.js @@ -210,22 +210,19 @@ YUI.add('ez-platformuiapp-tests', function (Y) { }, tearDown: function () { - this.app.destroy(); delete this.app; }, "Should scroll to top and left of the window when showing main view": function () { - var that = this; - window.scroll(800, 800); - this.app.showView('view', {}, function () { - that.resume(function () { + this.app.showView('view', {}, Y.bind(function () { + this.resume(function () { Assert.areSame(window.pageXOffset, 0 ,"window should be scrolled to left"); Assert.areSame(window.pageYOffset, 0 ,"window should be scrolled to top"); }); - }); + }, this)); this.wait(); }, }); diff --git a/Tests/js/views/assets/ez-navigationhubview-tests.js b/Tests/js/views/assets/ez-navigationhubview-tests.js index c40d1f35e..7e0478b05 100644 --- a/Tests/js/views/assets/ez-navigationhubview-tests.js +++ b/Tests/js/views/assets/ez-navigationhubview-tests.js @@ -537,7 +537,17 @@ YUI.add('ez-navigationhubview-tests', function (Y) { Y.Assert.areEqual(2, eventFired, "The 'navigationModeChange' event should be been fire twice"); }, - + + "Should set navigationFixed to false on navigationChange": function () { + this.view.set('active', true); + this.view.set('activeNavigation', 'platform'); + + Y.Assert.isFalse( + this.view.get('navigationFixed'), + "navigationFixed attribute should be false" + ); + }, + "Should fire the heightChange event when getting fixed": function () { var heightChange = false;