Zepto is a minimalist JavaScript library for modern browsers with a largely jQuery-compatible API. If you use jQuery, you already know how to use Zepto.
See zeptojs.com for an extended introduction, downloads and documentation.
Zepto.js is licensed under the terms of the MIT License.
The official site offers a download of the default distribution of Zepto. This is good for starting out. However, at some point you might want to add some optional modules and remove some of the default ones you don't need, to keep the size at minimum. That's when you need to check out Zepto's source code and use the build commands.
You will need ruby, RubyGems, and rake installed on your system.
# dependencies:
$ ruby -v
$ gem -v
$ rake -V
# required to generate the minified version:
$ gem install uglifier
Build Zepto by running rake
:
$ rake
Original version: 40.423k
Minified: 18.776k
Minified and gzipped: 7.033k, compression factor 5.747
The resulting files are:
dist/zepto.js
dist/zepto.min.js
To include optional modules and remove default ones, use the concat
task. In
this example, "fx" is removed, but "data" and "selector" are added:
$ rake concat[-fx:data:selector] dist
Zepto modules are individual files in the "src/" directory. You can also list
the available modules by running rake modules
.
module | default | description |
---|---|---|
polyfill | ✔ | Provides String.prototype.trim and Array.prototype.reduce methods if they are missing (required for iOS 3.x) |
zepto | ✔ | Core module; contains most methods |
event | ✔ | Event handling via on() & off() |
detect | ✔ | Provides $.os and $.browser information |
fx | ✔ | The animate() method |
fx_methods |
Animated show , hide , toggle ,
and fade*() methods.
|
|
ajax | ✔ | XMLHttpRequest and JSONP functionality |
form | ✔ | Serialize & submit web forms |
assets | Experimental support for cleaning up iOS memory after removing image elements from the DOM. | |
data |
A full-blown data() method, capable of storing arbitrary
objects in memory.
|
|
selector |
Experimental jQuery
CSS extensions support for functionality such as $('div:first') and
el.is(':visible') .
|
|
touch | Fires tap– and swipe–related events on touch devices | |
gesture | Fires pinch gesture events on touch devices | |
stack | Provides andSelf & end() chaining methods |
Get in touch:
- IRC channel: #zepto on freenode.net
- @zeptojs
- Check if the bug is already fixed in the master branch since the last release.
- Check existing issues. Open a new one, including exact browser & platform information. For better formatting of your report, see GitHub-flavored Markdown.
Zepto test suite is in "test/*.html" files. Open the individual files in a web browser to run the tests. Files named with "_functional" are not automated tests, but require interaction. Automated tests are written using Evidence.js.
Detailed test information such as specific failures is logged to the JavaScript console of your browser.
It's possible to run automated tests from the command-line in headless Webkit with PhantomJS:
# install on Mac OS
$ brew install phantomjs
# run all tests
$ rake test
# run individual files
$ script/test test/selector.html
function name() { }
for named functionsfunction(){ }
for anonymous functions- No curly braces for single-line control flow statements such as
if
& friends - Don't write semicolons that are optional
- Put a single semicolon before statements that start with
(
or[
(see above article as for why it's needed) - Use long, descriptive variable and method names
- Use blank lines to separate "paragraphs" of code for readability
- Use comments to describe non-obvious code behavior