mobile web on drupal!

95
The Mobile Web on Drupal! Thursday, January 13, 2011

Upload: lyza-gardner

Post on 03-Jul-2015

6.907 views

Category:

Technology


1 download

DESCRIPTION

Presentation from Jan. 12, 2011 meeting of Portland (Ore.) Drupal Users Group (PDXDUG). A whirlwind tour of mobile Web topics from a Drupal 6 viewpoint. As much as I could get into a 45-minute slide deck! Whew.

TRANSCRIPT

Page 1: Mobile Web on Drupal!

The Mobile Web on Drupal!

Thursday, January 13, 2011

Page 2: Mobile Web on Drupal!

Where are we going today?

Mobile Web development theories and philosophies

Reality check!

Core tenets I like to stick to

So, about Drupal...the good and the bad

Digging in and putting some pieces together (CODE!)

Stuff to read so you can learn more

Thursday, January 13, 2011

Page 3: Mobile Web on Drupal!

How technical is this going to be?

We’ll start high level (everyone)

We’ll talk about strategy and device grouping (everyone/solution architects)

We’ll talk about Drupal’s strengths and weaknesses and 3rd-party stuff. (everyone/somewhat technical)

We’ll look at code for a hypothetical module and work with Drupal hooks and whatnot. (devs/code)

We’ll talk about mobile theming strategy. (designers)

I’ll recommend some books, blogs and mailing lists. (everyone)

Thursday, January 13, 2011

Page 4: Mobile Web on Drupal!

Nope.

This topic is huge. We won’t have time to talk about:

Detailed (HTML/CSS) markup for mobile devices.

The finer points of device-specific support for technologies (CSS/JS/HTML5/whatever).

Design and UX best practices.

Testing.

All of these areas are incredibly important, though!

Thursday, January 13, 2011

Page 5: Mobile Web on Drupal!

By The Way

This presentation is based on Drupal 6

My current feeling about D7*

* SorryThursday, January 13, 2011

Page 6: Mobile Web on Drupal!

Leading Philosophies of Mobile Web Development

Thursday, January 13, 2011

Page 7: Mobile Web on Drupal!

The “One Web”

Thursday, January 13, 2011

Page 8: Mobile Web on Drupal!

One Web means making, as far as is reasonable, the same information and services available to users irrespective of the device they are using. However, it does not mean that exactly the same information is available in exactly the same representation across all devices. The context of mobile use, device capability variations, bandwidth issues and mobile network capabilities all affect the representation...

...it is considered best practice to provide as reasonable experience as is possible given device limitations and not to

exclude access from any particular class of device, except where this is necessary because of device limitations....

Errr...

Thursday, January 13, 2011

Page 9: Mobile Web on Drupal!

That means...

Separate mobile site or domain (e.g. m.mysite.com) is discouraged.

All users should get, for the most part, the same text, features, markup, images, functionality, etc. (within reason, which you get to determine).

Develop once (I do like this part).

Thursday, January 13, 2011

Page 10: Mobile Web on Drupal!

Responsive Web Design (RWD)

Thursday, January 13, 2011

Page 11: Mobile Web on Drupal!

RWD

Using sophisticated markup and CSS techniques to make the “One Web” ideal more attainable.

Using CSS Media Queries to adapt content, allowing for “One Web” success

Fluid grid designs

For the most part, send the same HTML markup and media (e.g. images) to everyone

http://www.alistapart.com/articles/responsive-web-design/

Thursday, January 13, 2011

Page 12: Mobile Web on Drupal!

<link rel="stylesheet" type="text/css" media="screen and (max-device-width: 480px)" href="shetland.css" />

I am a CSS Media Query:

Thursday, January 13, 2011

Page 13: Mobile Web on Drupal!

Progressive Enhancement

Thursday, January 13, 2011

Page 14: Mobile Web on Drupal!

Progressive Enhancement

Not just a mobile concern

Luke W’s “Mobile First” credo is in the same family

Design your baseline site for mobile, then go from there

