SlideShare una empresa de Scribd logo
1 de 39
jQuery


         Lê Văn Viễn
               Social
           17/05/2012
Agenda


 1   Introduce



 2   Compare with other libraries js



 3                       APIs



 4                     Q&A




                 www.exoplatform.com - Copyright 2012 eXo Platform   2
Introduce
Introduce
1. What is jQuery?
2. Why use jQuery?

3. History of jQuery?

4. How to use jQuery?

5. Document and source code




                www.exoplatform.com - Copyright 2012 eXo Platform   4
What is jQuery


   jQuery is a fast and concise JavaScript Library that
       simplifies HTML document traversing, event
    handling, animating, and Ajax interactions for rapid
                     web development.




                 www.exoplatform.com - Copyright 2012 eXo Platform   5
Why use jQuery

   Lightweight: 1.7.2 minified 32KB, development 247 KB

   CSS3 compliant: support css 1 - 3


   Cross brower: IE6.0+, FF 3.6+, Safari 5.0+, Opera, Chrome




               www.exoplatform.com - Copyright 2012 eXo Platform   6
History of jQuery
    Ausgt 22nd, 2005: John Resig first hints of a javascript libraty to
        use css selector with more succint syntax than existing
                               libraries

   2006: Release jQuery 1.0 and planning for jQuery 1.1

    2007: Release 1.2

   2008: Release jQuery UI 1.5

   2009: Release jQuery UI 1.7 and jQuery 1.3

  2010: Release jQuery 1.4



                www.exoplatform.com - Copyright 2012 eXo Platform   7
How to use jQuery



    <script src="jquery.js"></script>
    <script>
        $(document).ready(function(){
                   // Your code here
            });
    </script>




                  www.exoplatform.com - Copyright 2012 eXo Platform   8
Document and source code


 http://docs.jquery.com/Main_Page
 https://github.com/jquery/




                    www.exoplatform.com - Copyright 2012 eXo Platform   9
Compare with other libraries js
Background – Developer survey




                www.exoplatform.com - Copyright 2012 eXo Platform   11
Background jQuery, prototype, mootools, dojo, YUI




                                                                     jQuery
                                                                     prototype
                                                                     dojo
                                                                     mootools

                                                                     YUI




                 www.exoplatform.com - Copyright 2012 eXo Platform            12
Compare with other js libraries


  User slickspeed to test performance (selector) http://
                mootools.net/slickspeed/




                www.exoplatform.com - Copyright 2012 eXo Platform   13
Compare with other js libraries




               www.exoplatform.com - Copyright 2012 eXo Platform   14
Compare with other js libraries




               www.exoplatform.com - Copyright 2012 eXo Platform   15
APIs
APIs

1.DOM
2.Event
3.Ajax
4.Animation
5.Plugin




              www.exoplatform.com - Copyright 2012 eXo Platform   17
jQuery()
Description: Accepts a string containing a CSS selector which is then used to
match a set of elements.


jQuery( selector [ , context ] )
jQuery( element )
jQuery( object )
jQuery( elementArray )
jQuery( jQuery object )
jQuery()
jQuery( html [ , ownerDocument ] )
jQuery( html [, ownerDocument] )




                     www.exoplatform.com - Copyright 2012 eXo Platform          18
jQuery()
jQuery( selector [ , context ] )
 selector A string containing a selector expression
 context A DOM element, Document, or jQuery to use context
 Ex: $('div.foo');
 Search through the DOM element for any elements that match the provided selector and
   creates a new jquery object references these elements

jQuery( element )
 element A Dom element to wrap in a jquery object
 Ex: $('div.foo').click(function() {
         $('span', this).addClass('bar');
     });

jQuery( jQuery object )
 object An existing jquery object to clone
 Clone the object is passed, new jQuery object references the same DOM elements as the initial
   one

jQuery()
 return an empty jQuery set as 1.4, in previous version return a set containing the document
    node



                         www.exoplatform.com - Copyright 2012 eXo Platform                     19
jQuery()
jQuery( html [ , ownerDocument ] )

Description: Creates DOM elements on the fily from provided string of raw HTML
html A string of HTML to create on the fly, parses the html, not xml.
ownerDocument A document in which the new elements will be created
Ex: $('<p id="test">My <em>new</em> text</p>').appendTo('body');

