SlideShare a Scribd company logo
write less.
 do more.
who are we?
Yehuda Katz
Andy Delcambre
 Rails Presentation - Technology Books, Tech Conferences
How is this going to
       work?
Introduction to
    jQuery
Event Driven
 JavaScript
Labs!
Labs!
git clone git://github.com/adelcambre/jquery-tutorial.git
Introduction to
    jQuery
h1 {
  color: #999;
}

         UJS With jQuery
                 $(“h1”).click(function() {
                   $(this).fadeIn();
                 });
get some elements.
     but how?
CSS 3 plus
• div          • div:first       • div:header
• div#foo      • div:last        • div:animated
• div.class    • div:not(#foo)   • div:contains(txt)
• div, p, a    • div:even        • div:empty
• div p        • div:odd         • div:has(p)
• div > p      • div:eq(1)       • div:parent
• div + p      • div:gt(1)       • div:hidden
• div ~ p      • div:lt(1)       • div:visible
CSS 3 plus
• div[foo]            • :last-child   • :reset
• div[foo=bar]        • :only-child   • :button
• div[foo!=bar]       • :input        • :file
• div[foo^=bar]       • :text         • :hidden
• div[foo$=bar]       • :password     • :enabled
• div[foo*=bar]       • :radio        • :disabled
• :nth-child(2)       • :checkbox     • :checked
• :nth-child(even)    • :submit       • :selected
• :first-child        • :image
get some elements.
$(“table tr:nth-
child(even) > td:visible”)
do stuff.
$(“div”)
Returns jquery object
$(“div”).fadeIn()
   Returns jquery object
$(“div”).fadeIn()
.css(“color”, “green”)
      Returns jquery object
we call this chaining
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 ]
Lab 1: Selectors
•Select every other row of the table
• Select the Checked checkboxes
• Select the first column of the table
• Select the top level of the outline
• Select any links to jquery.com
• Select any images that contain flowers
5 parts of jquery
        dom
      events
      effects
       ajax
      plugins
dom traversal
$(“div”).parent();
$(“div”).siblings();
$(“div”).next();
$(“div”).nextAll(“p”);
$(“div”).nextAll(“p:first”);



                               dom
$(“div”)

                          <body>




            <div>         <div>         <pre>




<p>   <p>           <p>           <p>    <p>    <p>




                                                      dom
