orcreatehappyusers

94
Combining advanced JavaScript/DOM techniques and Ajax to build better User Interfaces Thomas Fuchs

description

 

Transcript of orcreatehappyusers

Page 1: orcreatehappyusers

Combining advanced JavaScript/DOM techniques

and Ajax to build better User Interfaces

Thomas Fuchs

Page 2: orcreatehappyusers

Or:Create Happy Users

Thomas Fuchs

Page 3: orcreatehappyusers

Thomas Fuchs

• wollzelle• Core team member of

Ruby on Rails

• script.aculo.us

• mir.aculo.us

Page 4: orcreatehappyusers

• Branding/Design/Web

• fluxiom Digital Asset Managementhttp://www.fluxiom.com

• http://www.wollzelle.com/

Page 5: orcreatehappyusers

Tools

Page 6: orcreatehappyusers

JavaScript,as seen by the browser

Source: http://www.pollux.franken.de/KNF/

Page 7: orcreatehappyusers

JavaScript Frameworksmake you…

Page 8: orcreatehappyusers

…write less code…

Page 9: orcreatehappyusers

…code more elegantly…

Page 10: orcreatehappyusers

…deal less withbrowser bugs…

Page 11: orcreatehappyusers

…and ultimately stay happy.

Page 12: orcreatehappyusers

Concentrate on your application…

Page 13: orcreatehappyusers

…and not onbrowser bugs.

Page 14: orcreatehappyusers

1.5

Page 15: orcreatehappyusers

Prototype isJavaScript, reloaded

Page 16: orcreatehappyusers

Ajax

Page 17: orcreatehappyusers

Basic Ajax calls(HTML snippets)

Page 18: orcreatehappyusers

Ajax Forms

Page 19: orcreatehappyusers

Ajax behavioursServer-side JavaScript generation:

Prototype automatically evaluates JavaScript when Content-type: text/javascript is set

The hot topic

of 2006!

Page 20: orcreatehappyusers

Hooks for integration with UI enhancements(like activity indicators)

Page 21: orcreatehappyusers

Extensions tobuilt-in object types

Page 22: orcreatehappyusers
Page 23: orcreatehappyusers

Enumerables

Page 24: orcreatehappyusers
Page 25: orcreatehappyusers

$ and $$

Page 26: orcreatehappyusers
Page 27: orcreatehappyusers

Direct Element extensions

Page 28: orcreatehappyusers

vs

Prototype 1.4

Prototype 1.5

Page 29: orcreatehappyusers

.update()

.replace()

.remove()

.visible()

.setStyle()

.addClassName()

(…and lots more)

Page 30: orcreatehappyusers

Events(without cross-browser

pain)

Page 31: orcreatehappyusers
Page 32: orcreatehappyusers

http://www.snook.ca/archives/000531.php

cheat sheet!

Page 33: orcreatehappyusers

Of course,just think of it as magic.

Sam Stephenson,author of Prototype

Page 34: orcreatehappyusers

1.6

Page 35: orcreatehappyusers

Visual effects

Page 36: orcreatehappyusers

Drag and Drop

Page 37: orcreatehappyusers

2 lines of code!

Page 38: orcreatehappyusers

Ready-to-use controls

Page 39: orcreatehappyusers

Real-time search

Autocompleting

Drag and Drop

Inplace editor

Slider

Page 40: orcreatehappyusers

Plus some extrasJavaScript unit testing, DOM Builder

Page 41: orcreatehappyusers
Page 42: orcreatehappyusers

Docs & Help

• Wiki:http://wiki.script.aculo.us/

• Mailing list:http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

• IRC channel:#prototype on freenode.net

Page 43: orcreatehappyusers

Add-ons

Page 44: orcreatehappyusers

event:Selectors

http://encytemedia.com/event-selectors/

Page 45: orcreatehappyusers

Lightbox JS

http://www.huddletogether.com/projects/lightbox2/

Page 46: orcreatehappyusers

Windows

http://blogus.xilinus.com/pages/javawin

Page 47: orcreatehappyusers

Visual effectsSliding panels and homegrown effects

Page 48: orcreatehappyusers

Advancedengine for visual effects

Time-based

Complex effects easily possible

Page 49: orcreatehappyusers

More than just „eye candy“

Visual feedback

Loading times „feel shorter“

Can help move away from proprietary plugins

Page 50: orcreatehappyusers

On board

Often-used effects

„Yellow Fade Technique“

Fade in and out

Sliding panels

Puff, Shake, etc.

