Merge lp:~abreu-alexandre/ubuntu-html5-theme/fix-page-actions into lp:ubuntu-html5-theme

Proposed by Alexandre Abreu
Status: Merged
Approved by: Alexandre Abreu
Approved revision: 206
Merged at revision: 208
Proposed branch: lp:~abreu-alexandre/ubuntu-html5-theme/fix-page-actions
Merge into: lp:ubuntu-html5-theme
Diff against target: 425 lines (+221/-45)
7 files modified
0.1/ambiance/js/core.js (+37/-21)
0.1/ambiance/js/tabs.js (+10/-8)
tests/autopilot/ubuntu_html5_ui_toolkit/tests/__init__.py (+2/-1)
tests/autopilot/ubuntu_html5_ui_toolkit/tests/test_page_actions.py (+46/-0)
tests/autopilot/ubuntu_html5_ui_toolkit/tests/test_tabs.py (+2/-5)
tests/data/html/apps/rss-reader/index.html (+7/-10)
tests/data/html/test-page-actions.html (+117/-0)
To merge this branch: bzr merge lp:~abreu-alexandre/ubuntu-html5-theme/fix-page-actions
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Ubuntu HTML5 Theme Developers Pending
Review via email: mp+259515@code.launchpad.net

Commit message

Fix page actions; no need to create actions when none is defined

Description of the change

Fix page actions; no need to create actions when none is defined

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
206. By Alexandre Abreu

