SlideShare uma empresa Scribd logo
1 de 48
Baixar para ler offline
Wednesday, 28 April 2010   1
What are we talking about




Wednesday, 28 April 2010              2
What are we talking about
                           client side scripting implemented as part of a
                           browser to provide:




Wednesday, 28 April 2010                                                    2
What are we talking about
                           client side scripting implemented as part of a
                           browser to provide:

                             enhanced UI




Wednesday, 28 April 2010                                                    2
What are we talking about
                           client side scripting implemented as part of a
                           browser to provide:

                             enhanced UI

                             dynamic websites




Wednesday, 28 April 2010                                                    2
Why should I care?
                           “JavaScript sucks”




Wednesday, 28 April 2010                         3
Why should I care?
                           “JavaScript sucks”
                             it’s different - prototypal inheritance




Wednesday, 28 April 2010                                               3
Why should I care?
                           “JavaScript sucks”
                             it’s different - prototypal inheritance


                           DOM is key BUT “sucks”




Wednesday, 28 April 2010                                               3
Why should I care?
                           “JavaScript sucks”
                             it’s different - prototypal inheritance


                           DOM is key BUT “sucks”
                             Element selection sucks




Wednesday, 28 April 2010                                               3
Why should I care?
                           “JavaScript sucks”
                             it’s different - prototypal inheritance


                           DOM is key BUT “sucks”
                             Element selection sucks

                             x-Browser DOM sucks




Wednesday, 28 April 2010                                               3
Demo




Wednesday, 28 April 2010                                                           4

DOM selection and Cross Browser DOM selection code demo
var   objById = getElementById('id');
var   objById = $('#id');
var   firstParagraph = getElementByTagName('p')[0];
var   firstParagraph = $('p:first');

/////////// example cross browser functions ////

/*********************************************************************
    * Get an object, this function is cross browser
    * Usage:
    * var object = get_object(element_id);
    * @Author Hamid Alipour http://blog.code-head.com/
  **/
  function get_object(id) {
    var object = null;
    if (document.layers) { // Mozilla 4.0 based browsers
      object = document.layers[id];
    } else if (document.all) { // IE6
      object = document.all[id];
    } else if (document.getElementById) { // Modern browsers
      object = document.getElementById(id);
    }
    return object;
  }
  /*********************************************************************/


var obj = get_object('id');

// jquery

var obj = $('#id');
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.
                           jQuery is designed to change the way that
                           you write JavaScript." http://jquery.com

                           “Write less, do more”



Wednesday, 28 April 2010                                                  5
What is jQuery?




Wednesday, 28 April 2010                     6
What is jQuery?

                           A fast concise library with an OO interface




Wednesday, 28 April 2010                                                 6
What is jQuery?

                           A fast concise library with an OO interface

                           Features
                             Lightweight

                             Cross-browser

                             CSS3 Compliant




Wednesday, 28 April 2010                                                 6
CSS3 Compliant???




Wednesday, 28 April 2010                       7
CSS3 Compliant???
                           We really mean “selectors” as in DOM
                           selection




Wednesday, 28 April 2010                                          7
CSS3 Compliant???
                           We really mean “selectors” as in DOM
                           selection

                           Starts with CSS2




Wednesday, 28 April 2010                                          7
CSS3 Compliant???
                           We really mean “selectors” as in DOM
                           selection

                           Starts with CSS2

                           Id, Class, Type, Universal, Grouping,
                           Descendant, Child, Adjacent Sibling,
                           Attribute, etc.




Wednesday, 28 April 2010                                           7
CSS Selector
                                                                    Demo
                                         Id, Class, Type, Universal, Grouping, Descendant,
                                         Child, Adjacent Sibling, Attribute, etc.




Wednesday, 28 April 2010                                                                                                                             8

CSS Selector Demo with CSS code
From to http://www.w3.org/TR/CSS2/selector.html

Id

#idvalue {
font-family: sans-serif;
}

Class

.classname {
font-family: Sans-Serif;
}

.classone.classtwo {
font-family: Sans-Serif;
}

Grouping

h1 { font-family: sans-serif }
h2 { font-family: sans-serif }
h3 { font-family: sans-serif }

is equivalent to:

h1, h2, h3 { font-family: sans-serif }

Descendant

For example, consider the following rules:

h1 { color: red }
em { color: red }

