SlideShare a Scribd company logo
Julie Iskander, Lecturer at ITI
MSc. Communication and Electronics
LectureOutlines
 Object Oriented JavaScript Revision
 Prototype js
 Extending the DOM
 Elements dimensions
 Event Model
 Classes and inheritance
 JSON
 Ajax
OO JavaScript
Remember
 Everything is an Object
 Every Object can have instance methods
 All objects have prototype
 Functions are first-class Objects
 JavaScript is multi-paradigm language
 Imperative style of C
 Object oriented style of Java
 Functional style of Lisp
Prototype Framework
Prototype JS
Prototype
Prototype
 It is about the abstract not the concrete
 Many toolkits is built over it like script.aculo.us
$ Function
 $()  document.getElementById()
 $(‘menu’)  returns element with id=menu
 $(element)  if element is a node, it is returned back
 $(‘menu’,’menuitem1’,’menuitem2’)  return an array of 3
nodes id=menu and menuitem1 and menuitem2
 $ extends node returned with useful prototype node
methods
$$ Function
 $$(), selects node using CSS selectors, support CSS3 selectors
 $$(‘li’)  select all li elements
 $$(‘li.current’)  select all li elements of class=current
 $$(‘#menu a’) select element all a elements inside of
element with id=menu
 $$ extends nodes returned with useful prototype node
methods
Enumerable Object
 A mixin that provides methods useful for collections
 Use in the following classes
 Array
 Hash
 DOM- related objects
 Instance Methods:
 all; any; collect; detect; each; eachSlice; entries; every; filter;
find; find;All; grep; include; inGroupsOf; inject; inspect; invoke;
map; max; member; min; partition; pluck; reject; select; size;
some; sortBy; toArray; zip
each
 elem.each(Visitor object)
 Implements visitor on each element
 Example:
[1,3,4,7,89,6,3,4,5].each(function(elem)
{
alert(elem);
});
each
 Implement continue using return
 Example:
[1,3,4,7,89,6,3,4,5].each(function(elem)
{
if(elem>10)
return;
alert(elem);
});
each
 Implement break by throw $break
 Example:
[1,3,4,7,89,6,3,4,5].each(function(elem)
{
if(elem>10)
return;
if(elem==4)
throw $break;
alert(elem);
});
detect
 Takes function that returns true/false
 Returns first element that returns true
 If no match returns undefined
 Examples:
[1,3,4,6,8,0,9].detect(function(elem)
{
return elem==0
}));
 See also select, reject, partition
map
 Applies function on each element, pushes the
return into an array that is eventually returned
 Example:
[2, 5, 7, 9,50].map(function(item)
{
return item*item;
});
Extending DOM
Prototype’s DOM extension
Modifying properties of elements
Visibility
 .hide()
 .show()
 .visible()  returns true/false
 .toggle()
Prototype’s DOM extension
Modifying properties of elements
Style and classes
 .addClassName(‘class name’)
 .removeClassName(‘class name’)
 .hasClassName(‘class name’) returns true/false
 .toggleClassName(‘class name’)
 .setStyle({ prop:val,prop:val,……… })
 .getStyle(‘css property’)
Prototype’s DOM extension
Modifying DOM
.update(‘ ’)
Change content of element
.replace(‘ ’)
 Remove element and add a new one in its place
.insert(‘ ’), insert({top:’ ’,bottom:’ ‘, after:’
‘, before : ‘ ’ })
.remove()
Templates
Templates
 TheTemplate class uses a basic formatting syntax, similar to
Ruby.
 The templates are created from strings that use symbols in
