Merge lp:~daker/ubuntu-html5-theme/fix.1202349 into lp:ubuntu-html5-theme
- fix.1202349
- Merge into trunk
Proposed by
Adnane Belmadiaf
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 140 | ||||
Proposed branch: | lp:~daker/ubuntu-html5-theme/fix.1202349 | ||||
Merge into: | lp:ubuntu-html5-theme | ||||
Diff against target: |
388 lines (+225/-75) 5 files modified
0.1/ambiance/js/core.js (+1/-1) 0.1/ambiance/js/toolbars.js (+203/-46) examples/html5-theme/apps/rss-reader/app.js (+2/-0) examples/html5-theme/apps/rss-reader/index.html (+2/-1) examples/html5-theme/widgets/Toolbar.html (+17/-27) |
||||
To merge this branch: | bzr merge lp:~daker/ubuntu-html5-theme/fix.1202349 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexandre Abreu | Needs Fixing | ||
Review via email: mp+199902@code.launchpad.net |
Commit message
Add swipe to reveal/hide the toolbar
Description of the change
To post a comment you must log in.
- 99. By Adnane Belmadiaf
-
Added fixes for yuidoc
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 2013-12-16 17:50:33 +0000 |
3 | +++ 0.1/ambiance/js/core.js 2013-12-21 21:50:50 +0000 |
4 | @@ -327,7 +327,7 @@ |
5 | */ |
6 | toolbar: function (id) { |
7 | if (typeof Toolbar != 'undefined' && Toolbar) { |
8 | - return new Toolbar(this, id); |
9 | + return new Toolbar(id, this.__getTabInfosDelegate()); |
10 | } |
11 | }, |
12 | |
13 | |
14 | === modified file '0.1/ambiance/js/toolbars.js' |
15 | --- 0.1/ambiance/js/toolbars.js 2013-12-06 14:03:50 +0000 |
16 | +++ 0.1/ambiance/js/toolbars.js 2013-12-21 21:50:50 +0000 |
17 | @@ -21,10 +21,10 @@ |
18 | */ |
19 | |
20 | /** |
21 | - * A Toolbar is the JavaScript representation of an Ubuntu HTML5 app <em>footer</em>. |
22 | + * A Toolbar is the JavaScript representation of an Ubuntu HTML5 app <em>footer</em>. |
23 | |
24 | ######Contained List provides buttons |
25 | -The Toolbar contains a List, where each list item is treated as a Button (see below). List items (Buttons) are pushed to the right. The default Back button always exists to the left and does not need to be declared. |
26 | +The Toolbar contains a List, where each list item is treated as a Button (see below). List items (Buttons) are pushed to the right. The default Back button always exists to the left and does not need to be declared. |
27 | |
28 | #####Default and custom footers |
29 | See the Pagestack class documentation for information about the default application-wide Footer, customizing it, and adding Page-specific Footers. |
30 | @@ -50,47 +50,204 @@ |
31 | |
32 | */ |
33 | |
34 | -var Toolbar = function (UbuntuUI, id) { |
35 | - this.toolbar = document.getElementById(id); |
36 | -}; |
37 | - |
38 | -Toolbar.prototype = { |
39 | - /**- |
40 | - * Display a Toolbar |
41 | - * @method show |
42 | - */ |
43 | - show: function () { |
44 | - this.toolbar.classList.add('revealed'); |
45 | - }, |
46 | - /**- |
47 | - * Hide a Toolbar |
48 | - * @method hide |
49 | - */ |
50 | - hide: function () { |
51 | - this.toolbar.classList.remove('revealed'); |
52 | - }, |
53 | - /** |
54 | - * Toggle show/hide status of a Toolbar |
55 | - * @method toggle |
56 | - */ |
57 | - toggle: function () { |
58 | - this.toolbar.classList.toggle('revealed'); |
59 | - }, |
60 | - /** |
61 | - * Provide a callback function that's called with the Toolbar is touched |
62 | - * @method touch |
63 | - * @param {Function} function - The function that is called when the Toolbar is touched |
64 | - */ |
65 | - touch: function (callback) { |
66 | - this.toolbar.addEventListener(UbuntuUI.touchEvents.touchEnd, callback); |
67 | - }, |
68 | - /** |
69 | - * Returns the DOM element associated with the id this widget is bind to. |
70 | - * @method element |
71 | - * @example |
72 | - var mytoolbar = UI.toolbar("toolbarid").element(); |
73 | - */ |
74 | - element: function () { |
75 | - return this.toolbar; |
76 | - } |
77 | -}; |
78 | +var Toolbar = (function () { |
79 | + |
80 | + function Toolbar(id, touchInfoDelegate) { |
81 | + |
82 | + this.PHASE_START = "start"; |
83 | + this.PHASE_MOVE = "move"; |
84 | + this.PHASE_END = "end"; |
85 | + this.PHASE_CANCEL = "cancel"; |
86 | + |
87 | + this.phase = null; |
88 | + |
89 | + this.UI = UI; |
90 | + |
91 | + this.toolbar = document.getElementById(id); |
92 | + |
93 | + this._touchInfoDelegate = touchInfoDelegate; |
94 | + |
95 | + var touchEvents = touchInfoDelegate.touchEvents; |
96 | + |
97 | + this.fingerData = []; |
98 | + this.fingerData.push({ |
99 | + start: { |
100 | + x: 0, |
101 | + y: 0 |
102 | + }, |
103 | + end: { |
104 | + x: 0, |
105 | + y: 0 |
106 | + }, |
107 | + identifier: 0 |
108 | + }); |
109 | + |
110 | + this.toolbar.addEventListener(touchEvents.touchStart, this.__onTouchStart.bind(this)); |
111 | + this.toolbar.addEventListener(touchEvents.touchMove, this.__onTouchMove.bind(this)); |
112 | + this.toolbar.addEventListener(touchEvents.touchEnd, this.__onTouchEnd.bind(this)); |
113 | + this.toolbar.addEventListener(touchEvents.touchLeave, this.__onTouchLeave.bind(this)); |
114 | + }; |
115 | + |
116 | + Toolbar.prototype = { |
117 | + /**- |
118 | + * Display a Toolbar |
119 | + * @method show |
120 | + */ |
121 | + show: function () { |
122 | + this.toolbar.classList.add('revealed'); |
123 | + }, |
124 | + |
125 | + /**- |
126 | + * Hide a Toolbar |
127 | + * @method hide |
128 | + */ |
129 | + hide: function () { |
130 | + this.toolbar.classList.remove('revealed'); |
131 | + }, |
132 | + |
133 | + /** |
134 | + * Toggle show/hide status of a Toolbar |
135 | + * @method toggle |
136 | + */ |
137 | + toggle: function () { |
138 | + this.toolbar.classList.toggle('revealed'); |
139 | + }, |
140 | + |
141 | + /** |
142 | + * Provide a callback function that's called with the Toolbar is touched |
143 | + * @method touch |
144 | + * @param {Function} function - The function that is called when the Toolbar is touched |
145 | + */ |
146 | + touch: function (callback) { |
147 | + this.toolbar.addEventListener(this.touchEvents.touchEnd, callback); |
148 | + }, |
149 | + |
150 | + /** |
151 | + * Returns the DOM element associated with the id this widget is bind to. |
152 | + * @method element |
153 | + * @example |
154 | + var mytoolbar = UI.toolbar("toolbarid").element(); |
155 | + */ |
156 | + element: function () { |
157 | + return this.toolbar; |
158 | + }, |
159 | + |
160 | + /** |
161 | + * @private |
162 | + */ |
163 | + __onTouchStart: function (evt) { |
164 | + |
165 | + this.phase = this.PHASE_START; |
166 | + var identifier = evt.identifier !== undefined ? evt.identifier : 0; |
167 | + |
168 | + if (!this.UI.isTouch) { |
169 | + evt.touches = [{ |
170 | + pageX: evt.pageX, |
171 | + pageY: evt.pageY |
172 | + }]; |
173 | + } |
174 | + |
175 | + this.fingerData[0].identifier = identifier; |
176 | + this.fingerData[0].start.x = this.fingerData[0].end.x = evt.touches[0].pageX; |
177 | + this.fingerData[0].start.y = this.fingerData[0].end.y = evt.touches[0].pageY; |
178 | + }, |
179 | + |
180 | + /** |
181 | + * @private |
182 | + */ |
183 | + __onTouchMove: function (evt) { |
184 | + |
185 | + if (this.phase === this.PHASE_END || this.phase === this.PHASE_CANCEL) |
186 | + return; |
187 | + |
188 | + if (this.phase == this.PHASE_START) { |
189 | + if (!this.UI.isTouch) { |
190 | + evt.touches = [{ |
191 | + pageX: evt.pageX, |
192 | + pageY: evt.pageY |
193 | + }]; |
194 | + } |
195 | + |
196 | + var identifier = evt.identifier !== undefined ? evt.identifier : 0; |
197 | + var f = this.__getFingerData(identifier); |
198 | + |
199 | + f.end.x = evt.touches[0].pageX; |
200 | + f.end.y = evt.touches[0].pageY; |
201 | + |
202 | + direction = this.__calculateDirection(f.start, f.end); |
203 | + |
204 | + if (direction == "DOWN") { |
205 | + this.hide(); |
206 | + } |
207 | + |
208 | + if (direction == "UP") { |
209 | + this.show(); |
210 | + } |
211 | + |
212 | + phase = this.PHASE_MOVE; |
213 | + } |
214 | + }, |
215 | + |
216 | + /** |
217 | + * @private |
218 | + */ |
219 | + __onTouchEnd: function (e) { |
220 | + phase = this.PHASE_END; |
221 | + }, |
222 | + |
223 | + /** |
224 | + * @private |
225 | + */ |
226 | + __onTouchLeave: function (e) { |
227 | + phase = this.PHASE_CANCEL; |
228 | + }, |
229 | + |
230 | + /** |
231 | + * @private |
232 | + */ |
233 | + __calculateDirection: function (startPoint, endPoint) { |
234 | + var angle = this.__calculateAngle(startPoint, endPoint); |
235 | + |
236 | + if ((angle <= 45) && (angle >= 0)) { |
237 | + return "LEFT"; |
238 | + } else if ((angle <= 360) && (angle >= 315)) { |
239 | + return "LEFT"; |
240 | + } else if ((angle >= 135) && (angle <= 225)) { |
241 | + return "RIGHT"; |
242 | + } else if ((angle > 45) && (angle < 135)) { |
243 | + return "DOWN"; |
244 | + } else { |
245 | + return "UP"; |
246 | + } |
247 | + }, |
248 | + |
249 | + /** |
250 | + * @private |
251 | + */ |
252 | + __getFingerData: function (id) { |
253 | + for (var i = 0; i < this.fingerData.length; i++) { |
254 | + if (this.fingerData[i].identifier == id) { |
255 | + return this.fingerData[i]; |
256 | + } |
257 | + } |
258 | + }, |
259 | + |
260 | + /** |
261 | + * @private |
262 | + */ |
263 | + __calculateAngle: function (startPoint, endPoint) { |
264 | + var x = startPoint.x - endPoint.x; |
265 | + var y = endPoint.y - startPoint.y; |
266 | + var r = Math.atan2(y, x); //radians |
267 | + var angle = Math.round(r * 180 / Math.PI); //degrees |
268 | + |
269 | + //ensure value is positive |
270 | + if (angle < 0) { |
271 | + angle = 360 - Math.abs(angle); |
272 | + } |
273 | + |
274 | + return angle; |
275 | + } |
276 | + }; |
277 | + return Toolbar; |
278 | +})(); |
279 | |
280 | === modified file 'examples/html5-theme/apps/rss-reader/app.js' |
281 | --- examples/html5-theme/apps/rss-reader/app.js 2013-11-05 15:13:05 +0000 |
282 | +++ examples/html5-theme/apps/rss-reader/app.js 2013-12-21 21:50:50 +0000 |
283 | @@ -26,6 +26,8 @@ |
284 | |
285 | UI.init(); |
286 | UI.pagestack.push("main"); |
287 | + toolbar = UI.toolbar("footer1"); |
288 | + |
289 | |
290 | if (typeof localStorage["feeds"] == "undefined") { |
291 | restoreDefault(); |
292 | |
293 | === modified file 'examples/html5-theme/apps/rss-reader/index.html' |
294 | --- examples/html5-theme/apps/rss-reader/index.html 2013-12-12 11:12:42 +0000 |
295 | +++ examples/html5-theme/apps/rss-reader/index.html 2013-12-21 21:50:50 +0000 |
296 | @@ -47,6 +47,7 @@ |
297 | <script src="../../../../0.1/ambiance/js/pagestacks.js"></script> |
298 | <script src="../../../../0.1/ambiance/js/popovers.js"></script> |
299 | <script src="../../../../0.1/ambiance/js/list.js"></script> |
300 | + <script src="../../../../0.1/ambiance/js/toolbars.js"></script> |
301 | <script src="../../../../0.1/ambiance/js/tabs.js"></script> |
302 | <script src="app.js"></script> |
303 | </head> |
304 | @@ -66,7 +67,7 @@ |
305 | <div data-role="pagestack"> |
306 | <div data-role="page" id="main"> |
307 | <section data-role="list" id="yourfeeds"></section> |
308 | - <footer data-role="footer" class="revealed"> |
309 | + <footer id="footer1" data-role="footer" class="revealed"> |
310 | <nav> |
311 | <ul> |
312 | <li> |
313 | |
314 | === modified file 'examples/html5-theme/widgets/Toolbar.html' |
315 | --- examples/html5-theme/widgets/Toolbar.html 2013-12-12 08:28:52 +0000 |
316 | +++ examples/html5-theme/widgets/Toolbar.html 2013-12-21 21:50:50 +0000 |
317 | @@ -5,18 +5,18 @@ |
318 | This file is part of ubuntu-html5-theme. |
319 | |
320 | This package is free software; you can redistribute it and/or modify |
321 | - it under the terms of the GNU Lesser General Public License as |
322 | - published by the Free Software Foundation; either version 3 of the |
323 | + it under the terms of the GNU Lesser General Public License as |
324 | + published by the Free Software Foundation; either version 3 of the |
325 | License, or |
326 | (at your option) any later version. |
327 | - |
328 | + |
329 | This package is distributed in the hope that it will be useful, |
330 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
331 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
332 | GNU General Public License for more details. |
333 | - |
334 | - You should have received a copy of the GNU Lesser General Public |
335 | - License along with this program. If not, see |
336 | + |
337 | + You should have received a copy of the GNU Lesser General Public |
338 | + License along with this program. If not, see |
339 | <http://www.gnu.org/licenses/>. |
340 | --> |
341 | |
342 | @@ -40,22 +40,12 @@ |
343 | </head> |
344 | <body> |
345 | <div data-role="page"> |
346 | - <header data-role="header"> |
347 | - <nav data-role="navbar" class="tabs"> |
348 | - <div class="tabs-inner"> |
349 | - <ul data-role="tabs"> |
350 | - <li class="active" data-role="tab"> |
351 | - <a href="#item1">Tab 1</a> |
352 | - </li> |
353 | - <li class="inactive" data-role="tab"> |
354 | - <a href="#item2">Tab 2</a> |
355 | - </li> |
356 | - <li class="inactive" data-role="tab"> |
357 | - <a href="#item3">Tab 3</a> |
358 | - </li> |
359 | - </ul> |
360 | - </div> |
361 | - </nav> |
362 | + |
363 | + <header data-role="header" id="headerID"> |
364 | + <ul data-role="tabs"> |
365 | + <li data-role="tab" data-page="main">Tab 1</li> |
366 | + <li data-role="tab" data-page="page2">Tab 2</li> |
367 | + </ul> |
368 | </header> |
369 | |
370 | <div data-role="content"> |
371 | @@ -82,12 +72,12 @@ |
372 | </div> |
373 | </div> |
374 | <script type="text/javascript"> |
375 | - var UI = new UbuntuUI(), |
376 | - tabs = UI.tabs("[data-role='tabs']"); |
377 | + var UI = new UbuntuUI(); |
378 | + window.onload = function() { |
379 | + UI.init(); |
380 | toolbar = UI.toolbar("footer1"); |
381 | - toolbar.touch(function (event) { |
382 | - toolbar.toggle(); |
383 | - }); |
384 | + }; |
385 | + </script> |
386 | </script> |
387 | </body> |
388 | </html> |
L89: shouldn't refer to global implicit var, should go through the delegate for the touch requests ...
L91: check for null,
L114: the initial state of the toolbar (not visible) should be set,
L146: the semantics is not very clear, ... why on touchleave while it is being said "called when the toolbar is touched" ?
L168: UI reference
L254: nothing returned if id not found?
I am not sure about the approach of forcing the user to go through a toolbar() call just to make a toolbar work properly & as expected instead of relying on the mandatory init() call ...