Page 51: orcreatehappyusers
Page 52: orcreatehappyusers
Page 53: orcreatehappyusers
Page 55: orcreatehappyusers

Do-it-yourself effects

Very easy to do

Automatically use all the features from the visual

effects engine

Page 57: orcreatehappyusers

Activity indicatorsShow what‘s going on

Page 58: orcreatehappyusers

„There‘s something going on, wait a sec“

Revival of theanimated GIF

Both „per use“ and „global“ indicators possible

Page 59: orcreatehappyusers

„Local“ indicator

for a specific request,show/hide indicator image

Page 60: orcreatehappyusers

„Global“ indicator

for a all Ajax requests,appear/fade an indicator image

Page 61: orcreatehappyusers

Need an indicator image?

http://www.ajaxload.info/

Page 62: orcreatehappyusers

Annonyances & Debugging

Page 63: orcreatehappyusers

Lessons learnedfrom a year of Ajax

Page 64: orcreatehappyusers

Not all Browsers are created equal.

Page 65: orcreatehappyusers

CSS

Page 66: orcreatehappyusers

CSS can eliminate or save on server accesses

HTML sizes are reduced

Be creative, CSS is extremely capable

Page 67: orcreatehappyusers

JavaScript performance

Page 68: orcreatehappyusers

DOM-API can be slow

Firefox is the slowest (better in 1.5)

Caching references in JavaScript vars

.innerHTML is your friend

Venkman profiling

Page 69: orcreatehappyusers

Ajax Security

Page 70: orcreatehappyusers

Ajax is as secure as any browser request

So: Don‘t trust it

Always verify user submitted data on the server

Page 71: orcreatehappyusers

Which data format?

Page 72: orcreatehappyusers

Trivial updates: HTML

Complex updates: JavaScript

Use HTTP caching

Don‘t overengineer

be pragmatic!

Page 73: orcreatehappyusers

Some helpful hints

Page 74: orcreatehappyusers

Local calls only

• Ajax can only call originating server

• Also works with file:// URLs

• Use server-side proxying if you want to tie in other services

Page 75: orcreatehappyusers

The Back button

• The browser back button works by returning the user to the last „non-ajax“ loaded page

• Keep that in mind, especially for public sites

• Workarounds available, but aren‘t working with all browsers

Page 76: orcreatehappyusers

display: none

• Don‘t use display:none in external CSS

• Browser can‘t determine the original (built-in) display value of an element (like „block“ for DIVs, and „inline“ for SPANs)

• Use the style attribute instead:<div style=“display:none“>...</div>

Page 77: orcreatehappyusers

Internet Explorerimage cache

• Internet Explorer doesn‘t use its cache when HTML page fragments that are inserted via Ajax are loading images (IMG tag)

• Some proprietary HTTP headers exist to work around this (hey, it‘s Microsoft!):

• http://mir.aculo.us/articles/2005/08/28/internet-explorer-and-ajax-image-caching-woes

Page 78: orcreatehappyusers

The verboten IDsof Internet Explorer

• IE 6 has some bugs regarding naming ID attributes

• Don‘t use: „length“, „item“, „namedItem“, „tags“ or „urns“

• http://meyerweb.com/eric/thoughts/2005/08/29/reserved-id-values/

Page 79: orcreatehappyusers

JavaScript objectsnew Ajax.Updater('test', 'update.php', { onComplete: function() {}, insertion: Insertion.Top,});

This code works in Firefox,but doesn‘t in Safari.

evil commaof browser

death

Always test in all browsers you want to support!

Page 80: orcreatehappyusers

Debugging JavaScript

Page 81: orcreatehappyusers

No rocket surgery here

Page 82: orcreatehappyusers

The first rule of AJAX

debugging:Use Firefox

Page 83: orcreatehappyusers

+Extensions

The second rule of AJAX

debugging:Use Firefox

Page 84: orcreatehappyusers

Firebug

Page 85: orcreatehappyusers

Firebug

Version 0.4 will include a lightweight JavaScript debugger

Page 86: orcreatehappyusers

Web DeveloperExtension

Page 87: orcreatehappyusers

Venkman JavaScript Debugger

also does

profiling!

Page 88: orcreatehappyusers

Tamperdata

Page 89: orcreatehappyusers

The third rule:

Test with all browsers

you want to support

Page 90: orcreatehappyusers

Safari Web Inspector

Page 92: orcreatehappyusers

„It‘s more like Web 3.0“What can you actually do with all this?

Page 93: orcreatehappyusers

Available nowwww.fluxiom.com

Page 94: orcreatehappyusers

Q & A