SlideShare une entreprise Scribd logo
1  sur  19
Willian Fernandes
willianfernandes.com.br
   twitter.com/willian
Use Dólar e seja feliz!


               $('#element-id')
               $('.element-class-name')
               $('tag-name')
               $('any css/xpath syntax')




  Willian Fernandes | willianfernandes.com.br | twitter.com/willian
Escreva menos
Adicione uma classe em mais de um elemento ao mesmo tempo



          // Prototype
          $$('.element').each(function(node) {
              Element.addClassName(node, 'className');
          });




               // jQuery
               $('.element').addClass('className');




           Willian Fernandes | willianfernandes.com.br | twitter.com/willian
Escreva menos
                   Criar uma lista zebrada:
                             row1    row1     row1

                             row2    row2     row2

                             row3    row3     row3

                             row4    row4     row4

                             row5    row5     row5


// Prototype
$$("table").each(function(table){
    Selector.findChildElements(table, ["tr"])
        .findAll(function(row,i){ return i % 2 == 1; })
        .invoke("addClassName", "odd");
});

   // jQuery
   $("table tr:nth-child(odd)").addClass("odd");


        Willian Fernandes | willianfernandes.com.br | twitter.com/willian
Trabalhando com
     seletores

// Prototype
$('entries').select('div.entry').invoke('hide');



            // jQuery
            $('#entries div.entry').hide();




   Willian Fernandes | willianfernandes.com.br | twitter.com/willian
Documento carregado?

 // Prototype
 document.observe('contentloaded', function() {});



                       // jQuery
                       $(function() {});




    Willian Fernandes | willianfernandes.com.br | twitter.com/willian
Iteração de Arrays

// Prototype
[el1, el2].each(function(el, i) { alert(el); });



// jQuery
$([el1, el2]).each(function(i) { alert(this); });




   Willian Fernandes | willianfernandes.com.br | twitter.com/willian
Adicionando elementos
$('ul').html('<li><a href="/contact">Contato</a></li>');

$('ul').append('<li><a href="/logout">Sair</a></li>');

$('ul').prepend('<li><a href="/">Home</a></li>');

$('ul').before('<h1><a href="/">Home</a></h1>');

$('ul').after('<p>Willian Fernandes</p>');




       Willian Fernandes | willianfernandes.com.br | twitter.com/willian
Manipulando classes

         if ($('ul').is('menu')) {
             $('ul').removeClass('menu');
         } else {
             $('ul').addClass('menu');
         }

         // ou simplesmente

         $('ul').toggleClass('menu');




  Willian Fernandes | willianfernandes.com.br | twitter.com/willian
Efeitos nativos
$('selector').animate({param1: value1, param2: value2}, speed);
$('selector').fadeIn('slow/400/fast'[, function() {}]);
$('selector').fadeOut('slow/400/fast'[, function() {}]);
$('selector').fadeTo('slow/400/fast', 0.5[, function() {}]);
$('selector').hide('slow/400/fast'[, function() {}]);
$('selector').show('slow/400/fast'[, function() {}]);
$('selector').slideDown('slow/400/fast'[, function() {}]);
$('selector').slideUp('slow/400/fast'[, function() {}]);
$('selector').slideToggle('slow/400/fast');
$('selector').toggle('slow/400/fast');




          Willian Fernandes | willianfernandes.com.br | twitter.com/willian
AJAX
$.ajax({
    url: "mydomain.com/url",
    type: "POST",
    dataType: "xml/html/script/json",
    data: $.param( $("Element or Expression") ),
    complete: function() {
         //called when complete
    },
    success: function() {
         //called when successful
    },
    error: function() {
         //called when there is an error
    }
});




   Willian Fernandes | willianfernandes.com.br | twitter.com/willian
AJAX

$.post(
    '/path/to/file.cgi',
    { param1: "value1", param2: "value2" },
    function() {
        //stuff to do *after* page is loaded;
    }
);




 Willian Fernandes | willianfernandes.com.br | twitter.com/willian
AJAX

$.get(
    '/test/ajax-test.xml',
    function(xml) {
        alert(("title",xml).text()); //optional stuff to do after get;
    }
);




              Willian Fernandes | willianfernandes.com.br | twitter.com/willian
AJAX

$.getJSON(
    '/path/to/file.cgi',
    { param1: "value1", param2: "value2" },
    function(json) {
        //stuff to do after event occurs;
    }
);




Willian Fernandes | willianfernandes.com.br | twitter.com/willian
AJAX

$('selector').load(
    '/path/to/file.htm',
    { param1: "value1", param2: "value2" },
    function(){
        // Stuff to do after the page is loaded
    }
);




  Willian Fernandes | willianfernandes.com.br | twitter.com/willian
