SlideShare uma empresa Scribd logo
1 de 42
An in-depth look at




    with Paul Bakaus
Web developing
Web developer
Has to fight against..
   • ..the DOM
    • verbose
    • horribly inefficient
   • Cross-browser issues
    • CSS
    • JavaScript
Meet jQuery
jQuery is not a
  framework.
jQuery is a library.
Framework                       Library




            Application / Website

            Framework / Library
uh oh, no OOP?
A thought problem.
•   JavaScript is entirely object oriented -
    almost to the extend of Ruby!

•   Unless most others, we don‘t hate JavaScript. Why
    simulate another language?
Basic features
The jQuery way
• Grab something and do something with it
• Human readable syntax
• Cross-browser normalization
• Chaining:
  $(quot;<div/>quot;)
   .html(quot;yay!quot;)
   .appendTo(quot;bodyquot;)
Feature sets
    Selections
 DOM Traversing
DOM Manipulations
 Attributes & CSS
     Events
    Animation
      Ajax
Selections
•                                  •
    CSS-based selections:              Attribute filters:
    $(quot;#idquot;) / $(quot;.classquot;)             [attr], [attr=value]

•                                  •
    Grab elements directly:            Child filters:
    $(DOMelement)                      :nth-child(), :first-child, :last-
                                       child, :only-child
•   Basic filters:
                                   •   Forms:
    :even, :odd, :first, :last
                                       :input, :text, :password, :radio,
•                                      :hidden
    Content filters:
    :contains(), :empty, :has(),
                                   •   Form filters:
    :parent
                                       :enabled, :disabled, :checked,
•                                      :selected
    Visibility filters:
    :hidden, :visible
DOM Traversing
 •   Remove from collection:
     filter(), not(), slice()

 •   Add to collection:
     add()

 •   Traverse:

     •   children(), parent(), parents()

     •   next(), prev(), siblings()
DOM Manipulations
•                                       •
    Changing contents:                      Replacing:
    html(), text()                          replaceWith(), replaceAll()

•                                       •
    Inserting inside:                       Removing:
    append(), appendTo(),                   empty(), remove()
    prepend(), prependTo()
                                        •   Copying:
•   Inserting outside:                      clone()
    after(), before(), insertAfter(),
    insertBefore()

•   Inserting around:
    wrap(), wrapAll, wrapInner()
Attributes & CSS
•                                        •
    Attributes:                              Height and width:
    attr(), removeAttr(), val()              height(), width(), innerHeight(),
                                             innerWidth(), outerHeight(),
•                                            outerWidth()
    Class:
    addClass(), hasClass(),
    removeClass(), toggleClass()

•   CSS:
    css()

•   Positioning:
    offset(), position(), scrollTop(),
    scrollLeft()
Events
•                                 •
    Page load:                        Event helpers:
    ready()                           blur(), change(), click(),
                                      dblclick(), error(), focus(),
•                                     keydown, keypress(), keyup(),
    Event handling:
                                      load() ...
    bind(), trigger(), unbind()

•   Live events:
    live(), die()

•   Interaction helpers:
    hover(), toggle()
Around jQuery
   Useful JavaScript
Prototypal inheritance
Basic understanding
    Objects inherit from other objects

      JavaScript inheritance is implicit

   JavaScript supports true encapsulation

   Syntax: new, instanceof, Object.prototype
Scoping & Anonymous
      functions
      (function() {})()
Recursive anonymous
     functions
      arguments.callee
Shorter Syntax
  Spice up your JavaScript
• firstCondition() && secondCondition()
• var one = 1, two = 2, three = 3;
• condition ? foo() : bar()
• var available = foo || bar
• (new Date()).getTime()
• !!()
Within jQuery
Iteration
 $(..).each(fn)
Extending
$.extend(firstObject, secondObject, ..)
Events
• Event-driven architecture
• Event namespacing
• Custom events
• Event delegation
 • Live events
Client-side programming is
an inherently asychronous
           world.
Event-driven code
•                                •
    Ericsson uses Erlang to          Any JS-Object can be a
    control their                    container
    telecommunication
                                 •   Each module needs to
    infrastructure
                                     know very little - it
•   In Erlang, modules talk to       doesn‘t care how to get
    other modules through            information
    event-passing
                                 •   Any number of modules
•   Most common modules:             can be waiting to receive
    DOM elements                     information back at the
                                     same time without
                                     hanging the browser
Event namespacing
$(quot;divquot;)
	 .bind(quot;clickquot;, function() {
	 	 alert(quot;fooquot;);
	 })
	 .$(quot;divquot;).bind(quot;click.barquot;, function() {
    	 alert(quot;barquot;);
    });

$(quot;divquot;).trigger(quot;clickquot;); //Alerts foo and bar
$(quot;divquot;).trigger(quot;click.barquot;); //Alerts only bar

$(quot;divquot;).unbind(quot;.barquot;) //Unbinds all .bar events
Custom events
• Events don‘t have to be browser events -
  invent your own!
• Events can be bound to anything - even
  generic Javascript objects
• Use the data API to pass along data with
  DOM elements without causing memory
  leaks
Event delegation
• Scales to any number of elements
• No need to rebind / unbind on DOM
  changes

• 1. Binds events to a root node instead of
  the actual context node

• 2. Checks for actual context during the
  trigger
(Demo)
Live events

• New in jQuery 1.3
• Makes event delegation totally transparent
• $().live(name, fn) to bind
• $().die(name, fn) to remove
Extending jQuery
What can be extended?
   Functions               Selectors               Animations
• most jQuery plugins   • $(‘ div:pseudo‘)   • $(..).animate({ property: 100 })
• $(..).doSomething()
Functions

• jQuery.fn is the plugin namespace
• jQuery.fn.myFunction = fn results in $
  (..).myFunction()
• In your function, this points to the current
  selection, and all arguments are passed
  along
Selectors
• The selector can be extended with custom
  pseudo selectors
• Simply extend jQuery.expr[quot;:quot;]
 • key is your pseudo selector
 • value is a function that receives the
    element as first arg and needs to return a
    boolean
Animations
• Add your own properties to animate
  (i.e. ,corner‘)
• Extend jQuery.fx.step:
 • key is the property name
 • value is a function that receives an fx
    object

Mais conteúdo relacionado

Mais procurados

Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do MoreRemy Sharp
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)jeresig
 