Although the intention of these rules is to add emphasis to text by changing its color, the effect will be lost in a case such as:

<H1>This headline is <EM>very</EM> important</H1>
We address this case by supplementing the previous rules with a rule that sets the text color to blue whenever an EM occurs anywhere within an H1:

h1 { color: red }
em { color: red }
h1 em { color: blue }

The third rule will match the EM in the following fragment:

<H1>This <SPAN class="myclass">headline
is <EM>very</EM> important</SPAN></H1>


Child

The following rule sets the style of all P elements that are children of BODY:

body > P { line-height: 1.3 }
CSS3 Compliant???
                           We really mean “selectors” as in DOM
                           selection

                           Start with CSS2

                           More at
                             http://api.jquery.com/category/selectors/

                             http://www.w3.org/TR/CSS2/selector.html

                             http://www.w3.org/TR/css3-selectors/

                             http://www.456bereastreet.com/archive/200601/css_3_selectors_explained/

                             http://www.w3schools.com/css/css_examples.asp


Wednesday, 28 April 2010                                                                               9
jQuery Core Concepts
                           $()

                           Get then Act

                           Chainability

                       $("p.neat").addClass("ohmy").show("slow");




Wednesday, 28 April 2010                                            10

KS take over here
$() = jQuery()
                           $ is a jquery object.

                           $ is used to keep the code shorter,
                           javascript is downloaded

                           $(selector) is how you get an element as a
                           jQuery object.




Wednesday, 28 April 2010                                                11
Chainability
                           Get then Act

                           Chainability

                             jQuery has chainablity of commends you
                             can link one commend to an other

          $("p.neat").addClass("ohmy").show("slow");

          $('#boo').filter(':funny').addClass('funny').css('color',
          'red').show();




Wednesday, 28 April 2010                                              12
Hello world
                                                     Demo




Wednesday, 28 April 2010                                                                  13

jQuery DOM selection (get) then act (PS do)
http://jquery.com - show this demo do a couple different things

ask what is the code going to do, discuss and run, then ask for do something different?
BrightTALK Conventions




Wednesday, 28 April 2010                    14

Check time
BrightTALK Conventions
                           $.bt




Wednesday, 28 April 2010                    14

Check time
BrightTALK Conventions
                           $.bt

                           filenames




Wednesday, 28 April 2010                    14

Check time
BrightTALK Conventions
                           $.bt

                           filenames

                             bt.XXX.js




Wednesday, 28 April 2010                    14

Check time
BrightTALK Conventions
                           $.bt

                           filenames

                             bt.XXX.js

                             jquery.XXX.js




Wednesday, 28 April 2010                     14

Check time
BrightTALK Conventions
                           $.bt

                           filenames

                             bt.XXX.js

                             jquery.XXX.js

                           custom events




Wednesday, 28 April 2010                     14

Check time
BrightTALK Conventions
                           $.bt

                           filenames

                             bt.XXX.js

                             jquery.XXX.js

                           custom events

                           plugins


Wednesday, 28 April 2010                     14

Check time
BrightTALK Conventions
                           $.bt              Reasons

                           filenames

                             bt.XXX.js

                             jquery.XXX.js

                           custom events

                           plugins


Wednesday, 28 April 2010                               14

Check time
BrightTALK Conventions
                           $.bt              Reasons

                           filenames           reusable

                             bt.XXX.js

                             jquery.XXX.js

                           custom events

                           plugins


Wednesday, 28 April 2010                                 14

Check time
BrightTALK Conventions
                           $.bt              Reasons

                           filenames           reusable

                             bt.XXX.js        maintable

                             jquery.XXX.js

                           custom events

                           plugins


Wednesday, 28 April 2010                                  14

Check time
$.bt




Wednesday, 28 April 2010          15

PS take over
$.bt
                     namespace - globals are evil




Wednesday, 28 April 2010                            15

PS take over
$.bt
                     namespace - globals are evil

                     static functions




Wednesday, 28 April 2010                            15

PS take over
$.bt
                     namespace - globals are evil

                     static functions

                     public / private conventions




Wednesday, 28 April 2010                            15

PS take over
$.bt
                     namespace - globals are evil

                     static functions

                     public / private conventions

                           $.bt.publicFunction




Wednesday, 28 April 2010                            15

PS take over
$.bt
                     namespace - globals are evil

                     static functions

                     public / private conventions

                           $.bt.publicFunction

                           $.bt._privateFunction




