Tuesday, April 24, 2012

Jquery Mobile - iOS location bar hiding research


So I’ve been trying to learn about location bar behavior of the iOS Safari browser on the iPhone/iPod Touch, and just wanted to share some of my observations. All of the observations below, are based on a test-case I wrote, which can be found here:

Observations:

  • The dropping of the location bar is triggered by the clicking of a link that has a reference to an external file. - You can preventDefault and stopPropagation on the “click” event so the link does nothing, but the location bar will still drop down. - The location bar does not drop down for links that contain just hashes. - We’re often compared to jQTouch in this department …” Why doesn’t jQTouch have this location bar problem?” and its because they only use internal content so their links all use hashes.
  • Loading content via XHR does NOT trigger the location bar to drop down.
  • Links with href=”#” cause the document to scroll to the top and the location bar is updated. You need to preventDefault() on the “click” event to kill this behavior.
  • Links with hashes to non-existent content do nothing. Location bar is updated though. preventDefault() on the “click” event kills this behavior.
  • Updating location.hash does NOT cause the location bar to drop down.
  • Calling preventDefault() and stopPropagation() on “touchend” events seem to have no impact on the location bar behavior or the default click behavior.

Fastclick Fixes Branch:

Given the observations above, I’m a bit puzzled as to what exactly moving our link click handler to vclick accomplishes. I originally created the branch based on previous discussions I had with Scott that calling preventDefault() on any touch event prevents the location bar from dropping, but I’m not seeing that with my test case above. After thinking about it a bit, I think I know why links in jQM are broken on the fastclick-fixes branch. My touchend handler that does a preventDefault() is called before vclick is dispatched … this is important because when my vclick handler kicks in, it creates a virtual event event based on the native touchend event … since that native event already has preventDefault called on it, the vclick event I create also has its preventDefault set because it copies it off the native event. For a vclick event, if preventDefault has been called on it, it automatically blocks any click events, which is why the links don’t fire.
So now I’m trying to figure out what to do. I still occasionally see the location bar drop down on the jquerymobile.com/test/ site, but it doesn’t happen most of the time. What I’m wondering is if it seems suppressed because we are also scrolling to the top. I just added that to the test case above, but I can’t test that theory since Adobe’s public network, which all my devices communicate through just went off line. < sigh >

Final Analysis

I spent most of today so far trying to figure out why moving click handling to vclick stops the location bar from dropping down. And I think I’ve figured some things out.
  • We are NOT doing a preventDefault on the touchend event. So that isn’t what is preventing the location bar from dropping.
  • Commenting out the $.mobile.showPageLoadingMsg() call in loadPage() is enough to make the location bar start dropping down anytime you click on a link to an external file.
  • Armed with this knowledge, I went down the path of thinking it had to do with the fact that we were using CSS3 animations for the load image. Turns out it contributes but that isn’t the whole story.
  • It seems as if there are a couple of things at play here:
-- The amount of work that is done in a touchend callback. -- The speed at which the user taps the link.
Moving the click handling to the “vclick” event places all that page loading logic, including the display of the loading dialog, on to the touchend notification. It seems like there is logic in Safari that tracks the amount of time between the touchstart and touchend events. If the time between these 2 events exceeds some “show location bar” threshold, but is less than the threshold that shows the “Open, Open in New Page, Copy, Cancel” dialog, the location bar is guaranteed to drop down when the click event is dispatched.
If the time between the 2 events is less than this “show location bar” threshold, the display of the location bar when the click event is fired seems to depend on how long, or the amount of work was generated off of the touchend event. In the case we have today where we are processing stuff on “vclick”, which is really touchend, we are doing quite a bit of work:
  • Search the current page for the active button. (vclick handler)
  • Search the entire document for an active button. (showPageLoadingMsg())
  • Re-inserting the load dialog markup at the end of the DOM. (triggers a reflow request)
  • Retrieval of scroll position for positioning of the dialog. -- This triggers a synchronous layout.
  • Setting of inline CSS on the loading dialog for positioning. -- Triggers an async layout and paint request.
  • Setting of the ui-loading class on the HTML element. -- Causes the body and page elements to adjust their overflow. -- Displays the dialog and starts the CSS3 animations.
  • Kick-off an ajax load.
I think this amount of work that we are doing and generating for the browser is enough to exceed this theoretical threshold that keeps the location bar from dropping. In a nutshell, I think we’re just getting lucky.

Jquery Mobile - Position:fixed and Overflow: testing