http://www.lukew.com/ff/entry.asp?933

Thursday, January 13, 2011

Page 15: Mobile Web on Drupal!

Server-Side Device Detection and Adaptation

Thursday, January 13, 2011

Page 16: Mobile Web on Drupal!

Who goes there?

Thursday, January 13, 2011

Page 17: Mobile Web on Drupal!

Server-Side Device Detection

Based on using User Agent strings to make an educated guess at what a device is and what capabilities it has

Several device libraries support this. Two of the best known are:

WURFL

DeviceAtlas

Thursday, January 13, 2011

Page 18: Mobile Web on Drupal!

WURFL

http://wurfl.sourceforge.net/

Maintained/moderated by Luca Passani.

Exhaustive details about mobile device and client capabilities based on User Agent.

Contributors have created APIs in several languages.

Free and open source.

Thursday, January 13, 2011

Page 19: Mobile Web on Drupal!

Let’s Look at some WURFL Capabilities

Tera-WURFL Explorer

http://www.tera-wurfl.com/explore/

Thursday, January 13, 2011

Page 20: Mobile Web on Drupal!

DeviceAtlas

Licenses run from $99/yr (per server) to ... well, more.

You get guaranteed updates.

API is PHP, Java, .Net

Analytics as well.

Web site is free and a useful reference for looking up devices right quick.

http://deviceatlas.com

Thursday, January 13, 2011

Page 21: Mobile Web on Drupal!

Client-Side Adaptation

Thursday, January 13, 2011

Page 22: Mobile Web on Drupal!

Whereas server-side detection asks “Who goes there?,” client-side adaptation allows you to say things like:

Thursday, January 13, 2011

Page 23: Mobile Web on Drupal!

Oh, yeah? prove it.

Thursday, January 13, 2011

Page 24: Mobile Web on Drupal!

Client-Side Adaptation

Determining real client capabilities a la Modernizr

Using CSS Media queries

Taking delivered markup the final mile

Ensures that the client can walk the walk

Thursday, January 13, 2011

Page 25: Mobile Web on Drupal!

Modernizr (A Quick Aside)

Runs tests on the client

Adds CSS classes to the <html> element based on what it discovers

You, noble developer/themer, can:

Write your CSS accordingly

Use JavaScript to extend your stuff

Based on what the browser can actually do

http://www.modernizr.com

Thursday, January 13, 2011

Page 26: Mobile Web on Drupal!

So, that all sounds lovely and clean and unicorn-shaped.

Thursday, January 13, 2011

Page 27: Mobile Web on Drupal!

The Reality

Thursday, January 13, 2011

Page 28: Mobile Web on Drupal!

Thursday, January 13, 2011

Page 29: Mobile Web on Drupal!

Love,The W3C

Dear Puny Human,

Make one Web site such that it’s, like, the same on all devices, except, well, make sure that it is appropriately different on some devices. Don’t exclude anyone, except when “device limitations” force you to.

I’ll leave deciding what a device limitation is as an exercise for the reader.

http://www.w3.org/TR/mobile-bp/#OneWeb

“One Web” is vague

Thursday, January 13, 2011

Page 30: Mobile Web on Drupal!

RWD has performance and bandwidth implications

Image resizing on devices can be inefficient and uses bandwidth you might not need to use.

CSS media query support is fragmented and only on modern devices.

For the most part, images hidden in CSS still get downloaded.

We’re sending the device bytes that it is not going to use.

http://www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/

Thursday, January 13, 2011

Page 31: Mobile Web on Drupal!

http://www.cloudfour.com/adventures-on-the-mobile-web-frontier-wrangling-drupal-third-party-apis-and-server-oomph-into-an-enterprise-class-

experience/

Adventures on the Mobile Web Frontier, Nov. 4, 2010

—Lyza Gardner (Me)

*Sorry about that URL; my bad*