jQuery(callback)
Description: Binds a function to be executed when the DOM has finished loading.
Callback the function to execute when the DOM is ready
Ex:
  jQuery(function($) {
      // Your code using failsafe $ alias here...
  });




                         www.exoplatform.com - Copyright 2012 eXo Platform        20
Jquery.noConflict()
Description: Relingquish jQuery's control of the $ variable

jQuery.noConflict( [removeAll] )
RemoveAll A Boolean indicating whether to remove all jQuery variables from the global scope
(including jQuery itself)




                        www.exoplatform.com - Copyright 2012 eXo Platform                     21
Jquery.noConflict() - How to work with other libraries js

  1. Overriding the $ function
  <script src="prototype.js"></script>
  <script src="jquery.js"></script>
  <script>
    jQuery.noConflict();

     // Use jQuery via jQuery(...)
     jQuery(document).ready(function(){
       jQuery("div").hide();
     });
     // Use Prototype with $(...), etc.
     $('someid').hide();
  </script>

  <script src="prototype.js"></script>
  <script src="jquery.js"></script>
  <script>
    var $j = jQuery.noConflict();

     // Use jQuery via $j(...)
     $j(document).ready(function(){
       $j("div").hide();
     });

     // Use Prototype with $(...), etc.
     $('someid').hide();
  </script>

                              www.exoplatform.com - Copyright 2012 eXo Platform   22
Jquery.noConflict() - How to work with other libraries js
<script src="prototype.js"></script>
<script src="jquery.js"></script>
<script>
  jQuery.noConflict();

   // Put all your code in your document ready area
   jQuery(document).ready(function($){
     // Do jQuery stuff using $
     $("div").hide();
   });

   // Use Prototype with $(...), etc.
   $('someid').hide();
</script>

2. Including jquery before other libraries
<script src="jquery.js"></script>
<script src="prototype.js"></script>
<script>
  // Use jQuery via jQuery(...)
  jQuery(document).ready(function(){
    jQuery("div").hide();
  });

   // Use Prototype with $(...), etc.
   $('someid').hide();
</script>


                                www.exoplatform.com - Copyright 2012 eXo Platform   23
Jquery.noConflict() - How to work with multiple
version jquery
<script type='text/javascript' src='js/jquery_1.3.js'></script>

<script type='text/javascript'>

   var $jq_1.3 = jQuery.noConflict();

</script>

<script type='text/javascript' src='js/jquery_1.2.js'></script>




                         www.exoplatform.com - Copyright 2012 eXo Platform   24
Selector
Compliant CSS 1-3

