|
1 | | -//TODO: need to set panel widths according to media width - is this necessary? |
2 | 1 | //ISSUE: activeBtnClass not removed when a new link is given this class - causing a lot of active buttons. |
3 | | -//ISSUE: history doesn't change when links in main panel is clicked, and the back button points to |
4 | | -// the previous page which don't make sense. idea: use data-history="false,crumb" on panel div |
5 | | -//ISSUE: clicking on a navbar link twice ruins the entire hash history. need to see what happened. |
6 | | -//ISSUE: line 1872 in jqm, in transitionPages adds a history entry anyways - does this affect the transition path for history? |
7 | | - |
8 | 2 | (function($,window,undefined){ |
9 | 3 | $( window.document ).bind('mobileinit', function(){ |
10 | 4 | if ($.mobile.media("screen and (min-width:480px)")) { |
|
19 | 13 | $(window).trigger('orientationchange'); |
20 | 14 | }); |
21 | 15 |
|
| 16 | +//---------------------------------------------------------------------------------- |
| 17 | +//Main event bindings: click, form submits, hashchange and orientationchange/resize |
| 18 | +//---------------------------------------------------------------------------------- |
22 | 19 | //DONE: link click event binding for changePage |
23 | 20 | $("a").die('click'); |
24 | 21 | //this will mostly be a copy of the original handler with some modifications |
|
52 | 49 | return; |
53 | 50 | } |
54 | 51 |
|
55 | | - //temporary fix to remove activeBtnClass |
| 52 | + //TODO: temporary fix to remove activeBtnClass |
56 | 53 | $(".ui-btn."+$.mobile.activeBtnClass).removeClass($.mobile.activeBtnClass); |
57 | 54 | $activeClickedLink = $this.closest( ".ui-btn" ).addClass( $.mobile.activeBtnClass ); |
58 | 55 |
|
|
102 | 99 | } |
103 | 100 | //if link refers to a page inside the same panel, changePage on that panel |
104 | 101 | else { |
105 | | - //BUG: this setting is panel insensitive - so links in main panel also behave as specified below |
106 | | - // need to define more data attributes in panels to allow custom panel behaviour |
107 | 102 | from=$currPanelActivePage; |
108 | 103 | $.mobile.pageContainer=$currPanel; |
109 | 104 | var hashChange= (hash == 'false' || hash == 'crumbs')? false : true; |
|
206 | 201 | $.mobile.activePage=$mainPanelActivePage.length? $mainPanelActivePage : undefined; |
207 | 202 | $.mobile.changePage(to, transition, undefined, false, true ); |
208 | 203 | } |
209 | | - //there's no hash, go to the first page in the dom, and set all other panels to its first page. |
| 204 | + //there's no hash, go to the first page in the main panel. |
210 | 205 | else { |
211 | | - //temp fix - need to get an array of panels and set their first pages to show. |
212 | 206 | $.mobile.pageContainer=$mainPanel; |
213 | 207 | $.mobile.activePage=$mainPanelActivePage? $mainPanelActivePage : undefined; |
214 | | - //temp: set false for fromHashChange due to isPageTransitioning causing pageContainer settings to be overriden |
215 | | - $.mobile.changePage($mainPanelFirstPage, 'none', true, false, false ); |
216 | | - $.mobile.pageContainer=$menuPanel; |
217 | | - $.mobile.activePage=$menuPanelActivePage? $menuPanelActivePage : undefined; |
218 | | - $.mobile.changePage($menuPanelFirstPage, 'none', false, false, false); |
| 208 | + $.mobile.changePage($mainPanelFirstPage, transition, undefined, false, true ); |
219 | 209 | } |
220 | 210 | }); |
221 | 211 |
|
222 | | - //DONE: pageshow binding for scrollview |
223 | | - $('div[data-role="page"]').live('pagebeforeshow', function(event){ |
224 | | - var $page = $(this); |
225 | | - $page.find('div[data-role="content"]').attr('data-scroll', 'true'); |
226 | | - if ($.support.touch) { |
227 | | - $page.find("[data-scroll]:not(.ui-scrollview-clip)").each(function(){ |
228 | | - var $this = $(this); |
229 | | - // XXX: Remove this check for ui-scrolllistview once we've |
230 | | - // integrated list divider support into the main scrollview class. |
231 | | - if ($this.hasClass("ui-scrolllistview")) |
232 | | - $this.scrolllistview(); |
233 | | - else |
234 | | - { |
235 | | - var st = $this.data("scroll") + ""; |
236 | | - var paging = st && st.search(/^[xy]p$/) != -1; |
237 | | - var dir = st && st.search(/^[xy]/) != -1 ? st.charAt(0) : null; |
238 | | - |
239 | | - var opts = {}; |
240 | | - if (dir) |
241 | | - opts.direction = dir; |
242 | | - if (paging) |
243 | | - opts.pagingEnabled = true; |
244 | | - |
245 | | - var method = $this.data("scroll-method"); |
246 | | - if (method) |
247 | | - opts.scrollMethod = method; |
248 | | - |
249 | | - $this.scrollview(opts); |
250 | | - } |
251 | | - }); |
252 | | - } |
253 | | - }); |
254 | | - |
255 | | - //popover button click handler - from http://www.cagintranet.com/archive/create-an-ipad-like-dropdown-popover/ |
256 | | - $('#popover-btn').live('click', function(e){ |
257 | | - e.preventDefault(); |
258 | | - $('.panel-popover').fadeToggle('fast'); |
259 | | - if ($('#popover-btn').hasClass($.mobile.activeBtnClass)) { |
260 | | - $('#popover-btn').removeClass($.mobile.activeBtnClass); |
261 | | - } else { |
262 | | - $('#popover-btn').addClass($.mobile.activeBtnClass); |
263 | | - } |
264 | | - }); |
265 | | - |
266 | | - $('body').live('vclick', function(event) { |
267 | | - if (!$(event.target).closest('.panel-popover').length && !$(event.target).closest('#popover-btn').length) { |
268 | | - $(".panel-popover").stop(true, true).hide(); |
269 | | - $('#popover-btn').removeClass($.mobile.activeBtnClass); |
270 | | - }; |
271 | | - }); |
272 | | - |
273 | | - //TODO: bind orientationchange and resize |
274 | | - //In order to do this, we need to: |
275 | | - //1. hide and resize menu panel |
276 | | - //2. make main panel fullscreen |
277 | | - //3. wrap design divs around menu panel |
278 | | - //4. add menu button to top left of main panel |
279 | | - //5. bind show() menu panel onclick of menu button |
| 212 | + //DONE: bind orientationchange and resize |
280 | 213 | $(window).bind('orientationchange resize', function(event){ |
281 | 214 | var $menu=$('div[data-id="menu"]'), |
282 | 215 | $main=$('div[data-id="main"]'), |
283 | 216 | $mainHeader=$main.find('div.'+$.mobile.activePageClass+'> div[data-role="header"]'), |
284 | 217 | $window=$(window); |
285 | 218 |
|
286 | 219 | function popoverBtn(header) { |
287 | | - if(!header.children('#popover-btn').length){ |
| 220 | + if(!header.children('.popover-btn').length){ |
288 | 221 | if(header.children('a.ui-btn-left').length){ |
289 | | - header.children('a.ui-btn-left').replaceWith('<a id="popover-btn">Navigation</a>'); |
290 | | - header.children('a#popover-btn').addClass('ui-btn-left').buttonMarkup(); |
| 222 | + header.children('a.ui-btn-left').replaceWith('<a class="popover-btn">Navigation</a>'); |
| 223 | + header.children('a.popover-btn').addClass('ui-btn-left').buttonMarkup(); |
291 | 224 | } |
292 | 225 | else{ |
293 | | - header.prepend('<a id="popover-btn">Navigation</a>'); |
294 | | - header.children('a#popover-btn').addClass('ui-btn-left').buttonMarkup() |
| 226 | + header.prepend('<a class="popover-btn">Navigation</a>'); |
| 227 | + header.children('a.popover-btn').addClass('ui-btn-left').buttonMarkup() |
295 | 228 | } |
296 | 229 | } |
297 | 230 | } |
|
307 | 240 | .css('width', ''); |
308 | 241 | popoverBtn($mainHeader); |
309 | 242 |
|
310 | | - $main.delegate('div[data-role="page"]','pagecreate.popover', function(){ |
| 243 | + $main.undelegate('div[data-role="page"]', 'pagebeforeshow.splitview'); |
| 244 | + $main.delegate('div[data-role="page"]','pagebeforeshow.popover', function(){ |
311 | 245 | var $thisHeader=$(this).children('div[data-role="header"]'); |
312 | 246 | popoverBtn($thisHeader); |
313 | 247 | }); |
|
322 | 256 | .width(function(){ |
323 | 257 | return $(window).width()-$('div[data-id="menu"]').width(); |
324 | 258 | }); |
325 | | - $mainHeader.children('#popover-btn').remove(); |
326 | | - $main.undelegate('div[data-role="page"]', 'pageshow.popover'); |
| 259 | + $mainHeader.children('.popover-btn').remove(); |
| 260 | + |
| 261 | + $main.undelegate('div[data-role="page"]', 'pagebeforeshow.popover'); |
| 262 | + $main.delegate('div[data-role="page"]', 'pagebeforeshow.splitview', function(){ |
| 263 | + var $thisHeader=$(this).children('div[data-role="header"]'); |
| 264 | + $thisHeader.children('.popover-btn').remove(); |
| 265 | + }); |
327 | 266 |
|
328 | 267 | } |
329 | 268 |
|
|
343 | 282 | } |
344 | 283 | }); |
345 | 284 |
|
| 285 | +//---------------------------------------------------------------------------------- |
| 286 | +//Other event bindings: scrollview, popover buttons, and toolbar hacks |
| 287 | +//---------------------------------------------------------------------------------- |
| 288 | + |
| 289 | + //DONE: pageshow binding for scrollview |
| 290 | + $('div[data-role="page"]').live('pagebeforeshow', function(event){ |
| 291 | + var $page = $(this); |
| 292 | + $page.find('div[data-role="content"]').attr('data-scroll', 'true'); |
| 293 | + if ($.support.touch) { |
| 294 | + $page.find("[data-scroll]:not(.ui-scrollview-clip)").each(function(){ |
| 295 | + var $this = $(this); |
| 296 | + // XXX: Remove this check for ui-scrolllistview once we've |
| 297 | + // integrated list divider support into the main scrollview class. |
| 298 | + if ($this.hasClass("ui-scrolllistview")) |
| 299 | + $this.scrolllistview(); |
| 300 | + else |
| 301 | + { |
| 302 | + var st = $this.data("scroll") + ""; |
| 303 | + var paging = st && st.search(/^[xy]p$/) != -1; |
| 304 | + var dir = st && st.search(/^[xy]/) != -1 ? st.charAt(0) : null; |
| 305 | + |
| 306 | + var opts = {}; |
| 307 | + if (dir) |
| 308 | + opts.direction = dir; |
| 309 | + if (paging) |
| 310 | + opts.pagingEnabled = true; |
| 311 | + |
| 312 | + var method = $this.data("scroll-method"); |
| 313 | + if (method) |
| 314 | + opts.scrollMethod = method; |
| 315 | + |
| 316 | + $this.scrollview(opts); |
| 317 | + } |
| 318 | + }); |
| 319 | + } |
| 320 | + }); |
| 321 | + |
| 322 | + //popover button click handler - from http://www.cagintranet.com/archive/create-an-ipad-like-dropdown-popover/ |
| 323 | + $('.popover-btn').live('click', function(e){ |
| 324 | + e.preventDefault(); |
| 325 | + $('.panel-popover').fadeToggle('fast'); |
| 326 | + if ($('.popover-btn').hasClass($.mobile.activeBtnClass)) { |
| 327 | + $('.popover-btn').removeClass($.mobile.activeBtnClass); |
| 328 | + } else { |
| 329 | + $('.popover-btn').addClass($.mobile.activeBtnClass); |
| 330 | + } |
| 331 | + }); |
| 332 | + |
| 333 | + $('body').live('vclick', function(event) { |
| 334 | + if (!$(event.target).closest('.panel-popover').length && !$(event.target).closest('.popover-btn').length) { |
| 335 | + $(".panel-popover").stop(true, true).hide(); |
| 336 | + $('.popover-btn').removeClass($.mobile.activeBtnClass); |
| 337 | + }; |
| 338 | + }); |
| 339 | + |
| 340 | + |
| 341 | + |
346 | 342 | //temporary toolbar mods to present better in tablet/desktop view |
347 | 343 | //TODO: API this so that people can specify using data- attributes how they want their toolbars displayed |
348 | 344 | //potential toolbar behaviour: |
|
0 commit comments