Wednesday, 28 April 2010                            15

PS take over
$.bt
                     namespace - globals are evil

                     static functions

                     public / private conventions

                           $.bt.publicFunction

                           $.bt._privateFunction

                     common way to extend bt object


Wednesday, 28 April 2010                              15

PS take over
$.bt
                                                   Demo




Wednesday, 28 April 2010                                  16
extension demo (PS)
examples -
discuss good and bad

good - doesn’t pollute global name space
bad
 - still global static functions just namespaced
 - leads to tight coupling

early prototype jquery.btuser
better example bt.operations.js
.bind() & custom events

                           The .bind() method is the primary means of
                           attaching behavior to a document. All
                           JavaScript event types, such as focus,
                           mouseover, and resize, are allowed for
                           eventType.

                           With the help of .bind we can create our
                           custom events.



Wednesday, 28 April 2010                                                17

KS take over
Creating custom event

                           Creating custom event.
            $(document).bind('foo', function() {

                 alert('hello world');

            })


                     Calling custom event

            $(document).trigger("foo");




Wednesday, 28 April 2010                            18
Custom Event
                                                         Demo



Wednesday, 28 April 2010                                                            19
Custom event - login handler vs registration, date time locale conversion (KS DO)

$(document).bind("myCustomEvent", function(e, myName, myValue){
      $(this).text(myName + ", hi there!");
      $("span").stop().css("opacity", 1)
               .text("myName = " + myName)
               .fadeIn(30).fadeOut(1000);
    });
 $("button").click(function () {
    $(document).trigger("myCustomEvent", [ "John" ]);
  });

/// BRIGHTTALK
 $(document).bind('localiseDate', function(e) {
   $.btTimeZone.updateDateItem(0, e.target);
 });

 $('#csv-report-date', $('#report-XXX')).trigger("localiseDate", jQuery(this));
jQuery plugins
                           Learn how to write plugins

                             http://docs.jquery.com/Plugins/Authoring

                           Find plugins at

                             http://plugins.jquery.com/

                           Custom plugins on the platform

                             csvreport

                           Benefits vs static functions


Wednesday, 28 April 2010                                                20
Plugin
                                            Demo



Wednesday, 28 April 2010                             21
Check time (prob not time for this)

Walkthrough

CSVreport or jquery docs authoring page??

Mais conteúdo relacionado

Semelhante a Jquery Introduction

Browser Extensions in Mozilla Firefox & Google Chrome
Browser Extensions in Mozilla Firefox & Google ChromeBrowser Extensions in Mozilla Firefox & Google Chrome
Browser Extensions in Mozilla Firefox & Google ChromeKenneth Auchenberg
 
Nick Sieger-Exploring Rails 3 Through Choices
Nick Sieger-Exploring Rails 3 Through Choices Nick Sieger-Exploring Rails 3 Through Choices
Nick Sieger-Exploring Rails 3 Through Choices ThoughtWorks
 
Mobile, Media & Touch
Mobile, Media & TouchMobile, Media & Touch
Mobile, Media & TouchTim Wright
 
jQuery Learning
jQuery LearningjQuery Learning
jQuery LearningUzair Ali
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5Adrian Olaru
 
Campus Party 2010
Campus Party 2010Campus Party 2010
Campus Party 2010Fabio Akita
 
WordPress Front End Optimizations
WordPress Front End OptimizationsWordPress Front End Optimizations
WordPress Front End OptimizationsScott Taylor
 
Passing a Front end Developer interview
Passing a Front end Developer interview Passing a Front end Developer interview
Passing a Front end Developer interview tonyfarnsworth
 
The Tech Side of Project Argo
The Tech Side of Project ArgoThe Tech Side of Project Argo
The Tech Side of Project ArgoWesley Lindamood
 
Ruby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChairRuby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChairJonathan Weiss
 
Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010
Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010
Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010Guillaume Laforge
 
Please Don't Touch the Slow Parts
Please Don't Touch the Slow PartsPlease Don't Touch the Slow Parts
Please Don't Touch the Slow PartsFederico Galassi
 
Node.js and websockets intro
Node.js and websockets introNode.js and websockets intro
Node.js and websockets introkompozer
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneDeepu S Nath
 
Javascript framework and backbone
Javascript framework and backboneJavascript framework and backbone
Javascript framework and backboneDaniel Lv
 
