-
+
- Tab 1 +
- Tab 2 +
=== modified file '0.1/ambiance/js/core.js' --- 0.1/ambiance/js/core.js 2015-03-04 21:21:52 +0000 +++ 0.1/ambiance/js/core.js 2015-05-19 17:32:11 +0000 @@ -71,6 +71,9 @@ this._prevScrollTop = this._y = 0; this._header = document.querySelector('[data-role="header"]'); + if ( ! this._header) { + return; + } this._content = document.querySelector('[data-role="content"]'); this._headerHeight = this._header.offsetHeight + 17; this._content.style.paddingTop = this._headerHeight + "px"; @@ -133,11 +136,18 @@ this._pageStack.push(pages[0].getAttribute('id')); } - this._pageActions = d.createElement('div'); - this._pageActions.setAttribute('data-role', 'actions'); + this._pageActions = null; header.appendChild(this._tabTitle); - header.appendChild(this._pageActions); + }, + + __createPageActions: function() { + if ( ! this._pageActions) { + this._pageActions = document.createElement('div'); + this._pageActions.setAttribute('data-role', 'actions'); + var header = document.querySelector("[data-role='header']"); + header.appendChild(this._pageActions); + } }, __transformHeader: function(y) { @@ -162,10 +172,10 @@ var actionBar; var apptabsElements = document.querySelectorAll('[data-role=tab]'); - if (apptabsElements.length >= 0) { + if (apptabsElements.length > 0) { for (var idx = 0; idx < apptabsElements.length; ++idx) { var footers = apptabsElements[idx].querySelectorAll("[data-role='footer']"); - if (footers.length >= 0) { + if (footers.length > 0) { // TODO: validate footer count: should be 1 footer actionBar = this.__setupTabAction(footers[0], apptabsElements[idx]); if (footers[0] != null) footers[0].remove(); @@ -174,10 +184,10 @@ } var apppagesElements = document.querySelectorAll('[data-role=page]'); - if (apppagesElements.length >= 0) { + if (apppagesElements.length > 0) { for (var idx = 0; idx < apppagesElements.length; ++idx) { var footers = apppagesElements[idx].querySelectorAll("[data-role='footer']"); - if (footers.length >= 0) { + if (footers.length > 0) { // TODO: validate footer count: should be 1 footer actionBar = this.__setupPageAction(footers[0], apppagesElements[idx]); if (footers[0] != null) footers[0].remove(); @@ -213,7 +223,11 @@ this._overlay = document.querySelector('[data-role="overlay"]'); + this.__createPageActions(); + var newActionsBar = document.querySelector('[data-role="actions"]'); + if ( ! newActionsBar) + return; if (!this._oldFooter) return; @@ -239,20 +253,18 @@ firstId = firstAction.querySelector('a').getAttribute('id'), k = 1; - if (this._tabs != 'undefined' && this._tabs) { - if (this._tabs._tabsItems.length == 1) { - k = 2; - this._tabs._tabTitle.style.width = "calc(100% - 155px)"; + if (this._tabs && this._tabs._tabsitems.length == 1) { + k = 2; + this._tabs._tabTitle.style.width = "calc(100% - 155px)"; - // Maintain the second item - var secondAction = actionButtons[1], - /* Action Button */ - secondButton = document.createElement('button'), - /* Icon */ - secondIcon = secondAction.querySelector('img').getAttribute('src'), - /* ID*/ - secondId = secondAction.querySelector('a').getAttribute('id'); - } + // Maintain the second item + var secondAction = actionButtons[1], + /* Action Button */ + secondButton = document.createElement('button'), + /* Icon */ + secondIcon = secondAction.querySelector('img').getAttribute('src'), + /* ID*/ + secondId = secondAction.querySelector('a').getAttribute('id'); } overflowList.setAttribute('data-role', 'actions-overflow-list'); @@ -286,7 +298,7 @@ newActionsBarWrapper.appendChild(firstButton); if (this._tabs != 'undefined' && this._tabs) { - if (this._tabs._tabsItems.length == 1) { + if (this._tabs._tabsitems && this._tabs._tabsitems.length == 1) { secondButton.setAttribute('id', secondId); document.styleSheets[0].addRule('#' + secondId + ':after', 'background-image: url("' + secondIcon + '");'); newActionsBarWrapper.appendChild(secondButton); @@ -325,7 +337,11 @@ this._oldFooterParent = parent; this._overlay = document.querySelector('[data-role="overlay"]'); + this.__createPageActions(); + var newActionsBar = document.querySelector('[data-role="actions"]'); + if (! newActionsBar) + return; if (!this._oldFooter) return; === modified file '0.1/ambiance/js/tabs.js' --- 0.1/ambiance/js/tabs.js 2015-03-03 23:30:16 +0000 +++ 0.1/ambiance/js/tabs.js 2015-05-19 17:32:11 +0000 @@ -188,9 +188,6 @@ var tabtitle_value = document.createTextNode('Main'); this._tabtitle.appendChild(tabtitle_value); - this._tabsactions = document.createElement('div'); - this._tabsactions.setAttribute('data-role', 'actions'); - var tab = this._tabs.querySelector('[data-role="tabitem"]:first-child'); /*tab.classList.remove('inactive'); tab.classList.add('active');*/ @@ -208,7 +205,6 @@ }; } else { this._tabtitle.style.marginLeft = '16px'; } this._header.appendChild(this._tabtitle); - this._header.appendChild(this._tabsactions); var self = this; this._overlay.onclick = function (e) { @@ -315,8 +311,11 @@ __toggleTabs: function () { this._tabs.classList.toggle('opened'); this._overlay.classList.toggle('active'); - if (this._tabsactions.querySelector('.opened') !== null) - this._tabsactions.querySelector('.opened').classList.remove('opened'); + + var tabsActions = document.querySelector('[data-role="actions"]'); + if (tabsActions && + tabsActions.querySelector('.opened') !== null) + tabsActions.querySelector('.opened').classList.remove('opened'); }, /** @@ -325,8 +324,11 @@ __hideMenus: function () { this._tabs.classList.remove('opened'); this._overlay.classList.remove('active'); - if (this._tabsactions.querySelector('.opened') !== null) - this._tabsactions.querySelector('.opened').classList.remove('opened'); + + var tabsActions = document.querySelector('[data-role="actions"]'); + if (tabsActions && + tabsActions.querySelector('.opened') !== null) + tabsActions.querySelector('.opened').classList.remove('opened'); } }; === modified file 'tests/autopilot/ubuntu_html5_ui_toolkit/tests/__init__.py' --- tests/autopilot/ubuntu_html5_ui_toolkit/tests/__init__.py 2015-01-21 16:41:33 +0000 +++ tests/autopilot/ubuntu_html5_ui_toolkit/tests/__init__.py 2015-05-19 17:32:11 +0000 @@ -86,7 +86,8 @@ '/usr/share/ubuntu-html5-ui-toolkit/tests/tools/qml/webview.qml' BROWSER_QML_APP_LAUNCHER = "/usr/lib/{}/qt5/bin/qmlscene".format( subprocess.check_output( - ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip().decode('utf-8')) + ["dpkg-architecture", + "-qDEB_HOST_MULTIARCH"]).strip().decode('utf-8')) # TODO: fix version LOCAL_HTML_EXAMPLES_PATH = os.path.abspath( === added file 'tests/autopilot/ubuntu_html5_ui_toolkit/tests/test_page_actions.py' --- tests/autopilot/ubuntu_html5_ui_toolkit/tests/test_page_actions.py 1970-01-01 00:00:00 +0000 +++ tests/autopilot/ubuntu_html5_ui_toolkit/tests/test_page_actions.py 2015-05-19 17:32:11 +0000 @@ -0,0 +1,46 @@ +# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- +# Copyright 2013 Canonical +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License version 3, as +# published by the Free Software Foundation. + +from __future__ import absolute_import + +from testtools.matchers import Equals, NotEquals +from autopilot.matchers import Eventually + +from ubuntu_html5_ui_toolkit.tests import UbuntuHTML5TestCaseBase + + +class UbuntuThemePageStackTestCase(UbuntuHTML5TestCaseBase): + + def setUp(self): + super(UbuntuThemePageStackTestCase, self).setUp() + + def test_tabWithActions(self): + self.browse_to_test_html('test-page-actions.html') + self.eval_expression_in_page_unsafe( + 'var UI = new UbuntuUI(); UI.init();'), + self.assertThat( + self.eval_expression_in_page_unsafe( + 'return document.querySelector\ +(\'[data-role="actions"]\') != null;'), + Equals('true')) + self.assertThat( + lambda: self.eval_expression_in_page_unsafe( + 'return document.getElementById\ +("addfeed").parentNode.style.display;'), + Eventually(NotEquals('none'))) + + def test_noActions(self): + self.browse_to_test_html('test-nopagestack-in-app.html') + self.assertThat( + self.eval_expression_in_page_unsafe( + 'var UI = new UbuntuUI(); UI.init(); return "ok";'), + Equals('ok')) + self.assertThat( + self.eval_expression_in_page_unsafe( + 'return document.querySelector\ +(\'[data-role="actions"]\') != null;'), + Equals('false')) === modified file 'tests/autopilot/ubuntu_html5_ui_toolkit/tests/test_tabs.py' --- tests/autopilot/ubuntu_html5_ui_toolkit/tests/test_tabs.py 2014-11-19 18:36:44 +0000 +++ tests/autopilot/ubuntu_html5_ui_toolkit/tests/test_tabs.py 2015-05-19 17:32:11 +0000 @@ -39,8 +39,5 @@ self.assertThat( self.eval_expression_in_page_unsafe( - 'var UI = new UbuntuUI(); ' - 'UI.init(); ' - 'return UI.tabs.selectedTabIndex;'), - Equals('1')) - + 'return document.getElementById("tab2").style.display;'), + Equals('block')) === modified file 'tests/data/html/apps/rss-reader/index.html' --- tests/data/html/apps/rss-reader/index.html 2014-01-30 19:56:22 +0000 +++ tests/data/html/apps/rss-reader/index.html 2015-05-19 17:32:11 +0000 @@ -55,23 +55,20 @@