JavaScript Libraries (@Media)
JavaScript Libraries (@Media)JavaScript Libraries (@Media)
JavaScript Libraries (@Media)jeresig
 
jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jeresig
 
Using jQuery to Extend CSS
Using jQuery to Extend CSSUsing jQuery to Extend CSS
Using jQuery to Extend CSSChris Coyier
 
JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)jeresig
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryZeeshan Khan
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQueryAngel Ruiz
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingDoug Neiner
 
Dr. Strangelove or: How I learned to stop worrying and love HTML, CSS and Jav...
Dr. Strangelove or: How I learned to stop worrying and love HTML, CSS and Jav...Dr. Strangelove or: How I learned to stop worrying and love HTML, CSS and Jav...
Dr. Strangelove or: How I learned to stop worrying and love HTML, CSS and Jav...RobotDeathSquad
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery PresentationRod Johnson
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoiddmethvin
 
JavaScript for Flex Devs
JavaScript for Flex DevsJavaScript for Flex Devs
JavaScript for Flex DevsAaronius
 
Contextual jQuery
Contextual jQueryContextual jQuery
Contextual jQueryDoug Neiner
 

Mais procurados (20)

Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
 
jQuery
jQueryjQuery
jQuery
 
JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)JavaScript Libraries (Kings of Code)
JavaScript Libraries (Kings of Code)
 
JavaScript Libraries (@Media)
JavaScript Libraries (@Media)JavaScript Libraries (@Media)
JavaScript Libraries (@Media)
 
jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)
 
Using jQuery to Extend CSS
Using jQuery to Extend CSSUsing jQuery to Extend CSS
Using jQuery to Extend CSS
 
Jquery ui
Jquery uiJquery ui
Jquery ui
 
JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Dr. Strangelove or: How I learned to stop worrying and love HTML, CSS and Jav...
Dr. Strangelove or: How I learned to stop worrying and love HTML, CSS and Jav...Dr. Strangelove or: How I learned to stop worrying and love HTML, CSS and Jav...
Dr. Strangelove or: How I learned to stop worrying and love HTML, CSS and Jav...
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
jQuery UI and Plugins
jQuery UI and PluginsjQuery UI and Plugins
jQuery UI and Plugins
 
Jquery
JqueryJquery
Jquery
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoid
 
JavaScript for Flex Devs
JavaScript for Flex DevsJavaScript for Flex Devs
JavaScript for Flex Devs
 
Contextual jQuery
Contextual jQueryContextual jQuery
Contextual jQuery
 

Destaque

Building Robust jQuery Plugins
Building Robust jQuery PluginsBuilding Robust jQuery Plugins
Building Robust jQuery PluginsJörn Zaefferer
 
Beyond the Standards
Beyond the StandardsBeyond the Standards
Beyond the StandardsPaul Bakaus
 
VBA on Main - Member Center
VBA on Main - Member CenterVBA on Main - Member Center
VBA on Main - Member CenterMarilyn Shaw
 
