Merge lp:~abreu-alexandre/ubuntu-html5-theme/add-setselected-tab-index into lp:ubuntu-html5-theme

Proposed by Alexandre Abreu
Status: Merged
Merged at revision: 157
Proposed branch: lp:~abreu-alexandre/ubuntu-html5-theme/add-setselected-tab-index
Merge into: lp:ubuntu-html5-theme
Diff against target: 288 lines (+168/-18)
5 files modified
0.1/ambiance/js/tab.js (+0/-1)
0.1/ambiance/js/tabs.js (+44/-13)
tests/autopilot/tools/qml/webview.qml (+3/-4)
tests/autopilot/ubuntu_html5_ui_toolkit/tests/test_tabs.py (+31/-0)
tests/data/html/test-tabs-in-app.html (+90/-0)
To merge this branch: bzr merge lp:~abreu-alexandre/ubuntu-html5-theme/add-setselected-tab-index
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Adnane Belmadiaf Approve
Review via email: mp+209532@code.launchpad.net

Commit message

Add a set selectedTabIndex property,
Add associated tabs AP tests,
Some minor fixes in tabs,

Description of the change

Add a set selectedTabIndex property,
Add associated tabs AP tests,
Some minor fixes in tabs,

To post a comment you must log in.
153. By Alexandre Abreu

remove trailing log

154. By Alexandre Abreu

remove trailing js

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Adnane Belmadiaf (daker) wrote :

Spaces instead of tabs.

review: Needs Fixing
155. By Alexandre Abreu

untabify

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> Spaces instead of tabs.
done

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Adnane Belmadiaf (daker) wrote :

+1

review: Approve
156. By Alexandre Abreu