Shoving a 153,600-pixel image at a phone that only has about 16,000 pixels of real estate to work with is like giving 4-by-8-foot sheets of plywood to a kid who wants to build a miniature birdhouse. Even if wood is cheap, it tastelessly wastes a lot of trees...

Thursday, January 13, 2011

Page 32: Mobile Web on Drupal!

Hello, Web Server, I am a sheep!

Server-side device detection via UA is not infallible...

Who goes there?

Thursday, January 13, 2011

Page 33: Mobile Web on Drupal!

Web Server! I am also a sheep!*

*Not really a sheep.

Who goes there?

Thursday, January 13, 2011

Page 34: Mobile Web on Drupal!

Client-side enhancement can be pretty tricky if your user’s device isn’t up to it

“Hi, I’m BlackBerry version 4.5. You’d be surprised at how many people at big companies still use me and love me.

You cannot manipulate my DOM and my JavaScript performance is very sad.

Sorry.”

Thursday, January 13, 2011

Page 35: Mobile Web on Drupal!

Thursday, January 13, 2011

Page 36: Mobile Web on Drupal!

The Duct Tape Programmer, Sept. 23, 2009Joel on Software

—Joel Spolsky

“Duct tape programmers are pragmatic...

“A 50%-good solution that people actually have solves more problems and survives longer than a 99% solution that nobody has because it’s in your lab where you’re endlessly polishing the damn thing.

“Shipping is a feature. A really important feature. Your product must have it.”

http://www.joelonsoftware.com/items/2009/09/23.html

Duct Tape Programming

Thursday, January 13, 2011

Page 37: Mobile Web on Drupal!

Thursday, January 13, 2011

Page 38: Mobile Web on Drupal!

So, how do we keep our nose clean in this tragicomical environment?Staying True to a Couple of Tenets...

Thursday, January 13, 2011

Page 39: Mobile Web on Drupal!

1. Don’t send bits to a device that it won’t use

Thursday, January 13, 2011

Page 40: Mobile Web on Drupal!

bits == dollarsbits == waitingbits ~= processing

Thursday, January 13, 2011

Page 41: Mobile Web on Drupal!

2. The client is always right*

* This one gets me in a bit of trouble

Thursday, January 13, 2011

Page 42: Mobile Web on Drupal!

Remember how I said that User Agents aren’t always 100% honest and forthcoming? Or, at least, sane?

Thursday, January 13, 2011

Page 43: Mobile Web on Drupal!

Whose User Agent is this?

Mozilla/5.0 (Macintosh; U; Intel Mac OS X10_5_7; en-us) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0Safari/530.17

Thursday, January 13, 2011

Page 44: Mobile Web on Drupal!

A Sane Person would guess...

Desktop Safari

And that’s what WURFL will tell you, too

Thursday, January 13, 2011

Page 45: Mobile Web on Drupal!

But

It’s Skyfire for Android.

Thursday, January 13, 2011

Page 46: Mobile Web on Drupal!

http://www.skyfire.com/product/android

Skyfire Web Site

Laughing all the way to the Bank or whatever,Love,

Skyfire

“Load web pages as either traditional Android user agent or as a desktop browser. The desktop option gives you more flexibility in accessing web sites and allows discovery of video content that might not be visible on the mobile site.”

Thursday, January 13, 2011

Page 47: Mobile Web on Drupal!

What do we do?!

So, the User Agent for Skyfire’s desktop mode is cruel and manipulative.

What should we do?

Me: Give them the desktop experience. They asked for it. If it sucks enough for enough people, Skyfire will hopefully adapt.

This is not a universally-embraced opinion, to say the least. And leaves some folks out in the cold.

What do you think?

Thursday, January 13, 2011

Page 48: Mobile Web on Drupal!

Thursday, January 13, 2011

Page 49: Mobile Web on Drupal!

Let’s make something that works

Thursday, January 13, 2011

Page 50: Mobile Web on Drupal!

Device Classes

A device class is a collection of attributes and capabilities that define a group of mobile devices.

There are no industry-standard device classes, but there are some rules of thumb and generalizations that can help you define your device classes.