Building a game engine with jQuery
Building a game engine with jQueryBuilding a game engine with jQuery
Building a game engine with jQueryPaul Bakaus
 
Rapid Prototyping With jQuery
Rapid Prototyping With jQueryRapid Prototyping With jQuery
Rapid Prototyping With jQueryPaul Bakaus
 
Rapid Prototyping mit jQuery (German)
Rapid Prototyping mit jQuery (German)Rapid Prototyping mit jQuery (German)
Rapid Prototyping mit jQuery (German)Paul Bakaus
 

Destaque (6)

Building Robust jQuery Plugins
Building Robust jQuery PluginsBuilding Robust jQuery Plugins
Building Robust jQuery Plugins
 
Beyond the Standards
Beyond the StandardsBeyond the Standards
Beyond the Standards
 
VBA on Main - Member Center
VBA on Main - Member CenterVBA on Main - Member Center
VBA on Main - Member Center
 
Building a game engine with jQuery
Building a game engine with jQueryBuilding a game engine with jQuery
Building a game engine with jQuery
 
Rapid Prototyping With jQuery
Rapid Prototyping With jQueryRapid Prototyping With jQuery
Rapid Prototyping With jQuery
 
Rapid Prototyping mit jQuery (German)
Rapid Prototyping mit jQuery (German)Rapid Prototyping mit jQuery (German)
Rapid Prototyping mit jQuery (German)
 

Semelhante a An in-depth look at jQuery

The Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryThe Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryQConLondon2008
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryRemy Sharp
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuerydeimos
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersYehuda Katz
 
Reverse Engineering Malicious Javascript
Reverse Engineering Malicious JavascriptReverse Engineering Malicious Javascript
Reverse Engineering Malicious JavascriptYusuf Motiwala
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Patrick Chanezon
 
DOSUG Intro to JQuery JavaScript Framework
DOSUG Intro to JQuery JavaScript FrameworkDOSUG Intro to JQuery JavaScript Framework
DOSUG Intro to JQuery JavaScript FrameworkMatthew McCullough
 
JavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQueryJavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQuerykatbailey
 
Everything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebEverything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebJames Rakich
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
 
Bubbles & Trees with jQuery
Bubbles & Trees with jQueryBubbles & Trees with jQuery
Bubbles & Trees with jQueryBastian Feder
 
javascript teach
javascript teachjavascript teach
javascript teachguest3732fa
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_Whiteguest3732fa
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Developmentwolframkriesing
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserHoward Lewis Ship
 

Semelhante a An in-depth look at jQuery (20)

The Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryThe Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J Query
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuery
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails Developers
 
Reverse Engineering Malicious Javascript
Reverse Engineering Malicious JavascriptReverse Engineering Malicious Javascript
Reverse Engineering Malicious Javascript
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
 
DOSUG Intro to JQuery JavaScript Framework
DOSUG Intro to JQuery JavaScript FrameworkDOSUG Intro to JQuery JavaScript Framework
DOSUG Intro to JQuery JavaScript Framework
 
JavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQueryJavaScript the Smart Way - Getting Started with jQuery
JavaScript the Smart Way - Getting Started with jQuery
 
Everything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebEverything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the Web
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
dojo.Patterns
dojo.Patternsdojo.Patterns
dojo.Patterns
 
Bubbles & Trees with jQuery
Bubbles & Trees with jQueryBubbles & Trees with jQuery
Bubbles & Trees with jQuery
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
 
Web2.0 with jQuery in English
Web2.0 with jQuery in EnglishWeb2.0 with jQuery in English
Web2.0 with jQuery in English
 
javascript teach
javascript teachjavascript teach
javascript teach
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_White
 
Trimming The Cruft
Trimming The CruftTrimming The Cruft
Trimming The Cruft
 
Efficient JavaScript Development
Efficient JavaScript DevelopmentEfficient JavaScript Development
Efficient JavaScript Development
 
Better code in JavaScript
Better code in JavaScriptBetter code in JavaScript
Better code in JavaScript
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
 

Último

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

