SlideShare a Scribd company logo
1 of 39
Download to read offline
Why not use Prototype, jQuery, etc.
Lots of code = long time to download
Caching on mobile devices is not so great
Most code is for browsers that you don’t need to
support (IE6 doesn’t run on an iPhone!)
Natively supported features are duplicated,
for example JSON support and animations
Goals for a mobile
JavaScript framework
Very small codebase
Easy to use API for common DOM tasks
Easy to extend & customize
No need to deal with browser cruft (IE6, etc)
Inlineable
http://en.wikipedia.org/wiki/Aerogel
0.002kg
2.5kg
Size: ~2K
jQuery-compatible API
Uses mobile WebKit features as much as possible
Easily replaceable with larger libs if your app grows
Open source (MIT license)
$('p').html('test').css('color:red');
get(): return array of all elements found
get(0): return first element found
each(callback): iterate over array of all elements found
index('selector'): return an integer indicating the position of 'selector' in array of all elements found
first(): remove all but the first element from the list of found elements
find('selector'): find all children/grandchildren that match the given selector
closest('selector'): traverses the DOM upwards to find the first matching element
next(): next siblings
prev(): previous siblings
is('selector'): returns true/false if first element matches the selector
remove(): remove element
html('new html'): set the contents of the element(s)
append, prepend, before, after: like html, but add html to element contents (or before/after)
html(): get first elements .innerHTML
show(): forces elements to be displayed (only works correctly for block elements right now)
hide(): removes a elements from layout
offset(): get object with top: left: width: height: properties (in px)
height(): get first elements height in px
width(): get first elements width in px
attr('attribute'): get element attribute
attr('attribute', 'value'): set element attribute
css('css property', 'value'): set a CSS property
css({ property1: value1, property2: value2 }): set multiple CSS properties
css('css property'): get this CSS property of the first element
addClass('classname'): adds a CSS class name
removeClass('classname'): removes a CSS class name
hasClass('classname'): returns true of first element has a classname set
bind(type, function): add an event listener (see below)
delegate(selector, type, function): add an event listener w/ event delegation (see below)
live(type, function): add an event listener that listens to the selector for current and future elements
trigger(type): triggers an event
get(): return array of all elements found
get(0): return first element found
each(callback): iterate over array of all elements found
index('selector'): return an integer indicating the position of 'selector' in array of all elements found
first(): remove all but the first element from the list of found elements
find('selector'): find all children/grandchildren that match the given selector
closest('selector'): traverses the DOM upwards to find the first matching element
next(): next siblings
prev(): previous siblings
is('selector'): returns true/false if first element matches the selector
remove(): remove element
html('new html'): set the contents of the element(s)
append, prepend, before, after: like html, but add html to element contents (or before/after)
html(): get first elements .innerHTML
show(): forces elements to be displayed (only works correctly for block elements right now)
hide(): removes a elements from layout
offset(): get object with top: left: width: height: properties (in px)
height(): get first elements height in px
width(): get first elements width in px
attr('attribute'): get element attribute
attr('attribute', 'value'): set element attribute
css('css property', 'value'): set a CSS property
css({ property1: value1, property2: value2 }): set multiple CSS properties
css('css property'): get this CSS property of the first element
addClass('classname'): adds a CSS class name
removeClass('classname'): removes a CSS class name
hasClass('classname'): returns true of first element has a classname set
bind(type, function): add an event listener (see below)
delegate(selector, type, function): add an event listener w/ event delegation (see below)
live(type, function): add an event listener that listens to the selector for current and future elements
trigger(type): triggers an event
Basically, everything
$.get(url, callback)
$.post(url, callback)
$.getJSON(url, callback)
$('selector').load('url'[, callback]);
$('selector').load('url #fragment-selector'[, callback]);
Ajax
$('some selector').tap(function(){ ... });
$('some selector').doubleTap(function(){ ... });
$('some selector').swipe(function(){ ... });
Tap & Swipe
Uncompresed Minified Minified & Gzipped
0K
50K
100K
150K
200K
180K
160K
9K
78K 87K
6K
27K
27K
2K
Uncompresed Minified Minified & Gzipped
0K
50K
100K
150K
200K
180K
160K
9K
78K 87K
6K
27K
27K
2K
Uncompresed Minified Minified & Gzipped
jQuery
0K
50K
100K
150K
200K
180K
160K
9K
78K 87K
6K
27K
27K
2K
Uncompresed Minified Minified & Gzipped
jQuery
Prototype
0K
50K
100K
150K
200K
180K
160K
9K
78K 87K
6K
27K
27K
2K
Uncompresed Minified Minified & Gzipped
jQuery
Prototype
Zepto.js
Uncompresed Minified Minified & Gzipped
8.788K
5.816K
2.368K
Uncompresed Minified Minified & Gzipped
var $ = function(selector){
return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)),
anim: $.anim, css: $.css, html: $.html };
}
$.html = function(html){
this.dom.forEach(function(el){ el.innerHTML = html }); return this;
}
$.css = function(style){
this.dom.forEach(function(el){ el.style.cssText += ';'+style }); return this;
}
Core implementation (simplified)
var $ = function(selector){
return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)),
anim: $.anim, css: $.css, html: $.html };
}
$.html = function(html){
this.dom.forEach(function(el){ el.innerHTML = html }); return this;
}
$.css = function(style){
this.dom.forEach(function(el){ el.style.cssText += ';'+style }); return this;
}
$(‘some CSS selector’)
var $ = function(selector){
return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)),
anim: $.anim, css: $.css, html: $.html };
}
$.html = function(html){
this.dom.forEach(function(el){ el.innerHTML = html }); return this;
}
$.css = function(style){
this.dom.forEach(function(el){ el.style.cssText += ';'+style }); return this;
}
returns a zepto.js object
var $ = function(selector){
return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)),
anim: $.anim, css: $.css, html: $.html };
}
$.html = function(html){
this.dom.forEach(function(el){ el.innerHTML = html }); return this;
}
$.css = function(style){
this.dom.forEach(function(el){ el.style.cssText += ';'+style }); return this;
}
html(‘new html’) sets the contents
of one or more elements
css(‘style’) sets the style of
one or more elements
var $ = function(selector){
return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)),
anim: $.anim, css: $.css, html: $.html };
}
$.html = function(html){
this.dom.forEach(function(el){ el.innerHTML = html }); return this;
}
$.css = function(style){
this.dom.forEach(function(el){ el.style.cssText += ';'+style }); return this;
}
var $ = function(selector){
return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)),
anim: $.anim, css: $.css, html: $.html };
}
How $() works
var $ = function(selector){
return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)),
anim: $.anim, css: $.css, html: $.html };
}
select elements on the page as per
the user-specified CSS selector
$('p')
How $() works
var $ = function(selector){
return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)),
anim: $.anim, css: $.css, html: $.html };
}
return a “zepto” object
{
dom: [/* element 1, element 2, element 3, etc.*/],
css: $.css, html: $.html
}
How $() works
(cc) http://www.flickr.com/photos/gloson/4594527045
$.html = function(html){
this.dom.forEach(function(el){ el.innerHTML = html }); return this;
}
How a chainable function works
this.dom refers to the nodes
selected by the call to $
How a chainable function works
$.html = function(html){
this.dom.forEach(function(el){ el.innerHTML = html }); return this;
}
forEach iterates over all the nodes
(nodelist was converted to an array)
How a chainable function works
$.html = function(html){
this.dom.forEach(function(el){ el.innerHTML = html }); return this;
}
set the contents of the node to
some specificed html
How a chainable function works
$.html = function(html){
this.dom.forEach(function(el){ el.innerHTML = html }); return this;
}
return the “zepto” object
for chaining
How a chainable function works
$.html = function(html){
this.dom.forEach(function(el){ el.innerHTML = html }); return this;
}
Inlining FTW
<!DOCTYPE html>
<html>
<head>
<title>Zepto.js</title>
<script>
// stick all JS stuff in here
</script>
</head>
<body>
<p>
Blah
</p>
<p>
Blub
</p>
<script>
$('p').html('test').css('color:red');
</script>
</body>
</html>
function $$(el, selector){
return slice.call(el.querySelectorAll(selector))
}
function compact(array){
return array.filter(function(el){
return el !== void 0 && el !== null
})
}
function $(_, context){
if(context !== void 0) return $(context).find(_);
function fn(_){ return fn.dom.forEach(_), fn }
fn.dom = compact((typeof _ == 'function' && 'dom' in _) ?
_.dom : (_ instanceof Array ? _ :
(_ instanceof Element ? [_] :
$$(d, fn.selector = _))));
$.extend(fn, $.fn);
return fn;
}
Only targets mobile browsers
Minimalist, jQuery-ish framework
Use WebKit features as much as possible
Can be “upgraded”
Inlineable
http://zeptojs.com/