Short answer: position:fixed is pretty well supported, falls back to inline and is only a tad buggy on some browsers. Even the buggy platforms are roughly equivalent to our dynamically positioned script.
I'd recommend that we look into deprecating the script-based approach and use CSS only for 1.1 though we could offer the dynamic re-position as an optional polyfill for iOS 3-4. We'd need to disable zoom for Android support, but that is probably an ok tradeoff. This may not need to be qualified by support tests since it degrades so well.
Overflow is not ready for primetime but does work well on iOS5, Honeycomb and Playbook 1 (a bit slow).

Kindle Fire

Fixed, Zoom - Falls back to inline headers
Fixed, no Zoom - Works well
Overflow, Zoom - Content clipped
Overflow, no Zoom - Content clipped

Blackberry 5

Fixed, Zoom - Not truly fixed. Re-positions itself frequently, leading to a jitter as you scroll. Not broken, but sort of ugly.
Fixed, no Zoom - Not truly fixed. Re-positions itself frequently, leading to a jitter as you scroll. Not broken, but sort of ugly.
Overflow, Zoom - Scrollbars appear around region that doen't appear operable with touch. Broken.
Overflow, no Zoom - Scrollbars appear around region that doen't appear operable with touch. Broken.

Blackberry 6

Fixed, Zoom - Fixed headers sort of work. They scroll out of view, then re-appear when scrolling stops. When scrolling up, they look like they get stuck in the middle of the page during scroll, then re-position. This is probably the worst case scenario.
Fixed, no Zoom - Fixed headers sort of work. They scroll out of view, then re-appear when scrolling stops. When scrolling up, they look like they get stuck in the middle of the page during scroll, then re-position. This is probably the worst case scenario.
Overflow, Zoom - Scrolls w/o momentum so feels odd
Overflow, no Zoom - Scrolls w/o momentum so feels odd

Blackberry 7

Fixed, Zoom - Fixed headers work well, header shifts by ~5px at bottom of page
Fixed, no Zoom - Fixed headers work well, header shifts by ~5px at bottom of page
Overflow, Zoom - Works, but adds ugly h/v scrollbars that are very hard to use
Overflow, no Zoom - Works, but adds ugly h/v scrollbars that are very hard to use

Playbook 1.0

Fixed, Zoom - Fixed headers work well
Fixed, no Zoom - Fixed headers work well
Overflow, Zoom - Scrolling works smoothly
Overflow, no Zoom - Scrolling works smoothly

Nokia N9 (MeeGo)

Fixed, Zoom - Falls back to inline headers
Fixed, no Zoom - Falls back to inline headers
Overflow, Zoom - Content clipped, two-finger scroll w/o momentum
Overflow, no Zoom - Content clipped, two-finger scroll w/o momentum

WP7

Fixed, Zoom - Falls back to inline headers
Fixed, no Zoom - Falls back to inline headers
Overflow, Zoom - Scrolling works, but ugly h/v scrollbars appear, parent scrolls if you scroll before scroll stops
Overflow, no Zoom - Scrolling works, but ugly h/v scrollbars appear, parent scrolls if you scroll before scroll stops

WP7.5 (Mango)

Fixed, Zoom - Falls back to inline headers
Fixed, no Zoom - Falls back to inline headers
Overflow, Zoom - Scrolling works, but no momentum
Overflow, no Zoom - Scrolling works, but no momentum

Android 2.1

Fixed, Zoom - Falls back to inline headers
Fixed, no Zoom - Falls back to inline headers
Overflow, Zoom - Content clipped, can't scroll
Overflow, no Zoom - Content clipped, can't scroll

Android 2.2

Fixed, Zoom - Falls back to inline headers
Fixed, no Zoom - Fixed headers work well
Overflow, Zoom - Content clipped, can't scroll
Overflow, no Zoom - Content clipped, can't scroll

Android 2.3

Fixed, Zoom - Falls back to headers inline
Fixed, no Zoom - Fixed headers work well
Overflow, Zoom - Content clipped, can't scroll
Overflow, no Zoom - Content clipped, can't scroll

Android 3.1 - Honeycomb

Fixed, Zoom - Fixed headers work well, but 1px line jitter above the toolbar when scrolling
Fixed, no Zoom - Fixed headers work well, but 1px line jitter above the toolbar when scrolling
Overflow, Zoom - Scrolling works smoothly
Overflow, no Zoom - Scrolling works smoothly

iOS 5, iPad

Fixed, Zoom - Fixed headers work well
Fixed, no Zoom - Fixed headers work well
Overflow, Zoom - Scrolling works smoothly
Overflow, no Zoom - Scrolling works smoothly

iOS 4.3, iPad

Fixed, Zoom - Falls back to inline headers
Fixed, no Zoom - Falls back to inline headers
Overflow, Zoom - Content clipped, two-finger scroll w/o momentum
Overflow, no Zoom - Content clipped, two-finger scroll w/o momentum

iOS 3.2, iPad

