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

Combining advanced JavaScript/DOM techniques and Ajax to ...

May 15, 2015

Download

Documents

Sampetruda
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Combining advanced JavaScript/DOM techniques and Ajax to ...

Combining advanced JavaScript/DOM techniques

and Ajax to build better User Interfaces

Thomas Fuchs

Page 2: Combining advanced JavaScript/DOM techniques and Ajax to ...

Or:Create Happy Users

Thomas Fuchs

Page 3: Combining advanced JavaScript/DOM techniques and Ajax to ...

Thomas Fuchs

• wollzelle• Core team member of

Ruby on Rails

• script.aculo.us

• mir.aculo.us

Page 4: Combining advanced JavaScript/DOM techniques and Ajax to ...

• Branding/Design/Web

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

• http://www.wollzelle.com/

Page 5: Combining advanced JavaScript/DOM techniques and Ajax to ...

Tools

Page 6: Combining advanced JavaScript/DOM techniques and Ajax to ...

JavaScript,as seen by the browser

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

Page 7: Combining advanced JavaScript/DOM techniques and Ajax to ...

JavaScript Frameworksmake you…

Page 8: Combining advanced JavaScript/DOM techniques and Ajax to ...

…write less code…

Page 9: Combining advanced JavaScript/DOM techniques and Ajax to ...

…code more elegantly…

Page 10: Combining advanced JavaScript/DOM techniques and Ajax to ...

…deal less withbrowser bugs…

Page 11: Combining advanced JavaScript/DOM techniques and Ajax to ...

…and ultimately stay happy.

Page 12: Combining advanced JavaScript/DOM techniques and Ajax to ...

Concentrate on your application…

Page 13: Combining advanced JavaScript/DOM techniques and Ajax to ...

…and not onbrowser bugs.

Page 14: Combining advanced JavaScript/DOM techniques and Ajax to ...

1.5

Page 15: Combining advanced JavaScript/DOM techniques and Ajax to ...

Prototype isJavaScript, reloaded

Page 16: Combining advanced JavaScript/DOM techniques and Ajax to ...

Ajax

Page 17: Combining advanced JavaScript/DOM techniques and Ajax to ...

Basic Ajax calls(HTML snippets)

Page 18: Combining advanced JavaScript/DOM techniques and Ajax to ...

Ajax Forms

Page 19: Combining advanced JavaScript/DOM techniques and Ajax to ...

Ajax behavioursServer-side JavaScript generation:

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

The hot topic

of 2006!

Page 20: Combining advanced JavaScript/DOM techniques and Ajax to ...

Hooks for integration with UI enhancements(like activity indicators)

Page 21: Combining advanced JavaScript/DOM techniques and Ajax to ...

Extensions tobuilt-in object types

Page 22: Combining advanced JavaScript/DOM techniques and Ajax to ...
Page 23: Combining advanced JavaScript/DOM techniques and Ajax to ...

Enumerables

Page 24: Combining advanced JavaScript/DOM techniques and Ajax to ...
Page 25: Combining advanced JavaScript/DOM techniques and Ajax to ...

$ and $$

Page 26: Combining advanced JavaScript/DOM techniques and Ajax to ...
Page 27: Combining advanced JavaScript/DOM techniques and Ajax to ...

Direct Element extensions

Page 28: Combining advanced JavaScript/DOM techniques and Ajax to ...

vs

Prototype 1.4

Prototype 1.5

Page 29: Combining advanced JavaScript/DOM techniques and Ajax to ...

.update()

.replace()

.remove()

.visible()

.setStyle()

.addClassName()

(…and lots more)

Page 30: Combining advanced JavaScript/DOM techniques and Ajax to ...

Events(without cross-browser

pain)

Page 31: Combining advanced JavaScript/DOM techniques and Ajax to ...
Page 32: Combining advanced JavaScript/DOM techniques and Ajax to ...

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

cheat sheet!

Page 33: Combining advanced JavaScript/DOM techniques and Ajax to ...

Of course,just think of it as magic.

Sam Stephenson,author of Prototype

Page 34: Combining advanced JavaScript/DOM techniques and Ajax to ...

1.6

Page 35: Combining advanced JavaScript/DOM techniques and Ajax to ...

Visual effects

Page 36: Combining advanced JavaScript/DOM techniques and Ajax to ...

Drag and Drop

Page 37: Combining advanced JavaScript/DOM techniques and Ajax to ...

2 lines of code!

Page 38: Combining advanced JavaScript/DOM techniques and Ajax to ...

Ready-to-use controls

Page 39: Combining advanced JavaScript/DOM techniques and Ajax to ...

Real-time search

Autocompleting

Drag and Drop

Inplace editor

Slider

Page 40: Combining advanced JavaScript/DOM techniques and Ajax to ...

Plus some extrasJavaScript unit testing, DOM Builder

Page 41: Combining advanced JavaScript/DOM techniques and Ajax to ...
Page 42: Combining advanced JavaScript/DOM techniques and Ajax to ...

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: Combining advanced JavaScript/DOM techniques and Ajax to ...

Add-ons

Page 44: Combining advanced JavaScript/DOM techniques and Ajax to ...

event:Selectors

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

Page 45: Combining advanced JavaScript/DOM techniques and Ajax to ...

Lightbox JS

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