More Related Content

What's hot

History of jQuery
History of jQueryHistory of jQuery
History of jQueryjeresig
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Thinqloud
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQueryRemy Sharp
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
Testing Web Applications with GEB
Testing Web Applications with GEBTesting Web Applications with GEB
Testing Web Applications with GEBHoward Lewis Ship
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery PresentationRod Johnson
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIsRemy Sharp
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuerySudar Muthu
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryZeeshan Khan
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoiddmethvin
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryGunjan Kumar
 

What's hot (20)

History of jQuery
History of jQueryHistory of jQuery
History of jQuery
 
jQuery
jQueryjQuery
jQuery
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
Jquery
JqueryJquery
Jquery
 
jQuery
jQueryjQuery
jQuery
 
jQuery
jQueryjQuery
jQuery
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Testing Web Applications with GEB
Testing Web Applications with GEBTesting Web Applications with GEB
Testing Web Applications with GEB
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIs
 
The jQuery Divide
The jQuery DivideThe jQuery Divide
The jQuery Divide
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoid
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 

Viewers also liked

The Beauty Of The White Mountains In New Hampshire
The Beauty Of The White Mountains In New HampshireThe Beauty Of The White Mountains In New Hampshire
The Beauty Of The White Mountains In New HampshireTiffany Kate Roth
 