the form (e.g., #{fieldName})
 The symbols are replaced by actual values when the
template is applied (evaluated) to an object.
Example
var myTemplate =
newTemplate('<p>The TV show #{title} was directed
by  #{author}.</p>');
// Create hashes with the required values for placeholders
var record1 = {title: 'Metrix', author:'Arun Pandey'};
var record2 = {title: 'Junoon', author:'Manusha'};
var record3 = {title: 'Red Moon', author:'Paul, John'};
var record4 = {title: 'Henai', author:'Robert'};
Example
var records = [record1, record2, record3, record4 ];
// Now apply template to produce desired formatted output
records.each( function(conv)
{
$$('p')[0].insert( {bottom: "<div>Formatted Output : " +
myTemplate.evaluate(conv)+"</div>" });
});
}
Prototype Framework
Form Management
Prototype Form Methods
 disable() Disables the form as whole. Form controls will
be visible but uneditable.
 enable() Enables a fully or partially disabled form.
Prototype Form Methods
 findFirstElement() Finds first non-hidden, non-disabled
form control.
 focusFirstElement() Gives keyboard focus to the first
element of the form.
 getElements() Returns a collection of all form controls
within a form.
Prototype Form Methods
 getInputs() Returns a collection of all INPUT elements in a
form. Use optional type and name arguments to restrict the
search on these attributes.
 request() A convenience method for serializing and
submitting the form via an Ajax.Request to the URL of the
form's action attribute.The options parameter is passed to
the Ajax.Request instance, allowing to override the HTTP
method and to specify additional parameters.
 reset() Resets a form to its default values.
Element Dimensions
Element Dimension
 Solve problem of inconsistent browser
measurements
 .measure(‘ property‘ )
 $(‘mydiv’).measure(‘width’)  pixel values
 For better performance, when measuring more than
one dimension
 .getLayout()  Layout object
 $(‘mydiv’).getLayout().get(‘width’);
 http://prototypejs.org/learn/element-layout
Event Model
Events
 A single model for all browsers
 Event.observe(element,’event’,function{}())
 Event.observe(window,’load’,function(){})
Element.observe
 $(‘ ’).observe(‘event’,function(){})
Events
 Can register events on elements or children of an
element.
 The selection of children is done using CSS-selectors
 Element.on
 $(‘ ’).on(‘event’,function(){})
 $(‘ ’).on(‘event’,’css selector for child’,function(){})
 $(‘item’).on(‘click’,’li’, function(){
………………
});
Event Object
 All event handlers are receive an event object
 function submitFun(evnt)
{
evnt.element() //returns element object that triggered event
evnt.preventDefault() //stop default behaviour
evnt.isLeftClick() or isRightClick() or isMiddleClick()
evnt.pointerX() or pointerY()
evnt.pointer()  object{x: , y: }
}
Classes and Inheritance
Class
 Manages Prototype’s class-based OOP system
 Class methods:
 create()
 Instance Methods:
 addMethods()
Class.create([superclass][, methods...])
 superclass (class): superclass to inherit from.
 method (object): an object (mix-in) that will be mixed-in to my
new class. Multiple mixins can be used, later mixins take
precedence.
 returns a constructor function that can be called using new
operator. It will invoke the initialize method.
 The object mixin must contain ‘initialize’ method to be called
when new is called.
Class.create()
var Person = Class.create({
initialize: function(name) { this.name = name; },
say: function(message) {
return this.name + ': ' + message;
}
});
Example
 Create your own class that’s mixed with
Enumerable
Var MyClass=Class.Create(Enumerable, {
initialize:function(){………….},
_each: function(iterator){
for(var i=0;i<……)
{
iterator(….);
}
}
});
JSON
Encoding
 Number#toJSON, String#toJSON,Array#toJSON, Hash#toJSON, Date#toJSON, and
Object.toJSON.
 var data = {name: 'Violet', occupation: 'character', age: 25 };
 Object.toJSON(data); //-> '{"name": "Violet", "occupation": "character", "age": 25}’
 For custom objects,
 Set toJSON method which will be used by Object.toJSON.
 var Person = Class.create({
 initialize: function(name) {
 this.name = name;
 },
 toJSON: function() {
 return ('My name is ' + this.name + ' and I am ' + this.age + ' years old.').toJSON();
 }
 });
 var john = new Person('John', 49);
 Object.toJSON(john); //-> '"My name is John and I am 49 years old.”’
Parsing
 String#evalJSON
 var data = '{ "name": "Violet", "occupation": "character"
}'.evalJSON();
 data.name; //-> "Violet”
Ajax
Ajax
 A wrapper class around the XMLHttpRequest
 Uses callbacks to handle different phases of the
asynchronous request.
 If requested page is a JavaScript code then it is automatically
evaluated and executed.
Ajax.Request
new Ajax.Request(URL, Option)
 URL : string representing the url to request
 Options hash
 method
 parameters
 contentType
 onSuccess
 onFailure
 For complete details:
 http://api.prototypejs.org/ajax/
Ajax.Updater
 Updates a portion of the DOM with external source
 new Ajax.Updater(ID , URL , Options)
 ID: the id of the element to be updated
 URL: url to fetch
 Options: hash same as previous
 insertion: Insertion.Top
Insertion.Bottom
Insertion.After
Insertion.Before
Ajax.PeriodicalUpdater
 Runs Updater in periodical Intervals to repeatedly fetch