We usually end up with about 3-5 major device classes per project.

Thursday, January 13, 2011

Page 51: Mobile Web on Drupal!

Device Classes: Why?

Keeps you sane.

Helps you focus on your target users.

Gives you a context to think within when designing UX and IA for your site or app.

Roughly, device class == context

Thursday, January 13, 2011

Page 52: Mobile Web on Drupal!

Some Advice about Device Classes

Don’t get too distracted by pixel dimensions.

Choose your “baseline” class carefully. Who’s your main audience?

You’ve heard this nag before,: don’t assume everyone has an iPhone or Android.

device class != theme/layout

Thursday, January 13, 2011

Page 53: Mobile Web on Drupal!

Example Device ClassesDevice Class Criteria Notes

“Mobile Webkit”• Webkit-based browser• Minimum resolution 320x480• Sophisticated CSS/JS/XHR support

“There is no Webkit on mobile”.—Peter-Paul Koch, QuirksMode

Smartphones• Resolution 240-320px• Robust XHTML support• Reasonable AJAX and JS• Quite possibly less awesome CSS

Don’t neglect this class! BB5, Win 6.x, etc.

Dumbphones• Resolution 128-240px• HTML support• Cookie/HTTPs support• Limited CSS support

a.k.a. feature phones

Thursday, January 13, 2011

Page 54: Mobile Web on Drupal!

And Then you draw the line somewhere

e.g. “For a mobile device to be successful using this Web-based application, it must support images, cookies and HTTPs, and have a resolution of at least 128px.”

Thursday, January 13, 2011

Page 55: Mobile Web on Drupal!

And the rest, you gently kick to the curb. Gently.

Thursday, January 13, 2011

Page 56: Mobile Web on Drupal!

OK, Here comes the Drupal part...

Thursday, January 13, 2011

Page 57: Mobile Web on Drupal!

First, some good news

Thursday, January 13, 2011

Page 58: Mobile Web on Drupal!

Drupal is great because:

We can easily extend it by writing modules or using those that others have kindly already written

The theming stack and hook architecture is flexible enough that we can override almost anything we need to

Sub-theming gives us even more power here

There are already some third-party modules that can help us

Your site may already be running on it.

Thursday, January 13, 2011

Page 59: Mobile Web on Drupal!

Now some bad news...

Thursday, January 13, 2011

Page 60: Mobile Web on Drupal!

Drupal makes kittens cry because:

Drupal 6 doesn’t have a definitive hook for managing CSS and JS

Theme inheritance can only go so far

WYSIWTF

There is no simple, 3rd-party solution you can just drop into place. I bet there will be in the future. But.

Thursday, January 13, 2011

Page 61: Mobile Web on Drupal!

WYSIWTF

How the heck can your site’s editors create content that will look right on all devices?

CKEditor can’t save your butt here

Don’t blame Drupal per se: No one has nailed this one

I don’t have a good answer for you here...yet

Thursday, January 13, 2011

Page 62: Mobile Web on Drupal!

Everything you learn today is obsolete tomorrow

Case in point: This just in!

http://drupal.org/project/tinysrc

Thursday, January 13, 2011

Page 63: Mobile Web on Drupal!

Modules: Theirs (3rd-party)

Thursday, January 13, 2011

Page 64: Mobile Web on Drupal!

mobile tools

function mobile_tools_device_groups() {  return array('iphone', 'ipod', 'android', 'opera mini', 'blackberry');}

“The Mobile Tools module currently doesn't provide information on the device characteristics such as screen size, browser capabilities, javascript support, etc ...” (from the project page)

A lot of stuff in this module, and it can integrate with WURFL or BrowserCap.

These are your device classes. Take ‘em or leave ‘em.

Generally, I find that I want a bit more control than this module gives me, but it could serve as a great starting point.

Thursday, January 13, 2011

Page 65: Mobile Web on Drupal!

wurflUses PHP API

Recent rewrite...not backwards compatible so much. UGH.

