Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 10.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 JavaScript and XHTML Documents Programming the World Wide Web Fourth.
Advertisements

5.1 JavaScript Execution Environment
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 11.
Chapter 7 © 2001 by Addison Wesley Longman, Inc. 1 Chapter 7 Sebesta: Programming the World Wide Web.
Tutorial 16 Working with Dynamic Content and Styles.
Tutorial 15 Working with the Event Model. XP Objectives Compare the IE and W3C event models Study how events propagate under both event models Write a.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 12.
XML DOM and SAX Parsers By Omar RABI. Introduction to parsers  The word parser comes from compilers  In a compiler, a parser is the module that reads.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 9.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Cos 381 Day 7. © 2006 Pearson Addison-Wesley. All rights reserved. 5-2 Agenda Assignment one graded –Did not see any big issues »Some still have issues.
XP Tutorial 8 New Perspectives on JavaScript, Comprehensive1 Working with the Event Model Creating a Drag-and-Drop Shopping Cart.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Events.
4.1 JavaScript Introduction
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Chapter 5 © 2003 by Addison-Wesley, Inc. 1 Chapter 5 JavaScript and HTML Documents.
Execution Environment for JavaScript " Java Script Window object represents the window in which the browser displays documents. " The Window object provides.
Chapter 5 JavaScript and HTML Documents. © 2006 Pearson Addison-Wesley. All rights reserved JavaScript Execution Environment - The JavaScript.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 JavaScript and HTML Documents.
Chapter 5 © 2012 by Addison Wesley Longman, Inc JavaScript Execution Environment - The JavaScript Window object represents the window in which the.
DOM and JavaScript Aryo Pinandito.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
Working with the XML Document Object Model ©NIITeXtensible Markup Language/Lesson 7/Slide 1 of 44 Objectives In this lesson, you will learn to: *Identify.
Client side web programming Introduction Jaana Holvikivi, DSc. School of ICT.
JavaScript, Part 3 Instructor: Charles Moen CSCI/CINF 4230.
5.2 DOM (Document Object Model). 2 Motto: To write it, it took three months; to conceive it three minutes; to collect the data in it — all my life. —F.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
Chapter 5 © 2005 by Addison Wesley Longman, Inc JavaScript Execution Environment - The JavaScript Window object represents the window in which the.
Chapter 5 © 2014 by Pearson Education JavaScript Execution Environment - The JavaScript Window object represents the window in which the browser.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Dimiter Kunchev.  JavaScript library written by Sam Stephenson   Adds object oriented techniques  Provides.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
1 Javascript DOM Peter Atkinson. 2 Objectives Understand the nature and structure of the DOM Add and remove content from the page Access and change element.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Chapter 5 © 2010 by Addison Wesley Longman, Inc JavaScript Execution Environment - The JavaScript Window object represents the window in which the.
Review of the DOM Node properties and methods Some ways of accessing nodes Appending, copying and removing nodes Event handling – Inline – Scripting –
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 5. JavaScript and HTML Documents.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
Event Handling & AJAX IT210 Web Systems. Question How do we enable users to dynamically interact with a website? Answer: Use mouse and keyboard to trigger.
H.Melikyan/4910/031 Programming the World Wide Web JavaScript Dr.Hayk Melikyan Departmen of Mathematics and CS JavaScript and HTML Documents.
Host Objects: Browsers and the DOM
Events Event Handling in JavaScript SoftUni Team Technical Trainers Software University
JS: Document Object Model (DOM) DOM stands for Document Object Model, and allows programmers generic access to: DOM stands for Document Object Model, and.
Chapter 6 Murach's JavaScript and jQuery, C6© 2012, Mike Murach & Associates, Inc.Slide 1.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
XML DOM Week 11 Web site:
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
Internet & World Wide Web How to Program, 5/e.  JavaScript events  allow scripts to respond to user interactions and modify the page accordingly  Events.
Introduction to JavaScript DOM Instructor: Sergey Goldman.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 5 Host Objects: Browsers.
Chapter 5 JavaScript and HTML Documents. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 5-2 FIGURE 5.1 The DOM structure for a simple document.
REEM ALMOTIRI Information Technology Department Majmaah University.
THE DOM.
Introduction to JavaScript DOM and Events
5.1 JavaScript Execution Environment
Introduction to JavaScript Events
JavaScript Functions.
JAVASCRIPTS AND HTML DOCUMENTS
JavaScript and Events.
Document Object Model (DOM): Objects and Collections
JavaScript and HTML Documents
Working with the Event Model
Events.
© 2015, Mike Murach & Associates, Inc.
5.1 JavaScript Execution Environment
CHAPTER 6 EVENTS. CHAPTER 6 EVENTS WHAT IS AN EVENT?
Presentation transcript:

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 10