Published Sox9 Paper!
Published Sox9 Paper!Published Sox9 Paper!
Published Sox9 Paper!Tim Rutkowski
 
Optical flares installation
Optical flares installationOptical flares installation
Optical flares installationgalamo11
 
Hands Down Teacher's Worksheet
Hands Down Teacher's WorksheetHands Down Teacher's Worksheet
Hands Down Teacher's WorksheetEOI GAMES
 
Examples of successful simulation in the development cycly of Kolektor Etra
Examples of successful simulation in the development cycly of Kolektor EtraExamples of successful simulation in the development cycly of Kolektor Etra
Examples of successful simulation in the development cycly of Kolektor EtraSIMTEC Software and Services
 
6847575 a-saga-dos-foxworth-4-sementes-do-passado-virginia-c-andrews
6847575 a-saga-dos-foxworth-4-sementes-do-passado-virginia-c-andrews6847575 a-saga-dos-foxworth-4-sementes-do-passado-virginia-c-andrews
6847575 a-saga-dos-foxworth-4-sementes-do-passado-virginia-c-andrewsAlessandra Vidal
 
Ratib al haddad(revised-2011)
Ratib al haddad(revised-2011)Ratib al haddad(revised-2011)
Ratib al haddad(revised-2011)Zhulkeflee Ismail
 
Simple present for schedules
Simple present for schedulesSimple present for schedules
Simple present for schedulesNadia Espinosa
 
X2 t08 04 inequality techniques (2012)
X2 t08 04 inequality techniques (2012)X2 t08 04 inequality techniques (2012)
X2 t08 04 inequality techniques (2012)Nigel Simmons
 
Strategic Management Ch05
Strategic Management Ch05Strategic Management Ch05
Strategic Management Ch05Chuong Nguyen
 

Viewers also liked (20)

Service!
Service!Service!
Service!
 
Boe February 10 2009 Agenda
Boe February 10 2009 AgendaBoe February 10 2009 Agenda
Boe February 10 2009 Agenda
 
4 p xopoo
4 p xopoo4 p xopoo
4 p xopoo
 
Escala digital
Escala digitalEscala digital
Escala digital
 
KV Menu 6-25-2015
KV Menu 6-25-2015KV Menu 6-25-2015
KV Menu 6-25-2015
 
Ppt32
Ppt32Ppt32
Ppt32
 
The Beauty Of The White Mountains In New Hampshire
The Beauty Of The White Mountains In New HampshireThe Beauty Of The White Mountains In New Hampshire
The Beauty Of The White Mountains In New Hampshire
 
Published Sox9 Paper!
Published Sox9 Paper!Published Sox9 Paper!
Published Sox9 Paper!
 
