Merge lp:~abreu-alexandre/ubuntu-html5-theme/fix-toolbar-swipe into lp:ubuntu-html5-theme

Proposed by Alexandre Abreu
Status: Merged
Approved by: Alexandre Abreu
Approved revision: no longer in the source branch.
Merged at revision: 140
Proposed branch: lp:~abreu-alexandre/ubuntu-html5-theme/fix-toolbar-swipe
Merge into: lp:ubuntu-html5-theme
Diff against target: 341 lines (+221/-51)
4 files modified
0.1/ambiance/js/core.js (+14/-1)
0.1/ambiance/js/toolbars.js (+199/-44)
examples/html5-theme/apps/rss-reader/index.html (+2/-1)
examples/html5-theme/widgets/Toolbar.html (+6/-5)
To merge this branch: bzr merge lp:~abreu-alexandre/ubuntu-html5-theme/fix-toolbar-swipe
Reviewer Review Type Date Requested Status
Adnane Belmadiaf Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+206242@code.launchpad.net

Commit message

Based on a branch from daker: lp:~daker/ubuntu-html5-theme/fix.1202349

Revamped & made it work on desktop and touch. Remove the need to declare the toolbar in js.

Description of the change

Based on a branch from daker: lp:~daker/ubuntu-html5-theme/fix.1202349

Revamped & made it work on desktop and touch. Remove the need to declare the toolbar in js.

It needs:

https://code.launchpad.net/~abreu-alexandre/ubuntu-html5-theme/resize-webview-with-qtquick-resize/+merge/206971

to work properly on the device

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Adnane Belmadiaf (daker) wrote :

LGTM but it still needs more work to make it perfect.

review: Approve
137. By Alexandre Abreu

Fix page & pagestack behavior regarding the page title updates & tabs relationship which is very flawed atm.

A page should have a title.
In a page stack, the page's title should be reflected *dynamically* in the header as the page is pushed/popped. Fixes: 1279891

138. By Alexandre Abreu

Fix touch detection on UbuntuTouch & Desktop: we handle both. Touch detection does not work reliably, we should embrace the dual world.

139. By PS Jenkins bot

Releasing 0.1.2+14.04.20140217-0ubuntu1

140. By Alexandre Abreu

