35
sparcs.org 1 LOGO jQuery Tutorial 100610

LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

Embed Size (px)

Citation preview

Page 1: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

sparcs.org

1

LOGO

jQuery Tutorial100610

Page 2: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

2

Presenter

ㅎㅇㅎㅇ

Page 3: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

3

Background Topics

HTMLJavascriptCSSCGIAJAX

Page 4: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

4

Evolution

Page 5: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

5

Javascript

A script language that interpreted by browser

OOP

Dynamic typing

Run-time evaluation

Page 6: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

6

Javascript

Cannot access host computer (except cookie)

Same origin policy

Non-persistence

Cannot access history object

Cannot write the value of file upload field

Page 7: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

7

Javascript

Javascript is not a good language design(??)

Writing Javascript code is tedious, time-consuming, and error-prone (really??)

Browser compatibility

AJAX

Page 8: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

8

Alternatives

jQuery

Mootools

Prototype

YUI

Page 9: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

9

jQuery

jQuery is a new kind of JavaScript library

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.

Page 10: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

10

Presenter

공부해봅시다ㅋㅋ

Page 11: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

11

jQuery

Only jquery.js file is needed<html>

<head> <script type="text/javascript“ src="http://code.jQuery.com/j

query-latest.min.js"></script> <script type="text/javascript“ src=“jquerypractice.js”>

</script> </head> <body>

<!--Your body content here… --></body>

</html>

What is jquery.js?

Page 12: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

12

jQuery

Print Hello jQuery

<!—body part of the html file -->

<body>

<div id=“hello”>Hello, World!</div>

</body>

//jQuerypractice.js file

$(document).ready(function(){

$(“#hello”).html(“Hello, jQuery!”);

});

Page 13: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

13

jQuery Core

jQuery( selector, [ context ] ) : Accepts a string containing a CSS selector which is then used to match a set of elements and returns a jQuery object. jQuery( element ) jQuery( elementArray ) jQuery( jQuery object ) jQuery()

can be written as $()

Page 14: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

14

jQuery Events

.ready( handler ) : execute handler when the DOM is fully loaded.

jsfunction printhello(){ $(“#hello”).html(“Hello, jQuery!”);}

$(document).ready(printhello());

Same as window.onload???

js

$(document).ready(function(){ $(“#hello”).html(“Hello, jQuery!”);});

Page 15: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

15

jQuery Events

.bind() .blur() .change() .click() .focus() .hover() .select() .toggle() .trigger() .submit()

.mousedown() .mouseenter() .mouseleave() .keypress() .keyup()

Page 16: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

16

jQuery Events

$(document).keyup(function(event){ switch(event.which){

case 32:alert(“32 pressed”);break;

}});

event.preventDefault() event.stopPropagation()

Page 17: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

17

jQuery Selectors

follows CSS1~3 Selectorshttp://www.w3.org/TR/css3-selectors

:animated:has():gt()

Page 18: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

18

jQuery Attributes

.addClass().removeClass().hasClass().toggleClass().attr().removeattr().val().html()

Page 19: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

19

jQuery Each

.each() : Iterate over a jQuery object, executing a function for each matched element.

html

<ul> <li>garbage</li> <li>food</li> <li>abroad</li></ul>

js

$(document).ready(function(){ $('li').each(function(index) { alert(index + ': ' + $(this).text()); }); });

Page 20: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

20

jQuery Traversing

.add().children().contents().filter().find().next().not().prev()

Page 21: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

21

jQuery Manipulations

.append().appendTo().clone().detach().insertAfter().insertBefore().remove()

Page 22: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

22

jQuery CSS

.css().height().width().position().offset().scrollTop().scrollLeft()

Page 23: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

23

jQuery Effect

.animate()

html

<button id="left">left</button> <button id="right">right</button><div class="block"></div>

js

$(document).ready(function(){ $(".block").css({ 'position': 'absolute', 'backgroundColor': "#abc", 'left': '100px', 'width': '90px', 'height': '90px', 'margin': '5px' }); $("#left").click(function(){ $(".block").animate({left: "-=50px"}, "slow"); }); $("#right").click(function(){ $(".block").animate({left: "+=50px"}, "slow"); });

});

Page 24: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

24

jQuery Effect

.fadeIn().hide().show().toggle()

Page 25: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

25

jQuery AJAX

jQuery.get( url, [ data ], [ callback(data, textStatus, XMLHttpRequest) ], [ dataType ] ) Returns: XMLHttpRequest

jQuery.post()

jQuery.getJSON()

.load()

jQuery.getScript()

Page 26: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

26

만들자

jQuery

HTMLSPARCS serverusername

Does ‘username’ exist?

yes/no

check…print

Page 27: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

27

jQuery AJAX

html<div id="user_check"> <input id="username" type="text"></input> <input id="username_submit" type="button" value="submit"></input> <p id="check_result"></p></div>

js

$(document).ready(function(){ $("#username_submit").click(function(){ $.get('jqtest.cgi', {"username" : $("#username").val()}, function(data){ $('#check_result').html(data); }); }); });

#! /usr/bin/python import cgi import os

form = cgi.FieldStorage() print "Content-Type: text/html\n\n“username = form.getvalue('username', '1')

if os.path.exists("/home/“ + username + "/"): print "exists" else: print "not exists"

CGI

Page 28: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

28

Data transfer & save

XML (xPath) JSON HTML

Cookie window object

Page 30: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

30

Presenter

거의끝났음 !!

개발하며 생각해야할

점…

Page 31: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

31

Let’s consider…

What does jQuery(JS) do?

Fat client vs Thin client

Page 32: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

32

Let’s consider…

Separate all layers!!! No event handler in HTML template

No <a href=“#” …>

location.replace() instead of location.href

Users don’t like popup

Page 33: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

33

Accessibility

What if javascript is not available?

screen reader

Page 34: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

34

Homework

look Gmail

단축키로 커서를 움직일 때 마다 auto scrolling, focusing을 하는 스크립트를 작성 해 보자 .

Page 35: LOGO sparcs.org 1 jQuery Tutorial 100610. 2 Presenter ㅎㅇㅎㅇ

sparcs.org

35

LOGO