Child selector (“parent > child”)
Class selector (“.class”)
ID selector (“#id”)
All selector (“*”)
:button selector
:checkbox selector
:checked selector
:contains() selector
:disable selector
:enable selector
:empty selector
:file selector
:first selector
:has() selector
:hidden selector
:image selector
:parent selector
:reset selector
:submit selector
:text selector
…...


                           www.exoplatform.com - Copyright 2012 eXo Platform   25
Event – Event handler attach
 .bind(eventType [, eventData], handler(eventObject))
 Description: Attach a handler to an event for the elements

 .bind(eventType [,eventData], handler(eventObject))
 eventType A string contain one or more DOM event types
 eventData A map of data that will be passed to the event handler
 handler(eventObject) function to execute each time the event is triggered

 .bind(eventType [, eventData], preventBuble)
 preventBuble false will attach a function that prevents the default action from
 occurring and stop the event from bubbling. The default is true.

 .bind(event)
 events A map of one or more DOM event types and functions to execute them

 $("form").bind("submit", function(event) {
   event.stopPropagation();
 });

 $("form").bind("submit", function(event) {
 event.preventDefault();
 });

 $("form").bind("submit", function() { return false; })

                           www.exoplatform.com - Copyright 2012 eXo Platform       26
Event – Event handler attach

 .live(event, handler(eventObject))
 Description: Attach an event handler for all elements which match the
 current selector, now and the future.

 .live(event, data, handler(eventObject))

 .live(events-map)
 events-map A map of one or more js event types and functions to execute for them

 <script>
          $("p").live({
                     click: function() {
                              $(this).after("<p>Another paragraph!</p>");
                     },
                    mouseover: function() {
                               $(this).addClass("over");
                     },
                    mouseout: function() {
                              $(this).removeClass("over");
                     }
          });
 </script>

                          www.exoplatform.com - Copyright 2012 eXo Platform         27
Event – Event handler attach

 .delegate( selector, eventType, handler(eventObject) )
 Description: Attach a handler to one or more events for all elements
 that match the selector, now or in the future, based on a specific set of
 root elements.

 .delegate( selector, eventType, handler(eventObject) )
 selectorA selector to filter the elements that trigger the event.

 .delegate( selector, eventType, eventData, handler(eventObject) )

 .delegate( selector, events )




                           www.exoplatform.com - Copyright 2012 eXo Platform   28
Event – Event handler attach

 .on( events [, selector] [, data] , handler(eventObject) )
 Description: Attach an event handler function for one or more events to
 the selected elements.

 .on( events [, selector] [, data], handler(eventObject) )
 selectorA selector to filter the elements that trigger the event.

 .on( events-map [, selector] [, data] )

 $("#dataTable tbody tr").on("click", function(event){
         alert($(this).text());
 });




                           www.exoplatform.com - Copyright 2012 eXo Platform   29
Event – bind vs live vs delegate vs on?




               www.exoplatform.com - Copyright 2012 eXo Platform   30
Event – Document loading

 .load( handler(eventObject) )
 Description: Bind an event handler to the "load" JavaScript event.

 .load( handler(eventObject) )
 handler(eventObject)A function to execute when the event is triggered.

 .load( [eventData], handler(eventObject) )

 $(window).load(function () {
   // run code
 });




                        www.exoplatform.com - Copyright 2012 eXo Platform   31
Event – Document loading

 .ready( handler)
 Description: Specify a function to execute when the DOM is fully
 loaded.
 handlerA function to execute after the DOM is ready.

 jQuery(document).ready(function($) {
   // Code using $ as usual goes here.
 });




                        www.exoplatform.com - Copyright 2012 eXo Platform   32
Event – load vs ready




               www.exoplatform.com - Copyright 2012 eXo Platform   33
Ajax

 .jQuery.ajax( url [, settings] )
 Description: Perform an asynchronous HTTP (Ajax) request.
 url A string containing the URL to which the request is sent.
 Settings A set of key/value pairs that configure the Ajax request. All settings are
 optional.

 $.ajax({
   type: "POST",
   url: "some.php",
   data: { name: "John", location: "Boston" }
 }).done(function( msg ) {
   alert( "Data Saved: " + msg );
 });




                         www.exoplatform.com - Copyright 2012 eXo Platform             34
Ajax

 .jQuery.ajaxSetup( options )
 Description: Set default values for future Ajax requests.
 options A set of key/value pairs that configure the default Ajax request. All options
 are optional.

 $.ajaxSetup({
   url: "/xmlhttp/",
   global: false,
   type: "POST"

  });
  $.ajax({ data: myData });




                         www.exoplatform.com - Copyright 2012 eXo Platform               35
Ajax

 .jQuery.get( url [, data] [, success(data, textStatus,
 jqXHR)] [, dataType] )
 Description: Load data from the server using a HTTP GET request.
 url A string containing the URL to which the request is sent.
 data A map or string that is sent to the server with the request.
 success(data, textStatus, jqXHR)A callback function that is executed if the request
 succeeds.

 dataTypeThe type of data expected from the server. Default: Intelligent Guess
 (xml, json, script, or html).

 $.get("test.cgi", { name: "John", time: "2pm" },
   function(data){
     alert("Data Loaded: " + data);
   });




                         www.exoplatform.com - Copyright 2012 eXo Platform             36
Ajax

 .jQuery.getJSON( url [, data] [, success(data, textStatus,
 jqXHR)] )
 Description: Load JSON-encoded data from the server using a GET
 HTTP request.
 <script>
 $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?
 jsoncallback=?",
   {
     tags: "cat",
     tagmode: "any",
     format: "json"
   },
   function(data) {
     $.each(data.items, function(i,item){
       $("<img/>").attr("src", item.media.m).appendTo("#images");
       if ( i == 3 ) return false;
     });
   });
 </script>




                        www.exoplatform.com - Copyright 2012 eXo Platform   37
