Top Banner
presentation by: Tom Friedhof Javascript, jQuery and jQuery UI
52
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Javascript jQuery jQuery Ui

presentation by: Tom Friedhof

Javascript, jQuery and jQuery UI

Page 2: Javascript jQuery jQuery Ui

Stuff I’ll cover today.

• JavaScript.

• The DOM (Document Object Model).

• Adding Behaviors to HTML.

• You don’t need to learn the DOM

• jQuery

• jQuery UI Tabs

• jQuery the Drupal Way

Page 3: Javascript jQuery jQuery Ui

What is JavaScript?

Page 4: Javascript jQuery jQuery Ui

What is JavaScript?

• Client Side Scripting Language

• JavaScript is not Java

• Used to provide instant feedback

• Better Usability

• Richer Web Applications

• Works the DOM (i.e. HTML, XML, etc...)

Page 5: Javascript jQuery jQuery Ui

What is the DOM?

The Document Object Model (DOM) is an API for HTML and XML documents. It provides a structural representation of the document, enabling you to modify its content and visual presentation. Essentially, it connects web pages to scripts or programming languages.

https://developer.mozilla.org/en/DOM

Page 6: Javascript jQuery jQuery Ui

HTML and the DOM.

html

head

body

div

ul div div div

pli li li

a

meta title

p p

a a

Page 7: Javascript jQuery jQuery Ui

The real DOMDocument

htmlElement

head

Elementbody

Elementdiv

Elementul

Elementdiv

Elementdiv

Elementdiv

Elementmeta

Elementtitle

Elementa

Elementa

Elementli

Elementli

Elementli

Elementa

Elementp

Elementp

Elementp

.getElementById(‘tabs’)

.innerHTML

id=”tabs”

Page 8: Javascript jQuery jQuery Ui
Page 9: Javascript jQuery jQuery Ui

One other thing to mention

Page 10: Javascript jQuery jQuery Ui

The DOM is NOT JavaScript

Blue is for JavaScript, Red is for DOM

var anchorTags = document.getElementsByTagName(“a”)

for (var i = 0;i <anchorTags.length; i++){alert(“Href of this a element is: “ +

anchorTags[i].href);}

https://developer.mozilla.org/en/The_DOM_and_JavaScript

Page 11: Javascript jQuery jQuery Ui

Adding Behaviors to HTML

EVENTS

Page 12: Javascript jQuery jQuery Ui

onLoad

Page 13: Javascript jQuery jQuery Ui

onClick

Page 14: Javascript jQuery jQuery Ui

onMouseOver

Page 15: Javascript jQuery jQuery Ui

etc...

http://www.w3schools.com/jsref/jsref_events.asp

Page 16: Javascript jQuery jQuery Ui

That’s the Basics.

Page 17: Javascript jQuery jQuery Ui

Awesome!

We know the DOM

Now What?

Page 18: Javascript jQuery jQuery Ui

JavaScript Libraries can work with the DOM better

than you!.

You don’t need to learn the DOM

Page 19: Javascript jQuery jQuery Ui

JavaScript Libraries encapsulate browser

inconsistencies.

Page 20: Javascript jQuery jQuery Ui

jQueryWrite Less. Do More

Page 21: Javascript jQuery jQuery Ui

jQuery Basics

$( [find something] ).doSomething();

CSS Selector jQuery Method

Page 22: Javascript jQuery jQuery Ui

Hide Children of Element

Page 23: Javascript jQuery jQuery Ui

Get Elements by Class

Good Luck doing this with just the DOM and JavaScript

Page 24: Javascript jQuery jQuery Ui
Page 25: Javascript jQuery jQuery Ui

jQuery.com

Page 26: Javascript jQuery jQuery Ui

visualjquery.com

Page 27: Javascript jQuery jQuery Ui

OK... Let’s build tabs

Page 29: Javascript jQuery jQuery Ui

Objective.

• Turn an HTML Document with an Unordered List into tabbed content.

• Format the HTML using CSS.

• Add Behavior so that you can change tabs onClick of the tab name.

Page 30: Javascript jQuery jQuery Ui

The HTML (again)

Page 31: Javascript jQuery jQuery Ui
Page 32: Javascript jQuery jQuery Ui

The CSS

A topic for another day

Page 33: Javascript jQuery jQuery Ui
Page 34: Javascript jQuery jQuery Ui

Four JavaScript Functions

• init() sets up the tabs.

• showTab() displays a clicked tab's content and highlights the tab.

• getFirstChildWithTagName() is a helper function that retrieves the first child of a given element that has a given tag name.

• getHash() is another short helper function that takes a URL and returns the part of the URL that appears after the hash (#) symbol.

Page 35: Javascript jQuery jQuery Ui

Demoindex_hard.html

Page 36: Javascript jQuery jQuery Ui

You need to know a lot.

• CSS

• Document Object Model (DOM)

• JavaScript

• Language Constructs

• Verify that the JavaScript works in other browsers.

Page 37: Javascript jQuery jQuery Ui

This won’t work in IE

Finds a different node in IE

Page 38: Javascript jQuery jQuery Ui

I just want tabs.

Not a Computer Science Degree

Page 39: Javascript jQuery jQuery Ui

The Easy Way.

Page 40: Javascript jQuery jQuery Ui

jQueryand

jQuery UI

Page 41: Javascript jQuery jQuery Ui

Review jQuery Basics

$( [find something] ).doSomething();

$(“#tabs”).tabs();

CSS Selector jQuery UI Method

Page 42: Javascript jQuery jQuery Ui

A Few jQuery UI Methods

.draggable()

.droppable()

.selectable()

.accordion()

.slider()

etc...

Page 43: Javascript jQuery jQuery Ui

Include the Library

and a one liner to implement

Page 44: Javascript jQuery jQuery Ui

The DOM has to be ready

$(document).ready(function() {

// Code Goes Here

});

Page 45: Javascript jQuery jQuery Ui

The DOM has to be ready

$(document).ready(function() {

$(“#tabs”).tabs();

});

Page 46: Javascript jQuery jQuery Ui

The Drupal Way

Drupal.behaviors.loadTabs = function(context) {

// Code Goes Here

};

Page 47: Javascript jQuery jQuery Ui

The Drupal Way

Drupal.behaviors.loadTabs = function(context) {

$(“#tabs”).tabs();

};

Page 48: Javascript jQuery jQuery Ui

Why use Drupal.behaviors?

• Ability to override JS

• Behaviors are re-attachable

• Attach Behaviors to a specific context

• HTML loaded via AHAH

Drupal.attachBehaviors(elem);

Page 49: Javascript jQuery jQuery Ui

Demoindex_easy.html

Page 50: Javascript jQuery jQuery Ui

DemoDrupal.behaviors

Page 51: Javascript jQuery jQuery Ui

Resources

http://jquery.com and http://jqueryui.com

http://www.elated.com/articles/javascript-tabs/

http://api.drupal.org/api/file/developer/topics/javascript_startup_guide.html/6

http://raincitystudios.com/blogs-and-pods/katherine-bailey/the-lowdown-jquery-drupal-part-two

http://www.chapterthree.com/blog/josh_koenig/handling_aysnchronous_data_drupal_session_materials

https://developer.mozilla.org/en/JavaScript

Page 52: Javascript jQuery jQuery Ui

Questions?