Permalink
Browse files

Normalize whitespace

  • Loading branch information...
1 parent eeaa9d6 commit ad1e969eb50f96be2e7929f4a309f662309500c7 @sstephenson sstephenson committed Dec 1, 2010
View
@@ -18,4 +18,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -2,7 +2,7 @@
Zepto.js is a minimalist inlinable framework for mobile WebKit browsers, with a jQuery-like 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.
+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.
Primary target platforms are:
@@ -18,19 +18,19 @@ Secondary platforms are:
= Syntax & features:
Basic call with CSS selector:
-
+
$('p>span').html('yoho').css('color:red');
-
+
Instead of a selector, a DOM Element, or a list of nodes can be passed in.
The $ function takes an optional context argument, which can be a DOM Element or a Zepto object:
$('span', $('p')) // -> find all <span> elements in <p> elements
-
+
$('p').bind('click', function(){
$('span', this).css('color:red'); // affects "span" children/grandchildren
});
-
+
Context and .find calls are equivalent:
$('span', $('p')) // same
@@ -43,15 +43,15 @@ Context and .find calls are equivalent:
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)
text('new text'): set the text contents of the element(s)
append, prepend, before, after: like html, but add html to element contents (or before/after)
@@ -63,32 +63,32 @@ Context and .find calls are equivalent:
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
-
+
== Non-jQuery functions
pluck(property):
return property for each element
e.g. pluck('innerHTML') returns an array of all innerHTML properties of all elements found
-
+
compact():
remove all null or undefined elements from list of elements found
-
+
anim(transform, opacity, duration):
use -webkit-transform/opacity and do an animation
@@ -101,19 +101,19 @@ Context and .find calls are equivalent:
Adding an event listener:
$('some selector').bind('click', function(event){ ... });
-
+
Adding an event listener on multiple events:
-
+
$('some selector').bind('touchstart touchmove touchend', function(event){ ... });
-
+
Adding one event listener that uses event delegation to be only active on a range of children/grandchildren (as given with the subselector):
-
+
$('some selector').delegate('some subselector', 'touchstart', function(event){ alert("I'm touched!") });
-
+
Adding a "live" event listener, that fires on all elements that match the selector now and in the future:
$('p.yay').live('click', function(){ alert("Clicked a p.yay element!") });
-
+
Removing an event listener:
$('some selector').unbind('click', listener);
@@ -133,16 +133,16 @@ Double-tapping:
Swiping (e.g. "delete" button when swiping over a list entry):
$('some selector').swipe(function(){ ... });
-
+
= Ajax:
$.get(url, callback)
$.post(url, callback)
$.getJSON(url, callback)
-
+
$('selector').load('url'[, callback]);
$('selector').load('url #fragment-selector'[, callback]);
-
+
= Environmental information
Zepto includes information about the environment it is running in the $.os object:
@@ -161,23 +161,23 @@ zepto.js can be used as-is. However, for best efficiency, run the included build
For this to work, you need Ruby and Rake installed.
$ rake
-
+
You'll see an output like:
Original version: 5.7k
Minified: 3.7k
Minified and gzipped: 1.6k, compression factor 3.6
-
+
The minified file is saved in dist/zepto.min.js.
= Loading Zepto
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.
+
+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!
= Contributing!
@@ -198,4 +198,4 @@ Have fun!
= License
-Zepto.js is is licensed under the terms of the MIT License, see the included MIT-LICENSE file.
+Zepto.js is is licensed under the terms of the MIT License, see the included MIT-LICENSE file.
View
@@ -21,7 +21,7 @@ ZEPTO_FILES = [
task :default => [:clean, :concat, :dist]
desc "Clean the distribution directory."
-task :clean do
+task :clean do
rm_rf ZEPTO_DIST_DIR
mkdir ZEPTO_DIST_DIR
end
@@ -44,7 +44,7 @@ end
desc "Concatenate Zepto core and plugins to build a distributable zepto.js file"
task :concat => :whitespace do
File.open(File.join(ZEPTO_DIST_DIR,'zepto.js'),"w") do |f|
- f.puts ZEPTO_FILES.map{ |s| IO.read(s) }
+ f.puts ZEPTO_FILES.map{ |s| IO.read(s) }
end
end
@@ -62,14 +62,14 @@ def process_minified(src, target)
cp target, File.join(ZEPTO_DIST_DIR,'temp.js')
msize = File.size(File.join(ZEPTO_DIST_DIR,'temp.js'))
`gzip -9 #{File.join(ZEPTO_DIST_DIR,'temp.js')}`
-
+
osize = File.size(src)
dsize = File.size(File.join(ZEPTO_DIST_DIR,'temp.js.gz'))
rm_rf File.join(ZEPTO_DIST_DIR,'temp.js.gz')
-
+
puts "Original version: %.3fk" % (osize/1024.0)
puts "Minified: %.3fk" % (msize/1024.0)
- puts "Minified and gzipped: %.3fk, compression factor %.3f" % [dsize/1024.0, osize/dsize.to_f]
+ puts "Minified and gzipped: %.3fk, compression factor %.3f" % [dsize/1024.0, osize/dsize.to_f]
end
desc "Generates a minified version for distribution."
@@ -98,4 +98,4 @@ Rake::PackageTask.new('zepto', ZEPTO_VERSION) do |package|
'test/**/*',
'examples/**/*'
)
-end
+end
View
@@ -23,7 +23,7 @@
$.getJSON = function(url, success){
$.get(url, function(json){ success(JSON.parse(json)) });
};
-
+
$.fn.load = function(url, success){
var self = this, parts = url.split(/\s/), selector;
if(!this.dom.length) return this;
View
@@ -1,6 +1,6 @@
(function($){
var cache = [], timeout;
-
+
$.fn.remove = function(){
return this.each(function(el){
if(el.tagName=='IMG'){
@@ -11,5 +11,5 @@
}
el.parentNode.removeChild(el);
});
- }
+ }
})(Zepto);
View
@@ -5,4 +5,4 @@
return this.css({ '-webkit-transition': 'all '+(dur||0.5)+'s '+(ease||''),
'-webkit-transform': transforms.join(' '), opacity: opacity });
}
-})(Zepto);
+})(Zepto);
View
@@ -1,10 +1,10 @@
(function($){
var touch={}, touchTimeout;
-
+
function parentIfText(node){
return 'tagName' in node ? node : node.parentNode;
}
-
+
$(document).ready(function(){
$(document.body).bind('touchstart', function(e){
var now = Date.now(), delta = now-(touch.last || now);
@@ -13,8 +13,8 @@
touch.x1 = e.touches[0].pageX;
if (delta > 0 && delta <= 250) touch.isDoubleTap = true;
touch.last = now;
- }).bind('touchmove', function(e){
- touch.x2 = e.touches[0].pageX
+ }).bind('touchmove', function(e){
+ touch.x2 = e.touches[0].pageX
}).bind('touchend', function(e){
if (touch.isDoubleTap) {
$(touch.target).trigger('doubleTap');
@@ -31,7 +31,7 @@
}
}).bind('touchcancel', function(){ touch={} });
});
-
+
['swipe', 'doubleTap', 'tap'].forEach(function(m){
$.fn[m] = function(callback){ return this.bind(m, callback) }
});
View
@@ -22,7 +22,7 @@ var Zepto = (function() {
camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) }
$.fn = {
- ready: function(callback){
+ ready: function(callback){
d.addEventListener('DOMContentLoaded', callback, false); return this;
},
compact: function(){ this.dom=compact(this.dom); return this },
@@ -34,7 +34,7 @@ var Zepto = (function() {
filter: function(selector){
return $(this.dom.filter(function(el){ return $$(el.parentNode, selector).indexOf(el)>=0; }));
},
- is: function(selector){
+ is: function(selector){
return this.dom.length>0 && $(this.dom[0]).filter(selector).dom.length>0;
},
first: function(callback){ this.dom=compact([this.dom[0]]); return this },
@@ -52,8 +52,8 @@ var Zepto = (function() {
prev: function(){ return $(this.pluck('previousElementSibling')) },
next: function(){ return $(this.pluck('nextElementSibling')) },
html: function(html){
- return html === un ?
- (this.dom.length>0 ? this.dom[0].innerHTML : null) :
+ return html === un ?
+ (this.dom.length>0 ? this.dom[0].innerHTML : null) :
this.each(function(el){ el.innerHTML = html });
},
text: function(text){
@@ -62,7 +62,7 @@ var Zepto = (function() {
this.each(function(el){ el.innerText = text });
},
attr: function(name,value){
- return (typeof name == 'string' && value === un) ?
+ return (typeof name == 'string' && value === un) ?
(this.dom.length>0 ? this.dom[0].getAttribute(name) || undefined : null) :
this.each(function(el){
if (typeof name == 'object') for(k in name) el.setAttribute(k, name[k])
@@ -92,7 +92,7 @@ var Zepto = (function() {
return this.each(function(el){ el.className = el.className.replace(classRE(name), ' ').trim() });
}
};
-
+
['width','height'].forEach(function(m){ $.fn[m] = function(){ return this.offset()[m] }});
for(k in ADJ_OPS)
Oops, something went wrong.

0 comments on commit ad1e969

Please sign in to comment.