5-2 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Agenda Questions?? Resources Source Code Available for examples in Text Book in Blackboard Html and XHTML examples Assignment 2 Not created yet Assignment 3 will be creating a board game using JavaScript and DOM Capstone Proposals Over Due STILL 2 missing Some type of web based applications Discussions on JAVASCRIPT & HTML

5-3 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Assignment 3 UUUK MFKK FKFM UMFK Randomly placed letters Users may swap adjacent tiles Cost for swap? Spelling UMFK scores points Correctly placed tiles are removed Down and across Empty slots are filled with random Letters Gravity? Games continues till ? X numbers of tiles games missing letter (no M’s) max score score goes negative User quits Extra Features Animations larger than 4 X 4 Spelling on diagonals

5-4 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5.8 DOM 2 Event Model DOM 2 is defined in modules The Events module defines several submodules HTMLEvents and MouseEvents are common An event object is passed as a parameter to an event handler Properties of this object provide information about the event Some event types will extend the interface to include information relevant to the subtype. For example, a mouse event will include the location of the mouse at the time of the event

5-5 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5.8 Event Flow DOM 2 defines a process for determining which handlers to execute for a particular event The process has three phases Different event types The event object representing the event is created at a particular node called the target node

5-6 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5.8 Event Propagation (continued) Three traversal phases then occur In the capturing phase each node from the document root to the target node, in order, is examined. If the node is not the target node and there is a handler for that event at the node and the handler is enabled for capture for the node, the handler is executed Then all handlers registered for the target node, if any, are executed In the bubbling phase each node from the parent of the target node to the root node, in order, is examined If there is a handler for that event at the node and the handler is not enabled for capture for the node, the handler is executed Some event types are not allowed to bubble: load, unload, blur and focus among the HTML event types

5-7 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5.8 Event Propagation As each handler is executed, properties of the event provide context The currentTarget property is the node to which the handler is registered The target property is the node to which the event was originally directed One major advantage of this scheme over DOM 0 is that event handling can be centralized in an ancestor node For example, a calculator keyboard will have a number of digit buttons In some GUI frameworks, a handler must be added to each button separately In DOM 2, the buttons could be organized under a single node and the handler placed on the node

5-8 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5.8 Event Handler Registration Handlers are called listeners in DOM 2 addEventListener is used to register a handler, it takes three parameters A string naming the event type The handler A boolean specifying whether the handler is enabled for the capture phase or not dom2 = doucument.getElementById(“custName”); dom2.addEventListner (“change”, chkName, false); Wrong in TEXT!

5-9 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Demonstration of Dom event bubbling Every event fires only once Some in capture phase (enable) Target node Some in bubble phase (disable) 5/bubble.htmhttp://perleybrook.umfk.maine.edu/SourceCode/w4code 5/bubble.htm scripts\bubble.txt scripts\bubbler.txt

5-10 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5.8 Example of DOM 2 Event Model The 5/validator2.html example modifies the validation example to use DOM 2 style event handling 5/validator2.html scripts\validator2.txt scripts\validator2r.txt

5-11 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5.9 The navigator Object Properties of the navigator object allow the script to determine characteristics of the browser in which the script is executing The appName property gives the name of the browser The appVersion gives the browser version

5-12 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5.9 Output From navigate.html tmlhttp://perleybrook.umfk.maine.edu/SourceCode/w4code5/navigate.h tml scripts\navigate.txt Note that the browser is actually FireFox and the version is

5-13 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5.10 DOM Tree Traversal and Modification Each element in an XHTML document has a corresponding ELEMENT object in the DOM representation The ELEMENT object has methods to support Traversing the document, that is, visiting each of the document nodes Modifying the document For example, removing and inserting child nodes

5-14 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5.10 DOM Tree Traversal Various properties of Element objects are related nodes parentNode references the parent node of the Element previousSibling and nextSibling connect the children of a node into a list firstChild and lastChild reference children of an Element These would be text nodes or element nodes contained in the Element

5-15 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5.10 DOM Tree Modification The insertBefore method inserts a new child of the target node replaceChild will replace a child node with a new node removeChild removes a child node appendChild adds a node as a child node at the end of the children Lets write a quick calculator using JavaScript and DOM Input 2 numbers Select (+, -, *, /, %) Output answer