Ajax

 .load( url [, data] [, complete(responseText, textStatus,
 XMLHttpRequest)] )
 Description: Load data from the server and place the returned HTML
 into the matched element

 urlA string containing the URL to which the request is sent.
 dataA map or string that is sent to the server with the request.
 complete(responseText, textStatus, XMLHttpRequest)A callback function that is
 executed when the request completes.

 <script>
 $("#success").load("/not-here.php", function(response, status, xhr) {
   if (status == "error") {
     var msg = "Sorry but there was an error: ";
     $("#error").html(msg + xhr.status + " " + xhr.statusText);
   }
 });
 </script>




                        www.exoplatform.com - Copyright 2012 eXo Platform        38
Q&A

Más contenido relacionado

La actualidad más candente

Organizing Code with JavascriptMVC
Organizing Code with JavascriptMVCOrganizing Code with JavascriptMVC
Organizing Code with JavascriptMVCThomas Reynolds
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETJames Johnson
 
Basic Tutorial of React for Programmers
Basic Tutorial of React for ProgrammersBasic Tutorial of React for Programmers
Basic Tutorial of React for ProgrammersDavid Rodenas
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery EssentialsMark Rackley
 
Arquitetando seu aplicativo Android com Jetpack
Arquitetando seu aplicativo Android com JetpackArquitetando seu aplicativo Android com Jetpack
Arquitetando seu aplicativo Android com JetpackNelson Glauber Leal
 
Intoduction on Playframework
Intoduction on PlayframeworkIntoduction on Playframework
Intoduction on PlayframeworkKnoldus Inc.
 
Node.js in action
Node.js in actionNode.js in action
Node.js in actionSimon Su
 
Mastering Oracle ADF Bindings
Mastering Oracle ADF BindingsMastering Oracle ADF Bindings
Mastering Oracle ADF BindingsEuegene Fedorenko
 
Web Components With Rails
Web Components With RailsWeb Components With Rails
Web Components With RailsBoris Nadion
 
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил АнохинFwdays
 
Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"Fwdays
 
Jquery dojo slides
Jquery dojo slidesJquery dojo slides
Jquery dojo slideshelenmga
 
HtmlElements – естественное расширение PageObject
HtmlElements – естественное расширение PageObjectHtmlElements – естественное расширение PageObject
HtmlElements – естественное расширение PageObjectSQALab
 
Drupal 8 entities & felds
Drupal 8 entities & feldsDrupal 8 entities & felds
Drupal 8 entities & feldsAndy Postnikov
 
Overlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MyOverlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MySteve McMahon
 
Intorduction of Playframework
Intorduction of PlayframeworkIntorduction of Playframework
Intorduction of Playframeworkmaltiyadav
 

La actualidad más candente (20)

Organizing Code with JavascriptMVC
Organizing Code with JavascriptMVCOrganizing Code with JavascriptMVC
Organizing Code with JavascriptMVC
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
 
The jQuery Library
The  jQuery LibraryThe  jQuery Library
The jQuery Library
 
Basic Tutorial of React for Programmers
Basic Tutorial of React for ProgrammersBasic Tutorial of React for Programmers
Basic Tutorial of React for Programmers
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery Essentials
 
Arquitetando seu aplicativo Android com Jetpack
Arquitetando seu aplicativo Android com JetpackArquitetando seu aplicativo Android com Jetpack
Arquitetando seu aplicativo Android com Jetpack
 
Intoduction on Playframework
Intoduction on PlayframeworkIntoduction on Playframework
Intoduction on Playframework
 
jQuery
jQueryjQuery
jQuery
 
Node.js in action
Node.js in actionNode.js in action
Node.js in action
 
Mastering Oracle ADF Bindings
Mastering Oracle ADF BindingsMastering Oracle ADF Bindings
Mastering Oracle ADF Bindings
 
Web Components With Rails
Web Components With RailsWeb Components With Rails
Web Components With Rails
 
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин
 
Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"Михаил Анохин "Data binding 2.0"
Михаил Анохин "Data binding 2.0"
 
Jquery dojo slides
Jquery dojo slidesJquery dojo slides
Jquery dojo slides
 
netbeans
netbeansnetbeans
netbeans
 
HtmlElements – естественное расширение PageObject
HtmlElements – естественное расширение PageObjectHtmlElements – естественное расширение PageObject
HtmlElements – естественное расширение PageObject
 
Drupal 8 entities & felds
Drupal 8 entities & feldsDrupal 8 entities & felds
Drupal 8 entities & felds
 
Overlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh MyOverlays, Accordions & Tabs, Oh My
Overlays, Accordions & Tabs, Oh My
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Intorduction of Playframework
Intorduction of PlayframeworkIntorduction of Playframework
Intorduction of Playframework
 

Destacado

Destacado (7)

Advance jquery-plugin
Advance jquery-pluginAdvance jquery-plugin
Advance jquery-plugin
 
Wg11 automaive
Wg11 automaiveWg11 automaive
Wg11 automaive
 
E xo mobile_overview_best_practice_in_mobile_application_design
E xo mobile_overview_best_practice_in_mobile_application_designE xo mobile_overview_best_practice_in_mobile_application_design
E xo mobile_overview_best_practice_in_mobile_application_design
 
I os
I osI os
I os
 
Hadoop
HadoopHadoop
Hadoop
 
Magento
MagentoMagento
Magento
 
Memory and runtime analysis
Memory and runtime analysisMemory and runtime analysis
Memory and runtime analysis
 

Similar a Jquery

Starting with jQuery
Starting with jQueryStarting with jQuery
Starting with jQueryAnil Kumar
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Libraryrsnarayanan
 
jQuery Tips Tricks Trivia
jQuery Tips Tricks TriviajQuery Tips Tricks Trivia
jQuery Tips Tricks TriviaCognizant
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginnersDivakar Gu
 
J Query(04 12 2008) Foiaz
J Query(04 12 2008) FoiazJ Query(04 12 2008) Foiaz
J Query(04 12 2008) Foiaztestingphase
 
Web Development Introduction to jQuery
Web Development Introduction to jQueryWeb Development Introduction to jQuery
Web Development Introduction to jQueryLaurence Svekis ✔
 
jQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesjQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesMark Roden
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQueryRemy Sharp
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAERon Reiter
 
A to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java DeveloperA to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java DeveloperManoj Bhuva
 

Similar a Jquery (20)

Starting with jQuery
Starting with jQueryStarting with jQuery
Starting with jQuery
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Jquery beltranhomewrok
Jquery beltranhomewrokJquery beltranhomewrok
Jquery beltranhomewrok
 
Jquery beltranhomewrok
Jquery beltranhomewrokJquery beltranhomewrok
Jquery beltranhomewrok
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
 
jQuery Tips Tricks Trivia
jQuery Tips Tricks TriviajQuery Tips Tricks Trivia
jQuery Tips Tricks Trivia
 
jQuery Basic API
jQuery Basic APIjQuery Basic API
jQuery Basic API
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
J Query(04 12 2008) Foiaz
J Query(04 12 2008) FoiazJ Query(04 12 2008) Foiaz
J Query(04 12 2008) Foiaz
 
netbeans
netbeansnetbeans
netbeans
 
jQuery
jQueryjQuery
jQuery
 
Web Development Introduction to jQuery
Web Development Introduction to jQueryWeb Development Introduction to jQuery
Web Development Introduction to jQuery
 
jQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPagesjQuery - the world's most popular java script library comes to XPages
jQuery - the world's most popular java script library comes to XPages
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
jQuery for web development
jQuery for web developmentjQuery for web development
jQuery for web development
 
J query
J queryJ query
J query
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAE
 
A to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java DeveloperA to Z about JQuery - Become Newbie to Expert Java Developer
A to Z about JQuery - Become Newbie to Expert Java Developer
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 

Más de adm_exoplatform

Más de adm_exoplatform (8)

Development withforce
Development withforceDevelopment withforce
Development withforce
 
Jquery ui
Jquery uiJquery ui
Jquery ui
 
Cmsms
CmsmsCmsms
Cmsms
 
Java application server in the cloud
Java application server in the cloudJava application server in the cloud
Java application server in the cloud
 
Jvm mbeans jmxtran
Jvm mbeans jmxtranJvm mbeans jmxtran
Jvm mbeans jmxtran
 
Git training
Git trainingGit training
Git training
 
Cluster mode and plf cluster
Cluster mode and plf clusterCluster mode and plf cluster
Cluster mode and plf cluster
 
Cluster mode and plf cluster
Cluster mode and plf clusterCluster mode and plf cluster
Cluster mode and plf cluster
 

