presentation as pdf

76

Upload: sampetruda

Post on 20-Jan-2015

649 views

Category:

Documents


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Presentation as PDF
Page 2: Presentation as PDF

who am I?

Page 3: Presentation as PDF
Page 4: Presentation as PDF

what is jquery?

Page 5: Presentation as PDF

jquery’score philosophy

Page 6: Presentation as PDF

get some elements.do some stuff.

Page 7: Presentation as PDF

get some elements.but how?

Page 8: Presentation as PDF

why reinvent the wheel?

Page 9: Presentation as PDF

CSS 3 plus• div

• div#foo

• div.class

• div, p, a

• div p

• div > p

• div + p

• div ~ p

• div:first

• div:last

• div:not(#foo)

• div:even

• div:odd

• div:eq(1)

• div:gt(1)

• div:lt(1)

• div:header

• div:animated

• div:contains(txt)

• div:empty

• div:has(p)

• div:parent

• div:hidden

• div:visible

Page 10: Presentation as PDF

CSS 3 plus• div

• div#foo

• div.class

• div, p, a

• div p

• div > p

• div + p

• div ~ p

• div:first

• div:last

• div:not(#foo)

• div:even

• div:odd

• div:eq(1)

• div:gt(1)

• div:lt(1)

• div:header

• div:animated

• div:contains(txt)

• div:empty

• div:has(p)

• div:parent

• div:hidden

• div:visible

Page 11: Presentation as PDF

CSS 3 plus• div[foo]

• div[foo=bar]

• div[foo!=bar]

• div[foo^=bar]

• div[foo$=bar]

• div[foo*=bar]

• :nth-child(2)

• :nth-child(even)

• :first-child

• :last-child

• :only-child

• :input

• :text

• :password

• :radio

• :checkbox

• :submit

• :image

• :reset

• :button

• :file

• :hidden

• :enabled

• :disabled

• :checked

• :selected

Page 12: Presentation as PDF

get some elements.

Page 13: Presentation as PDF

$(“table tr:nth-child(even) > td:visible”)

Page 14: Presentation as PDF

do stuff.

Page 15: Presentation as PDF

$(“div”)Returns jquery object

Page 16: Presentation as PDF

$(“div”).fadeIn()Returns jquery object

Page 17: Presentation as PDF

$(“div”).fadeIn().css(“color”, “green”)

Returns jquery object

Page 18: Presentation as PDF

we call this chaining

Page 19: Presentation as PDF

Crazy chains$(“ul.open”) // [ ul, ul, ul ] .children(“li”) // [ li, li, li ] .addClass(“open”) // [ li, li, li] .end() // [ ul, ul, ul ] .find(“a”) // [ a, a, a ] .click(function(){ $(this).next().toggle(); return false; }) // [ a, a, a ] .end(); // [ ul, ul, ul ]

Page 20: Presentation as PDF

5 parts of jquerydom

eventseffects

ajaxplugins

Page 21: Presentation as PDF

dom

$(“div”)

<body>

<div>

<p> <p> <p>

<div> <pre>

<p> <p> <p>

Page 22: Presentation as PDF

dom

$(“div”).next()

<body>

<div>

<p> <p> <p>

<div> <pre>

<p> <p> <p>

Page 23: Presentation as PDF

dom

$(“div”).nextall(“p”)

<body>

<div id='foo'> <p> <p> <pre> <p>

Page 24: Presentation as PDF

dom

$(“div”).nextall(“p:first”)

<body>

<div id='foo'> <p> <p> <pre> <p>

Page 25: Presentation as PDF

find

dom

Page 26: Presentation as PDF

dom

$(“div pre”)

<body>

<div>

<p> <pre> <pre>

<div> <pre>

<p> <pre> <p>

Page 27: Presentation as PDF

dom

$(“div”).find(“pre”)<body>

<div>

<p> <pre> <pre>

<div> <pre>

<p> <pre> <p>

Page 28: Presentation as PDF

filter$(“div:contains(some text)”)

$(“div”).filter( “:contains(some text)”)

dom

Page 29: Presentation as PDF

filter$(“div”).filter(function() { return $(this).text() .match(“some text”)})

dom

Page 30: Presentation as PDF

andself()

dom

Page 31: Presentation as PDF

dom

$(“div”).parent().andself()

<body>

<div id='foo'>

<p> <p> <p>

<div> <pre>

<p> <p> <p>

Page 32: Presentation as PDF

attributes$(“div”).attr(“id”)

$(“div”).attr(“id”, “hello”)

dom

Getter

Setter

Page 33: Presentation as PDF

attributes$(“div”).attr(“id”, function() { return this.name })

$(“div”).attr( {id: “foo”, name: “bar”})

dom

Page 34: Presentation as PDF

other$(“div”).html()

$(“div”).html(“<p>Hello</p>”)

dom

Getter

Setter

Page 35: Presentation as PDF

other$(“div”).text()

$(“div”).text(“Hello”)

dom

Getter

Setter

Page 36: Presentation as PDF

other$(“div”).val()

$(“div”).val(“Hello”)

dom

Getter

Setter

Page 37: Presentation as PDF

noticing a pattern?

Page 38: Presentation as PDF

5 parts of jquerydom

eventseffects

ajaxplugins

Page 39: Presentation as PDF

bind$(“div”).bind(“click”, function()

{ ... })

Alias: $(“div”).click(function() { ... })

Page 40: Presentation as PDF

“this”refers to the element bound

Page 41: Presentation as PDF

e$(“div”).click(function(e) { ... })

Page 42: Presentation as PDF

corrected event object

Property Correction

target The element that triggered the event (event delegation)

relatedTarget The element that the mouse is moving in (or out) of

pageX/Y The mouse cursor relative to the document

which mouse: 1 (left) 2 (middle) 3 (right)

keypress: The ASCII value of the text input

metaKey Control on Windows and Apple on OSX

Page 43: Presentation as PDF

trigger$(“div”).trigger(“click”)

Alias: $(“div”).click()

Page 44: Presentation as PDF

triggerhandlerdoesn’t trigger the browser’s default actions

Page 45: Presentation as PDF

custom events$(“div”).bind(“myEvent”, function()

{ ... })

$(“div”).trigger(“myEvent”)

Page 46: Presentation as PDF

namespaces$(“div”)

.bind(“activate.autocomplete”, function() { ... })

$(“div”).trigger(“activate”)

Page 47: Presentation as PDF

5 parts of jquerydom

eventseffects

ajaxplugins

Page 48: Presentation as PDF

make easy things easy$(“div”).load(“some_url”);

$(“div”).load(“some_url”, {data: “foo”},

Page 49: Presentation as PDF

it’s easy to do it right

$.getJSON(“some_url”, function(json) { ... })

$.getJSON(“some_url”, {data: “foo”}, function(json) { ... })

Page 50: Presentation as PDF

it’s consistent$.get(“some_url”, function(text) { ... })

$.post(“some_url”, {data: “foo”}, function(text) { ... })

Page 51: Presentation as PDF

and powerful

• async

• beforeSend

• cache

• complete

• contentType

• data

• dataType

• error

• global

• ifModified

• jsonp

• processData

• success

• timeout

• type

$.ajax Options

Page 52: Presentation as PDF

and powerful/* No Ajax requests exist, and one starts */$(“div.progress”).ajaxStart(function() { $(this).show() });

/* The last Ajax request stops */$(“div.progress”).ajaxStop(function() { $(this).hide() });

/* Any Ajax request is sent */$(“p”).ajaxSend(function() { ... });

/* Any Ajax request completes (success or failure) */$(“div”).ajaxComplete(function() { ... });

/* Any Ajax request errors out */$(“div”).ajaxError(function() { ... });

/* Any Ajax request succeeds */$(“div”).ajaxSucccess(function() { ... });

global ajax settings

Page 53: Presentation as PDF

5 parts of jquerydom

eventseffects

ajaxplugins

Page 54: Presentation as PDF

metadata

Page 55: Presentation as PDF

metadata<input class="autocomplete" metadata="{ cluster_id: 1, get: '/customers/from_salesforce’ fields: {id: 'details[salesforce_id]'} }" />

Page 56: Presentation as PDF

in rails<%= autocomplete( “Search for Salesforce Customer”, { :cluster_id => @cluster.id, :get => “/customers/from_salesforce”, :fields => {:id => ‘details[salesforce_id]’} }) %>

Page 57: Presentation as PDF

livequery

Page 58: Presentation as PDF

replaces each$("input.autocomplete").each(function() { var match = $(this).metadata().match || "name"; $(this).autocomplete({ ajax: $(this).metadata().get, insertText: function(obj) { return obj[match]; }, match: function(typed) { var regex = new RegExp(typed, “i”); return this[match || "name"] .toString().match(regex); }, template: function(obj) { return "<li>" + obj[match || "name"] + "</li>"; } })});

metadata

Page 59: Presentation as PDF

replaces each$("input.autocomplete").each(function() { var match = $(this).metadata().match || "name"; $(this).autocomplete({ ajax: $(this).metadata().get, insertText: function(obj) { return obj[match]; }, match: function(typed) { var regex = new RegExp(typed, “i”); return this[match || "name"] .toString().match(regex); }, template: function(obj) { return "<li>" + obj[match || "name"] + "</li>"; } })});

metadata<%= autocomplete( “Search for Salesforce Customer”, { :cluster_id => @cluster.id, :get => “/customers/from_salesforce”, :fields => {:id => ‘details[salesforce_id]’} }) %>

reminder

Page 60: Presentation as PDF

replaces each$("input.autocomplete").livequery(function() { var match = $(this).metadata().match || "name"; $(this).autocomplete({ ajax: $(this).metadata().get, insertText: function(obj) { return obj[match]; }, match: function(typed) { var regex = new RegExp(typed, “i”); return this[match || "name"] .toString().match(regex); }, template: function(obj) { return "<li>" + obj[match || "name"] + "</li>"; } })});

catch that?

Page 61: Presentation as PDF

replaces bind$("a.edit_autocomplete").bind("click", function() { $(this).parent().hide() .prev().show() .find("input").focus(); return false;});

Page 62: Presentation as PDF

replaces bind$("a.edit_autocomplete").livequery("click", function() { $(this).parent().hide() .prev().show() .find("input").focus(); return false;

catch that?

Page 63: Presentation as PDF

seamless interaction

Page 64: Presentation as PDF

ajax$("input.autocomplete").livequery(function() { $(this).bind("activate.autocomplete", function(e, d) { var data = {}, self = this, meta = $(this).metadata() var self = this; var fields = meta.fields, field = meta.field; if(meta.put) { for(prop in fields) data[fields[prop]] = d[prop];

$.post(meta.put, data, function(json) { $(self).val(""); $(self).parent().hide().after("<h5>" + json[field] + " <a href='#' class='edit_autocomplete'>(Edit)</a></h5>"); }, "json"); } else { for(prop in fields) $(":input[name=\"" + fields[prop] + "\"]").val(d[prop]); } });});

var self = this;

Page 65: Presentation as PDF

ajax$("input.autocomplete").livequery(function() { $(this).bind("activate.autocomplete", function(e, d) { var data = {}, self = this, meta = $(this).metadata() var self = this; var fields = meta.fields, field = meta.field; if(meta.put) { for(prop in fields) data[fields[prop]] = d[prop];

$.post(meta.put, data, function(json) { $(self).val(""); $(self).parent().hide().after("<h5>" + json[field] + " <a href='#' class='edit_autocomplete'>(Edit)</a></h5>"); }, "json"); } else { for(prop in fields) $(":input[name=\"" + fields[prop] + "\"]").val(d[prop]); } });});

meta.put

Page 66: Presentation as PDF

ajax$("input.autocomplete").livequery(function() { $(this).bind("activate.autocomplete", function(e, d) { var data = {}, self = this, meta = $(this).metadata() var self = this; var fields = meta.fields, field = meta.field; if(meta.put) { for(prop in fields) data[fields[prop]] = d[prop];

$.post(meta.put, data, function(json) { $(self).val(""); $(self).parent().hide().after("<h5>" + json[field] + " <a href='#' class='edit_autocomplete'>(Edit)</a></h5>"); }, "json"); } else { for(prop in fields) $(":input[name=\"" + fields[prop] + "\"]").val(d[prop]); } });});

function(json)

Page 67: Presentation as PDF

in railsclass CustomersController

def update @customer = Customer.find(params[:id]) @customer.update(params[:details]) respond_to do |format| format.html format.json :json => @customer end endend

send JSON

Page 68: Presentation as PDF

in merbclass Customers

def update(id, details) @customer = Customer.get!(id) @customer.update(details) display @customer endend

send JSON

Page 69: Presentation as PDF

ajax$("input.autocomplete").livequery(function() { $(this).bind("activate.autocomplete", function(e, d) { var data = {}, self = this, meta = $(this).metadata() var self = this; var fields = meta.fields, field = meta.field; if(meta.put) { for(prop in fields) data[fields[prop]] = d[prop];

$.post(meta.put, data, function(json) { $(self).val(""); $(self).parent().hide().after("<h5>" + json[field] + " <a href='#' class='edit_autocomplete'>(Edit)</a></h5>"); }, "json"); } else { for(prop in fields) $(":input[name=\"" + fields[prop] + "\"]").val(d[prop]); } });});

$.post(meta.put, data, function(json) { $(self).val(""); $(self).parent().hide().after("<h5>" + json[field] + " <a href='#' class='edit_autocomplete'> " + "(Edit)</a></h5>");}, "json");

receive JSON

Page 70: Presentation as PDF

who’s using jquery?

Page 71: Presentation as PDF

who, you ask?• Google

• Dell

• NBC

• CBS

• MSNBC

• Bank of America

• BBC

• Reuters

• Digg

• Business Week

• Newsweek

• Amazon

• Intel

• Oracle

• Cisco

• Slashdot

• Technorati

• Sourceforge

Page 72: Presentation as PDF

not enough?• Intuit

• American Eagle

• Salesforce

• Newsgator

• Boston Globe

• New York Post

• Miami Herald

• The Food Network

• The Onion

• Feedburner

• WB Records

• Def Jam Records

• AOL

• Classmates.com

• Fandango

• Pandora

• Vodafone

• Ars Technica

Page 73: Presentation as PDF

you say you want more?

• Linux.com

• Super Smash Bros.

• Barack Obama

• Joost

• iFilm.com

• Mozilla

• Wordpress

• PEAR

• Trac

• Zend

• Hackety Hack

• Joomla

• Age of Empires 3

• myYearbook.com

• REI

• Poker Room

• isoHunt

• Ask a Ninja

Page 74: Presentation as PDF

get a complete list at

http://docs.jquery.com/Sites_Using_jQuery

Page 75: Presentation as PDF

this is only the beginning

Page 76: Presentation as PDF

thank you.