intro to jquery - lugor - part 1

36
for Linux Lovers

Upload: ralph-whitbeck

Post on 10-May-2015

3.958 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Intro to jQuery - LUGOR - Part 1

for Linux Lovers

Page 2: Intro to jQuery - LUGOR - Part 1

Introduction

Ralph Whitbeck

• jQuery Team Member, on the Developer Relations team

• Co-authored O’Rielly’s “jQuery Cookbook”

• Senior Web Application Engineer  BrandLogic Corporation (http://brandlogic.com)

• Blog: http://ralphwhitbeck.com

• Twitter: @RedWolves

Page 3: Intro to jQuery - LUGOR - Part 1

The Official jQuery Podcast

Page 4: Intro to jQuery - LUGOR - Part 1

Overview

• Who, what, where and why of jQuery

• Review Core jQuery Concepts

• jQuery API Overview

• jQuery plugins

• jQuery UI

Page 5: Intro to jQuery - LUGOR - Part 1

Who uses jQuery

• 39.25% of all sites that use JavaScript

• About 30% of the top 10,000 sites

http://trends.builtwith.com/javascript/JQuery

Page 6: Intro to jQuery - LUGOR - Part 1

Who uses jQuery

• 39.25% of all sites that use JavaScript

• About 30% of the top 10,000 sites

http://trends.builtwith.com/javascript/JQuery

Page 7: Intro to jQuery - LUGOR - Part 1

What is jQuery?

jQuery is a JavaScript Library!

• Dealing with the DOM(e.g. selecting, creating, traversing, changing, etc.)

• JavaScript Events

• Animations

• Ajax interactions

Page 8: Intro to jQuery - LUGOR - Part 1

What does that mean?

Page 9: Intro to jQuery - LUGOR - Part 1

if (browserType == "ie") document.poppedLayer =

eval('document.getElementById("HiddenDIV")'); else

document.poppedLayer = eval('document.layers["HiddenDIV"]');

document.poppedLayer.style.visibility = "visible";

It means no more of this…

Page 10: Intro to jQuery - LUGOR - Part 1

Using jQuery we can do this

 jQuery(“#HiddenDiv”).show();

Page 11: Intro to jQuery - LUGOR - Part 1

Using jQuery we can do this

 jQuery(“#HiddenDIV”).show();

jQuery function

var $ = jQuery;

$(“#HiddenDiv”).show();

Page 12: Intro to jQuery - LUGOR - Part 1

Using jQuery we can do this

 jQuery(“#HiddenDIV”).show();

jQuery Function

jQuery Selector(CSS expression)

Page 13: Intro to jQuery - LUGOR - Part 1

jQuery Wrapped Set

Using jQuery we can do this

 jQuery(“#HiddenDIV”).show();

jQuery Function

jQuery Selector(CSS expression)

Page 14: Intro to jQuery - LUGOR - Part 1

jQuery Wrapped Set

Using jQuery we can do this

 jQuery(“#HiddenDIV”).show();

jQuery Function

jQuery Selector(CSS expression)

jQuery Method

Page 15: Intro to jQuery - LUGOR - Part 1

jQuery really is the

“write less, do more”

JavaScript Library!

Page 16: Intro to jQuery - LUGOR - Part 1

Why use jQuery?

• Helps us to simplify and speed up web development

• Allows us to avoid common headaches associated with cross-browser development

• Provides a large pool of plugins

• Large and active community

• Tested on 50 browsers, 11 platforms and mobile

• It’s for both developers and designers

Page 17: Intro to jQuery - LUGOR - Part 1

Why use jQuery?

• Helps us to simplify and speed up web development

• Allows us to avoid common headaches associated with cross-browser development

• Provides a large pool of plugins

• Large and active community

• Tested on 50 browsers, 11 platforms and mobile

• It’s for both developers and designers

Page 18: Intro to jQuery - LUGOR - Part 1

Why use jQuery?

• Helps us to simplify and speed up web development

• Allows us to avoid common headaches associated with cross-browser development

• Provides a large pool of plugins

• Large and active community

• Tested on 50 browsers, 11 platforms and mobile

• It’s for both developers and designers

Page 19: Intro to jQuery - LUGOR - Part 1

Where to get jQuery

• Download the source from Github

• Or use a CDN• jQuery CDN (Edgecast via (mt)

• http://code.jquery.com/jquery-1.4.2.min.js Minified version

• http://code.jquery.com/jquery-1.4.2.js Source version •Google•Microsoft

Page 20: Intro to jQuery - LUGOR - Part 1

Core jQuery Concepts

• Select Something, do something

• Create something, do something

• Chaining and Operating

Demo’d http://ejohn.org/apps/learn-jquery/andhttp://ralphwhitbeck.com/talks/stackoverflowdevdays/

createdosomething.html

Page 21: Intro to jQuery - LUGOR - Part 1

jQuery API Overview

• Core

• Selectors

• Attributes

• Traversing

• Manipulation

• CSS

• Events

• Effects

• Ajax

• Utilities

You can review Core Methods at:

http://api.jquery.com

Page 22: Intro to jQuery - LUGOR - Part 1

jQuery Plugins

• There are over 2200 plugins

• Plugins extend jQuery’s functionality

• If you can’t find the functionality in a plugin, make your own!

• You can make a jQuery Plugin in six steps

Page 23: Intro to jQuery - LUGOR - Part 1

Step 1. create a private scope for $ alias<!DOCTYPE html><html><body><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script>(function($){ })(jQuery);</script></body></html>

A jQuery plugin in 6 steps

Page 24: Intro to jQuery - LUGOR - Part 1

Step 2. attach plugin to fn alias<!DOCTYPE html><html><body><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script>(function($){

$.fn.loveNotHate = function(){$(this).text($(this).text().replace(/hate/g,'love'));

};

})(jQuery);</script></body></html>

A jQuery plugin in 6 steps

Page 25: Intro to jQuery - LUGOR - Part 1

Step 2. attach plugin to fn alias<!DOCTYPE html><html><body><p>I hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script>(function($){

$.fn.loveNotHate = function(){$(this).text($(this).text().replace(/hate/g,'love'));

};

})(jQuery);jQuery('p').loveNotHate();</script></body></html>

A jQuery plugin in 6 steps

Page 26: Intro to jQuery - LUGOR - Part 1

Step 3. add implicit iteration<!DOCTYPE html><html><body><p>I hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script>(function($){

$.fn.loveNotHate = function(){ this.each(function(){

$(this).text($(this).text().replace(/hate/g,'love'));

}); };

})(jQuery);jQuery('p').loveNotHate();</script></body></html>

A jQuery plugin in 6 steps

Page 27: Intro to jQuery - LUGOR - Part 1

Step 3. add implicit iteration<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script>(function($){

$.fn.loveNotHate = function(){ this.each(function(){

$(this).text($(this).text().replace(/hate/g,'love'));

}); };

})(jQuery);jQuery('p').loveNotHate();</script></body></html>

A jQuery plugin in 6 steps

Page 28: Intro to jQuery - LUGOR - Part 1

Step 4. enable chaining<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script>(function($){

$.fn.loveNotHate = function(){ return this.each(function(){

$(this).text($(this).text().replace(/hate/g,'love'));

}); };

})(jQuery);jQuery('p').loveNotHate();</script></body></html>

A jQuery plugin in 6 steps

Page 29: Intro to jQuery - LUGOR - Part 1

Step 4. enable chaining<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script>(function($){

$.fn.loveNotHate = function(){ return this.each(function(){

$(this).text($(this).text().replace(/hate/g,'love'));

}); };

})(jQuery);jQuery('p').loveNotHate().hide();</script></body></html>

A jQuery plugin in 6 steps

Page 30: Intro to jQuery - LUGOR - Part 1

Step 5. add default options<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script>(function($){

$.fn.loveNotHate = function(){ return this.each(function(){

$(this).text($(this).text().replace(/hate/g,$.fn.loveNotHate.defaultOptions.text));

}); }; $.fn.loveNotHate.defaultOptions = {text:'love'};

})(jQuery);jQuery('p').loveNotHate();</script></body></html>

A jQuery plugin in 6 steps

Page 31: Intro to jQuery - LUGOR - Part 1

Step 6. add custom options<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script>(function($){

$.fn.loveNotHate = function(){ return this.each(function(){

$(this).text($(this).text().replace(/hate/g, $.fn.loveNotHate.defaultOptions.text));

}); }; $.fn.loveNotHate.defaultOptions = {text:'love'};

})(jQuery);jQuery('p').loveNotHate({text:'love-love-love'});</script></body></html>

A jQuery plugin in 6 steps

Page 32: Intro to jQuery - LUGOR - Part 1

Step 6. add custom options<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script>(function($){

$.fn.loveNotHate = function(customOptions){ return this.each(function(){

$(this).text($(this).text().replace(/hate/g, $.fn.loveNotHate.defaultOptions.text));

}); }; $.fn.loveNotHate.defaultOptions = {text:'love'};

})(jQuery);jQuery('p').loveNotHate({text:'love-love-love'});</script></body></html>

A jQuery plugin in 6 steps

Page 33: Intro to jQuery - LUGOR - Part 1

Step 6. add custom options<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script>(function($){

$.fn.loveNotHate = function(customOptions){ var options = $.extend({},$.fn.loveNotHate.defaultOptions, customOptions); return this.each(function(){

$(this).text($(this).text().replace(/hate/g, $.fn.loveNotHate.defaultOptions.text));

}); }; $.fn.loveNotHate.defaultOptions = {text:'love'};

})(jQuery);jQuery('p').loveNotHate({text:'love-love-love'});</script></body></html>

A jQuery plugin in 6 steps

Page 34: Intro to jQuery - LUGOR - Part 1

Step 6. add custom options<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script>(function($){

$.fn.loveNotHate = function(customOptions){ var options = $.extend({},$.fn.loveNotHate.defaultOptions, customOptions); return this.each(function(){

$(this).text($(this).text().replace(/hate/g,options.text));

}); }; $.fn.loveNotHate.defaultOptions = {text:'love'};

})(jQuery);jQuery('p').loveNotHate({text:'love-love-love'});</script></body></html>

A jQuery plugin in 6 steps

Page 35: Intro to jQuery - LUGOR - Part 1

Plugins are simple, just follow the steps!

Page 36: Intro to jQuery - LUGOR - Part 1

jQuery UI

• Official jQuery Project

• Provides plugins that make user interface elements easy

• Contains:

– Interactions

– Widgets

– Effects

– Theming