Criando Plugins
(function($){
    // disable submit buttons after they were clicked
    $.disableSubmit = function(text) {
        $(':submit, input.submit')
            .not('.skip')
            .each(function() {
                if (this.title) {
                    this.value = this.title;
                    $(this).removeAttr('title');
                }
            })
            .click(function() {
                $(':submit, input.submit').each(function() {
                    this.disabled = true;
                    this.value = text || "Please wait...";
                });
                this.form.submit();
            });
    };
})(jQuery);

       Willian Fernandes | willianfernandes.com.br | twitter.com/willian
Rails



                    Iniciar Teste




Willian Fernandes | willianfernandes.com.br | twitter.com/willian
Dúvidas?



Willian Fernandes | willianfernandes.com.br | twitter.com/willian
Obrigado!



Willian Fernandes | willianfernandes.com.br | twitter.com/willian

Contenu connexe

En vedette

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

jQuery

  • 2. Use Dólar e seja feliz! $('#element-id') $('.element-class-name') $('tag-name') $('any css/xpath syntax') Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 3. Escreva menos Adicione uma classe em mais de um elemento ao mesmo tempo // Prototype $$('.element').each(function(node) { Element.addClassName(node, 'className'); }); // jQuery $('.element').addClass('className'); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 4. Escreva menos Criar uma lista zebrada: row1 row1 row1 row2 row2 row2 row3 row3 row3 row4 row4 row4 row5 row5 row5 // Prototype $$("table").each(function(table){ Selector.findChildElements(table, ["tr"]) .findAll(function(row,i){ return i % 2 == 1; }) .invoke("addClassName", "odd"); }); // jQuery $("table tr:nth-child(odd)").addClass("odd"); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 5. Trabalhando com seletores // Prototype $('entries').select('div.entry').invoke('hide'); // jQuery $('#entries div.entry').hide(); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 6. Documento carregado? // Prototype document.observe('contentloaded', function() {}); // jQuery $(function() {}); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 7. Iteração de Arrays // Prototype [el1, el2].each(function(el, i) { alert(el); }); // jQuery $([el1, el2]).each(function(i) { alert(this); }); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 8. Adicionando elementos $('ul').html('<li><a href="/contact">Contato</a></li>'); $('ul').append('<li><a href="/logout">Sair</a></li>'); $('ul').prepend('<li><a href="/">Home</a></li>'); $('ul').before('<h1><a href="/">Home</a></h1>'); $('ul').after('<p>Willian Fernandes</p>'); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 9. Manipulando classes if ($('ul').is('menu')) { $('ul').removeClass('menu'); } else { $('ul').addClass('menu'); } // ou simplesmente $('ul').toggleClass('menu'); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 10. Efeitos nativos $('selector').animate({param1: value1, param2: value2}, speed); $('selector').fadeIn('slow/400/fast'[, function() {}]); $('selector').fadeOut('slow/400/fast'[, function() {}]); $('selector').fadeTo('slow/400/fast', 0.5[, function() {}]); $('selector').hide('slow/400/fast'[, function() {}]); $('selector').show('slow/400/fast'[, function() {}]); $('selector').slideDown('slow/400/fast'[, function() {}]); $('selector').slideUp('slow/400/fast'[, function() {}]); $('selector').slideToggle('slow/400/fast'); $('selector').toggle('slow/400/fast'); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 11. AJAX $.ajax({ url: "mydomain.com/url", type: "POST", dataType: "xml/html/script/json", data: $.param( $("Element or Expression") ), complete: function() { //called when complete }, success: function() { //called when successful }, error: function() { //called when there is an error } }); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 12. AJAX $.post( '/path/to/file.cgi', { param1: "value1", param2: "value2" }, function() { //stuff to do *after* page is loaded; } ); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 13. AJAX $.get( '/test/ajax-test.xml', function(xml) { alert(("title",xml).text()); //optional stuff to do after get; } ); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 14. AJAX $.getJSON( '/path/to/file.cgi', { param1: "value1", param2: "value2" }, function(json) { //stuff to do after event occurs; } ); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 15. AJAX $('selector').load( '/path/to/file.htm', { param1: "value1", param2: "value2" }, function(){ // Stuff to do after the page is loaded } ); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 16. Criando Plugins (function($){ // disable submit buttons after they were clicked $.disableSubmit = function(text) { $(':submit, input.submit') .not('.skip') .each(function() { if (this.title) { this.value = this.title; $(this).removeAttr('title'); } }) .click(function() { $(':submit, input.submit').each(function() { this.disabled = true; this.value = text || "Please wait..."; }); this.form.submit(); }); }; })(jQuery); Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 17. Rails Iniciar Teste Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 18. Dúvidas? Willian Fernandes | willianfernandes.com.br | twitter.com/willian
  • 19. Obrigado! Willian Fernandes | willianfernandes.com.br | twitter.com/willian

Notes de l'éditeur