Doesn’t expose everything from the PHP API, but does encapsulate some.

Multiple sites? You’ll be replicating the WURFL data.

Install process is a bit painful.

But, overall, a good place to start, and we’ll be using it in our examples tonight.

Thursday, January 13, 2011

Page 66: Mobile Web on Drupal!

Putting it Together

Thursday, January 13, 2011

Page 67: Mobile Web on Drupal!

Alert! Code!

Thursday, January 13, 2011

Page 68: Mobile Web on Drupal!

We are going to...

Use and depend on the wurfl module

Create our own module

Detect Devices

Switch Themes

Create and implement a Device Class Definition hook

Define some device classes

Test devices against defined device classes

Create some mobile themes

Add some useful code to our themes to strip certain JS and CSS

Thursday, January 13, 2011

Page 69: Mobile Web on Drupal!

Disclaimer!

OMG! Don’t take this code too literally. It’s meant as:

A. A stepping-off point and

B. Pseudo-code

It is based on real code (which has been tested) but has not been tested in its current form.

You don’t have to implement it this way! These are just rough ideas for yah.

Thursday, January 13, 2011

Page 70: Mobile Web on Drupal!

Our Module: mobile_web (structure)

Thursday, January 13, 2011

Page 71: Mobile Web on Drupal!

First Pass at the hook_init()

Thursday, January 13, 2011

Page 72: Mobile Web on Drupal!

Create a Hook for Device Classes

Thursday, January 13, 2011

Page 73: Mobile Web on Drupal!

Device Class Definitions

This can be read:((is_wireless_device == TRUE) && (ajax_xhr_type != ‘none’) && (mobile_browser === ‘Safari’ || mobile_browser === ‘Android Webkit’))

Thursday, January 13, 2011

Page 74: Mobile Web on Drupal!

Define some Device Classes

In the interest of brevity, only two device classes here and “Webkit on Mobile” is over-simplified.

Thursday, January 13, 2011

Page 75: Mobile Web on Drupal!

Second Pass at hook_init()

Thursday, January 13, 2011

Page 76: Mobile Web on Drupal!

Matching Device Classes

Get the code for mobile_web_device_match(), if you want it, at http://pastebin.com/jtufBq38

Returns TRUE if the current set of device class capabilities match the current user’s device

Thursday, January 13, 2011

Page 77: Mobile Web on Drupal!

Themes!

Thursday, January 13, 2011

Page 78: Mobile Web on Drupal!

Creating some Themes

Consider your DOCTYPE

Familiarize yourself with what’s supported in XHTML-MP

Drupal-specific gotcha: You’ll need to override theme(‘table’) if you want your code to validate in XHTML-MP 1.2 (<thead> is invalid).

You can mostly disregard WML these days.