Optical flares installation
Optical flares installationOptical flares installation
Optical flares installation
 
Hands Down Teacher's Worksheet
Hands Down Teacher's WorksheetHands Down Teacher's Worksheet
Hands Down Teacher's Worksheet
 
Examples of successful simulation in the development cycly of Kolektor Etra
Examples of successful simulation in the development cycly of Kolektor EtraExamples of successful simulation in the development cycly of Kolektor Etra
Examples of successful simulation in the development cycly of Kolektor Etra
 
6847575 a-saga-dos-foxworth-4-sementes-do-passado-virginia-c-andrews
6847575 a-saga-dos-foxworth-4-sementes-do-passado-virginia-c-andrews6847575 a-saga-dos-foxworth-4-sementes-do-passado-virginia-c-andrews
6847575 a-saga-dos-foxworth-4-sementes-do-passado-virginia-c-andrews
 
Ratib al haddad(revised-2011)
Ratib al haddad(revised-2011)Ratib al haddad(revised-2011)
Ratib al haddad(revised-2011)
 
Fgcfg
FgcfgFgcfg
Fgcfg
 
Simple present for schedules
Simple present for schedulesSimple present for schedules
Simple present for schedules
 
X2 t08 04 inequality techniques (2012)
X2 t08 04 inequality techniques (2012)X2 t08 04 inequality techniques (2012)
X2 t08 04 inequality techniques (2012)
 
INGLES A1
INGLES A1INGLES A1
INGLES A1
 
Strategic Management Ch05
Strategic Management Ch05Strategic Management Ch05
Strategic Management Ch05
 
Chinese stone lions
Chinese stone lionsChinese stone lions
Chinese stone lions
 
Easy but Difficult
Easy but DifficultEasy but Difficult
Easy but Difficult
 

Similar to Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K

Similar to Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K (20)

Javascript And J Query
Javascript And J QueryJavascript And J Query
Javascript And J Query
 
Prototype Framework
Prototype FrameworkPrototype Framework
Prototype Framework
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuery
 
jQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusionjQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusion
 
J Query
J QueryJ Query
J Query
 
Scala on Your Phone
Scala on Your PhoneScala on Your Phone
Scala on Your Phone
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
J query training
J query trainingJ query training
J query training
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
jQuery
jQueryjQuery
jQuery
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
 
jQuery
jQueryjQuery
jQuery
 
JQuery
JQueryJQuery
JQuery
 
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
 
jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling
 
JavaScript JQUERY AJAX
JavaScript JQUERY AJAXJavaScript JQUERY AJAX
JavaScript JQUERY AJAX
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using Room
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQuery
 

More from Thomas Fuchs

Zepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksZepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksThomas Fuchs
 
I Can't Believe It's Not Flash
I Can't Believe It's Not FlashI Can't Believe It's Not Flash
I Can't Believe It's Not FlashThomas Fuchs
 
Prototype & Scriptaculous
Prototype  & ScriptaculousPrototype  & Scriptaculous
Prototype & ScriptaculousThomas Fuchs
 
Extreme JavaScript Performance
Extreme JavaScript PerformanceExtreme JavaScript Performance
Extreme JavaScript PerformanceThomas Fuchs
 
Adventures In JavaScript Testing
Adventures In JavaScript TestingAdventures In JavaScript Testing
Adventures In JavaScript TestingThomas Fuchs
 
Ruby On Rails Introduction
Ruby On Rails IntroductionRuby On Rails Introduction
Ruby On Rails IntroductionThomas Fuchs
 
Rich and Snappy Apps (No Scaling Required)
Rich and Snappy Apps (No Scaling Required)Rich and Snappy Apps (No Scaling Required)
Rich and Snappy Apps (No Scaling Required)Thomas Fuchs
 

More from Thomas Fuchs (9)

Zepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-FrameworksZepto and the rise of the JavaScript Micro-Frameworks
Zepto and the rise of the JavaScript Micro-Frameworks
 
I Can't Believe It's Not Flash
I Can't Believe It's Not FlashI Can't Believe It's Not Flash
I Can't Believe It's Not Flash
 
Prototype & Scriptaculous
Prototype  & ScriptaculousPrototype  & Scriptaculous
Prototype & Scriptaculous
 