merge trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '0.1/ambiance/js/core.js'
2--- 0.1/ambiance/js/core.js 2014-02-13 15:54:50 +0000
3+++ 0.1/ambiance/js/core.js 2014-02-18 17:22:34 +0000
4@@ -227,6 +227,18 @@
5 };
6 },
7
8+ __setupToolbars: function(document) {
9+ var toolbars =
10+ document.querySelectorAll('footer[data-role="footer"]');
11+ for (var i = 0; i < toolbars.length; ++i) {
12+ var id = toolbars[i].getAttribute('id');
13+ if ( !id)
14+ continue;
15+ var toolbar = new Toolbar(
16+ id, this.__getTabInfosDelegate());
17+ }
18+ },
19+
20 __setupTabs: function (document) {
21 if (this._tabs != null)
22 return;
23@@ -256,6 +268,7 @@
24 init: function () {
25 this.__setupTabs(document);
26 this.__setupPage(document);
27+ this.__setupToolbars(document);
28 },
29
30 /**
31@@ -339,7 +352,7 @@
32 */
33 toolbar: function (id) {
34 if (typeof Toolbar != 'undefined' && Toolbar) {
35- return new Toolbar(this, id);
36+ return new Toolbar(id, this.__getTabInfosDelegate());
37 }
38 },
39
40
41=== modified file '0.1/ambiance/js/toolbars.js'
42--- 0.1/ambiance/js/toolbars.js 2014-01-27 18:42:31 +0000
43+++ 0.1/ambiance/js/toolbars.js 2014-02-18 17:22:34 +0000
44@@ -50,47 +50,202 @@
45
46 */
47
48-var Toolbar = function (UbuntuUI, id) {
49- this.toolbar = document.getElementById(id);
50-};
51-
52-Toolbar.prototype = {
53- /**-
54- * Display a Toolbar
55- * @method show
56- */
57- show: function () {
58- this.toolbar.classList.add('revealed');
59- },
60- /**-
61- * Hide a Toolbar
62- * @method hide
63- */
64- hide: function () {
65- this.toolbar.classList.remove('revealed');
66- },
67- /**
68- * Toggle show/hide status of a Toolbar
69- * @method toggle
70- */
71- toggle: function () {
72- this.toolbar.classList.toggle('revealed');
73- },
74- /**
75- * Provide a callback function that's called with the Toolbar is touched
76- * @method touch
77- * @param {Function} function - The function that is called when the Toolbar is touched
78- */
79- touch: function (callback) {
80- this.toolbar.addEventListener(UbuntuUI.touchEvents.touchEnd, callback);
81- },
82- /**
83- * Returns the DOM element associated with the id this widget is bind to.
84- * @method element
85- * @example
86- var mytoolbar = UI.toolbar("toolbarid").element();
87- */
88- element: function () {
89- return this.toolbar;
90- }
91-};
92+var Toolbar = (function () {
93+
94+ function Toolbar(id, touchInfoDelegate) {
95+
96+ this.PHASE_START = "start";
97+ this.PHASE_MOVE = "move";
98+ this.PHASE_END = "end";
99+ this.PHASE_CANCEL = "cancel";
100+
101+ this.phase = null;
102+
103+ this.toolbar = document.getElementById(id);
104+ if ( ! this.toolbar)
105+ throw "Invalid toolbar id";
106+
107+ this._touchDown = false;
108+ this._touchInfoDelegate = touchInfoDelegate;
109+
110+ this.fingerData = [];
111+ this.fingerData.push({
112+ start: {
113+ x: 0,
114+ y: 0
115+ },
116+ end: {
117+ x: 0,
118+ y: 0
119+ },
120+ identifier: 0
121+ });
122+
123+ var touchEvents = touchInfoDelegate.touchEvents;
124+ touchInfoDelegate.registerTouchEvent(
125+ touchEvents.touchStart, this.toolbar, this.__onTouchStart.bind(this));
126+ touchInfoDelegate.registerTouchEvent(
127+ touchEvents.touchEnd, this.toolbar, this.__onTouchEnd.bind(this));
128+ touchInfoDelegate.registerTouchEvent(
129+ touchEvents.touchMove, this.toolbar, this.__onTouchMove.bind(this));
130+ touchInfoDelegate.registerTouchEvent(
131+ touchEvents.touchLeave, this.toolbar, this.__onTouchLeave.bind(this));
132+ };
133+
134+ Toolbar.prototype = {
135+ /**-
136+ * Display a Toolbar
137+ * @method show
138+ */
139+ show: function () {
140+ this.toolbar.classList.add('revealed');
141+ },
142+
143+ /**-
144+ * Hide a Toolbar
145+ * @method hide
146+ */
147+ hide: function () {
148+ this.toolbar.classList.remove('revealed');
149+ },
150+
151+ /**
152+ * Toggle show/hide status of a Toolbar
153+ * @method toggle
154+ */
155+ toggle: function () {
156+ this.toolbar.classList.toggle('revealed');
157+ },
158+
159+ /**
160+ * Returns the DOM element associated with the id this widget is bind to.
161+ * @method element
162+ * @example
163+ var mytoolbar = UI.toolbar("toolbarid").element();
164+ */
165+ element: function () {
166+ return this.toolbar;
167+ },
168+
169+ /**
170+ * @private
171+ */
172+ __onTouchStart: function (evt) {
173+ this._touchDown = true;
174+
175+ evt.preventDefault();
176+
177+ this.phase = this.PHASE_START;
178+ var identifier = evt.identifier !== undefined ? evt.identifier : 0;
179+
180+ var touchEvent =
181+ this._touchInfoDelegate.translateTouchEvent(evt);
182+
183+ this.fingerData[0].identifier = identifier;
184+ this.fingerData[0].start.x =
185+ this.fingerData[0].end.x = touchEvent.touches[0].pageX;
186+ this.fingerData[0].start.y =
187+ this.fingerData[0].end.y = touchEvent.touches[0].pageY;
188+ },
189+
190+ /**
191+ * @private
192+ */
193+ __onTouchMove: function (evt) {
194+ if ( ! this._touchDown)
195+ return;
196+
197+ if (this.phase === this.PHASE_END || this.phase === this.PHASE_CANCEL)
198+ return;
199+
200+ if (this.phase == this.PHASE_START) {
201+ evt.preventDefault();
202+
203+ var touchEvent =
204+ this._touchInfoDelegate.translateTouchEvent(evt);
205+
206+ var identifier = evt.identifier !== undefined ? evt.identifier : 0;
207+ var f = this.__getFingerData(identifier);
208+
209+ f.end.x = touchEvent.touches[0].pageX;
210+ f.end.y = touchEvent.touches[0].pageY;
211+
212+ direction = this.__calculateDirection(f.start, f.end);
213+
214+ if (direction == "DOWN") {
215+ this.hide();
216+ }
217+
218+ if (direction == "UP") {
219+ this.show();
220+ }
221+
222+ phase = this.PHASE_MOVE;
223+ }
224+ },
225+
226+ /**
227+ * @private
228+ */
229+ __onTouchEnd: function (e) {
230+ this._touchDown = false;
231+ phase = this.PHASE_END;
232+ },
233+
234+ /**
235+ * @private
236+ */
237+ __onTouchLeave: function (e) {
238+ this._touchDown = false;
239+ phase = this.PHASE_CANCEL;
240+ },
241+
242+ /**
243+ * @private
244+ */
245+ __calculateDirection: function (startPoint, endPoint) {
246+ var angle = this.__calculateAngle(startPoint, endPoint);
247+
248+ if ((angle <= 45) && (angle >= 0)) {
249+ return "LEFT";
250+ } else if ((angle <= 360) && (angle >= 315)) {
251+ return "LEFT";
252+ } else if ((angle >= 135) && (angle <= 225)) {
253+ return "RIGHT";
254+ } else if ((angle > 45) && (angle < 135)) {
255+ return "DOWN";
256+ } else {
257+ return "UP";
258+ }
259+ },
260+
261+ /**
262+ * @private
263+ */
264+ __getFingerData: function (id) {
265+ for (var i = 0; i < this.fingerData.length; i++) {
266+ if (this.fingerData[i].identifier == id) {
267+ return this.fingerData[i];
268+ }
269+ }
270+ },
271+
272+ /**
273+ * @private
274+ */
275+ __calculateAngle: function (startPoint, endPoint) {
276+ var x = startPoint.x - endPoint.x;
277+ var y = endPoint.y - startPoint.y;
278+ var r = Math.atan2(y, x); //radians
279+ var angle = Math.round(r * 180 / Math.PI); //degrees
280+
281+ //ensure value is positive
282+ if (angle < 0) {
283+ angle = 360 - Math.abs(angle);
284+ }
285+
286+ return angle;
287+ }
288+ };
289+ return Toolbar;
290+})();
291
292=== modified file 'examples/html5-theme/apps/rss-reader/index.html'
293--- examples/html5-theme/apps/rss-reader/index.html 2014-02-13 16:55:29 +0000
294+++ examples/html5-theme/apps/rss-reader/index.html 2014-02-18 17:22:34 +0000
295@@ -47,6 +47,7 @@
296 <script src="../../../../0.1/ambiance/js/pagestacks.js"></script>
297 <script src="../../../../0.1/ambiance/js/popovers.js"></script>
298 <script src="../../../../0.1/ambiance/js/list.js"></script>
299+ <script src="../../../../0.1/ambiance/js/toolbars.js"></script>
300 <script src="../../../../0.1/ambiance/js/tabs.js"></script>
301 <script src="app.js"></script>
302 </head>
303@@ -63,7 +64,7 @@
304
305 <div data-role="page" id="main" data-title="RSS Mobile Reader">
306 <section data-role="list" id="yourfeeds"></section>
307- <footer data-role="footer" class="revealed">
308+ <footer id="footer1" data-role="footer" class="revealed">
309 <nav>
310 <ul>
311 <li>
312
313=== modified file 'examples/html5-theme/widgets/Toolbar.html'
314--- examples/html5-theme/widgets/Toolbar.html 2014-02-12 19:46:04 +0000
315+++ examples/html5-theme/widgets/Toolbar.html 2014-02-18 17:22:34 +0000
316@@ -40,6 +40,7 @@
317 </head>
318
319 <body>
320+
321 <div data-role="mainview">
322
323 <div data-role="content">
324@@ -66,12 +67,12 @@
325 </div>
326 </div>
327 <script type="text/javascript">
328- var UI = new UbuntuUI(),
329- tabs = UI.tabs("[data-role='tabs']");
330+ var UI = new UbuntuUI();
331+ window.onload = function() {
332+ UI.init();
333 toolbar = UI.toolbar("footer1");
334- toolbar.touch(function (event) {
335- toolbar.toggle();
336- });
337+ };
338+ </script>
339 </script>
340 </body>
341 </html>

Subscribers

People subscribed via source and target branches