content from the server.
 new Ajax.PeriodicalUpdater(ID, URL, Options)
 Same except Options
 frequency : interval in seconds
 decay : factor to multiply frequency by everytime the fetched
response is the same as the previously fetched.
 stop()
 start()
References
 http://prototypejs.org/
 Practical Prototype and script.aculo.us, Andrew
Dupont , 2008
Ad

More Related Content

What's hot (20)

jQuery
jQueryjQuery
jQuery
Julie Iskander
 
JavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashJavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and Lodash
Bret Little
 
Build your own entity with Drupal
Build your own entity with DrupalBuild your own entity with Drupal
Build your own entity with Drupal
Marco Vito Moscaritolo
 
DOM and Events
DOM and EventsDOM and Events
DOM and Events
Julie Iskander
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
saydin_soft
 
ActionScript3 collection query API proposal
ActionScript3 collection query API proposalActionScript3 collection query API proposal
ActionScript3 collection query API proposal
Slavisa Pokimica
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
Sasidhar Kothuru
 
#pugMi - DDD - Value objects
#pugMi - DDD - Value objects#pugMi - DDD - Value objects
#pugMi - DDD - Value objects
Simone Gentili
 
Ms Ajax Dom Element Class
Ms Ajax Dom Element ClassMs Ajax Dom Element Class
Ms Ajax Dom Element Class
jason hu 金良胡
 
jQuery 1.7 visual cheat sheet
jQuery 1.7 visual cheat sheetjQuery 1.7 visual cheat sheet
jQuery 1.7 visual cheat sheet
Jiby John
 
Jquery 17-visual-cheat-sheet1
Jquery 17-visual-cheat-sheet1Jquery 17-visual-cheat-sheet1
Jquery 17-visual-cheat-sheet1
Michael Andersen
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
Howard Lewis Ship
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونیاسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
Mohammad Reza Kamalifard
 
Drupal Entities - Emerging Patterns of Usage
Drupal Entities - Emerging Patterns of UsageDrupal Entities - Emerging Patterns of Usage
Drupal Entities - Emerging Patterns of Usage
Ronald Ashri
 
A evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no androidA evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no android
Rodrigo de Souza Castro
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
Marco Vito Moscaritolo
 
Python Metaclasses
Python MetaclassesPython Metaclasses
Python Metaclasses
Nikunj Parekh
 
Hello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesHello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and Classes
Cody Yun
 
OO in JavaScript
OO in JavaScriptOO in JavaScript
OO in JavaScript
Gunjan Kumar
 
JavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashJavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and Lodash
Bret Little
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
saydin_soft
 
ActionScript3 collection query API proposal
ActionScript3 collection query API proposalActionScript3 collection query API proposal
ActionScript3 collection query API proposal
Slavisa Pokimica
 
#pugMi - DDD - Value objects
#pugMi - DDD - Value objects#pugMi - DDD - Value objects
#pugMi - DDD - Value objects
Simone Gentili
 
jQuery 1.7 visual cheat sheet
jQuery 1.7 visual cheat sheetjQuery 1.7 visual cheat sheet
jQuery 1.7 visual cheat sheet
Jiby John
 
Jquery 17-visual-cheat-sheet1
Jquery 17-visual-cheat-sheet1Jquery 17-visual-cheat-sheet1
Jquery 17-visual-cheat-sheet1
Michael Andersen
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
Howard Lewis Ship
 
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونیاسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
Mohammad Reza Kamalifard
 
Drupal Entities - Emerging Patterns of Usage
Drupal Entities - Emerging Patterns of UsageDrupal Entities - Emerging Patterns of Usage
Drupal Entities - Emerging Patterns of Usage
Ronald Ashri
 
A evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no androidA evolução da persistência de dados (com sqlite) no android
A evolução da persistência de dados (com sqlite) no android
Rodrigo de Souza Castro
 
Hello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesHello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and Classes
Cody Yun
 

Similar to Prototype Framework (20)

Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
rsnarayanan
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
Pradeep Saraswathi
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
Subramanyan Murali
 
13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swing
Nataraj Dg
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick Lee
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
Ryunosuke SATO
 
droidparts
droidpartsdroidparts
droidparts
Droidcon Berlin
 
Javascript And J Query
Javascript And J QueryJavascript And J Query
Javascript And J Query
itsarsalan
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
Huiyi Yan
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using Room
Nelson Glauber Leal
 