Java Server Faces 2.0 - Der Standard für moderne und komponentenbasierte Weba...
Java Server Faces 2.0 - Der Standard für moderne und komponentenbasierte Weba...Java Server Faces 2.0 - Der Standard für moderne und komponentenbasierte Weba...
Java Server Faces 2.0 - Der Standard für moderne und komponentenbasierte Weba...GFU Cyrus AG
 
Web Standards @ Opera Talk Oslo
Web Standards @ Opera Talk OsloWeb Standards @ Opera Talk Oslo
Web Standards @ Opera Talk OsloZi Bin Cheah
 
Metacello
MetacelloMetacello
MetacelloESUG
 
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP GroupDeveloping Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Groupminddog
 

Semelhante a Jquery Introduction (20)

Browser Extensions in Mozilla Firefox & Google Chrome
Browser Extensions in Mozilla Firefox & Google ChromeBrowser Extensions in Mozilla Firefox & Google Chrome
Browser Extensions in Mozilla Firefox & Google Chrome
 
Nick Sieger-Exploring Rails 3 Through Choices
Nick Sieger-Exploring Rails 3 Through Choices Nick Sieger-Exploring Rails 3 Through Choices
Nick Sieger-Exploring Rails 3 Through Choices
 
Mobile, Media & Touch
Mobile, Media & TouchMobile, Media & Touch
Mobile, Media & Touch
 
jQuery Learning
jQuery LearningjQuery Learning
jQuery Learning
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
Campus Party 2010
Campus Party 2010Campus Party 2010
Campus Party 2010
 
WordPress Front End Optimizations
WordPress Front End OptimizationsWordPress Front End Optimizations
WordPress Front End Optimizations
 
Passing a Front end Developer interview
Passing a Front end Developer interview Passing a Front end Developer interview
Passing a Front end Developer interview
 
The Tech Side of Project Argo
The Tech Side of Project ArgoThe Tech Side of Project Argo
The Tech Side of Project Argo
 
Základy GWT
Základy GWTZáklady GWT
Základy GWT
 
Ruby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChairRuby on CouchDB - SimplyStored and RockingChair
Ruby on CouchDB - SimplyStored and RockingChair
 
Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010
Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010
Implementing Groovy Domain-Specific Languages - S2G Forum - Munich 2010
 
Please Don't Touch the Slow Parts
Please Don't Touch the Slow PartsPlease Don't Touch the Slow Parts
Please Don't Touch the Slow Parts
 
Node.js and websockets intro
Node.js and websockets introNode.js and websockets intro
Node.js and websockets intro
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
 
Javascript framework and backbone
Javascript framework and backboneJavascript framework and backbone
Javascript framework and backbone
 
Java Server Faces 2.0 - Der Standard für moderne und komponentenbasierte Weba...
Java Server Faces 2.0 - Der Standard für moderne und komponentenbasierte Weba...Java Server Faces 2.0 - Der Standard für moderne und komponentenbasierte Weba...
Java Server Faces 2.0 - Der Standard für moderne und komponentenbasierte Weba...
 
Web Standards @ Opera Talk Oslo
Web Standards @ Opera Talk OsloWeb Standards @ Opera Talk Oslo
Web Standards @ Opera Talk Oslo
 
Metacello
MetacelloMetacello
Metacello
 
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP GroupDeveloping Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
 

