SlideShare uma empresa Scribd logo
1 de 39
Baixar para ler 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/

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

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

Semelhante a 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
 

Mais de 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
 

Mais de 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)
 

Último

Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
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
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 

Último (20)

Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
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)
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 

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/