Dimiter Kunchev.  JavaScript library written by Sam Stephenson   Adds object oriented techniques  Provides.

Slides:



Advertisements
Similar presentations
Diego Guidi - DotNetMarche. DOM tree is clunky to use No multiple handlers per event No high-level functions Browser incompatibilities = jQuery to the.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Introduction to Ajax.
Lesson 12- Unit L Programming Web Pages with JavaScript.
The Web Warrior Guide to Web Design Technologies
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
9. AJAX & RIA. 2 Motto: O! call back yesterday, bid time return. — William Shakespeare.
JavaScript Forms Form Validation Cookies CGI Programs.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
19-Jun-15 Ajax. The hype Ajax (sometimes capitalized as AJAX) stands for Asynchronous JavaScript And XML Ajax is a technique for creating “better, faster,
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Cos 381 Day 10.
JQuery. What is jQuery? jQuery is a fast, small, and feature-rich JavaScript library that simplifies HTML document traversing and manipulation event handling.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
CST JavaScript Validating Form Data with JavaScript.
Christopher Paolini Computational Science Research Center College of Engineering San Diego State University Computational Science 670 Fall 2009 Monday.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.
JavaScript & jQuery the missing manual Chapter 11
Chapter 5 Java Script And Forms JavaScript, Third Edition.
JavaScript Libraries: Prototype.js. Get it at:
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
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.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 JavaScript and HTML Documents.
JQuery Adding behaviour…. Lecture Plan Review of last lesson Adding behaviour –click, mouseover Animation –fade, slideDown Navigation –parent, find, next.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
ASP.NET Controls. Slide 2 Lecture Overview Identify the types of controls supported by ASP.NET and the differences between them.
INTRODUCTION TO HTML5 Using jQuery with HTML5. Introducing jQuery  Although it is not a part of any W3C or WHATWG specification, jQuery performs an important.
Using Client-Side Scripts to Enhance Web Applications 1.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Chapter 5 © 2005 by Addison Wesley Longman, Inc JavaScript Execution Environment - The JavaScript Window object represents the window in which the.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
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.
Unit 13 –JQuery Basics Instructor: Brent Presley.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
Dr. Ahmet Cengizhan Dirican BIL 374 Internet Technologies 5. JavaScript and HTML Documents.
AJAX. Overview of Ajax Ajax is not an API or a programming language Ajax aims to provide more responsive web applications In normal request/response HTTP.
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
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
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 9.
Events Event Handling in JavaScript SoftUni Team Technical Trainers Software University
Introduction to JQuery COGS 187A – Fall JQuery jQuery is a JavaScript library, and allows us to manipulate HTML and CSS after the page has been.
 ASP.NET provides an event based programming model that simplifies web programming  All GUI applications are incomplete without enabling actions  These.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
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.
XHTML Forms.
JQuery.
5.1 JavaScript Execution Environment
Prototype.
CGS 3066: Web Programming and Design Spring 2017
JavaScript Functions.
JavaScript and Events.
CSE 154 Lecture 22: AJAX.
JavaScript & jQuery AJAX.
Presentation transcript:

Dimiter Kunchev

 JavaScript library written by Sam Stephenson   Adds object oriented techniques  Provides many utility functions  Extends JavaScript methods and objects  Hides cross-browser problems  Simplifies developing of heavy web applications

 $() – literal form for document.getElementById  Returns reference to the element with that ID  If specified multiple arguments, returns an array with the corresponding elements  $F() – returns the value of input form field  Works with text boxes, check boxes, radio buttons, buttons, etc var myDiv = $('myDiv'); var inputValue = $F('myInput');

 $$() – returns elements matching the given CSS filter rule  Try.these – takes multiple function calls as arguments and returns the value of the first that worked var arr = $$('div#login_form input'); Try.these ( function () {return XMLNode.text}, function () {return XMLNode.textContent} ); Try.these ( function () {return XMLNode.text}, function () {return XMLNode.textContent} );

 $A() – converts it's single argument into an Array object  Extends the array with some usefl methods  $H() – converts it's argument into an enumerable hash object  Also adds some methods var arr = $A(["a", "b", "c"]); arr.each(function(elem) {alert (elem);}); var arr = $A(["a", "b", "c"]); arr.each(function(elem) {alert (elem);}); var obj = $H( {"id":5, name:"test"} ); alert (obj.toQueryString()); //produces id=5&name=test var obj = $H( {"id":5, name:"test"} ); alert (obj.toQueryString()); //produces id=5&name=test

 bindAsEventListener (object, optinal arguments) – returns anonymous function  Can be used to attach object's method as event handler  The event handler receives the event object and all arguments passed to the bindAsEventListener method this.btn.onclick = this.onBtnClick.bindAsEventListener(this, 'btn'); … onBtnClick: function (event, some_string) { } this.btn.onclick = this.onBtnClick.bindAsEventListener(this, 'btn'); … onBtnClick: function (event, some_string) { }

 bind – similar to bindAsEventListener  Passes to the method all arguments, specified by the caller and to the bind method  Useful for attaching handlers of Ajax requests and timers setTimeout(this.onTimer.bind(this, 'timer'), 1000); … onTimer: function (caller) { // caller will be 'timer' // caller will be 'timer'} setTimeout(this.onTimer.bind(this, 'timer'), 1000); … onTimer: function (caller) { // caller will be 'timer' // caller will be 'timer'}

 Extensions to the Object object  extend (destination, source) – copies all properties and methods from source object to destination object  Used for class inheritance  keys – returns array with the names of all properties and methods of the object  values – returns array with the values of all properties and methods of the object  clone – creates shadow copy of the object

 Prototype.js AJAX classes and methods are capsulated in single object, named Ajax  Ajax.Request  Ajax.Updater  Ajax.PeriodicalUpdater  Ajax.Responders

 Simplifies the use of XMLHttpRequest  Hides browser differences  Object constructor takes two arguments  URL to send the request to  Associative array with options new Ajax.Request ('get-data.html', { method:"get", onSucccess: showData, // function to handle result parameters: $H({id:5, kw:'abc'}).toQueryString() }); new Ajax.Request ('get-data.html', { method:"get", onSucccess: showData, // function to handle result parameters: $H({id:5, kw:'abc'}).toQueryString() });

 Options that can be passed to the constructor:  method : 'get' or 'post'  parameters : string data to append to the URL  New versions of prototype support associative array as parameters  toQueryString is executed  postBody : string – the contents to send over HTTP POST request

 onSuccess : function to be called when data is read from server  The function takes one parameter – the XHMLHttpRequest object  contentType : string – sets the HTTP Content-Type header of the request  encoding : string – sets the encoding of the request body for POST method  By default it is 'UTF-8'

 Extension of Ajax.Request  Constructor takes one more parameter – id of element to place the fetched data in  Doesn't need onSuccess handler method new Ajax.Updater ( 'result', // element ID 'result', // element ID 'get-data.html', 'get-data.html', { method:"get", method:"get", parameters: $H({id:5,kw:'abc'}). parameters: $H({id:5,kw:'abc'}). toQueryString() toQueryString() }); new Ajax.Updater ( 'result', // element ID 'result', // element ID 'get-data.html', 'get-data.html', { method:"get", method:"get", parameters: $H({id:5,kw:'abc'}). parameters: $H({id:5,kw:'abc'}). toQueryString() toQueryString() });

 Extension of Ajax.Updater class  Constructor takes the same arguments as Ajax.Updater one  You can specify the frequency and decay of the requests in the options new Ajax.PeriodicalUpdater ( 'result', // element ID 'get-data.html', { method:"get", frequency: 100, decay: 1 }); new Ajax.PeriodicalUpdater ( 'result', // element ID 'get-data.html', { method:"get", frequency: 100, decay: 1 });

 Prototype.js introduces the Element object  Contains methods to work with the DOM  All methods are also copied as extensions to the element references, accessed by the $() function Element.show('my_div'); // The above is the same as: $('my_div').show();Element.show('my_div'); $('my_div').show();

 addClassName(element, className)  Adds the given class name(s) to the className property of the element  removeClassName(element, className)  Respectively removes the class name from the element  ancestors(element)  Returns array with all parent nodes of the element (from the element towards the root)

 childOf (element, ancestor)  Returns boolean – if the element is descendant of ancestor  desendantOf method is the same  descendants (element)  Returns array with all child nodes (recursively) of the element  getElementsByClassName(element, className)  Returns array with all child elements that have the given className in their classes

 Methods  serialize(form) – returns url-formated list of field names and their values  Useful for sending the data over Ajax  getElements(form) – returns array with the input fields in the form  disable(form), enable(form) – disable / enable all the inputs in the form

 Contains methods for working with events  element(event) – returns reference to the element that fired the event  isLeftClick(event) – returns true if the left mouse button was clicked  pointerX(event), pointerY(event) – return the X/Y coordinate of mouse event  stop(event) – abort event execution and stop its propagation

 Event.observe(element, name, observer, useCapture) – attach event listener to element  element is id or element reference  name is the event type – "load", "click", etc.  observer is the function that will handle the event  useCapture – specify whether to use capture or bubbling event flow models  Event.stopObserving – remove event handler  Parameters must be exactly the same as specified in Event.observer