Extreme JavaScript Performance
Extreme JavaScript PerformanceExtreme JavaScript Performance
Extreme JavaScript Performance
 
Textorize
TextorizeTextorize
Textorize
 
Adventures In JavaScript Testing
Adventures In JavaScript TestingAdventures In JavaScript Testing
Adventures In JavaScript Testing
 
Ruby On Rails Introduction
Ruby On Rails IntroductionRuby On Rails Introduction
Ruby On Rails Introduction
 
Twistori Tech
Twistori TechTwistori Tech
Twistori Tech
 
Rich and Snappy Apps (No Scaling Required)
Rich and Snappy Apps (No Scaling Required)Rich and Snappy Apps (No Scaling Required)
Rich and Snappy Apps (No Scaling Required)
 

Recently uploaded

Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 

Recently uploaded (20)

Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 

Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K

  • 1.
  • 2.
  • 3.
  • 4. Why not use Prototype, jQuery, etc. Lots of code = long time to download Caching on mobile devices is not so great Most code is for browsers that you don’t need to support (IE6 doesn’t run on an iPhone!) Natively supported features are duplicated, for example JSON support and animations
  • 5. Goals for a mobile JavaScript framework Very small codebase Easy to use API for common DOM tasks Easy to extend & customize No need to deal with browser cruft (IE6, etc) Inlineable
  • 6.
  • 7.
  • 8.
  • 10. Size: ~2K jQuery-compatible API Uses mobile WebKit features as much as possible Easily replaceable with larger libs if your app grows Open source (MIT license)
  • 12. get(): return array of all elements found get(0): return first element found each(callback): iterate over array of all elements found index('selector'): return an integer indicating the position of 'selector' in array of all elements found first(): remove all but the first element from the list of found elements find('selector'): find all children/grandchildren that match the given selector closest('selector'): traverses the DOM upwards to find the first matching element next(): next siblings prev(): previous siblings is('selector'): returns true/false if first element matches the selector remove(): remove element html('new html'): set the contents of the element(s) append, prepend, before, after: like html, but add html to element contents (or before/after) html(): get first elements .innerHTML show(): forces elements to be displayed (only works correctly for block elements right now) hide(): removes a elements from layout offset(): get object with top: left: width: height: properties (in px) height(): get first elements height in px width(): get first elements width in px attr('attribute'): get element attribute attr('attribute', 'value'): set element attribute css('css property', 'value'): set a CSS property css({ property1: value1, property2: value2 }): set multiple CSS properties css('css property'): get this CSS property of the first element addClass('classname'): adds a CSS class name removeClass('classname'): removes a CSS class name hasClass('classname'): returns true of first element has a classname set bind(type, function): add an event listener (see below) delegate(selector, type, function): add an event listener w/ event delegation (see below) live(type, function): add an event listener that listens to the selector for current and future elements trigger(type): triggers an event
  • 13. get(): return array of all elements found get(0): return first element found each(callback): iterate over array of all elements found index('selector'): return an integer indicating the position of 'selector' in array of all elements found first(): remove all but the first element from the list of found elements find('selector'): find all children/grandchildren that match the given selector closest('selector'): traverses the DOM upwards to find the first matching element next(): next siblings prev(): previous siblings is('selector'): returns true/false if first element matches the selector remove(): remove element html('new html'): set the contents of the element(s) append, prepend, before, after: like html, but add html to element contents (or before/after) html(): get first elements .innerHTML show(): forces elements to be displayed (only works correctly for block elements right now) hide(): removes a elements from layout offset(): get object with top: left: width: height: properties (in px) height(): get first elements height in px width(): get first elements width in px attr('attribute'): get element attribute attr('attribute', 'value'): set element attribute css('css property', 'value'): set a CSS property css({ property1: value1, property2: value2 }): set multiple CSS properties css('css property'): get this CSS property of the first element addClass('classname'): adds a CSS class name removeClass('classname'): removes a CSS class name hasClass('classname'): returns true of first element has a classname set bind(type, function): add an event listener (see below) delegate(selector, type, function): add an event listener w/ event delegation (see below) live(type, function): add an event listener that listens to the selector for current and future elements trigger(type): triggers an event Basically, everything
  • 14. $.get(url, callback) $.post(url, callback) $.getJSON(url, callback) $('selector').load('url'[, callback]); $('selector').load('url #fragment-selector'[, callback]); Ajax
  • 15. $('some selector').tap(function(){ ... }); $('some selector').doubleTap(function(){ ... }); $('some selector').swipe(function(){ ... }); Tap & Swipe
  • 23. var $ = function(selector){ return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)), anim: $.anim, css: $.css, html: $.html }; } $.html = function(html){ this.dom.forEach(function(el){ el.innerHTML = html }); return this; } $.css = function(style){ this.dom.forEach(function(el){ el.style.cssText += ';'+style }); return this; } Core implementation (simplified)
  • 24. var $ = function(selector){ return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)), anim: $.anim, css: $.css, html: $.html }; } $.html = function(html){ this.dom.forEach(function(el){ el.innerHTML = html }); return this; } $.css = function(style){ this.dom.forEach(function(el){ el.style.cssText += ';'+style }); return this; } $(‘some CSS selector’)
  • 25. var $ = function(selector){ return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)), anim: $.anim, css: $.css, html: $.html }; } $.html = function(html){ this.dom.forEach(function(el){ el.innerHTML = html }); return this; } $.css = function(style){ this.dom.forEach(function(el){ el.style.cssText += ';'+style }); return this; } returns a zepto.js object
  • 26. var $ = function(selector){ return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)), anim: $.anim, css: $.css, html: $.html }; } $.html = function(html){ this.dom.forEach(function(el){ el.innerHTML = html }); return this; } $.css = function(style){ this.dom.forEach(function(el){ el.style.cssText += ';'+style }); return this; } html(‘new html’) sets the contents of one or more elements
  • 27. css(‘style’) sets the style of one or more elements var $ = function(selector){ return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)), anim: $.anim, css: $.css, html: $.html }; } $.html = function(html){ this.dom.forEach(function(el){ el.innerHTML = html }); return this; } $.css = function(style){ this.dom.forEach(function(el){ el.style.cssText += ';'+style }); return this; }
  • 28. var $ = function(selector){ return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)), anim: $.anim, css: $.css, html: $.html }; } How $() works
  • 29. var $ = function(selector){ return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)), anim: $.anim, css: $.css, html: $.html }; } select elements on the page as per the user-specified CSS selector $('p') How $() works
  • 30. var $ = function(selector){ return { dom: Array.prototype.slice.apply(document.querySelectorAll(selector)), anim: $.anim, css: $.css, html: $.html }; } return a “zepto” object { dom: [/* element 1, element 2, element 3, etc.*/], css: $.css, html: $.html } How $() works
  • 32. $.html = function(html){ this.dom.forEach(function(el){ el.innerHTML = html }); return this; } How a chainable function works
  • 33. this.dom refers to the nodes selected by the call to $ How a chainable function works $.html = function(html){ this.dom.forEach(function(el){ el.innerHTML = html }); return this; }
  • 34. forEach iterates over all the nodes (nodelist was converted to an array) How a chainable function works $.html = function(html){ this.dom.forEach(function(el){ el.innerHTML = html }); return this; }
  • 35. set the contents of the node to some specificed html How a chainable function works $.html = function(html){ this.dom.forEach(function(el){ el.innerHTML = html }); return this; }
  • 36. return the “zepto” object for chaining How a chainable function works $.html = function(html){ this.dom.forEach(function(el){ el.innerHTML = html }); return this; }
  • 37. Inlining FTW <!DOCTYPE html> <html> <head> <title>Zepto.js</title> <script> // stick all JS stuff in here </script> </head> <body> <p> Blah </p> <p> Blub </p> <script> $('p').html('test').css('color:red'); </script> </body> </html>
  • 38. function $$(el, selector){ return slice.call(el.querySelectorAll(selector)) } function compact(array){ return array.filter(function(el){ return el !== void 0 && el !== null }) } function $(_, context){ if(context !== void 0) return $(context).find(_); function fn(_){ return fn.dom.forEach(_), fn } fn.dom = compact((typeof _ == 'function' && 'dom' in _) ? _.dom : (_ instanceof Array ? _ : (_ instanceof Element ? [_] : $$(d, fn.selector = _)))); $.extend(fn, $.fn); return fn; }
  • 39. Only targets mobile browsers Minimalist, jQuery-ish framework Use WebKit features as much as possible Can be “upgraded” Inlineable http://zeptojs.com/