diff --git a/Resources/public/js/apps/ez-platformuiapp.js b/Resources/public/js/apps/ez-platformuiapp.js index 3e728fc13..8ba083a59 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 (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/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 7f6fbd77e..dcbb8cd27 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,34 @@ 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 () { + window.scroll(800, 800); + + 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(); + }, + }); + handleMainViewTest = new Y.Test.Case({ name: "handleMainView app tests", @@ -2443,4 +2471,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..7e0478b05 100644 --- a/Tests/js/views/assets/ez-navigationhubview-tests.js +++ b/Tests/js/views/assets/ez-navigationhubview-tests.js @@ -538,6 +538,16 @@ 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;