Jquery Introduction

  • 2. What are we talking about Wednesday, 28 April 2010 2
  • 3. What are we talking about client side scripting implemented as part of a browser to provide: Wednesday, 28 April 2010 2
  • 4. What are we talking about client side scripting implemented as part of a browser to provide: enhanced UI Wednesday, 28 April 2010 2
  • 5. What are we talking about client side scripting implemented as part of a browser to provide: enhanced UI dynamic websites Wednesday, 28 April 2010 2
  • 6. Why should I care? “JavaScript sucks” Wednesday, 28 April 2010 3
  • 7. Why should I care? “JavaScript sucks” it’s different - prototypal inheritance Wednesday, 28 April 2010 3
  • 8. Why should I care? “JavaScript sucks” it’s different - prototypal inheritance DOM is key BUT “sucks” Wednesday, 28 April 2010 3
  • 9. Why should I care? “JavaScript sucks” it’s different - prototypal inheritance DOM is key BUT “sucks” Element selection sucks Wednesday, 28 April 2010 3
  • 10. Why should I care? “JavaScript sucks” it’s different - prototypal inheritance DOM is key BUT “sucks” Element selection sucks x-Browser DOM sucks Wednesday, 28 April 2010 3
  • 11. Demo Wednesday, 28 April 2010 4 DOM selection and Cross Browser DOM selection code demo var objById = getElementById('id'); var objById = $('#id'); var firstParagraph = getElementByTagName('p')[0]; var firstParagraph = $('p:first'); /////////// example cross browser functions //// /********************************************************************* * Get an object, this function is cross browser * Usage: * var object = get_object(element_id); * @Author Hamid Alipour http://blog.code-head.com/ **/ function get_object(id) { var object = null; if (document.layers) { // Mozilla 4.0 based browsers object = document.layers[id]; } else if (document.all) { // IE6 object = document.all[id]; } else if (document.getElementById) { // Modern browsers object = document.getElementById(id); } return object; } /*********************************************************************/ var obj = get_object('id'); // jquery var obj = $('#id');
  • 12. 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. jQuery is designed to change the way that you write JavaScript." http://jquery.com “Write less, do more” Wednesday, 28 April 2010 5
  • 13. What is jQuery? Wednesday, 28 April 2010 6
  • 14. What is jQuery? A fast concise library with an OO interface Wednesday, 28 April 2010 6
  • 15. What is jQuery? A fast concise library with an OO interface Features Lightweight Cross-browser CSS3 Compliant Wednesday, 28 April 2010 6
  • 17. CSS3 Compliant??? We really mean “selectors” as in DOM selection Wednesday, 28 April 2010 7
  • 18. CSS3 Compliant??? We really mean “selectors” as in DOM selection Starts with CSS2 Wednesday, 28 April 2010 7
  • 19. CSS3 Compliant??? We really mean “selectors” as in DOM selection Starts with CSS2 Id, Class, Type, Universal, Grouping, Descendant, Child, Adjacent Sibling, Attribute, etc. Wednesday, 28 April 2010 7
  • 20. CSS Selector Demo Id, Class, Type, Universal, Grouping, Descendant, Child, Adjacent Sibling, Attribute, etc. Wednesday, 28 April 2010 8 CSS Selector Demo with CSS code From to http://www.w3.org/TR/CSS2/selector.html Id #idvalue { font-family: sans-serif; } Class .classname { font-family: Sans-Serif; } .classone.classtwo { font-family: Sans-Serif; } Grouping h1 { font-family: sans-serif } h2 { font-family: sans-serif } h3 { font-family: sans-serif } is equivalent to: h1, h2, h3 { font-family: sans-serif } Descendant For example, consider the following rules: h1 { color: red } em { color: red } Although the intention of these rules is to add emphasis to text by changing its color, the effect will be lost in a case such as: <H1>This headline is <EM>very</EM> important</H1> We address this case by supplementing the previous rules with a rule that sets the text color to blue whenever an EM occurs anywhere within an H1: h1 { color: red } em { color: red } h1 em { color: blue } The third rule will match the EM in the following fragment: <H1>This <SPAN class="myclass">headline is <EM>very</EM> important</SPAN></H1> Child The following rule sets the style of all P elements that are children of BODY: body > P { line-height: 1.3 }
  • 21. CSS3 Compliant??? We really mean “selectors” as in DOM selection Start with CSS2 More at http://api.jquery.com/category/selectors/ http://www.w3.org/TR/CSS2/selector.html http://www.w3.org/TR/css3-selectors/ http://www.456bereastreet.com/archive/200601/css_3_selectors_explained/ http://www.w3schools.com/css/css_examples.asp Wednesday, 28 April 2010 9
  • 22. jQuery Core Concepts $() Get then Act Chainability $("p.neat").addClass("ohmy").show("slow"); Wednesday, 28 April 2010 10 KS take over here
  • 23. $() = jQuery() $ is a jquery object. $ is used to keep the code shorter, javascript is downloaded $(selector) is how you get an element as a jQuery object. Wednesday, 28 April 2010 11
  • 24. Chainability Get then Act Chainability jQuery has chainablity of commends you can link one commend to an other $("p.neat").addClass("ohmy").show("slow"); $('#boo').filter(':funny').addClass('funny').css('color', 'red').show(); Wednesday, 28 April 2010 12
  • 25. Hello world Demo Wednesday, 28 April 2010 13 jQuery DOM selection (get) then act (PS do) http://jquery.com - show this demo do a couple different things ask what is the code going to do, discuss and run, then ask for do something different?
  • 26. BrightTALK Conventions Wednesday, 28 April 2010 14 Check time
  • 27. BrightTALK Conventions $.bt Wednesday, 28 April 2010 14 Check time
  • 28. BrightTALK Conventions $.bt filenames Wednesday, 28 April 2010 14 Check time
  • 29. BrightTALK Conventions $.bt filenames bt.XXX.js Wednesday, 28 April 2010 14 Check time
  • 30. BrightTALK Conventions $.bt filenames bt.XXX.js jquery.XXX.js Wednesday, 28 April 2010 14 Check time
  • 31. BrightTALK Conventions $.bt filenames bt.XXX.js jquery.XXX.js custom events Wednesday, 28 April 2010 14 Check time
  • 32. BrightTALK Conventions $.bt filenames bt.XXX.js jquery.XXX.js custom events plugins Wednesday, 28 April 2010 14 Check time
  • 33. BrightTALK Conventions $.bt Reasons filenames bt.XXX.js jquery.XXX.js custom events plugins Wednesday, 28 April 2010 14 Check time
  • 34. BrightTALK Conventions $.bt Reasons filenames reusable bt.XXX.js jquery.XXX.js custom events plugins Wednesday, 28 April 2010 14 Check time
  • 35. BrightTALK Conventions $.bt Reasons filenames reusable bt.XXX.js maintable jquery.XXX.js custom events plugins Wednesday, 28 April 2010 14 Check time
  • 36. $.bt Wednesday, 28 April 2010 15 PS take over
  • 37. $.bt namespace - globals are evil Wednesday, 28 April 2010 15 PS take over
  • 38. $.bt namespace - globals are evil static functions Wednesday, 28 April 2010 15 PS take over
  • 39. $.bt namespace - globals are evil static functions public / private conventions Wednesday, 28 April 2010 15 PS take over
  • 40. $.bt namespace - globals are evil static functions public / private conventions $.bt.publicFunction Wednesday, 28 April 2010 15 PS take over
  • 41. $.bt namespace - globals are evil static functions public / private conventions $.bt.publicFunction $.bt._privateFunction Wednesday, 28 April 2010 15 PS take over
  • 42. $.bt namespace - globals are evil static functions public / private conventions $.bt.publicFunction $.bt._privateFunction common way to extend bt object Wednesday, 28 April 2010 15 PS take over
  • 43. $.bt Demo Wednesday, 28 April 2010 16 extension demo (PS) examples - discuss good and bad good - doesn’t pollute global name space bad - still global static functions just namespaced - leads to tight coupling early prototype jquery.btuser better example bt.operations.js
  • 44. .bind() & custom events The .bind() method is the primary means of attaching behavior to a document. All JavaScript event types, such as focus, mouseover, and resize, are allowed for eventType. With the help of .bind we can create our custom events. Wednesday, 28 April 2010 17 KS take over
  • 45. Creating custom event Creating custom event. $(document).bind('foo', function() { alert('hello world'); }) Calling custom event $(document).trigger("foo"); Wednesday, 28 April 2010 18
  • 46. Custom Event Demo Wednesday, 28 April 2010 19 Custom event - login handler vs registration, date time locale conversion (KS DO) $(document).bind("myCustomEvent", function(e, myName, myValue){       $(this).text(myName + ", hi there!");       $("span").stop().css("opacity", 1)                .text("myName = " + myName)                .fadeIn(30).fadeOut(1000);     });  $("button").click(function () {     $(document).trigger("myCustomEvent", [ "John" ]);   }); /// BRIGHTTALK  $(document).bind('localiseDate', function(e) {    $.btTimeZone.updateDateItem(0, e.target);  });  $('#csv-report-date', $('#report-XXX')).trigger("localiseDate", jQuery(this));
  • 47. jQuery plugins Learn how to write plugins http://docs.jquery.com/Plugins/Authoring Find plugins at http://plugins.jquery.com/ Custom plugins on the platform csvreport Benefits vs static functions Wednesday, 28 April 2010 20
  • 48. Plugin Demo Wednesday, 28 April 2010 21 Check time (prob not time for this) Walkthrough CSVreport or jquery docs authoring page??