Remove wrong 'inactive' class set on first visibility setup; Add a force selection flag to disable the unecessary 'inactive' check when forcefully setting the tab index; Fix tab index validation

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
1=== modified file '0.1/ambiance/js/tab.js'
2--- 0.1/ambiance/js/tab.js 2014-02-28 20:29:07 +0000
3+++ 0.1/ambiance/js/tab.js 2014-03-19 16:52:31 +0000
4@@ -91,7 +91,6 @@
5 * @method {} activate
6 */
7 activate: function (id) {
8- console.log('actiatin');
9 this.__hideVisibleSibling();
10 this.__updateVisibleState('block', function(footer) {
11 if (!footer)
12
13=== modified file '0.1/ambiance/js/tabs.js'
14--- 0.1/ambiance/js/tabs.js 2014-03-03 16:54:31 +0000
15+++ 0.1/ambiance/js/tabs.js 2014-03-19 16:52:31 +0000
16@@ -46,13 +46,13 @@
17 </header>
18
19 <div data-role="content">
20- <div data-role="tab" id="main">
21+ <div data-role="tab" id="main">
22 [...]
23- </div>
24+ </div>
25
26- <div data-role="tab" id="page2">
27+ <div data-role="tab" id="page2">
28 [...]
29- </div>
30+ </div>
31 </div>
32
33 </div>
34@@ -120,10 +120,23 @@
35 /**
36 * Return the index of the selected tab
37 * @property selectedTabIndex
38- * @return {Integer} - The index of the element in the list of tabs or -1
39+ * @return {Integer} - The zero based index of the element in the list of tabs or -1
40 */
41 get selectedTabIndex() {
42- return [].prototype.slice.call(this._tabs.querySelector('ul').children).indexOf(activeTab);
43+ return Array.prototype.slice.call(this._tabs.querySelectorAll('li')).indexOf(activeTab);
44+ },
45+
46+ /**
47+ * Sets the index of the selected tab
48+ * @property selectedTabIndex
49+ * @param {Integer} - The zero based index of the element in the list of tabs
50+ */
51+ set selectedTabIndex(index) {
52+ var tabs = Array.prototype.slice.call(this._tabs.querySelectorAll('li'));
53+ if (index < 0 || index >= tabs.length)
54+ return;
55+
56+ this.__doSelectTab(tabs[index], true);
57 },
58
59 /**
60@@ -181,6 +194,7 @@
61 */
62 __setupInitialTabVisibility: function() {
63 var tab = this._tabs.querySelector('[data-role="tabitem"]:first-child');
64+ tab.classList.remove('inactive');
65 tab.classList.add('active');
66 var updateDisplayStyle = function(tab, value) {
67 var targetPage = document.getElementById(tab.getAttribute('data-page'));
68@@ -191,6 +205,7 @@
69 [].slice.
70 call(this._tabs.querySelectorAll('[data-role="tabitem"]:not(:first-child)')).
71 forEach(function(element) {
72+ element.classList.remove('inactive');
73 updateDisplayStyle(element, 'none');
74 });
75 },
76@@ -396,9 +411,23 @@
77 var selectedTab = document.elementFromPoint(touch.pageX, touch.pageY);
78 if (selectedTab == null)
79 return;
80- if (selectedTab.getAttribute("data-role") !== 'tabitem')
81- return;
82- if ((selectedTab.className).indexOf('inactive') > -1) {
83+ this.__doSelectTab(selectedTab);
84+ e.preventDefault();
85+ },
86+
87+ /**
88+ * @private
89+ */
90+ __doSelectTab: function(tabElement, forcedSelection) {
91+ if ( ! tabElement)
92+ return;
93+
94+ if (tabElement.getAttribute("data-role") !== 'tabitem')
95+ return;
96+
97+ if (forcedSelection ||
98+ (Array.prototype.slice.call(tabElement.classList)).indexOf('inactive') > -1) {
99+
100 window.clearTimeout(t2);
101
102 activeTab = this._tabs.querySelector('[data-role="tabitem"].active');
103@@ -406,13 +435,13 @@
104 this._tabs.style['-webkit-transition-duration'] = '.3s';
105 this._tabs.style.webkitTransform = 'translate3d(-' + offsetX + 'px,0,0)';
106
107- this.__updateActiveTab(selectedTab, activeTab);
108+ this.__updateActiveTab(tabElement, activeTab);
109
110 [].forEach.call(this._tabs.querySelectorAll('[data-role="tabitem"]:not(.active)'), function (e) {
111 e.classList.remove('inactive');
112 });
113
114- var targetPageId = selectedTab.getAttribute('data-page');
115+ var targetPageId = tabElement.getAttribute('data-page');
116 this.activate(targetPageId);
117 this.__dispatchTabChangedEvent(targetPageId);
118 } else {
119@@ -420,13 +449,15 @@
120 [].forEach.call(this._tabs.querySelectorAll('[data-role="tabitem"]:not(.active)'), function (el) {
121 el.classList.toggle('inactive');
122 });
123+
124+ var self = this;
125 t2 = window.setTimeout(function () {
126- [].forEach.call(this._tabs.querySelectorAll('[data-role="tabitem"]:not(.active)'), function (el) {
127+ var nonActiveTabs = self._tabs.querySelectorAll('[data-role="tabitem"]:not(.active)');
128+ [].forEach.call(nonActiveTabs, function (el) {
129 el.classList.toggle('inactive');
130 });
131 }, 3000);
132 }
133- e.preventDefault();
134 },
135
136 /**
137
138=== modified file 'tests/autopilot/tools/qml/webview.qml'
139--- tests/autopilot/tools/qml/webview.qml 2014-02-11 03:16:49 +0000
140+++ tests/autopilot/tools/qml/webview.qml 2014-03-19 16:52:31 +0000
141@@ -116,13 +116,12 @@
142 function getAttributeForElementWithId(id,attribute) {
143 var tid = __gentid();
144 function __getAttributeWithId() {
145- try { return document.querySelector('#' + id).getAttribute(attribute); } catch (e) {};
146- return undefined;
147+ try { var value = document.querySelector('#' + id).getAttribute(attribute); return value || ""; } catch (e) { return e.toString(); };
148+ return "";
149 };
150-
151 var statement = __setupClosedVariables({'id': id, 'attribute': attribute});
152 statement += __getAttributeWithId.toString();
153- statement += "; return __getAttributeWithId(id,attribute,value); "
154+ statement += "; return __getAttributeWithId(); "
155
156 webview.experimental.evaluateJavaScript(__wrapJsCommands(statement),
157 function(result) { root.resultUpdated(root.__createResult(result, tid)); });
158
159=== added file 'tests/autopilot/ubuntu_html5_ui_toolkit/tests/test_tabs.py'
160--- tests/autopilot/ubuntu_html5_ui_toolkit/tests/test_tabs.py 1970-01-01 00:00:00 +0000
161+++ tests/autopilot/ubuntu_html5_ui_toolkit/tests/test_tabs.py 2014-03-19 16:52:31 +0000
162@@ -0,0 +1,31 @@
163+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
164+# Copyright 2014 Canonical
165+#
166+# This program is free software: you can redistribute it and/or modify it
167+# under the terms of the GNU Lesser General Public License version 3, as published
168+# by the Free Software Foundation.
169+
170+from __future__ import absolute_import
171+
172+import time
173+
174+from testtools.matchers import Contains, Equals
175+from autopilot.matchers import Eventually
176+
177+from ubuntu_html5_ui_toolkit.tests import UbuntuHTML5TestCaseBase
178+
179+class UbuntuUIToolkitTabsTestCase(UbuntuHTML5TestCaseBase):
180+
181+ def setUp(self):
182+ super(UbuntuUIToolkitTabsTestCase, self).setUp()
183+
184+ def test_programaticTabSelectIndex(self):
185+ self.browse_to_test_html('test-tabs-in-app.html')
186+ self.assertThat(self.eval_expression_in_page_unsafe('var UI = new UbuntuUI(); UI.init(); UI.tabs.selectedTabIndex = 1; return "ok";'), Equals('ok'));
187+
188+ self.assertThat(lambda: self.is_dom_node_visible('tab1'), Eventually(Equals(False)))
189+ self.assertThat(lambda: self.is_dom_node_visible('tab2'), Eventually(Equals(True)))
190+ self.assertThat(lambda: self.is_dom_node_visible('tab3'), Eventually(Equals(False)))
191+
192+ self.assertThat(self.eval_expression_in_page_unsafe('var UI = new UbuntuUI(); UI.init(); return UI.tabs.selectedTabIndex = 1;'), Equals(1));
193+
194
195=== added file 'tests/data/html/test-tabs-in-app.html'
196--- tests/data/html/test-tabs-in-app.html 1970-01-01 00:00:00 +0000
197+++ tests/data/html/test-tabs-in-app.html 2014-03-19 16:52:31 +0000
198@@ -0,0 +1,90 @@
199+<!--
200+ Copyright (C) 2013 Adnane Belmadiaf <daker@ubuntu.com>
201+
202+ This file is part of ubuntu-html5-ui-toolkit.
203+
204+ This package is free software; you can redistribute it and/or modify
205+ it under the terms of the GNU Lesser General Public License as
206+ published by the Free Software Foundation; either version 3 of the
207+ License, or
208+ (at your option) any later version.
209+
210+ This package is distributed in the hope that it will be useful,
211+ but WITHOUT ANY WARRANTY; without even the implied warranty of
212+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
213+ GNU General Public License for more details.
214+
215+ You should have received a copy of the GNU Lesser General Public
216+ License along with this program. If not, see
217+ <http://www.gnu.org/licenses/>.
218+-->
219+
220+<!DOCTYPE html>
221+<html>
222+<head>
223+ <meta charset="utf-8" />
224+ <meta name="copyright" content="Adnane Belmadiaf <daker@ubuntu.com>">
225+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
226+ <title>Ubuntu UI HTML5: Application Template</title>
227+
228+ <link href="../../../0.1/ambiance/css/appTemplate.css" rel="stylesheet" type="text/css" />
229+
230+ <!-- Ubuntu UI javascript imports - Ambiance theme -->
231+ <script src="../../../0.1/ambiance/js/fast-buttons.js"></script>
232+ <script src="../../../0.1/ambiance/js/core.js"></script>
233+ <script src="../../../0.1/ambiance/js/buttons.js"></script>
234+ <script src="../../../0.1/ambiance/js/dialogs.js"></script>
235+ <script src="../../../0.1/ambiance/js/page.js"></script>
236+ <script src="../../../0.1/ambiance/js/pagestacks.js"></script>
237+ <script src="../../../0.1/ambiance/js/popovers.js"></script>
238+ <script src="../../../0.1/ambiance/js/tab.js"></script>
239+ <script src="../../../0.1/ambiance/js/tabs.js"></script>
240+ <script>
241+ window.onload = function () {
242+ };
243+ </script>
244+
245+</head>
246+
247+<body>
248+
249+ <div data-role="mainview">
250+
251+ <header data-role="header">
252+ <ul data-role="tabs">
253+ <li data-role="tabitem" data-page="tab1">Tab 1</li>
254+ <li data-role="tabitem" data-page="tab2">Tab 2</li>
255+ <li data-role="tabitem" data-page="tab3">Tab 3</li>
256+ </ul>
257+ </header>
258+
259+ <div data-role="content">
260+
261+ <div data-role="tab" id="tab1">
262+ <footer data-role="footer" class="revealed">
263+ <nav>
264+ <ul>
265+ <li>
266+ <a href="#" id="addfeed">
267+ <img src="../../../0.1/ambiance/img/back@18.png" alt="Tap me!" />
268+ <span>Add feed</span>
269+ </a>
270+ </li>
271+ </ul>
272+ </nav>
273+ </footer>
274+ </div>
275+
276+ <div data-role="tab" id="tab2">
277+ </div>
278+
279+ <div data-role="tab" id="tab3">
280+ </div>
281+
282+ </div>
283+
284+ </div>
285+
286+</body>
287+
288+</html>

Subscribers

People subscribed via source and target branches