Page 46: Combining advanced JavaScript/DOM techniques and Ajax to ...

Windows

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

Page 47: Combining advanced JavaScript/DOM techniques and Ajax to ...

Visual effectsSliding panels and homegrown effects

Page 48: Combining advanced JavaScript/DOM techniques and Ajax to ...

Advancedengine for visual effects

Time-based

Complex effects easily possible

Page 49: Combining advanced JavaScript/DOM techniques and Ajax to ...

More than just „eye candy“

Visual feedback

Loading times „feel shorter“

Can help move away from proprietary plugins

Page 50: Combining advanced JavaScript/DOM techniques and Ajax to ...

On board

Often-used effects

„Yellow Fade Technique“

Fade in and out

Sliding panels

Puff, Shake, etc.

Page 51: Combining advanced JavaScript/DOM techniques and Ajax to ...
Page 52: Combining advanced JavaScript/DOM techniques and Ajax to ...
Page 53: Combining advanced JavaScript/DOM techniques and Ajax to ...
Page 55: Combining advanced JavaScript/DOM techniques and Ajax to ...

Do-it-yourself effects

Very easy to do

Automatically use all the features from the visual

effects engine

Page 57: Combining advanced JavaScript/DOM techniques and Ajax to ...

Activity indicatorsShow what‘s going on

Page 58: Combining advanced JavaScript/DOM techniques and Ajax to ...

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

Revival of theanimated GIF

Both „per use“ and „global“ indicators possible

Page 59: Combining advanced JavaScript/DOM techniques and Ajax to ...

„Local“ indicator

for a specific request,show/hide indicator image

Page 60: Combining advanced JavaScript/DOM techniques and Ajax to ...

„Global“ indicator

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

Page 61: Combining advanced JavaScript/DOM techniques and Ajax to ...

Need an indicator image?

http://www.ajaxload.info/

Page 62: Combining advanced JavaScript/DOM techniques and Ajax to ...

Annonyances & Debugging

Page 63: Combining advanced JavaScript/DOM techniques and Ajax to ...

Lessons learnedfrom a year of Ajax

Page 64: Combining advanced JavaScript/DOM techniques and Ajax to ...

Not all Browsers are created equal.

Page 65: Combining advanced JavaScript/DOM techniques and Ajax to ...

CSS

Page 66: Combining advanced JavaScript/DOM techniques and Ajax to ...

CSS can eliminate or save on server accesses

HTML sizes are reduced

Be creative, CSS is extremely capable

Page 67: Combining advanced JavaScript/DOM techniques and Ajax to ...

JavaScript performance

Page 68: Combining advanced JavaScript/DOM techniques and Ajax to ...

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: Combining advanced JavaScript/DOM techniques and Ajax to ...

Ajax Security

Page 70: Combining advanced JavaScript/DOM techniques and Ajax to ...

Ajax is as secure as any browser request

So: Don‘t trust it

Always verify user submitted data on the server

Page 71: Combining advanced JavaScript/DOM techniques and Ajax to ...

Which data format?

Page 72: Combining advanced JavaScript/DOM techniques and Ajax to ...

Trivial updates: HTML

Complex updates: JavaScript

Use HTTP caching

Don‘t overengineer

be pragmatic!

Page 73: Combining advanced JavaScript/DOM techniques and Ajax to ...

Some helpful hints

Page 74: Combining advanced JavaScript/DOM techniques and Ajax to ...

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: Combining advanced JavaScript/DOM techniques and Ajax to ...

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: Combining advanced JavaScript/DOM techniques and Ajax to ...

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: Combining advanced JavaScript/DOM techniques and Ajax to ...

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: Combining advanced JavaScript/DOM techniques and Ajax to ...

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: Combining advanced JavaScript/DOM techniques and Ajax to ...

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: Combining advanced JavaScript/DOM techniques and Ajax to ...

Debugging JavaScript

Page 81: Combining advanced JavaScript/DOM techniques and Ajax to ...

No rocket surgery here

Page 82: Combining advanced JavaScript/DOM techniques and Ajax to ...

The first rule of AJAX

debugging:Use Firefox

Page 83: Combining advanced JavaScript/DOM techniques and Ajax to ...

+Extensions

The second rule of AJAX

debugging:Use Firefox

Page 84: Combining advanced JavaScript/DOM techniques and Ajax to ...

Firebug

Page 85: Combining advanced JavaScript/DOM techniques and Ajax to ...

Firebug

Version 0.4 will include a lightweight JavaScript debugger

Page 86: Combining advanced JavaScript/DOM techniques and Ajax to ...

Web DeveloperExtension

Page 87: Combining advanced JavaScript/DOM techniques and Ajax to ...

Venkman JavaScript Debugger

also does

profiling!

Page 88: Combining advanced JavaScript/DOM techniques and Ajax to ...

Tamperdata

Page 89: Combining advanced JavaScript/DOM techniques and Ajax to ...

The third rule:

Test with all browsers

you want to support

Page 90: Combining advanced JavaScript/DOM techniques and Ajax to ...

Safari Web Inspector

Page 92: Combining advanced JavaScript/DOM techniques and Ajax to ...

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

Page 93: Combining advanced JavaScript/DOM techniques and Ajax to ...

Available nowwww.fluxiom.com

Page 94: Combining advanced JavaScript/DOM techniques and Ajax to ...

Q & A