Fixed, Zoom - Falls back to inline headers
Fixed, no Zoom - Falls back to inline headers
Overflow, Zoom - Content clipped, two-finger scroll w/o momentum
Overflow, no Zoom - Content clipped, two-finger scroll w/o momentum

HP TouchPad

Fixed, Zoom - Fixed headers animate into place while scrolling, looks janky
Fixed, no Zoom - Fixed headers animate into place while scrolling, looks janky
Overflow, Zoom - Scrolling works, but no momentum
Overflow, no Zoom - Scrolling works, but no momentum

WebOS 1.4

Fixed, Zoom - Fixed headers animate into place while scrolling, looks janky
Fixed, no Zoom - Fixed headers animate into place while scrolling, looks janky
Overflow, Zoom - Scrolling works, but no momentum
Overflow, no Zoom - Scrolling works, but no momentum

Monday, April 23, 2012

Jquery Mobile - Resources


In this section, we have gathered useful resources that will help you learn more about jQuery Mobile, find tools to develop jQuery Mobile application designs and mockups, tutorials and tools to guide your through the development of simple or more complex applications and related articles.

Featured sites | Books | Apps & Frameworks | Plugins | Extensions | Tools | Themes | Articles & Tutorials

Featured jQuery Mobile sites from jQMGallery.com

You will find below a great sample collection of Mobile sites built with jQuery Mobile. More examples can be found in the jQM Gallery.

Books

Master Mobile Web Apps with jQuery Mobile
by Matt Doyle,
Elated Books
jQuery Mobile: Up and Running
by Maximiliano Firtman,
O’Reilly Media
jQuery Mobile
By Jon Reid,
O’Reilly Media
jQuery Mobile First Look
by Giulio Bai,
Packt Publishing
Adobe Dreamweaver CS5.5: Designing and Developing for Mobile with jQuery, HTML5, and CSS3
by David Powers,
Adobe Press
Using the CSS3 Mobile Pack for Adobe Fireworks CS5
by Jim Babbage,
Peachpit Press
Pro jQuery Mobile
by Brad Broulik,
Apress
Sams Teach Yourself jQuery Mobile in 10 Minutes (Sams Teach Yourself — Minutes)
by Steven E. Holzner,
Sams
jQuery Mobile Web Development Essentials
by Raymond Camden and Andy Matthews,
Packt Publishing

Apps & frameworks

  •  PhoneGap – tool to wrap jQuery Mobile code for native app deployment
  •  Codiqa – rapid jQuery Mobile app prototyping
  •  Handheld Designer – drag and drop tool for building and hosting jQuery Mobile apps
  •  Application Craft – drag and drop tool for building jQuery Mobile apps
  •  Proto.io – drag and drop page builder
  •  Tiggzi – cloud-based drag and drop tool for building jQuery Mobile apps connected to any REST API
  •  NS Basic/App Studio – drag and drop tool for building jQuery Mobile apps
  •  MobDis – drag and drop tool for building jQuery Mobile apps
  •  Mobjectify – tool for building jQuery Mobile app mockups
  •  M-Project – MVC framework based on jQuery Mobile
  •  Rhomobile – enterprise mobile app framework
  •  Neptune Application Designer – SAP HTML5 Designer optimized for jQuery Mobile for SAP Mobility applications
  •  Octomobi – Online tool to create webapps with maps, image gallery and RSS feed in jQuery Mobile
  •  Adaptor for AngularJS
  •  jqmPHP – package of PHP classes for generating jQM markup
  •  Drupal theme – theme for jQuery Mobile
  •  Seaside (SmallTalk) – a jQuery Mobile implementation
  •  Pyramid – Starter scaffolding for creating a jQuery Mobile Pyramid application

3rd party plugins

These are all jQuery Mobile compatible plugins, many use the theme framework, auto-initialization and data- attribute configuration features or core mobile widgets.

3rd party extensions

These are 3rd Party extensions that add capabilities to existing functionality.
  • jQueryMobile-Rails – Incorporates the jQuery Mobile assets into your Rails application
  • Twitter Bootstrap jQuery Mobile Theme – A jQuery Mobile theme based on Twitter Bootstrap
  • jQuery Mobile Icon Pack – Extra icons for your jQuery Mobile project
  • AppBoilerplate – A jQuery mobile application boilerplate aimed at web application and PhoneGap developers including an OS based theme switcher and full plugin support
  • Router – Router/controller for jQuery Mobile that adds support for client-side parameters, regexp-based routes, and can be used with Backbone.js or Spine.js
  • Subpages – Allows multiple pages to be loaded in with a single request
  • Selective DOM caching – Allows pages to be selectively cached using the data-dom-cache attribute on each page. A custom pageshow event handler determines whether to remove the previous page.

Tools

Themes

Articles & Tutorials