fix tests

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
71 this._prevScrollTop = this._y = 0;71 this._prevScrollTop = this._y = 0;
7272
73 this._header = document.querySelector('[data-role="header"]');73 this._header = document.querySelector('[data-role="header"]');
74 if ( ! this._header) {
75 return;
76 }
74 this._content = document.querySelector('[data-role="content"]');77 this._content = document.querySelector('[data-role="content"]');
75 this._headerHeight = this._header.offsetHeight + 17;78 this._headerHeight = this._header.offsetHeight + 17;
76 this._content.style.paddingTop = this._headerHeight + "px";79 this._content.style.paddingTop = this._headerHeight + "px";
@@ -133,11 +136,18 @@
133 this._pageStack.push(pages[0].getAttribute('id'));136 this._pageStack.push(pages[0].getAttribute('id'));
134 }137 }
135138
136 this._pageActions = d.createElement('div');139 this._pageActions = null;
137 this._pageActions.setAttribute('data-role', 'actions');
138140
139 header.appendChild(this._tabTitle);141 header.appendChild(this._tabTitle);
140 header.appendChild(this._pageActions);142 },
143
144 __createPageActions: function() {
145 if ( ! this._pageActions) {
146 this._pageActions = document.createElement('div');
147 this._pageActions.setAttribute('data-role', 'actions');
148 var header = document.querySelector("[data-role='header']");
149 header.appendChild(this._pageActions);
150 }
141 },151 },
142152
143 __transformHeader: function(y) {153 __transformHeader: function(y) {
@@ -162,10 +172,10 @@
162 var actionBar;172 var actionBar;
163173
164 var apptabsElements = document.querySelectorAll('[data-role=tab]');174 var apptabsElements = document.querySelectorAll('[data-role=tab]');
165 if (apptabsElements.length >= 0) {175 if (apptabsElements.length > 0) {
166 for (var idx = 0; idx < apptabsElements.length; ++idx) {176 for (var idx = 0; idx < apptabsElements.length; ++idx) {
167 var footers = apptabsElements[idx].querySelectorAll("[data-role='footer']");177 var footers = apptabsElements[idx].querySelectorAll("[data-role='footer']");
168 if (footers.length >= 0) {178 if (footers.length > 0) {
169 // TODO: validate footer count: should be 1 footer179 // TODO: validate footer count: should be 1 footer
170 actionBar = this.__setupTabAction(footers[0], apptabsElements[idx]);180 actionBar = this.__setupTabAction(footers[0], apptabsElements[idx]);
171 if (footers[0] != null) footers[0].remove();181 if (footers[0] != null) footers[0].remove();
@@ -174,10 +184,10 @@
174 }184 }
175185
176 var apppagesElements = document.querySelectorAll('[data-role=page]');186 var apppagesElements = document.querySelectorAll('[data-role=page]');
177 if (apppagesElements.length >= 0) {187 if (apppagesElements.length > 0) {
178 for (var idx = 0; idx < apppagesElements.length; ++idx) {188 for (var idx = 0; idx < apppagesElements.length; ++idx) {
179 var footers = apppagesElements[idx].querySelectorAll("[data-role='footer']");189 var footers = apppagesElements[idx].querySelectorAll("[data-role='footer']");
180 if (footers.length >= 0) {190 if (footers.length > 0) {
181 // TODO: validate footer count: should be 1 footer191 // TODO: validate footer count: should be 1 footer
182 actionBar = this.__setupPageAction(footers[0], apppagesElements[idx]);192 actionBar = this.__setupPageAction(footers[0], apppagesElements[idx]);
183 if (footers[0] != null) footers[0].remove();193 if (footers[0] != null) footers[0].remove();
@@ -213,7 +223,11 @@
213223
214 this._overlay = document.querySelector('[data-role="overlay"]');224 this._overlay = document.querySelector('[data-role="overlay"]');
215225
226 this.__createPageActions();
227
216 var newActionsBar = document.querySelector('[data-role="actions"]');228 var newActionsBar = document.querySelector('[data-role="actions"]');
229 if ( ! newActionsBar)
230 return;
217231
218 if (!this._oldFooter)232 if (!this._oldFooter)
219 return;233 return;
@@ -239,20 +253,18 @@
239 firstId = firstAction.querySelector('a').getAttribute('id'),253 firstId = firstAction.querySelector('a').getAttribute('id'),
240 k = 1;254 k = 1;
241255
242 if (this._tabs != 'undefined' && this._tabs) {256 if (this._tabs && this._tabs._tabsitems.length == 1) {
243 if (this._tabs._tabsItems.length == 1) {257 k = 2;
244 k = 2;258 this._tabs._tabTitle.style.width = "calc(100% - 155px)";
245 this._tabs._tabTitle.style.width = "calc(100% - 155px)";
246259
247 // Maintain the second item260 // Maintain the second item
248 var secondAction = actionButtons[1],261 var secondAction = actionButtons[1],
249 /* Action Button */262 /* Action Button */
250 secondButton = document.createElement('button'),263 secondButton = document.createElement('button'),
251 /* Icon */264 /* Icon */
252 secondIcon = secondAction.querySelector('img').getAttribute('src'),265 secondIcon = secondAction.querySelector('img').getAttribute('src'),
253 /* ID*/266 /* ID*/
254 secondId = secondAction.querySelector('a').getAttribute('id');267 secondId = secondAction.querySelector('a').getAttribute('id');
255 }
256 }268 }
257269
258 overflowList.setAttribute('data-role', 'actions-overflow-list');270 overflowList.setAttribute('data-role', 'actions-overflow-list');
@@ -286,7 +298,7 @@
286298
287 newActionsBarWrapper.appendChild(firstButton);299 newActionsBarWrapper.appendChild(firstButton);
288 if (this._tabs != 'undefined' && this._tabs) {300 if (this._tabs != 'undefined' && this._tabs) {
289 if (this._tabs._tabsItems.length == 1) {301 if (this._tabs._tabsitems && this._tabs._tabsitems.length == 1) {
290 secondButton.setAttribute('id', secondId);302 secondButton.setAttribute('id', secondId);
291 document.styleSheets[0].addRule('#' + secondId + ':after', 'background-image: url("' + secondIcon + '");');303 document.styleSheets[0].addRule('#' + secondId + ':after', 'background-image: url("' + secondIcon + '");');
292 newActionsBarWrapper.appendChild(secondButton);304 newActionsBarWrapper.appendChild(secondButton);
@@ -325,7 +337,11 @@
325 this._oldFooterParent = parent;337 this._oldFooterParent = parent;
326 this._overlay = document.querySelector('[data-role="overlay"]');338 this._overlay = document.querySelector('[data-role="overlay"]');
327339
340 this.__createPageActions();
341
328 var newActionsBar = document.querySelector('[data-role="actions"]');342 var newActionsBar = document.querySelector('[data-role="actions"]');
343 if (! newActionsBar)
344 return;
329345
330 if (!this._oldFooter)346 if (!this._oldFooter)
331 return;347 return;
332348
=== 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 @@
188 var tabtitle_value = document.createTextNode('Main');188 var tabtitle_value = document.createTextNode('Main');
189 this._tabtitle.appendChild(tabtitle_value);189 this._tabtitle.appendChild(tabtitle_value);
190190
191 this._tabsactions = document.createElement('div');
192 this._tabsactions.setAttribute('data-role', 'actions');
193
194 var tab = this._tabs.querySelector('[data-role="tabitem"]:first-child');191 var tab = this._tabs.querySelector('[data-role="tabitem"]:first-child');
195 /*tab.classList.remove('inactive');192 /*tab.classList.remove('inactive');
196 tab.classList.add('active');*/193 tab.classList.add('active');*/
@@ -208,7 +205,6 @@
208 };205 };
209 } else { this._tabtitle.style.marginLeft = '16px'; }206 } else { this._tabtitle.style.marginLeft = '16px'; }
210 this._header.appendChild(this._tabtitle);207 this._header.appendChild(this._tabtitle);
211 this._header.appendChild(this._tabsactions);
212208
213 var self = this;209 var self = this;
214 this._overlay.onclick = function (e) {210 this._overlay.onclick = function (e) {
@@ -315,8 +311,11 @@
315 __toggleTabs: function () {311 __toggleTabs: function () {
316 this._tabs.classList.toggle('opened');312 this._tabs.classList.toggle('opened');
317 this._overlay.classList.toggle('active');313 this._overlay.classList.toggle('active');
318 if (this._tabsactions.querySelector('.opened') !== null)314
319 this._tabsactions.querySelector('.opened').classList.remove('opened');315 var tabsActions = document.querySelector('[data-role="actions"]');
316 if (tabsActions &&
317 tabsActions.querySelector('.opened') !== null)
318 tabsActions.querySelector('.opened').classList.remove('opened');
320 },319 },
321320
322 /**321 /**
@@ -325,8 +324,11 @@
325 __hideMenus: function () {324 __hideMenus: function () {
326 this._tabs.classList.remove('opened');325 this._tabs.classList.remove('opened');
327 this._overlay.classList.remove('active');326 this._overlay.classList.remove('active');
328 if (this._tabsactions.querySelector('.opened') !== null)327
329 this._tabsactions.querySelector('.opened').classList.remove('opened');328 var tabsActions = document.querySelector('[data-role="actions"]');
329 if (tabsActions &&
330 tabsActions.querySelector('.opened') !== null)
331 tabsActions.querySelector('.opened').classList.remove('opened');
330 }332 }
331 };333 };
332334
333335
=== 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 @@
86 '/usr/share/ubuntu-html5-ui-toolkit/tests/tools/qml/webview.qml'86 '/usr/share/ubuntu-html5-ui-toolkit/tests/tools/qml/webview.qml'
87 BROWSER_QML_APP_LAUNCHER = "/usr/lib/{}/qt5/bin/qmlscene".format(87 BROWSER_QML_APP_LAUNCHER = "/usr/lib/{}/qt5/bin/qmlscene".format(
88 subprocess.check_output(88 subprocess.check_output(
89 ["dpkg-architecture", "-qDEB_HOST_MULTIARCH"]).strip().decode('utf-8'))89 ["dpkg-architecture",
90 "-qDEB_HOST_MULTIARCH"]).strip().decode('utf-8'))
9091
91 # TODO: fix version92 # TODO: fix version
92 LOCAL_HTML_EXAMPLES_PATH = os.path.abspath(93 LOCAL_HTML_EXAMPLES_PATH = os.path.abspath(
9394
=== 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 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2# Copyright 2013 Canonical
3#
4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU Lesser General Public License version 3, as
6# published by the Free Software Foundation.
7
8from __future__ import absolute_import
9
10from testtools.matchers import Equals, NotEquals
11from autopilot.matchers import Eventually
12
13from ubuntu_html5_ui_toolkit.tests import UbuntuHTML5TestCaseBase
14
15
16class UbuntuThemePageStackTestCase(UbuntuHTML5TestCaseBase):
17
18 def setUp(self):
19 super(UbuntuThemePageStackTestCase, self).setUp()
20
21 def test_tabWithActions(self):
22 self.browse_to_test_html('test-page-actions.html')
23 self.eval_expression_in_page_unsafe(
24 'var UI = new UbuntuUI(); UI.init();'),
25 self.assertThat(
26 self.eval_expression_in_page_unsafe(
27 'return document.querySelector\
28(\'[data-role="actions"]\') != null;'),
29 Equals('true'))
30 self.assertThat(
31 lambda: self.eval_expression_in_page_unsafe(
32 'return document.getElementById\
33("addfeed").parentNode.style.display;'),
34 Eventually(NotEquals('none')))
35
36 def test_noActions(self):
37 self.browse_to_test_html('test-nopagestack-in-app.html')
38 self.assertThat(
39 self.eval_expression_in_page_unsafe(
40 'var UI = new UbuntuUI(); UI.init(); return "ok";'),
41 Equals('ok'))
42 self.assertThat(
43 self.eval_expression_in_page_unsafe(
44 'return document.querySelector\
45(\'[data-role="actions"]\') != null;'),
46 Equals('false'))
047
=== 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 @@
3939
40 self.assertThat(40 self.assertThat(
41 self.eval_expression_in_page_unsafe(41 self.eval_expression_in_page_unsafe(
42 'var UI = new UbuntuUI(); '42 'return document.getElementById("tab2").style.display;'),
43 'UI.init(); '43 Equals('block'))
44 'return UI.tabs.selectedTabIndex;'),
45 Equals('1'))
46
4744
=== 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 @@
55 <div data-role="mainview">55 <div data-role="mainview">
5656
57 <header data-role="header">57 <header data-role="header">
58 <ul data-role="tabs">
59 <li data-role="tabitem" data-page="main">RSS Mobile Reader</li>
60 <li data-role="tabitem" data-page="results">RSS Feed</li>
61 <li data-role="tabitem" data-page="article">Article</li>
62 </ul>
63 </header>58 </header>
6459
65 <div data-role="content">60 <div data-role="content">
66 <div data-role="pagestack">61
67 <div data-role="page" id="main">62 <div data-role="pagestack">
63
64 <div data-role="page" id="main" data-title="RSS Mobile Reader">
68 <section data-role="list" id="yourfeeds"></section>65 <section data-role="list" id="yourfeeds"></section>
69 <footer data-role="footer" class="revealed">66 <footer data-role="footer" class="revealed">
70 <nav>67 <nav>
71 <ul>68 <ul>
72 <li>69 <li>
73 <a href="#" id="addfeed">70 <a href="#" id="addfeed">
74 <img src="../../../ambiance/img/back@18.png" alt="Tap me!" />71 <img src="/usr/share/icons/suru/actions/scalable/note-new.svg" alt="Tap me!" />
75 <span>Add feed</span>72 <span>Add feed</span>
76 </a>73 </a>
77 </li>74 </li>
@@ -80,11 +77,11 @@
80 </footer>77 </footer>
81 </div>78 </div>
8279
83 <div data-role="page" id="results">80 <div data-role="page" id="results" data-title="Articles">
84 <section data-role="list" id="resultscontent"></section>81 <section data-role="list" id="resultscontent"></section>
85 </div>82 </div>
8683
87 <div data-role="page" id="article">84 <div data-role="page" id="article" data-title="Article">
88 <section id="articleinfo"></section>85 <section id="articleinfo"></section>
89 </div>86 </div>
90 </div>87 </div>
9188
=== added file 'tests/data/html/test-page-actions.html'
--- tests/data/html/test-page-actions.html 1970-01-01 00:00:00 +0000
+++ tests/data/html/test-page-actions.html 2015-05-19 17:32:11 +0000
@@ -0,0 +1,117 @@
1<!--
2 Copyright (C) 2015 Canonical Ltd
3
4 This file is part of ubuntu-html5-ui-toolkit.
5
6 This package is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 3 of the
9 License, or
10 (at your option) any later version.
11
12 This package is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this program. If not, see
19 <http://www.gnu.org/licenses/>
20-->
21
22<!DOCTYPE html>
23<html>
24<head>
25 <meta charset="utf-8" />
26 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
27
28 <title>Page Actions test</title>
29
30 <!-- Ubuntu UI Style imports - Ambiance theme -->
31 <link href="../../../0.1/ambiance/css/appTemplate.css" rel="stylesheet" type="text/css" />
32
33 <!-- Ubuntu UI javascript imports - Ambiance theme -->
34 <script src="../../../0.1/ambiance/js/fast-buttons.js"></script>
35 <script src="../../../0.1/ambiance/js/core.js"></script>
36 <script src="../../../0.1/ambiance/js/buttons.js"></script>
37 <script src="../../../0.1/ambiance/js/dialogs.js"></script>
38 <script src="../../../0.1/ambiance/js/popovers.js"></script>
39 <script src="../../../0.1/ambiance/js/list.js"></script>
40 <script src="../../../0.1/ambiance/js/tab.js"></script>
41 <script src="../../../0.1/ambiance/js/tabs.js"></script>
42</head>
43
44<body>
45 <div data-role="mainview">
46
47 <header data-role="header">
48 <ul data-role="tabs">
49 <li data-role="tabitem" data-page="tab1">Tab 1</li>
50 <li data-role="tabitem" data-page="tab2">Tab 2</li>
51 </ul>
52 </header>
53
54 <div data-role="content">
55
56 <div data-role="tab" id="tab1">
57 <div>tab1 content</div>
58
59 <footer id="footer1" data-role="footer" class="revealed">
60 <nav>
61 <ul>
62 <li>
63 <a href="#" id="addfeed">
64 <img src="/usr/share/icons/suru/actions/scalable/note-new.svg" alt="Tap me!" />
65 <span>Add feed</span>
66 </a>
67 </li>
68 </ul>
69 </nav>
70 </footer>
71 </div>
72
73 <div data-role="tab" id="tab2">
74 <div>tab2 content</div>
75
76 <footer id="footer2" data-role="footer" class="revealed">
77 <nav>
78 <ul>
79 <li>
80 <a href="#" id="new-email">
81 <img src="/usr/share/icons/suru/actions/scalable/notebook-new.svg" alt="Tap me!" />
82 <span>New Email</span>
83 </a>
84 </li>
85
86 <li>
87 <a href="#" id="edit-note">
88 <img src="/usr/share/icons/suru/actions/scalable/edit-paste.svg" alt="Tap me!" />
89 <span>Edit Note</span>
90 </a>
91 </li>
92
93 <li>
94 <a href="#" id="infos">
95 <img src="/usr/share/icons/suru/actions/scalable/info.svg" alt="Tap me!" />
96 <span>Infos</span>
97 </a>
98 </li>
99
100 <li>
101 <a href="#" id="private-browsing">
102 <img src="/usr/share/icons/suru/actions/scalable/private-browsing.svg" alt="Tap me!" />
103 <span>Private Browsing</span>
104 </a>
105 </li>
106 </ul>
107 </nav>
108 </footer>
109 </div>
110 </div>
111
112 <script>
113
114 </script>
115
116</body>
117</html>

Subscribers

People subscribed via source and target branches