An in-depth look at jQuery

  • 1. An in-depth look at with Paul Bakaus
  • 4. Has to fight against.. • ..the DOM • verbose • horribly inefficient • Cross-browser issues • CSS • JavaScript
  • 6. jQuery is not a framework.
  • 7. jQuery is a library.
  • 8. Framework Library Application / Website Framework / Library
  • 9. uh oh, no OOP?
  • 10. A thought problem. • JavaScript is entirely object oriented - almost to the extend of Ruby! • Unless most others, we don‘t hate JavaScript. Why simulate another language?
  • 12. The jQuery way • Grab something and do something with it • Human readable syntax • Cross-browser normalization • Chaining: $(quot;<div/>quot;) .html(quot;yay!quot;) .appendTo(quot;bodyquot;)
  • 13. Feature sets Selections DOM Traversing DOM Manipulations Attributes & CSS Events Animation Ajax
  • 14. Selections • • CSS-based selections: Attribute filters: $(quot;#idquot;) / $(quot;.classquot;) [attr], [attr=value] • • Grab elements directly: Child filters: $(DOMelement) :nth-child(), :first-child, :last- child, :only-child • Basic filters: • Forms: :even, :odd, :first, :last :input, :text, :password, :radio, • :hidden Content filters: :contains(), :empty, :has(), • Form filters: :parent :enabled, :disabled, :checked, • :selected Visibility filters: :hidden, :visible
  • 15. DOM Traversing • Remove from collection: filter(), not(), slice() • Add to collection: add() • Traverse: • children(), parent(), parents() • next(), prev(), siblings()
  • 16. DOM Manipulations • • Changing contents: Replacing: html(), text() replaceWith(), replaceAll() • • Inserting inside: Removing: append(), appendTo(), empty(), remove() prepend(), prependTo() • Copying: • Inserting outside: clone() after(), before(), insertAfter(), insertBefore() • Inserting around: wrap(), wrapAll, wrapInner()
  • 17. Attributes & CSS • • Attributes: Height and width: attr(), removeAttr(), val() height(), width(), innerHeight(), innerWidth(), outerHeight(), • outerWidth() Class: addClass(), hasClass(), removeClass(), toggleClass() • CSS: css() • Positioning: offset(), position(), scrollTop(), scrollLeft()
  • 18. Events • • Page load: Event helpers: ready() blur(), change(), click(), dblclick(), error(), focus(), • keydown, keypress(), keyup(), Event handling: load() ... bind(), trigger(), unbind() • Live events: live(), die() • Interaction helpers: hover(), toggle()
  • 19. Around jQuery Useful JavaScript
  • 21. Basic understanding Objects inherit from other objects JavaScript inheritance is implicit JavaScript supports true encapsulation Syntax: new, instanceof, Object.prototype
  • 22. Scoping & Anonymous functions (function() {})()
  • 23. Recursive anonymous functions arguments.callee
  • 24. Shorter Syntax Spice up your JavaScript
  • 25. • firstCondition() && secondCondition() • var one = 1, two = 2, three = 3; • condition ? foo() : bar() • var available = foo || bar • (new Date()).getTime() • !!()
  • 29. Events • Event-driven architecture • Event namespacing • Custom events • Event delegation • Live events
  • 30. Client-side programming is an inherently asychronous world.
  • 31. Event-driven code • • Ericsson uses Erlang to Any JS-Object can be a control their container telecommunication • Each module needs to infrastructure know very little - it • In Erlang, modules talk to doesn‘t care how to get other modules through information event-passing • Any number of modules • Most common modules: can be waiting to receive DOM elements information back at the same time without hanging the browser
  • 32. Event namespacing $(quot;divquot;) .bind(quot;clickquot;, function() { alert(quot;fooquot;); }) .$(quot;divquot;).bind(quot;click.barquot;, function() { alert(quot;barquot;); }); $(quot;divquot;).trigger(quot;clickquot;); //Alerts foo and bar $(quot;divquot;).trigger(quot;click.barquot;); //Alerts only bar $(quot;divquot;).unbind(quot;.barquot;) //Unbinds all .bar events
  • 33. Custom events • Events don‘t have to be browser events - invent your own! • Events can be bound to anything - even generic Javascript objects • Use the data API to pass along data with DOM elements without causing memory leaks
  • 35. • Scales to any number of elements • No need to rebind / unbind on DOM changes • 1. Binds events to a root node instead of the actual context node • 2. Checks for actual context during the trigger
  • 37. Live events • New in jQuery 1.3 • Makes event delegation totally transparent • $().live(name, fn) to bind • $().die(name, fn) to remove
  • 39. What can be extended? Functions Selectors Animations • most jQuery plugins • $(‘ div:pseudo‘) • $(..).animate({ property: 100 }) • $(..).doSomething()
  • 40. Functions • jQuery.fn is the plugin namespace • jQuery.fn.myFunction = fn results in $ (..).myFunction() • In your function, this points to the current selection, and all arguments are passed along
  • 41. Selectors • The selector can be extended with custom pseudo selectors • Simply extend jQuery.expr[quot;:quot;] • key is your pseudo selector • value is a function that receives the element as first arg and needs to return a boolean
  • 42. Animations • Add your own properties to animate (i.e. ,corner‘) • Extend jQuery.fx.step: • key is the property name • value is a function that receives an fx object

Notas do Editor