Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote branch 'origin/master' into local

  • Loading branch information...
commit 45194b69e4a13e830859c923bb205776911afaf4 2 parents 50eff2f + f4e92d3
@joaodubas joaodubas authored
View
53 README.rdoc
@@ -1,8 +1,13 @@
== Zepto.js: a minimalist framework for mobile WebKit browsers
-Zepto.js is a minimalist inlinable framework for mobile WebKit browsers, with a jQuery-like chaining syntax
+Zepto.js is a minimalist framework for mobile WebKit browsers,
+with a jQuery-compatible chaining syntax.
-The ultimate goal is to have a ~2k library that handles most basic dredge work for you in a nice API so you can concentrate on getting stuff done.
+100% jQuery coverage is not a design goal, however all APIs provided
+match their jQuery counterparts.
+
+The ultimate goal is to have a ~5k library that handles most basic dredge work
+for you in a nice API so you can concentrate on getting stuff done.
Primary target platforms are:
@@ -10,10 +15,11 @@ Primary target platforms are:
* Android 2.2+
* webOS 1.4.5+
-Secondary platforms are:
+Secondary platforms (for plugin/extension development) are:
* Safari 5+ (desktop)
* Chrome 5+ (desktop)
+* Other WebKit-based browsers/runtimes
= Syntax & features:
@@ -83,8 +89,12 @@ Context and .find calls are equivalent:
toggleClass('classname'[, switch]): adds/removes class, or adds/removes it when switch == true/false
bind(type, function): add an event listener (see below)
+ one(type, function): add an event listener that only fires once
+ unbind([type [, function]]): remove event listeners
delegate(selector, type, function): add an event listener w/ event delegation (see below)
+ undelegate(selector [, type[, function]]): remove event listeners w/ event delegation
live(type, function): add an event listener that listens to the selector for current and future elements
+ die([, type[, function]]): remove live listener
trigger(type): triggers an event
== Non-jQuery functions
@@ -95,7 +105,7 @@ Context and .find calls are equivalent:
anim(transform, opacity, duration):
use -webkit-transform/opacity and do an animation
-
+
= Utility functions:
$(document).ready(function(){ ... }): call function after DOM is ready to use (before load event fires)
@@ -129,6 +139,8 @@ Removing all event listeners:
= Touch events
+Zepto has several extensions over the jQuery API to make it easy to react to touch events.
+
Tapping:
$('some selector').tap(function(){ ... });
@@ -151,6 +163,8 @@ Simple GET and POST:
$.post(url, [data], [callback], [mime-type])
$.getJSON(url, callback)
+If the url contains a =? parameter, a JSONP request is assumed.
+
If you need more control (all keys are optional):
$.ajax({
type: 'POST', // defaults to 'GET'
@@ -173,12 +187,13 @@ Zepto includes information about the environment it is running in the $.os objec
$.os.android // => true if running on Android
$.os.webos // => true if running on HP/Palm WebOS
$.os.version // => string with version number, "4.0", "3.1.1", "2.1", etc.
- $.os.iphone // => true if running on iphone
- $.os.ipad // => true if running on ipad
+ $.os.iphone // => true if running on iPhone
+ $.os.ipad // => true if running on iPad
+ $.os.blackberry // => true if running on BlackBerry
= Building
-zepto.js can be used as-is. However, for best efficiency, run the included build step that uses the Google Closure Compiler to minify zepto.js and will give you an estimate on the compression that is achievable when zepto.js is served Gzipped.
+Zepto.js can be used as-is. However, for best efficiency, run the included build step that uses UglifyJS to minify Zepto.js and will give you an estimate on the compression that is achievable when Zepto.js is served Gzipped.
For this to work, you need Ruby and Rake installed.
@@ -198,9 +213,25 @@ You load Zepto by using
<script src="/path/to/zepto.min.js"></script>
-Or alternatively, you can just stick in the contents of zepto.min.js into
-a <script> tag in your HTML for the best loading performance.
-No need to load it form an external file!
+Or alternatively, you can just stick in the contents of zepto.min.js into a <script> tag
+in your HTML for the best loading performance, especially for single-page applications;
+no need to load it form an external file!
+
+= Bugs
+
+If you encounter bugs, please follow these steps:
+
+1. First, try if the bug is fixed in the latest Zepto.js master branch:
+ Get it from http://github.com/madrobby/zepto.
+
+2. Submit the bug on our issue tracker:
+ http://github.com/madrobby/zepto/issues
+
+Let us know in detail what is going on, including the exact browser version you're on
+and preferably a test case that can be reached online so we can quickly reproduce the
+error.
+
+Better, yet, fix the bug and bask in the glory of being a contributor (see below!).
= Contributing!
@@ -208,7 +239,7 @@ I'd love some help on this, so please feel free to mess around!
If you don't know how a method should behave, please use jQuery as a reference. Zepto.js should closely emulate it.
Note that emulation of all features of jQuery is not a project goal, rather we want the most useful parts while keeping
-to the ~2k minified goal.
+to the ~5k minified goal.
Also, Zepto.js contains some non-jQuery extensions, that are geared towards mobile devices.
View
17 Rakefile
@@ -61,8 +61,19 @@ def yui_compressor(src, target)
end
def uglifyjs(src, target)
- puts "Minifying #{src} with UglifyJS web service..."
- `curl -s --data-urlencode js_code@#{src} http://marijnhaverbeke.nl/uglifyjs > #{target}`
+ begin
+ require 'uglifier'
+ rescue LoadError => e
+ if verbose
+ puts "\nYou'll need the 'uglifier' gem for minification. Just run:\n\n"
+ puts " $ gem install uglifier"
+ puts "\nand you should be all set.\n\n"
+ exit
+ end
+ return false
+ end
+ puts "Minifying #{src} with UglifyJS..."
+ File.open(target, "w"){|f| f.puts Uglifier.new.compile(File.read(src))}
end
def process_minified(src, target)
@@ -79,7 +90,7 @@ def process_minified(src, target)
puts "Minified and gzipped: %.3fk, compression factor %.3f" % [dsize/1024.0, osize/dsize.to_f]
end
-desc "Generates a minified version for distribution, using the UglifyJS web service."
+desc "Generates a minified version for distribution, using UglifyJS."
task :dist do
src, target = File.join(ZEPTO_DIST_DIR,'zepto.js'), File.join(ZEPTO_DIST_DIR,'zepto.min.js')
uglifyjs src, target
View
6 examples/iphone/index.html
@@ -36,12 +36,12 @@
$("a.back").live('touchstart', function(event) {
var current = $(event.currentTarget).attr("href");
- $(".current").removeClass("current").addClass("reverse");
+ $(".current").removeClass("current").addClass("reverse");
$(current).addClass("current");
});
$(".menu a[href]").live('touchstart', function(event) {
- var section = $(event.currentTarget).closest('section'),
+ var section = $(event.currentTarget).closest('section'),
link = $(event.currentTarget),
prev_element = "#"+(section.removeClass("current").addClass("reverse").attr("id"));
$(link.attr("href")).addClass("current");
@@ -51,4 +51,4 @@
});
</script>
</body>
-</html>
+</html>
View
6 examples/iphone/iphone.css
@@ -129,7 +129,7 @@ ul li a, li.img a + a {
}
-.button, .back, .cancel, .add {
+.button, .back, .cancel, .add {
-webkit-border-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAeCAIAAACqmwlGAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAatJREFUeNqVlMtKw0AUhqfJSRpTk5Za1FAvxS6sgrVeFrpQdOcT+IpuBVHcuVBQpCDYjeAdkSpavDTGNJkz43FpFZz8DISZ+b75J5tJbWwfMsZuby7rh/vN5v1H+539TMZxPa84v7g0WirTFISQR/t7jdOTcqVaGp+ze50uIfDbL62H3a3NqerMwtIqXF9dnF+dL6+t9/S6hmFqut4luHns80aKpcrxwY43PKK7+f6J2ZVcYTCl6ZIxKuwatEhbpmU72UKjfgCakXFz/TwW7L8QlgIbTNtBwVAgU0g644IGZoycqYVgQGRRLBQFggEpHJUFBI4iUhYIBhSSPooCwUB0zEWiBsERlRsECJSIUlEgOHmDH3TM909FgWBgqe8oCgRrLGGADlcvIDB5A2nfQ7kD6D5J/jn5lZILBoAUQgWVUgDoWi5r8zhUEXgU5nOOVp0sB+0W+f8WEDY9MabpYNUqQ29Pd1Hoi79eA1qkLQIIY5CGIOwUvYHBQr5xdvn4/BSGnS7BstIDhexUbVo3jNarD1Ky5xfftszF+WqPZcKvp5IjfoYRoYHv0/QLHvXjAb8xkEMAAAAASUVORK5CYII=) 0 5 0 5 stretch stretch;
background: none;
border-width: 0px 5px;
@@ -152,11 +152,11 @@ white-space: nowrap;
width: auto;
}
-.back {
+.back {
-webkit-border-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACsAAAAeCAIAAAA6iHCJAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAArFJREFUeNrF0mtPE2EQBeB5t9vSRqEUKiAFkasggmC5x3CRECHx8sH/qMHEoKkiMUQTNJIIaAjeiFGUcEsotN22u9vtOzMKogYL39rlyfkBk3NG3HsyC8dLJhOzM8+/fvkcjexAtghRXVN/dXCkvOIcAKhEDMdY+7ESejgeqKpv7x3J9/ogS5hoc33l0YPxju6+YFefSkRwlI311cnQRM/gbd+ZUpfb43CokD2nCv2lFbVvZib9JaUqMUEGTYtNPZ7oHLpZXBJQFIUYSCJkj3A4830lrd3Di2/nVcxYwTSMift3m4LXCovKCYGQIDe8vrJveNQfTE+Fys9f8pdVSSTILeFyF/z/B8uflnSLG+qakRlRQo45XO5DHejJxOtXLzsG7yA7ME2Qe0hw6A+mn4ZqLvY4XR6UCLZAxH8rfFx6Z6BaXVJlSQS7SKSDC+JabGFurrnvBvJ+NXZBYpX4oP9AQ5eietKSAMDuDt4vLkhHfr6/XCKCvZBIjezuLMzPN/XcIhIADPYiZPXFs8lAQ7dwOA8KsL8Dr7/CoDzSDDgJCT2ljI0OOzBGKMVJACGUXU2/3h/Uo5vMDCdBQSRLcn9nox7bEgLsDoDCDKYli4p89ZXFZjJ6Ah3wvlhcb2mqPa1a0jIBhJ1RiPl3wpH4QG+bTGwDo51DKPwHMccS5mBvSzyyCcB2rgB/k5aoqK72xgo9FrbxgsMSulkZOBvwu1O6BjnGhO48p8IZfj1EsPWCR+jSMiCX0pbh9xXsrZCZrW1toOcy6mFMpyA3mNnUwi2NtQoxZwaZwzF9bKhTpHaN+C7KNGQPobTMhBZe7Wyts1iox729RNyOJkeHOj4sf19Z3YgmsraI251X6ve2BYMEIqIlVebjd0rj2la0rrrySkuDU1UhSySiYVrbkbiZ2qv2J5+53J2yzo3SAAAAAElFTkSuQmCC) 0 8 0 14 stretch stretch;
border-width: 0px 8px 0px 14px;
left: 6px;
max-width: 55px;
padding: 0px;
right: auto;
-}
+}
View
2  examples/iphone/zepto.min.js
@@ -1 +1 @@
-if(String.prototype.trim===undefined){String.prototype.trim=function(){return this.replace(/^\s+/,"").replace(/\s+$/,"")}}if(Array.prototype.reduce===undefined){Array.prototype.reduce=function(b){if(this===void 0||this===null){throw new TypeError()}var e=Object(this),a=e.length>>>0,d=0,c;if(typeof b!=="function"){throw new TypeError()}if(a==0&&arguments.length==1){throw new TypeError()}if(arguments.length>=2){c=arguments[1]}else{do{if(d in e){c=e[d++];break}if(++d>=a){throw new TypeError()}}while(true)}while(d<a){if(d in e){c=b.call(undefined,c,e[d],d,e)}d++}return c}}var Zepto=(function(){var m=[].slice,n,h,p,f,c,l=window.document,e;function o(q){return new RegExp("(^|\\s)"+q+"(\\s|$)")}function k(q){return q.filter(function(r){return r!==e&&r!==null})}function a(q){return q.reduce(function(s,r){return s.concat(r)},[])}function d(q){return q.replace(/-+(.)?/g,function(r,s){return s?s.toUpperCase():""})}f=/^\s*<.+>/;c=l.createElement("div");function j(r){c.innerHTML=(""+r).trim();var q=m.call(c.childNodes);c.innerHTML="";return q}function b(r,q){this.dom=r||[];this.length=this.dom.length;this.selector=q||""}function g(q,r){if(q==l){return new b}else{if(r!==e){return g(r).find(q)}else{if(typeof q==="function"){return g(l).ready(q)}else{var s;if(q instanceof b){s=q.dom}else{if(q instanceof Array){s=k(q)}else{if(q instanceof Element||q===window){s=[q]}else{if(f.test(q)){s=j(q)}else{s=p(l,q)}}}}return new b(s,q)}}}}g.extend=function(r,q){for(n in q){r[n]=q[n]}return r};g.qsa=p=function(r,q){return m.call(r.querySelectorAll(q))};g.fn={ready:function(q){l.addEventListener("DOMContentLoaded",q,false);return this},get:function(q){return q===e?this.dom:this.dom[q]},size:function(){return this.length},remove:function(){return this.each(function(){this.parentNode.removeChild(this)})},each:function(q){this.dom.forEach(function(s,r){q.call(s,r,s)});return this},filter:function(q){return g(this.dom.filter(function(r){return p(r.parentNode,q).indexOf(r)>=0}))},is:function(q){return this.length>0&&g(this.dom[0]).filter(q).length>0},eq:function(q){return g(this.get(q))},first:function(){return g(this.get(0))},last:function(){return g(this.get(this.length-1))},find:function(r){var q;if(this.length==1){q=p(this.get(0),r)}else{q=a(this.dom.map(function(s){return p(s,r)}))}return g(q)},closest:function(q,s){var t=this.dom[0],r=p(s!==e?s:l,q);if(r.length===0){t=null}while(t&&t!==l&&r.indexOf(t)<0){t=t.parentNode}return g(t)},parents:function(q){var s=[],r=this.get();while(r.length>0){r=k(r.map(function(t){if((t=t.parentNode)&&t!==l&&s.indexOf(t)<0){s.push(t);return t}}))}s=g(s);return q===e?s:s.filter(q)},parent:function(q){var s,r=[];this.each(function(){if((s=this.parentNode)&&r.indexOf(s)<0){r.push(s)}});r=g(r);return q===e?r:r.filter(q)},pluck:function(q){return this.dom.map(function(r){return r[q]})},show:function(){return this.css("display","block")},hide:function(){return this.css("display","none")},prev:function(){return g(this.pluck("previousElementSibling"))},next:function(){return g(this.pluck("nextElementSibling"))},html:function(q){return q===e?(this.length>0?this.dom[0].innerHTML:null):this.each(function(r){this.innerHTML=typeof q=="function"?q(r,this.innerHTML):q})},text:function(q){return q===e?(this.length>0?this.dom[0].innerText:null):this.each(function(){this.innerText=q})},attr:function(q,r){return(typeof q=="string"&&r===e)?(this.length>0&&this.dom[0].nodeName==="INPUT"&&this.dom[0].type==="text"&&q==="value")?(this.val()):(this.length>0?this.dom[0].getAttribute(q)||e:null):this.each(function(s){if(typeof q=="object"){for(n in q){this.setAttribute(n,q[n])}}else{this.setAttribute(q,typeof r=="function"?r(s,this.getAttribute(q)):r)}})},removeAttr:function(q){return this.each(function(){this.removeAttribute(q)})},val:function(q){return(q===e)?(this.length>0?this.dom[0].value:null):this.each(function(){this.value=q})},offset:function(){var q=this.dom[0].getBoundingClientRect();return{left:q.left+l.body.scrollLeft,top:q.top+l.body.scrollTop,width:q.width,height:q.height}},css:function(r,q){if(q===e&&typeof r=="string"){return this.dom[0].style[d(r)]}h="";for(n in r){h+=n+":"+r[n]+";"}if(typeof r=="string"){h=r+":"+q}return this.each(function(){this.style.cssText+=";"+h})},index:function(q){return this.dom.indexOf(g(q).get(0))},hasClass:function(q){return o(q).test(this.dom[0].className)},addClass:function(q){return this.each(function(){!g(this).hasClass(q)&&(this.className+=(this.className?" ":"")+q)})},removeClass:function(q){return this.each(function(){this.className=this.className.replace(o(q)," ").trim()})},toggleClass:function(r,q){return this.each(function(){((q!==e&&!q)||g(this).hasClass(r))?g(this).removeClass(r):g(this).addClass(r)})}};["width","height"].forEach(function(q){g.fn[q]=function(){return this.offset()[q]}});var i={append:"beforeEnd",prepend:"afterBegin",before:"beforeBegin",after:"afterEnd"};for(n in i){g.fn[n]=(function(q){return function(r){return this.each(function(s,u){if(r instanceof b){dom=r.dom;if(q=="afterBegin"||q=="afterEnd"){for(var t=0;t<dom.length;t++){u.insertAdjacentElement(q,dom[dom.length-t-1])}}else{for(var t=0;t<dom.length;t++){u.insertAdjacentElement(q,dom[t])}}}else{u["insertAdjacent"+(r instanceof Element?"Element":"HTML")](q,r)}})}})(i[n])}b.prototype=g.fn;return g})();"$" in window||(window.$=Zepto);(function(e){var k=e.qsa,a={},j=1;function i(m){return m._zid||(m._zid=j++)}function b(n,p,o,m){p=c(p);if(p.ns){var q=h(p.ns)}return(a[i(n)]||[]).filter(function(r){return r&&(!p.e||r.e==p.e)&&(!p.ns||q.test(r.ns))&&(!o||r.fn==o)&&(!m||r.sel==m)})}function c(m){var n=(""+m).split(".");return{e:n[0],ns:n.slice(1).sort().join(" ")}}function h(m){return new RegExp("(?:^| )"+m.replace(" "," .* ?")+"(?: |$)")}function l(o,n,q,m,p){var s=i(o),r=(a[s]||(a[s]=[]));n.split(/\s/).forEach(function(u){var t=e.extend(c(u),{fn:q,sel:m,del:p,i:r.length});r.push(t);o.addEventListener(t.e,p||q,false)})}function d(o,n,p,m){var q=i(o);(n||"").split(/\s/).forEach(function(r){b(o,r,p,m).forEach(function(s){delete a[q][s.i];o.removeEventListener(s.e,s.del||s.fn,false)})})}e.event={add:function(n,m,o){l(n,m,o)},remove:function(n,m,o){d(n,m,o)}};e.fn.bind=function(m,n){return this.each(function(){l(this,m,n)})};e.fn.unbind=function(m,n){return this.each(function(){d(this,m,n)})};var g=["preventDefault","stopImmediatePropagation","stopPropagation"];function f(n){var m=e.extend({originalEvent:n},n);g.forEach(function(o){m[o]=function(){return n[o].apply(n,arguments)}});return m}e.fn.delegate=function(m,n,o){return this.each(function(q,p){l(p,n,o,m,function(t){var s=t.target,r=k(p,m);while(s&&r.indexOf(s)<0){s=s.parentNode}if(s&&!(s===p)&&!(s===document)){o.call(s,e.extend(f(t),{currentTarget:s,liveFired:p}))}})})};e.fn.undelegate=function(m,n,o){return this.each(function(){d(this,n,o,m)})};e.fn.live=function(m,n){e(document.body).delegate(this.selector,m,n);return this};e.fn.die=function(m,n){e(document.body).undelegate(this.selector,m,n);return this};e.fn.trigger=function(m){return this.each(function(){var n=document.createEvent("Events");this.dispatchEvent(n,n.initEvent(m,true,false))})}})(Zepto);(function(c){function b(h){var h=h,i={},e=h.match(/(Android)\s+([\d.]+)/),j=h.match(/(iPhone\sOS)\s([\d_]+)/),d=h.match(/(iPad).*OS\s([\d_]+)/),g=h.match(/(webOS)\/([\d.]+)/),f=h.match(/(BlackBerry).*Version\/([\d.]+)/);if(e){i.android=true,i.version=e[2]}if(j){i.ios=true,i.version=j[2].replace(/_/g,"."),i.iphone=true}if(d){i.ios=true,i.version=d[2].replace(/_/g,"."),i.ipad=true}if(g){i.webos=true,i.version=g[2]}if(f){i.blackberry=true,i.version=f[2]}return i}c.os=b(navigator.userAgent);c.__detect=b;var a=navigator.userAgent.match(/WebKit\/([\d.]+)/);c.browser=a?{webkit:true,version:a[1]}:{webkit:false}})(Zepto);(function(a){a.fn.anim=function(d,f,g){var e=[],b,c;for(c in d){if(c==="opacity"){b=d[c]}else{e.push(c+"("+d[c]+")")}}return this.css({"-webkit-transition":"all "+(f!==undefined?f:0.5)+"s "+(g||""),"-webkit-transform":e.join(" "),opacity:b})}})(Zepto);(function(c){var d={},b;function a(e){return"tagName" in e?e:e.parentNode}c(document).ready(function(){c(document.body).bind("touchstart",function(g){var f=Date.now(),h=f-(d.last||f);d.target=a(g.touches[0].target);b&&clearTimeout(b);d.x1=g.touches[0].pageX;if(h>0&&h<=250){d.isDoubleTap=true}d.last=f}).bind("touchmove",function(f){d.x2=f.touches[0].pageX}).bind("touchend",function(f){if(d.isDoubleTap){c(d.target).trigger("doubleTap");d={}}else{if(d.x2>0){Math.abs(d.x1-d.x2)>30&&c(d.target).trigger("swipe")&&c(d.target).trigger("swipe"+(d.x1-d.x2>0?"Left":"Right"));d.x1=d.x2=d.last=0}else{if("last" in d){b=setTimeout(function(){b=null;c(d.target).trigger("tap");d={}},250)}}}}).bind("touchcancel",function(){d={}})});["swipe","swipeLeft","swipeRight","doubleTap","tap"].forEach(function(e){c.fn[e]=function(f){return this.bind(e,f)}})})(Zepto);(function(c){var d=0;function b(){}c.ajaxJSONP=function(f){var g;g="jsonp"+ ++d;window[g]=function(){f.success();delete window.jsonpString};var e=document.createElement("script");c(e).attr({src:f.url.replace(/=\?/,"="+g)});c("head").append(e)};c.ajax=function(f){f=f||{};if(f.url&&/=\?/.test(f.url)){return c.ajaxJSONP(f)}var i=f.data,k=f.success||b,e=f.error||b,h=a[f.dataType],g=f.contentType,j=new XMLHttpRequest();j.onreadystatechange=function(){if(j.readyState==4){if((j.status>=200&&j.status<300)||j.status==0){if(h=="application/json"){var l,m=false;try{l=JSON.parse(j.responseText)}catch(n){m=n}if(m){e(j,"parsererror",m)}else{k(l,"success",j)}}else{k(j.responseText,"success",j)}}else{e(j,"error")}}};j.open(f.type||"GET",f.url||window.location,true);if(h){j.setRequestHeader("Accept",h)}if(i instanceof Object){i=JSON.stringify(i),g=g||"application/json"}if(g){j.setRequestHeader("Content-Type",g)}j.setRequestHeader("X-Requested-With","XMLHttpRequest");j.send(i)};var a=c.ajax.mimeTypes={json:"application/json",xml:"application/xml",html:"text/html",text:"text/plain"};c.get=function(e,f){c.ajax({url:e,success:f})};c.post=function(f,g,h,e){if(g instanceof Function){e=e||h,h=g,g=null}c.ajax({type:"POST",url:f,data:g,success:h,dataType:e})};c.getJSON=function(e,f){c.ajax({url:e,success:f,dataType:"json"})};c.fn.load=function(g,i){if(!this.dom.length){return this}var f=this,h=g.split(/\s/),e;if(h.length>1){g=h[0],e=h[1]}c.get(g,function(j){f.html(e?c(document.createElement("div")).html(j).find(e).html():j);i&&i()});return this}})(Zepto);(function(c){var a=[],b;c.fn.remove=function(){return this.each(function(){if(this.tagName=="IMG"){a.push(this);this.src="data:image/gif;base64,R0lGODlhAQABAAAAADs=";if(b){clearTimeout(b)}b=setTimeout(function(){a=[]},60000)}this.parentNode.removeChild(this)})}})(Zepto);
+if(String.prototype.trim===undefined){String.prototype.trim=function(){return this.replace(/^\s+/,"").replace(/\s+$/,"")}}if(Array.prototype.reduce===undefined){Array.prototype.reduce=function(b){if(this===void 0||this===null){throw new TypeError()}var e=Object(this),a=e.length>>>0,d=0,c;if(typeof b!=="function"){throw new TypeError()}if(a==0&&arguments.length==1){throw new TypeError()}if(arguments.length>=2){c=arguments[1]}else{do{if(d in e){c=e[d++];break}if(++d>=a){throw new TypeError()}}while(true)}while(d<a){if(d in e){c=b.call(undefined,c,e[d],d,e)}d++}return c}}var Zepto=(function(){var m=[].slice,n,h,p,f,c,l=window.document,e;function o(q){return new RegExp("(^|\\s)"+q+"(\\s|$)")}function k(q){return q.filter(function(r){return r!==e&&r!==null})}function a(q){return q.reduce(function(s,r){return s.concat(r)},[])}function d(q){return q.replace(/-+(.)?/g,function(r,s){return s?s.toUpperCase():""})}f=/^\s*<.+>/;c=l.createElement("div");function j(r){c.innerHTML=(""+r).trim();var q=m.call(c.childNodes);c.innerHTML="";return q}function b(r,q){this.dom=r||[];this.length=this.dom.length;this.selector=q||""}function g(q,r){if(q==l){return new b}else{if(r!==e){return g(r).find(q)}else{if(typeof q==="function"){return g(l).ready(q)}else{var s;if(q instanceof b){s=q.dom}else{if(q instanceof Array){s=k(q)}else{if(q instanceof Element||q===window){s=[q]}else{if(f.test(q)){s=j(q)}else{s=p(l,q)}}}}return new b(s,q)}}}}g.extend=function(r,q){for(n in q){r[n]=q[n]}return r};g.qsa=p=function(r,q){return m.call(r.querySelectorAll(q))};g.fn={ready:function(q){l.addEventListener("DOMContentLoaded",q,false);return this},get:function(q){return q===e?this.dom:this.dom[q]},size:function(){return this.length},remove:function(){return this.each(function(){this.parentNode.removeChild(this)})},each:function(q){this.dom.forEach(function(s,r){q.call(s,r,s)});return this},filter:function(q){return g(this.dom.filter(function(r){return p(r.parentNode,q).indexOf(r)>=0}))},is:function(q){return this.length>0&&g(this.dom[0]).filter(q).length>0},eq:function(q){return g(this.get(q))},first:function(){return g(this.get(0))},last:function(){return g(this.get(this.length-1))},find:function(r){var q;if(this.length==1){q=p(this.get(0),r)}else{q=a(this.dom.map(function(s){return p(s,r)}))}return g(q)},closest:function(q,s){var t=this.dom[0],r=p(s!==e?s:l,q);if(r.length===0){t=null}while(t&&t!==l&&r.indexOf(t)<0){t=t.parentNode}return g(t)},parents:function(q){var s=[],r=this.get();while(r.length>0){r=k(r.map(function(t){if((t=t.parentNode)&&t!==l&&s.indexOf(t)<0){s.push(t);return t}}))}s=g(s);return q===e?s:s.filter(q)},parent:function(q){var s,r=[];this.each(function(){if((s=this.parentNode)&&r.indexOf(s)<0){r.push(s)}});r=g(r);return q===e?r:r.filter(q)},pluck:function(q){return this.dom.map(function(r){return r[q]})},show:function(){return this.css("display","block")},hide:function(){return this.css("display","none")},prev:function(){return g(this.pluck("previousElementSibling"))},next:function(){return g(this.pluck("nextElementSibling"))},html:function(q){return q===e?(this.length>0?this.dom[0].innerHTML:null):this.each(function(r){this.innerHTML=typeof q=="function"?q(r,this.innerHTML):q})},text:function(q){return q===e?(this.length>0?this.dom[0].innerText:null):this.each(function(){this.innerText=q})},attr:function(q,r){return(typeof q=="string"&&r===e)?(this.length>0&&this.dom[0].nodeName==="INPUT"&&this.dom[0].type==="text"&&q==="value")?(this.val()):(this.length>0?this.dom[0].getAttribute(q)||e:null):this.each(function(s){if(typeof q=="object"){for(n in q){this.setAttribute(n,q[n])}}else{this.setAttribute(q,typeof r=="function"?r(s,this.getAttribute(q)):r)}})},removeAttr:function(q){return this.each(function(){this.removeAttribute(q)})},val:function(q){return(q===e)?(this.length>0?this.dom[0].value:null):this.each(function(){this.value=q})},offset:function(){var q=this.dom[0].getBoundingClientRect();return{left:q.left+l.body.scrollLeft,top:q.top+l.body.scrollTop,width:q.width,height:q.height}},css:function(r,q){if(q===e&&typeof r=="string"){return this.dom[0].style[d(r)]}h="";for(n in r){h+=n+":"+r[n]+";"}if(typeof r=="string"){h=r+":"+q}return this.each(function(){this.style.cssText+=";"+h})},index:function(q){return this.dom.indexOf(g(q).get(0))},hasClass:function(q){return o(q).test(this.dom[0].className)},addClass:function(q){return this.each(function(){!g(this).hasClass(q)&&(this.className+=(this.className?" ":"")+q)})},removeClass:function(q){return this.each(function(){this.className=this.className.replace(o(q)," ").trim()})},toggleClass:function(r,q){return this.each(function(){((q!==e&&!q)||g(this).hasClass(r))?g(this).removeClass(r):g(this).addClass(r)})}};["width","height"].forEach(function(q){g.fn[q]=function(){return this.offset()[q]}});var i={append:"beforeEnd",prepend:"afterBegin",before:"beforeBegin",after:"afterEnd"};for(n in i){g.fn[n]=(function(q){return function(r){return this.each(function(s,u){if(r instanceof b){dom=r.dom;if(q=="afterBegin"||q=="afterEnd"){for(var t=0;t<dom.length;t++){u.insertAdjacentElement(q,dom[dom.length-t-1])}}else{for(var t=0;t<dom.length;t++){u.insertAdjacentElement(q,dom[t])}}}else{u["insertAdjacent"+(r instanceof Element?"Element":"HTML")](q,r)}})}})(i[n])}b.prototype=g.fn;return g})();"$" in window||(window.$=Zepto);(function(e){var k=e.qsa,a={},j=1;function i(m){return m._zid||(m._zid=j++)}function b(n,p,o,m){p=c(p);if(p.ns){var q=h(p.ns)}return(a[i(n)]||[]).filter(function(r){return r&&(!p.e||r.e==p.e)&&(!p.ns||q.test(r.ns))&&(!o||r.fn==o)&&(!m||r.sel==m)})}function c(m){var n=(""+m).split(".");return{e:n[0],ns:n.slice(1).sort().join(" ")}}function h(m){return new RegExp("(?:^| )"+m.replace(" "," .* ?")+"(?: |$)")}function l(o,n,q,m,p){var s=i(o),r=(a[s]||(a[s]=[]));n.split(/\s/).forEach(function(u){var t=e.extend(c(u),{fn:q,sel:m,del:p,i:r.length});r.push(t);o.addEventListener(t.e,p||q,false)})}function d(o,n,p,m){var q=i(o);(n||"").split(/\s/).forEach(function(r){b(o,r,p,m).forEach(function(s){delete a[q][s.i];o.removeEventListener(s.e,s.del||s.fn,false)})})}e.event={add:function(n,m,o){l(n,m,o)},remove:function(n,m,o){d(n,m,o)}};e.fn.bind=function(m,n){return this.each(function(){l(this,m,n)})};e.fn.unbind=function(m,n){return this.each(function(){d(this,m,n)})};var g=["preventDefault","stopImmediatePropagation","stopPropagation"];function f(n){var m=e.extend({originalEvent:n},n);g.forEach(function(o){m[o]=function(){return n[o].apply(n,arguments)}});return m}e.fn.delegate=function(m,n,o){return this.each(function(q,p){l(p,n,o,m,function(t){var s=t.target,r=k(p,m);while(s&&r.indexOf(s)<0){s=s.parentNode}if(s&&!(s===p)&&!(s===document)){o.call(s,e.extend(f(t),{currentTarget:s,liveFired:p}))}})})};e.fn.undelegate=function(m,n,o){return this.each(function(){d(this,n,o,m)})};e.fn.live=function(m,n){e(document.body).delegate(this.selector,m,n);return this};e.fn.die=function(m,n){e(document.body).undelegate(this.selector,m,n);return this};e.fn.trigger=function(m){return this.each(function(){var n=document.createEvent("Events");this.dispatchEvent(n,n.initEvent(m,true,false))})}})(Zepto);(function(c){function b(h){var h=h,i={},e=h.match(/(Android)\s+([\d.]+)/),j=h.match(/(iPhone\sOS)\s([\d_]+)/),d=h.match(/(iPad).*OS\s([\d_]+)/),g=h.match(/(webOS)\/([\d.]+)/),f=h.match(/(BlackBerry).*Version\/([\d.]+)/);if(e){i.android=true,i.version=e[2]}if(j){i.ios=true,i.version=j[2].replace(/_/g,"."),i.iphone=true}if(d){i.ios=true,i.version=d[2].replace(/_/g,"."),i.ipad=true}if(g){i.webos=true,i.version=g[2]}if(f){i.blackberry=true,i.version=f[2]}return i}c.os=b(navigator.userAgent);c.__detect=b;var a=navigator.userAgent.match(/WebKit\/([\d.]+)/);c.browser=a?{webkit:true,version:a[1]}:{webkit:false}})(Zepto);(function(a){a.fn.anim=function(d,f,g){var e=[],b,c;for(c in d){if(c==="opacity"){b=d[c]}else{e.push(c+"("+d[c]+")")}}return this.css({"-webkit-transition":"all "+(f!==undefined?f:0.5)+"s "+(g||""),"-webkit-transform":e.join(" "),opacity:b})}})(Zepto);(function(c){var d={},b;function a(e){return"tagName" in e?e:e.parentNode}c(document).ready(function(){c(document.body).bind("touchstart",function(g){var f=Date.now(),h=f-(d.last||f);d.target=a(g.touches[0].target);b&&clearTimeout(b);d.x1=g.touches[0].pageX;if(h>0&&h<=250){d.isDoubleTap=true}d.last=f}).bind("touchmove",function(f){d.x2=f.touches[0].pageX}).bind("touchend",function(f){if(d.isDoubleTap){c(d.target).trigger("doubleTap");d={}}else{if(d.x2>0){Math.abs(d.x1-d.x2)>30&&c(d.target).trigger("swipe")&&c(d.target).trigger("swipe"+(d.x1-d.x2>0?"Left":"Right"));d.x1=d.x2=d.last=0}else{if("last" in d){b=setTimeout(function(){b=null;c(d.target).trigger("tap");d={}},250)}}}}).bind("touchcancel",function(){d={}})});["swipe","swipeLeft","swipeRight","doubleTap","tap"].forEach(function(e){c.fn[e]=function(f){return this.bind(e,f)}})})(Zepto);(function(c){var d=0;function b(){}c.ajaxJSONP=function(f){var g;g="jsonp"+ ++d;window[g]=function(){f.success();delete window.jsonpString};var e=document.createElement("script");c(e).attr({src:f.url.replace(/=\?/,"="+g)});c("head").append(e)};c.ajax=function(f){f=f||{};if(f.url&&/=\?/.test(f.url)){return c.ajaxJSONP(f)}var i=f.data,k=f.success||b,e=f.error||b,h=a[f.dataType],g=f.contentType,j=new XMLHttpRequest();j.onreadystatechange=function(){if(j.readyState==4){if((j.status>=200&&j.status<300)||j.status==0){if(h=="application/json"){var l,m=false;try{l=JSON.parse(j.responseText)}catch(n){m=n}if(m){e(j,"parsererror",m)}else{k(l,"success",j)}}else{k(j.responseText,"success",j)}}else{e(j,"error")}}};j.open(f.type||"GET",f.url||window.location,true);if(h){j.setRequestHeader("Accept",h)}if(i instanceof Object){i=JSON.stringify(i),g=g||"application/json"}if(g){j.setRequestHeader("Content-Type",g)}j.setRequestHeader("X-Requested-With","XMLHttpRequest");j.send(i)};var a=c.ajax.mimeTypes={json:"application/json",xml:"application/xml",html:"text/html",text:"text/plain"};c.get=function(e,f){c.ajax({url:e,success:f})};c.post=function(f,g,h,e){if(g instanceof Function){e=e||h,h=g,g=null}c.ajax({type:"POST",url:f,data:g,success:h,dataType:e})};c.getJSON=function(e,f){c.ajax({url:e,success:f,dataType:"json"})};c.fn.load=function(g,i){if(!this.dom.length){return this}var f=this,h=g.split(/\s/),e;if(h.length>1){g=h[0],e=h[1]}c.get(g,function(j){f.html(e?c(document.createElement("div")).html(j).find(e).html():j);i&&i()});return this}})(Zepto);(function(c){var a=[],b;c.fn.remove=function(){return this.each(function(){if(this.tagName=="IMG"){a.push(this);this.src="data:image/gif;base64,R0lGODlhAQABAAAAADs=";if(b){clearTimeout(b)}b=setTimeout(function(){a=[]},60000)}this.parentNode.removeChild(this)})}})(Zepto);
View
3  src/compat.js
@@ -1,5 +1,4 @@
-// fix for iOS 3.2
-if (String.prototype.trim === undefined)
+if (String.prototype.trim === undefined) // fix for iOS 3.2
String.prototype.trim = function(){ return this.replace(/^\s+/, '').replace(/\s+$/, '') };
// For iOS 3.x
View
9 src/event.js
@@ -59,6 +59,15 @@
remove(this, event, callback);
});
};
+ $.fn.one = function(event, callback){
+ return this.each(function(){
+ var self = this;
+ add(this, event, function wrapper(){
+ callback();
+ remove(self, event, arguments.callee);
+ });
+ });
+ };
var eventMethods = ['preventDefault', 'stopImmediatePropagation', 'stopPropagation'];
function createProxy(event) {
View
2  src/zepto.js
@@ -145,7 +145,7 @@ var Zepto = (function() {
};
},
css: function(property, value){
- if (value === undefined && typeof property == 'string')
+ if (value === undefined && typeof property == 'string')
return this[0].style[camelize(property)] || getComputedStyle(this[0], '').getPropertyValue(property);
css = "";
for (key in property) css += key + ':' + property[key] + ';';
View
13 test/zepto.html
@@ -32,7 +32,7 @@
<div id="get_style_wrapper" style="font-size: 16px;">
<div id="get_style_element">Derp</div>
</div>
-
+
<div id="attr_1" data-id="someId1" data-name="someName1"></div>
<div id="attr_2" data-id="someId2" data-name="someName2"></div>
@@ -455,7 +455,7 @@
t.assertEqual('rgb(0, 0, 0)', $('#some_element').css('border-left-color'));
t.assertEqual('rgb(0, 255, 0)', $('#some_element').css('color'));
t.assertEqual('2px', $('#some_element').css('padding-left'));
-
+
var div = $('#get_style_element');
t.assertEqual('48px', div.css('font-size'));
t.assertEqual('rgb(0, 0, 0)', div.css('color'));
@@ -680,6 +680,15 @@
t.assertEqual(2, count);
},
+ testOne: function(t){
+ var counter = 0;
+ $(document.body).one('click', function(){ counter++ });
+ click($('#some_element').get(0));
+ t.assertEqual(1, counter);
+ click($('#some_element').get(0));
+ t.assertEqual(1, counter);
+ },
+
testAttr: function(t){
var els = $('#attr_1, #attr_2');
Please sign in to comment.
Something went wrong with that request. Please try again.