Structuring React.js Components
Structuring React.js ComponentsStructuring React.js Components
Structuring React.js Components
Bartek Witczak
 
4Developers 2018: Structuring React components (Bartłomiej Witczak)
4Developers 2018: Structuring React components (Bartłomiej Witczak)4Developers 2018: Structuring React components (Bartłomiej Witczak)
4Developers 2018: Structuring React components (Bartłomiej Witczak)
PROIDEA
 
jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling
WebStackAcademy
 
How te bring common UI patterns to ADF
How te bring common UI patterns to ADFHow te bring common UI patterns to ADF
How te bring common UI patterns to ADF
Getting value from IoT, Integration and Data Analytics
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScript
kvangork
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
kvangork
 
DIWE - Advanced PHP Concepts
DIWE - Advanced PHP ConceptsDIWE - Advanced PHP Concepts
DIWE - Advanced PHP Concepts
Rasan Samarasinghe
 
Backbone Basics with Examples
Backbone Basics with ExamplesBackbone Basics with Examples
Backbone Basics with Examples
Sergey Bolshchikov
 
How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF
Luc Bors
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
rsnarayanan
 
13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swing
Nataraj Dg
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick Lee
 
Javascript And J Query
Javascript And J QueryJavascript And J Query
Javascript And J Query
itsarsalan
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
Huiyi Yan
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using Room
Nelson Glauber Leal
 
Structuring React.js Components
Structuring React.js ComponentsStructuring React.js Components
Structuring React.js Components
Bartek Witczak
 
4Developers 2018: Structuring React components (Bartłomiej Witczak)
4Developers 2018: Structuring React components (Bartłomiej Witczak)4Developers 2018: Structuring React components (Bartłomiej Witczak)
4Developers 2018: Structuring React components (Bartłomiej Witczak)
PROIDEA
 
jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling
WebStackAcademy
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScript
kvangork
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
kvangork
 
How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF
Luc Bors
 
Ad

More from Julie Iskander (20)

HTML 5
HTML 5HTML 5
HTML 5
Julie Iskander
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Julie Iskander
 
C for Engineers
C for EngineersC for Engineers
C for Engineers
Julie Iskander
 
Design Pattern lecture 3
Design Pattern lecture 3Design Pattern lecture 3
Design Pattern lecture 3
Julie Iskander
 
Scriptaculous
ScriptaculousScriptaculous
Scriptaculous
Julie Iskander
 
Design Pattern lecture 4
Design Pattern lecture 4Design Pattern lecture 4
Design Pattern lecture 4
Julie Iskander
 
Design Pattern lecture 2
Design Pattern lecture 2Design Pattern lecture 2
Design Pattern lecture 2
Julie Iskander
 
Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1
Julie Iskander
 
Ajax and ASP.NET AJAX
Ajax and ASP.NET AJAXAjax and ASP.NET AJAX
Ajax and ASP.NET AJAX
Julie Iskander
 
ASP.NET Lecture 5
ASP.NET Lecture 5ASP.NET Lecture 5
ASP.NET Lecture 5
Julie Iskander
 
ASP.NET lecture 8
ASP.NET lecture 8ASP.NET lecture 8
ASP.NET lecture 8
Julie Iskander
 
ASP.NET Lecture 7
ASP.NET Lecture 7ASP.NET Lecture 7
ASP.NET Lecture 7
Julie Iskander
 
ASP.NET Lecture 6
ASP.NET Lecture 6ASP.NET Lecture 6
ASP.NET Lecture 6
Julie Iskander
 
ASP.NET Lecture 4
ASP.NET Lecture 4ASP.NET Lecture 4
ASP.NET Lecture 4
Julie Iskander
 
ASP.NET Lecture 3
ASP.NET Lecture 3ASP.NET Lecture 3
ASP.NET Lecture 3
Julie Iskander
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
Julie Iskander
 
ASP.NET Lecture 1
ASP.NET Lecture 1ASP.NET Lecture 1
ASP.NET Lecture 1
Julie Iskander
 
AJAX and JSON
AJAX and JSONAJAX and JSON
AJAX and JSON
Julie Iskander
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
Julie Iskander
 
HTML and CSS part 3
HTML and CSS part 3HTML and CSS part 3
HTML and CSS part 3
Julie Iskander
 
Ad

Recently uploaded (20)

The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 