$(“div#foo”).siblings()

                                   <body>




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




<p>   <p>                    <p>           <p>    <p>    <p>




                                                               dom
$(“div”).next()

                          <body>




            <div>         <div>         <pre>




<p>   <p>           <p>           <p>    <p>    <p>




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

                       <body>




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




                                              dom
$(“div”).nextall(“p: rst”)

                        <body>




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




                                               dom
nd
$(“div pre”)
$(“div”).find(“pre”)




                       dom
$(“div pre”)

                              <body>




              <div>           <div>         <pre>




<p>   <pre>           <pre>           <p>   <pre>   <p>




                                                          dom
$(“div”). nd(“pre”)

                                <body>




                <div>           <div>         <pre>




<p>     <pre>           <pre>           <p>   <pre>   <p>




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

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


                                              dom
andSelf()
$(“div”).siblings().andSelf()
$(“div”).parent().andSelf()




                                dom
$(“div”).siblings().andself()

                                      <body>




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




   <p>   <p>                    <p>           <p>    <p>    <p>




                                                                  dom
$(“p”).parent().andself()

                                    <body>




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




 <p>   <p>                    <p>           <p>    <p>    <p>




                                                                dom
Lab 2: Traversal


• Select any text areas and their labels
• Any span’s parent
• All of the form elements from a form that PUT’s
attributes
$(“div”).attr(“id”) // returns id
$(“div”).attr(“id”, “hello”) // sets id to hello
$(“div”).attr(“id”, function() { return this.name })
$(“div”).attr({id: “foo”, name: “bar”})
$(“div”).removeAttr(“id”);


                                                       dom
classes
$(“div”).addClass(“foo”)
$(“div”).removeClass(“foo”)
$(“div”).toggleClass(“foo”)
$(“div”).hasClass(“foo”)



                              dom
other
$(“div”).html()
$(“div”).html(“<p>Hello</p>”)
$(“div”).text()
$(“div”).text(“Hello”)
$(“div”).val()
$(“div”).val(“Hello”)

                                dom
noticing a pattern?
manipulation
$(“div”).append(“<p>Hello</p>”)
$(“<p>Hello</p>”).appendTo(“div”)
$(“div”).after(“<p>Hello</p>”)
$(“<p>Hello</p>”).insertAfter(“div”)



                                       dom
way more...
http://docs.jquery.com
 http://api.jquery.com




                         dom
Lab 3: Manipulation
                   Note: Use the Lab 2 File again



• Add CSS4 to the list after CSS3
• Remove any images with Dogs
• Turn the ruby row red
• Add some default text to the input field
5 parts of jquery
        dom
      events
      effects
       ajax
      plugins
document ready
$(document).ready(function() { ... })
  Alias: jQuery(function($) { ... })
bind
$(“div”).bind(“click”, function() { ... })
 Alias: $(“div”).click(function() { ... })
“this” bound
refers to the element
e
$(“div”).click(function(e) { ... })
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
trigger
$(“div”).trigger(“click”)
 Alias: $(“div”).click()
triggerHandler
doesn’t trigger the browser’s default actions
custom events
$(“div”).bind(“myEvent”, function() { ... })
         $(“div”).trigger(“myEvent”)
hover
$(“div”).hover(function() { ... }, function() { ... })
toggle
$(“div”).toggle(function() { ... }, function() { ... })
1.3



                live
$(“div”).live(“click”, function() { ... })
5 parts of jquery
        dom
      events
      effects
       ajax
      plugins
Fades
    $(“div”).fadeIn()
$(“div”).fadeOut(“slow”)
slides
   $(“div”).slideUp(200)
$(“div”).slideDown(“slow”)
animate
       $(“div”).animate({height: “toggle”, opacity: “toggle”})
$(“div”).animate({fontSize: “24px”, opacity: 0.5}, {easing: “expo”})
Lab 4: Events and Effects
                       Note: Use the Lab 2 File again



• Fade out all of the divs
• Make each img grow when you mouseover them (and shrink
    again after you leave)
•   Make clicking an li collapse the sub list
5 parts of jquery
        dom
      events
      effects
       ajax
      plugins
make easy things easy
$(“div”).load(“some_url”);
$(“div”).load(“some_url”, {data: “foo”},
  function(text) { ... });
it’s easy to do it right
$.getJSON(“some_url”, function(json) { ... })
$.getJSON(“some_url”, {data: “foo”},
  function(json) { ... })
it’s consistent
$.get(“some_url”, function(text) { ... })
$.post(“some_url”, {data: “foo”},
  function(text) { ... })
and powerful
              $.ajax Options

•   async             •   global
•   beforeSend        •   ifModi ed
•   cache             •   jsonp
•   complete          •   processData
•   contentType       •   success
•   data              •   timeout
•   dataType          •   type
•   error
and powerful
                  global ajax settings
/* 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() { ... });
5 parts of jquery
        dom
      events
      effects
       ajax
      plugins
there are hundreds
which are important?
jquery ui
• Draggables           • Accordion
• Droppables           • Date Picker
• Sortables            • Dialog
• Selectables          • Slider        Widgets

• Resizables           • Tabs
          Primitives

                             http://ui.jquery.com
jquery one easy step:
ajaxify a form in
                  forms
 $(“form.remote”).ajaxForm()




       http://www.malsup.com/jquery/form/
form validation
specify validation rules in your markup




               http://bassistance.de/jquery-
             plugins/jquery-plugin-validation/
BASE



 metadata plugin
specify metadata for elements in markup

         <div data=”{some: ‘data’}”>
$(“div”).metadata().some // returns ‘data’



             http://jqueryjs.googlecode.com/svn/
                   trunk/plugins/metadata/
Event Driven
 JavaScript
http://github.com/
wycats/blue-ridge
jQuery on Rails
jQuery and RJS
Rails 3
Ajax and Rails
  $.getJSON(“/rails/action”)
Ajax and Rails
 respond_to do |format|
     format.json {
       render :json => obj
     }
 end
link_to_remote
link_to_remote "Delete this post",
  :update => "posts",
  :url => { :action => "destroy",
            :id => post.id }
link_to_remote
link_to "Delete this post",
   url(:action => "destroy",
       :id => post.id),
   :rel => "#posts"
link_to_remote
$(‘a.remote’).live(“click”, function() {
  $(this.rel).load(this.href)
});
form_remote_tag
<% form_remote_tag :url => ...,
   :update => “res” do -%>

<% form_tag :url => ...,
   :rel => “#res” do -%>
form_remote_tag
$(‘form’).each(function() {
   $(this).ajaxForm({ target: this.rel })
})
observe_ eld
<%=                       var lastTime = new Date;
observe_field :suggest,   $('#suggest')
 :url => {                 .live(“keyup”, function() {
    :action => :find },     if(new Date - lastTime > 250) {
 :frequency => 0.25,          var field = $('#suggest');
 :update => :suggest,         var url = field.attr('rel');
 :with => 'q'                 field.load(url,
%>                              {q: field.val()});
                            }
                            lastTime = new Date;
                          });
periodically_call_remote
periodically_call_remote(   setInterval(function() {
  :url => {                   $('#avg')
    :action => 'avgs' },        .load('/some/avgs');
  :update => 'avg',         }, 20000);
  :frequency => '20')

More Related Content

What's hot (18)

PPTX
jQuery Fundamentals
Gil Fink
 
PDF
Testing Web Applications with GEB
Howard Lewis Ship
 
PPTX
jQuery from the very beginning
Anis Ahmad
 
ODP
Introduction to jQuery
manugoel2003
 
PPTX
jQuery Presentasion
Mohammad Usman
 
PDF
jQuery Essentials
Bedis ElAchèche
 
PPTX
jQuery
Jay Poojara
 
PPT
Propel sfugmd
iKlaus
 
PDF
The jQuery Divide
Rebecca Murphey
 
PDF
Using Templates to Achieve Awesomer Architecture
Garann Means
 
PDF
php plus mysql
Jayson de Leon
 
PDF
Organizing Code with JavascriptMVC
Thomas Reynolds
 
DOCX
logic321
logic321
 
PPT
jQuery
Mostafa Bayomi
 
PDF
Functionality Focused Code Organization
Rebecca Murphey
 
KEY
Potential Friend Finder
Richard Schneeman
 
PDF
Modern Application Foundations: Underscore and Twitter Bootstrap
Howard Lewis Ship
 
jQuery Fundamentals
Gil Fink
 
Testing Web Applications with GEB
Howard Lewis Ship
 
jQuery from the very beginning
Anis Ahmad
 
Introduction to jQuery
manugoel2003
 
jQuery Presentasion
Mohammad Usman
 
jQuery Essentials
Bedis ElAchèche
 
jQuery
Jay Poojara
 
Propel sfugmd
iKlaus
 
The jQuery Divide
Rebecca Murphey
 
Using Templates to Achieve Awesomer Architecture
Garann Means
 
php plus mysql
Jayson de Leon
 
Organizing Code with JavascriptMVC
Thomas Reynolds
 
logic321
logic321
 
Functionality Focused Code Organization
Rebecca Murphey
 
Potential Friend Finder
Richard Schneeman
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Howard Lewis Ship
 

Similar to Rails Presentation - Technology Books, Tech Conferences (20)

PDF
Introduction to jQuery
Zeeshan Khan
 
PPT
J query introduction
SMS_VietNam
 
PDF
DOM Scripting Toolkit - jQuery
Remy Sharp
 
PDF
jquery cheat sheet
johnnytomcat
 
PDF
Visual jQuery
guestc8e51c
 
PDF
jQuery1.2.cheatsheet.v1.0_1
brecke
 
PDF
jQuery1.2.cheatsheet.v1.0
guest922726
 
PDF
jQuery1.2.cheatsheet.v1.0
guest644d1d
 
PDF
J query1.2.cheatsheet.v1.0
Mariaa Maria
 
PDF
J query1.2.cheatsheet.v1.0
pointille1955
 
PDF
JQUERY TUTORIAL
guest9cdf90
 
PDF
J query1.2.cheatsheet.v1.0
Michael Grigsby
 
PDF
Remy Sharp The DOM scripting toolkit jQuery
deimos
 
KEY
An in-depth look at jQuery
Paul Bakaus
 
PDF
jQuery
Andrew Homeyer
 
PPTX
JQuery
SelmanJagxhiu
 
PDF
The Dom Scripting Toolkit J Query
QConLondon2008
 
PDF
jQuery Internals + Cool Stuff
jeresig
 
PPTX
Web technologies-course 11.pptx
Stefan Oprea
 
PDF
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
Introduction to jQuery
Zeeshan Khan
 
J query introduction
SMS_VietNam
 
DOM Scripting Toolkit - jQuery
Remy Sharp
 
jquery cheat sheet
johnnytomcat
 
Visual jQuery
guestc8e51c
 
jQuery1.2.cheatsheet.v1.0_1
brecke
 
jQuery1.2.cheatsheet.v1.0
guest922726
 
jQuery1.2.cheatsheet.v1.0
guest644d1d
 
J query1.2.cheatsheet.v1.0
Mariaa Maria
 
J query1.2.cheatsheet.v1.0
pointille1955
 
JQUERY TUTORIAL
guest9cdf90
 
J query1.2.cheatsheet.v1.0
Michael Grigsby
 
Remy Sharp The DOM scripting toolkit jQuery
deimos
 
An in-depth look at jQuery
Paul Bakaus
 
The Dom Scripting Toolkit J Query
QConLondon2008
 
jQuery Internals + Cool Stuff
jeresig
 
Web technologies-course 11.pptx
Stefan Oprea
 
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
Ad

More from tutorialsruby (20)

PDF
&lt;img src="../i/r_14.png" />
tutorialsruby
 
PDF
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
tutorialsruby
 
PDF
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
tutorialsruby
 
PDF
&lt;img src="../i/r_14.png" />
tutorialsruby
 
PDF
&lt;img src="../i/r_14.png" />
tutorialsruby
 
PDF
Standardization and Knowledge Transfer – INS0
tutorialsruby
 
PDF
xhtml_basics
tutorialsruby
 
PDF
xhtml_basics
tutorialsruby
 
PDF
xhtml-documentation
tutorialsruby
 
PDF
xhtml-documentation
tutorialsruby
 
PDF
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
PDF
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
PDF
HowTo_CSS
tutorialsruby
 
PDF
HowTo_CSS
tutorialsruby
 
PDF
BloggingWithStyle_2008
tutorialsruby
 
PDF
BloggingWithStyle_2008
tutorialsruby
 
PDF
cascadingstylesheets
tutorialsruby
 
PDF
cascadingstylesheets
tutorialsruby
 
&lt;img src="../i/r_14.png" />
tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
tutorialsruby
 
&lt;img src="../i/r_14.png" />
tutorialsruby
 
&lt;img src="../i/r_14.png" />
tutorialsruby
 
Standardization and Knowledge Transfer – INS0
tutorialsruby
 
xhtml_basics
tutorialsruby
 
xhtml_basics
tutorialsruby
 
xhtml-documentation
tutorialsruby
 
xhtml-documentation
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
HowTo_CSS
tutorialsruby
 
HowTo_CSS
tutorialsruby
 
BloggingWithStyle_2008
tutorialsruby
 
BloggingWithStyle_2008
tutorialsruby
 
cascadingstylesheets
tutorialsruby
 
cascadingstylesheets
tutorialsruby
 
Ad

Recently uploaded (20)

PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
July Patch Tuesday
Ivanti
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
July Patch Tuesday
Ivanti
 

Rails Presentation - Technology Books, Tech Conferences