I sub-theme quite a bit (http://drupal.org/node/225125)

Thursday, January 13, 2011

Page 79: Mobile Web on Drupal!

Might I suggest?

I’m a big fan of sub-themes.

Thursday, January 13, 2011

Page 80: Mobile Web on Drupal!

Another Variant

For hybrid desktop/mobile sites.

I also advise using the admin_theme module such that the admin interface stays sane.

Thursday, January 13, 2011

Page 81: Mobile Web on Drupal!

Don’t Panic!

You’re not going to have to implement full-fledged themes for all of your devices!

Our device class themes usually contain:

Additional CSS for that device class (in addition to default mobile or overrides)

Device-class-specific JS

Overrides for templates on an as-needed basis.

Thursday, January 13, 2011

Page 82: Mobile Web on Drupal!

My CSS and JS are Out of Control!

In D6, theme has final say-so of what JS and CSS get delivered

First call to drupal_add_js() always adds jQuery and drupal.js

I’ll show you how to get around this, but it is ugly

A brief D7 interlude: This is remedied in D7 with two new alter hooks for CSS and JS

Thursday, January 13, 2011

Page 83: Mobile Web on Drupal!

Control your JS and CSS

You’ll have to do this in a theme’s template.php file.

If you have themes subclassed from a single mobile theme, you can put this in one place (the top-level mobile theme).

I do it from a hook_preprocess_page(&$vars) implementation.

Thursday, January 13, 2011

Page 84: Mobile Web on Drupal!

Stripping JS and CSS

The premise of the code is:

Declare some JS (or CSS) that is allowed for the mobile theme at hand.

Iterate through the JS in the ‘scripts’ var (all current JS/CSS set up to be in the page) and make sure each entry is “allowed.”

Remove those that are not.

For JS, if only drupal.js and jQuery.js are left at the end, remove those, too.

Re-set the ‘scripts’ var by calling drupal_get_js() with the updated array of JS (or the same concept with CSS).

Thursday, January 13, 2011

Page 85: Mobile Web on Drupal!

Simplest Way to strip Extra JS...

The same approach works for CSS (the ‘styles’ variable).

Thursday, January 13, 2011

Page 86: Mobile Web on Drupal!

Sorry. That was a bit fugly.

Thursday, January 13, 2011

Page 87: Mobile Web on Drupal!

Thursday, January 13, 2011

Page 88: Mobile Web on Drupal!

Where to from here?Use the device class to help determine how theme functions behave, both on the theme level and module levels.

Use the imagecache module to serve appropriately-sized images to different device classes (or maybe tinysrc!).

Expand device class definitions to add any sort of arbitrary data you’d like.

Keep a WURFL object (or other data structure representing the WURFL attributes) available; you can ask about a device’s specific capabilities anywhere in your code.

Thursday, January 13, 2011

Page 89: Mobile Web on Drupal!

Exercises for the Reader

Some things we’ve done to make this stuff cooler:

Build an admin interface for managing allowed CSS/JS and other goodies.

Build logging to capture User Agents and their device class results (might not want to leave this on in production!)

Consider running a Tera-WURFL setup.

Thursday, January 13, 2011

Page 90: Mobile Web on Drupal!

Where are things heading?

More client-based stuff as mobile browsers get beefier

More 3rd-party Drupal support

This era is kind of like the JavaScript browser insanity of the late 90s

Thursday, January 13, 2011

Page 91: Mobile Web on Drupal!

Resources and Further Reading

Thursday, January 13, 2011

Page 92: Mobile Web on Drupal!

Read these books and blogs

Programming the Mobile WebMaximiliano Firtman (O’Reilly)

Beginning Smartphone Web DevelopmentGail Rahn Frederick/Rajesh Lal (Apress)

Because JS is Important for mobile:

High Performance JavaScriptNicholas C. Zakas (O’Reilly)

JavaScript: The Good PartsDouglas Crockford (O’Reilly)

Thursday, January 13, 2011

Page 93: Mobile Web on Drupal!

Read these books and blogs

QuirksBlog by PPK (Peter-Paul Koch)http://www.quirksmode.org/blog/

Andrea Trasatti’s tech notes and morehttp://blog.trasatti.it/

Communities Dominate Brands (Tomi Ahonen)http://communities-dominate.blogs.com/brands/

Luke Wroblewski aka @lukewhttp://www.lukew.com/ff/

Thursday, January 13, 2011

Page 94: Mobile Web on Drupal!

Super Useful Groups & Mailing Lists

mobile-web Yahoo! Grouphttp://tech.groups.yahoo.com/group/mobile-webAn active, useful list

wmlprogramming Yahoo! Grouphttp://tech.groups.yahoo.com/group/wmlprogrammingDespite the misleading name, this mailing list focuses on WURFL. Expect a rollicking time.

Mobile Portlandhttp://mobileportland.com/http://groups.google.com/group/mobile-portlandMeets the fourth Monday of each month

Thursday, January 13, 2011

Page 95: Mobile Web on Drupal!

Who Am I?Lyza Danger Gardnerco-founder, mobile Web developer type of person

Cloud Four

http://www.cloudfour.com

http://www.lyza.com

@lyzadanger

Thursday, January 13, 2011