Prototype Framework

  • 1. Julie Iskander, Lecturer at ITI MSc. Communication and Electronics
  • 2. LectureOutlines  Object Oriented JavaScript Revision  Prototype js  Extending the DOM  Elements dimensions  Event Model  Classes and inheritance  JSON  Ajax
  • 4. Remember  Everything is an Object  Every Object can have instance methods  All objects have prototype  Functions are first-class Objects  JavaScript is multi-paradigm language  Imperative style of C  Object oriented style of Java  Functional style of Lisp
  • 8. Prototype  It is about the abstract not the concrete  Many toolkits is built over it like script.aculo.us
  • 9. $ Function  $()  document.getElementById()  $(‘menu’)  returns element with id=menu  $(element)  if element is a node, it is returned back  $(‘menu’,’menuitem1’,’menuitem2’)  return an array of 3 nodes id=menu and menuitem1 and menuitem2  $ extends node returned with useful prototype node methods
  • 10. $$ Function  $$(), selects node using CSS selectors, support CSS3 selectors  $$(‘li’)  select all li elements  $$(‘li.current’)  select all li elements of class=current  $$(‘#menu a’) select element all a elements inside of element with id=menu  $$ extends nodes returned with useful prototype node methods
  • 11. Enumerable Object  A mixin that provides methods useful for collections  Use in the following classes  Array  Hash  DOM- related objects  Instance Methods:  all; any; collect; detect; each; eachSlice; entries; every; filter; find; find;All; grep; include; inGroupsOf; inject; inspect; invoke; map; max; member; min; partition; pluck; reject; select; size; some; sortBy; toArray; zip
  • 12. each  elem.each(Visitor object)  Implements visitor on each element  Example: [1,3,4,7,89,6,3,4,5].each(function(elem) { alert(elem); });
  • 13. each  Implement continue using return  Example: [1,3,4,7,89,6,3,4,5].each(function(elem) { if(elem>10) return; alert(elem); });
  • 14. each  Implement break by throw $break  Example: [1,3,4,7,89,6,3,4,5].each(function(elem) { if(elem>10) return; if(elem==4) throw $break; alert(elem); });
  • 15. detect  Takes function that returns true/false  Returns first element that returns true  If no match returns undefined  Examples: [1,3,4,6,8,0,9].detect(function(elem) { return elem==0 }));  See also select, reject, partition
  • 16. map  Applies function on each element, pushes the return into an array that is eventually returned  Example: [2, 5, 7, 9,50].map(function(item) { return item*item; });
  • 18. Prototype’s DOM extension Modifying properties of elements Visibility  .hide()  .show()  .visible()  returns true/false  .toggle()
  • 19. Prototype’s DOM extension Modifying properties of elements Style and classes  .addClassName(‘class name’)  .removeClassName(‘class name’)  .hasClassName(‘class name’) returns true/false  .toggleClassName(‘class name’)  .setStyle({ prop:val,prop:val,……… })  .getStyle(‘css property’)
  • 20. Prototype’s DOM extension Modifying DOM .update(‘ ’) Change content of element .replace(‘ ’)  Remove element and add a new one in its place .insert(‘ ’), insert({top:’ ’,bottom:’ ‘, after:’ ‘, before : ‘ ’ }) .remove()
  • 22. Templates  TheTemplate class uses a basic formatting syntax, similar to Ruby.  The templates are created from strings that use symbols in the form (e.g., #{fieldName})  The symbols are replaced by actual values when the template is applied (evaluated) to an object.
  • 23. Example var myTemplate = newTemplate('<p>The TV show #{title} was directed by #{author}.</p>'); // Create hashes with the required values for placeholders var record1 = {title: 'Metrix', author:'Arun Pandey'}; var record2 = {title: 'Junoon', author:'Manusha'}; var record3 = {title: 'Red Moon', author:'Paul, John'}; var record4 = {title: 'Henai', author:'Robert'};
  • 24. Example var records = [record1, record2, record3, record4 ]; // Now apply template to produce desired formatted output records.each( function(conv) { $$('p')[0].insert( {bottom: "<div>Formatted Output : " + myTemplate.evaluate(conv)+"</div>" }); }); }
  • 27. Prototype Form Methods  disable() Disables the form as whole. Form controls will be visible but uneditable.  enable() Enables a fully or partially disabled form.
  • 28. Prototype Form Methods  findFirstElement() Finds first non-hidden, non-disabled form control.  focusFirstElement() Gives keyboard focus to the first element of the form.  getElements() Returns a collection of all form controls within a form.
  • 29. Prototype Form Methods  getInputs() Returns a collection of all INPUT elements in a form. Use optional type and name arguments to restrict the search on these attributes.  request() A convenience method for serializing and submitting the form via an Ajax.Request to the URL of the form's action attribute.The options parameter is passed to the Ajax.Request instance, allowing to override the HTTP method and to specify additional parameters.  reset() Resets a form to its default values.
  • 31. Element Dimension  Solve problem of inconsistent browser measurements  .measure(‘ property‘ )  $(‘mydiv’).measure(‘width’)  pixel values  For better performance, when measuring more than one dimension  .getLayout()  Layout object  $(‘mydiv’).getLayout().get(‘width’);  http://prototypejs.org/learn/element-layout
  • 33. Events  A single model for all browsers  Event.observe(element,’event’,function{}())  Event.observe(window,’load’,function(){}) Element.observe  $(‘ ’).observe(‘event’,function(){})
  • 34. Events  Can register events on elements or children of an element.  The selection of children is done using CSS-selectors  Element.on  $(‘ ’).on(‘event’,function(){})  $(‘ ’).on(‘event’,’css selector for child’,function(){})  $(‘item’).on(‘click’,’li’, function(){ ……………… });
  • 35. Event Object  All event handlers are receive an event object  function submitFun(evnt) { evnt.element() //returns element object that triggered event evnt.preventDefault() //stop default behaviour evnt.isLeftClick() or isRightClick() or isMiddleClick() evnt.pointerX() or pointerY() evnt.pointer()  object{x: , y: } }
  • 37. Class  Manages Prototype’s class-based OOP system  Class methods:  create()  Instance Methods:  addMethods()
  • 38. Class.create([superclass][, methods...])  superclass (class): superclass to inherit from.  method (object): an object (mix-in) that will be mixed-in to my new class. Multiple mixins can be used, later mixins take precedence.  returns a constructor function that can be called using new operator. It will invoke the initialize method.  The object mixin must contain ‘initialize’ method to be called when new is called.
  • 39. Class.create() var Person = Class.create({ initialize: function(name) { this.name = name; }, say: function(message) { return this.name + ': ' + message; } });
  • 40. Example  Create your own class that’s mixed with Enumerable
  • 41. Var MyClass=Class.Create(Enumerable, { initialize:function(){………….}, _each: function(iterator){ for(var i=0;i<……) { iterator(….); } } });
  • 42. JSON
  • 43. Encoding  Number#toJSON, String#toJSON,Array#toJSON, Hash#toJSON, Date#toJSON, and Object.toJSON.  var data = {name: 'Violet', occupation: 'character', age: 25 };  Object.toJSON(data); //-> '{"name": "Violet", "occupation": "character", "age": 25}’  For custom objects,  Set toJSON method which will be used by Object.toJSON.  var Person = Class.create({  initialize: function(name) {  this.name = name;  },  toJSON: function() {  return ('My name is ' + this.name + ' and I am ' + this.age + ' years old.').toJSON();  }  });  var john = new Person('John', 49);  Object.toJSON(john); //-> '"My name is John and I am 49 years old.”’
  • 44. Parsing  String#evalJSON  var data = '{ "name": "Violet", "occupation": "character" }'.evalJSON();  data.name; //-> "Violet”
  • 45. Ajax
  • 46. Ajax  A wrapper class around the XMLHttpRequest  Uses callbacks to handle different phases of the asynchronous request.  If requested page is a JavaScript code then it is automatically evaluated and executed.
  • 47. Ajax.Request new Ajax.Request(URL, Option)  URL : string representing the url to request  Options hash  method  parameters  contentType  onSuccess  onFailure  For complete details:  http://api.prototypejs.org/ajax/
  • 48. Ajax.Updater  Updates a portion of the DOM with external source  new Ajax.Updater(ID , URL , Options)  ID: the id of the element to be updated  URL: url to fetch  Options: hash same as previous  insertion: Insertion.Top Insertion.Bottom Insertion.After Insertion.Before
  • 49. Ajax.PeriodicalUpdater  Runs Updater in periodical Intervals to repeatedly fetch content from the server.  new Ajax.PeriodicalUpdater(ID, URL, Options)  Same except Options  frequency : interval in seconds  decay : factor to multiply frequency by everytime the fetched response is the same as the previously fetched.  stop()  start()
  • 50. References  http://prototypejs.org/  Practical Prototype and script.aculo.us, Andrew Dupont , 2008