Último

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Jquery

  • 1. jQuery Lê Văn Viễn Social 17/05/2012
  • 2. Agenda 1 Introduce 2 Compare with other libraries js 3 APIs 4 Q&A www.exoplatform.com - Copyright 2012 eXo Platform 2
  • 4. Introduce 1. What is jQuery? 2. Why use jQuery? 3. History of jQuery? 4. How to use jQuery? 5. Document and source code www.exoplatform.com - Copyright 2012 eXo Platform 4
  • 5. What is jQuery jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. www.exoplatform.com - Copyright 2012 eXo Platform 5
  • 6. Why use jQuery Lightweight: 1.7.2 minified 32KB, development 247 KB CSS3 compliant: support css 1 - 3 Cross brower: IE6.0+, FF 3.6+, Safari 5.0+, Opera, Chrome www.exoplatform.com - Copyright 2012 eXo Platform 6
  • 7. History of jQuery Ausgt 22nd, 2005: John Resig first hints of a javascript libraty to use css selector with more succint syntax than existing libraries 2006: Release jQuery 1.0 and planning for jQuery 1.1 2007: Release 1.2 2008: Release jQuery UI 1.5 2009: Release jQuery UI 1.7 and jQuery 1.3 2010: Release jQuery 1.4 www.exoplatform.com - Copyright 2012 eXo Platform 7
  • 8. How to use jQuery <script src="jquery.js"></script> <script> $(document).ready(function(){ // Your code here }); </script> www.exoplatform.com - Copyright 2012 eXo Platform 8
  • 9. Document and source code http://docs.jquery.com/Main_Page https://github.com/jquery/ www.exoplatform.com - Copyright 2012 eXo Platform 9
  • 10. Compare with other libraries js
  • 11. Background – Developer survey www.exoplatform.com - Copyright 2012 eXo Platform 11
  • 12. Background jQuery, prototype, mootools, dojo, YUI jQuery prototype dojo mootools YUI www.exoplatform.com - Copyright 2012 eXo Platform 12
  • 13. Compare with other js libraries User slickspeed to test performance (selector) http:// mootools.net/slickspeed/ www.exoplatform.com - Copyright 2012 eXo Platform 13
  • 14. Compare with other js libraries www.exoplatform.com - Copyright 2012 eXo Platform 14
  • 15. Compare with other js libraries www.exoplatform.com - Copyright 2012 eXo Platform 15
  • 16. APIs
  • 17. APIs 1.DOM 2.Event 3.Ajax 4.Animation 5.Plugin www.exoplatform.com - Copyright 2012 eXo Platform 17
  • 18. jQuery() Description: Accepts a string containing a CSS selector which is then used to match a set of elements. jQuery( selector [ , context ] ) jQuery( element ) jQuery( object ) jQuery( elementArray ) jQuery( jQuery object ) jQuery() jQuery( html [ , ownerDocument ] ) jQuery( html [, ownerDocument] ) www.exoplatform.com - Copyright 2012 eXo Platform 18
  • 19. jQuery() jQuery( selector [ , context ] ) selector A string containing a selector expression context A DOM element, Document, or jQuery to use context Ex: $('div.foo'); Search through the DOM element for any elements that match the provided selector and creates a new jquery object references these elements jQuery( element ) element A Dom element to wrap in a jquery object Ex: $('div.foo').click(function() { $('span', this).addClass('bar'); }); jQuery( jQuery object ) object An existing jquery object to clone Clone the object is passed, new jQuery object references the same DOM elements as the initial one jQuery() return an empty jQuery set as 1.4, in previous version return a set containing the document node www.exoplatform.com - Copyright 2012 eXo Platform 19
  • 20. jQuery() jQuery( html [ , ownerDocument ] ) Description: Creates DOM elements on the fily from provided string of raw HTML html A string of HTML to create on the fly, parses the html, not xml. ownerDocument A document in which the new elements will be created Ex: $('<p id="test">My <em>new</em> text</p>').appendTo('body'); jQuery(callback) Description: Binds a function to be executed when the DOM has finished loading. Callback the function to execute when the DOM is ready Ex: jQuery(function($) { // Your code using failsafe $ alias here... }); www.exoplatform.com - Copyright 2012 eXo Platform 20
  • 21. Jquery.noConflict() Description: Relingquish jQuery's control of the $ variable jQuery.noConflict( [removeAll] ) RemoveAll A Boolean indicating whether to remove all jQuery variables from the global scope (including jQuery itself) www.exoplatform.com - Copyright 2012 eXo Platform 21
  • 22. Jquery.noConflict() - How to work with other libraries js 1. Overriding the $ function <script src="prototype.js"></script> <script src="jquery.js"></script> <script> jQuery.noConflict(); // Use jQuery via jQuery(...) jQuery(document).ready(function(){ jQuery("div").hide(); }); // Use Prototype with $(...), etc. $('someid').hide(); </script> <script src="prototype.js"></script> <script src="jquery.js"></script> <script> var $j = jQuery.noConflict(); // Use jQuery via $j(...) $j(document).ready(function(){ $j("div").hide(); }); // Use Prototype with $(...), etc. $('someid').hide(); </script> www.exoplatform.com - Copyright 2012 eXo Platform 22
  • 23. Jquery.noConflict() - How to work with other libraries js <script src="prototype.js"></script> <script src="jquery.js"></script> <script> jQuery.noConflict(); // Put all your code in your document ready area jQuery(document).ready(function($){ // Do jQuery stuff using $ $("div").hide(); }); // Use Prototype with $(...), etc. $('someid').hide(); </script> 2. Including jquery before other libraries <script src="jquery.js"></script> <script src="prototype.js"></script> <script> // Use jQuery via jQuery(...) jQuery(document).ready(function(){ jQuery("div").hide(); }); // Use Prototype with $(...), etc. $('someid').hide(); </script> www.exoplatform.com - Copyright 2012 eXo Platform 23
  • 24. Jquery.noConflict() - How to work with multiple version jquery <script type='text/javascript' src='js/jquery_1.3.js'></script> <script type='text/javascript'> var $jq_1.3 = jQuery.noConflict(); </script> <script type='text/javascript' src='js/jquery_1.2.js'></script> www.exoplatform.com - Copyright 2012 eXo Platform 24
  • 25. Selector Compliant CSS 1-3 Child selector (“parent > child”) Class selector (“.class”) ID selector (“#id”) All selector (“*”) :button selector :checkbox selector :checked selector :contains() selector :disable selector :enable selector :empty selector :file selector :first selector :has() selector :hidden selector :image selector :parent selector :reset selector :submit selector :text selector …... www.exoplatform.com - Copyright 2012 eXo Platform 25
  • 26. Event – Event handler attach .bind(eventType [, eventData], handler(eventObject)) Description: Attach a handler to an event for the elements .bind(eventType [,eventData], handler(eventObject)) eventType A string contain one or more DOM event types eventData A map of data that will be passed to the event handler handler(eventObject) function to execute each time the event is triggered .bind(eventType [, eventData], preventBuble) preventBuble false will attach a function that prevents the default action from occurring and stop the event from bubbling. The default is true. .bind(event) events A map of one or more DOM event types and functions to execute them $("form").bind("submit", function(event) { event.stopPropagation(); }); $("form").bind("submit", function(event) { event.preventDefault(); }); $("form").bind("submit", function() { return false; }) www.exoplatform.com - Copyright 2012 eXo Platform 26
  • 27. Event – Event handler attach .live(event, handler(eventObject)) Description: Attach an event handler for all elements which match the current selector, now and the future. .live(event, data, handler(eventObject)) .live(events-map) events-map A map of one or more js event types and functions to execute for them <script> $("p").live({ click: function() { $(this).after("<p>Another paragraph!</p>"); }, mouseover: function() { $(this).addClass("over"); }, mouseout: function() { $(this).removeClass("over"); } }); </script> www.exoplatform.com - Copyright 2012 eXo Platform 27
  • 28. Event – Event handler attach .delegate( selector, eventType, handler(eventObject) ) Description: Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements. .delegate( selector, eventType, handler(eventObject) ) selectorA selector to filter the elements that trigger the event. .delegate( selector, eventType, eventData, handler(eventObject) ) .delegate( selector, events ) www.exoplatform.com - Copyright 2012 eXo Platform 28
  • 29. Event – Event handler attach .on( events [, selector] [, data] , handler(eventObject) ) Description: Attach an event handler function for one or more events to the selected elements. .on( events [, selector] [, data], handler(eventObject) ) selectorA selector to filter the elements that trigger the event. .on( events-map [, selector] [, data] ) $("#dataTable tbody tr").on("click", function(event){ alert($(this).text()); }); www.exoplatform.com - Copyright 2012 eXo Platform 29
  • 30. Event – bind vs live vs delegate vs on? www.exoplatform.com - Copyright 2012 eXo Platform 30
  • 31. Event – Document loading .load( handler(eventObject) ) Description: Bind an event handler to the "load" JavaScript event. .load( handler(eventObject) ) handler(eventObject)A function to execute when the event is triggered. .load( [eventData], handler(eventObject) ) $(window).load(function () { // run code }); www.exoplatform.com - Copyright 2012 eXo Platform 31
  • 32. Event – Document loading .ready( handler) Description: Specify a function to execute when the DOM is fully loaded. handlerA function to execute after the DOM is ready. jQuery(document).ready(function($) { // Code using $ as usual goes here. }); www.exoplatform.com - Copyright 2012 eXo Platform 32
  • 33. Event – load vs ready www.exoplatform.com - Copyright 2012 eXo Platform 33
  • 34. Ajax .jQuery.ajax( url [, settings] ) Description: Perform an asynchronous HTTP (Ajax) request. url A string containing the URL to which the request is sent. Settings A set of key/value pairs that configure the Ajax request. All settings are optional. $.ajax({ type: "POST", url: "some.php", data: { name: "John", location: "Boston" } }).done(function( msg ) { alert( "Data Saved: " + msg ); }); www.exoplatform.com - Copyright 2012 eXo Platform 34
  • 35. Ajax .jQuery.ajaxSetup( options ) Description: Set default values for future Ajax requests. options A set of key/value pairs that configure the default Ajax request. All options are optional. $.ajaxSetup({ url: "/xmlhttp/", global: false, type: "POST" }); $.ajax({ data: myData }); www.exoplatform.com - Copyright 2012 eXo Platform 35
  • 36. Ajax .jQuery.get( url [, data] [, success(data, textStatus, jqXHR)] [, dataType] ) Description: Load data from the server using a HTTP GET request. url A string containing the URL to which the request is sent. data A map or string that is sent to the server with the request. success(data, textStatus, jqXHR)A callback function that is executed if the request succeeds. dataTypeThe type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html). $.get("test.cgi", { name: "John", time: "2pm" }, function(data){ alert("Data Loaded: " + data); }); www.exoplatform.com - Copyright 2012 eXo Platform 36
  • 37. Ajax .jQuery.getJSON( url [, data] [, success(data, textStatus, jqXHR)] ) Description: Load JSON-encoded data from the server using a GET HTTP request. <script> $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne? jsoncallback=?", { tags: "cat", tagmode: "any", format: "json" }, function(data) { $.each(data.items, function(i,item){ $("<img/>").attr("src", item.media.m).appendTo("#images"); if ( i == 3 ) return false; }); }); </script> www.exoplatform.com - Copyright 2012 eXo Platform 37
  • 38. Ajax .load( url [, data] [, complete(responseText, textStatus, XMLHttpRequest)] ) Description: Load data from the server and place the returned HTML into the matched element urlA string containing the URL to which the request is sent. dataA map or string that is sent to the server with the request. complete(responseText, textStatus, XMLHttpRequest)A callback function that is executed when the request completes. <script> $("#success").load("/not-here.php", function(response, status, xhr) { if (status == "error") { var msg = "Sorry but there was an error: "; $("#error").html(msg + xhr.status + " " + xhr.statusText); } }); </script> www.exoplatform.com - Copyright 2012 eXo Platform 38
  • 39. Q&A

Notas del editor

  1. This year we expanded on that, asking more and better questions to give you better and more accurate information. The survey itself ( found here ) provided data from over 1000+ Java EE developers and those responses were analyzed to create this report. We set out to discover: We asked the people we met at JavaOne 2010, emailed previous survey respondents and promoted the survey in the media. They were sent an email with the link to the survey and told they would be notified again once the results were made available. Participants were offered a chance to win free JRebel licenses and one recipient will receive an iPad once the final results are published.
  2. This year we expanded on that, asking more and better questions to give you better and more accurate information. The survey itself ( found here ) provided data from over 1000+ Java EE developers and those responses were analyzed to create this report. We set out to discover: We asked the people we met at JavaOne 2010, emailed previous survey respondents and promoted the survey in the media. They were sent an email with the link to the survey and told they would be notified again once the results were made available. Participants were offered a chance to win free JRebel licenses and one recipient will receive an iPad once the final results are published.