intro to jquery

42
Intro to JavaScript and JQuery

Upload: dan-pickett

Post on 27-Jun-2015

127 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Intro to jquery

Intro to JavaScript and JQuery

Page 2: Intro to jquery

Hi!

dpickett on Twitter

LaunchWare.com on the InterTubes

Page 3: Intro to jquery

Enough about me...

to learn JavaScript!

Page 4: Intro to jquery

Our Chat Today

• Where is JavaScript?

• Great uses of JavaScript

• The Basics of JavaScript

• An Intro to JQuery

Page 5: Intro to jquery

Where’s JavaScript?

• Most popularly used for client side behaviors on web pages

• Made popular on the server side with NodeJS

• Start with the client side

Page 6: Intro to jquery

A Note on Accessibility

• Great web developers develop with accessibility in mind

• Make your web pages work great without JavaScript using progressive enhancement (more on this later)

Page 7: Intro to jquery

Google Maps

Page 8: Intro to jquery

Twitter

Page 9: Intro to jquery

Your First Program

alert(“hello BarCamp”);

Page 10: Intro to jquery

alert(“hello BarCamp”);function string

Page 11: Intro to jquery

Putting JS on your webpage

<script type="text/javascript">

//your code here

/*

a multiline comment

*/

</script>

Page 12: Intro to jquery

Putting JS on your webpage

<script type="text/javascript" src="your_filename.js"></script>

Page 13: Intro to jquery

Firebug

Page 14: Intro to jquery

Chrome Inspector

Page 15: Intro to jquery

Node REPL

Page 16: Intro to jquery

How to Install NodeJS

Page 17: Intro to jquery

Let’s Refactor...function sayHello(msg){

alert(msg);}

var myMessage = “Hello BarCamp!”;

sayHello(myMessage);

Page 18: Intro to jquery

Let’s Refactor...function sayHello(msg){ alert(msg);

}

var myMessage = “Hello BarCamp!”;sayHello(myMessage);

variable assignment

Page 19: Intro to jquery

Let’s Refactor...function sayHello(msg){ alert(msg);

}

var myMessage = “Hello BarCamp!”;sayHello(myMessage);function invocation

Page 20: Intro to jquery

Let’s Refactor...function sayHello(msg){ alert(msg);

}

var myMessage = “Hello BarCamp!”;sayHello(myMessage);

function declaration

Page 21: Intro to jquery

Let’s Refactor...function sayHello(msg){ alert(msg);

}

var myMessage = “Hello BarCamp!”;sayHello(myMessage);

argument

Page 22: Intro to jquery

Let’s Refactor...function sayHello(msg){ alert(msg);

}

var myMessage = “Hello BarCamp!”;sayHello(myMessage);

function body

Page 23: Intro to jquery

For Optimal Page Performance

Put your scripts at the end of your body

Page 24: Intro to jquery

Control Logic

if(message === 'Hello'){

alert(msg);

}

else {

alert("Something else was set");

}

Page 25: Intro to jquery

Control Logic

if(typeof window != ‘undefined’){

alert(msg);

}

else {

console.log(msg);

}

Page 26: Intro to jquery

So Much More...

• Regular Expressions

• Loops and Iteration

• Arrays

• Objects

Page 27: Intro to jquery

JQuery

• A JavaScript Framework with roots in Boston (John Resig)

• Removes the friction of cross-browser behaviors for animation, event handling, AJAX, and DOM manipulation

Page 28: Intro to jquery

The JQuery Function

$(<selector>);

$(function(){}); // alias for $(document).ready

$(<html markup>);

Page 29: Intro to jquery

Selectors<a href="hello.html"

class="greeting"

style="color: blue;"

id="greeter">Say Hello</a>

<script type="text/javascript">

$("a");

$("a:first");

$("a.greeting");

$("#greeter"); //most efficient selector

</script>

Page 30: Intro to jquery

What Can I Do With a Selector?

$("a").css("color"); //the color of a: blue

$("a").offset().top; //position of the element

$("a").hide(); //hide the element

$("a").remove(); //remove the element

$("a").addClass("context"); //add a class

$("a").after("<p>Hello</p>")); //append

Page 31: Intro to jquery

What Can I Do With a Selector?

$("a").css("color");

$("a").offset().top;

$("a").hide();

$("a").remove();

$("a").addClass("context");

$("a").insertAfter($("<p>Hello</p>"));

DOMManipulation

Page 32: Intro to jquery

Events<a href=‘hello.html’ id="greeter">Say Hello</a>

<script type=”text/javascript">

$(document).ready(function(){

$("#greeter").click(function(event){

event.preventDefault();

alert("Hello BarCamp!");

});

});

Page 33: Intro to jquery

Events

<a href=‘hello.html’ id="greeter">Say Hello</a>

<script type=”text/javascript">

$(document).ready(function(){

console.log('The Page Has Completely Loaded');

});

</script>

Page 34: Intro to jquery

DOM Ready Shortcut

<script type=”text/javascript">

$(function(){

console.log('The Page Has Completely Loaded');

});

</script>

Page 35: Intro to jquery

Events<a href=‘hello.html’ id="greeter">Say Hello</a>

<script type=”text/javascript">

$(document).ready(function(){

$("#greeter").click(function(event){

event.preventDefault();

alert("Hello BarCamp!");

});

});

Page 36: Intro to jquery

Event Driven DOM Manipulation

<a href=‘hello.html’ id="greeter">Say Hello</a>

<script type=”text/javascript">

$(document).ready(function(){

$("#greeter").click(function(event){

event.preventDefault();

var paragraph = $("<p>").html("Hello Barcamp!");

$(this).after(paragraph);

});

});

</script>

Page 37: Intro to jquery

Reacting to Input<form>

<input id="name" name="name" type="text">

</form>

<script type="text/javascript">

$("#name").change(function(event){

console.log("Hello " + $("#name").val() + "!");

});

</script>

Page 38: Intro to jquery

Progressive Enhancement

<a href="hello.html" id="say-hello">Say Hello</a>

$(function(){

$("#say-hello").click(function(e){

e.preventDefault();

//enhance the experience

});

});

Page 39: Intro to jquery

Progressive Enhancement

<a href="hello.html" id="say-hello">Say Hello</a>

$(function(){

$("#say-hello").click(function(e){

e.preventDefault();

//enhance the experience

});

});

Page 40: Intro to jquery

So Much More..

• AJAX

• JQuery UI

• Testing

• BackboneJS

Page 41: Intro to jquery

More Lengthy Intro to JS

Free, 4 hour session

coming this summer!

Page 42: Intro to jquery

Thanks!

• Follow me on twitter @dpickett and give me a shout!

• Email me at [email protected]

• Chat with me after the talk