Skip to content

Commit

Permalink
no one escapes the austrian inquisition
Browse files Browse the repository at this point in the history
  • Loading branch information
madrobby committed Mar 28, 2012
1 parent 0366f9a commit 68cbe1f
Show file tree
Hide file tree
Showing 11 changed files with 424 additions and 684 deletions.
413 changes: 121 additions & 292 deletions src/ajax.js

Large diffs are not rendered by default.

26 changes: 9 additions & 17 deletions src/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,20 @@
// (c) 2010-2012 Thomas Fuchs
// Zepto.js may be freely distributed under the MIT license.

(function($){
var cache = [], timeout;
;(function($){
var cache = [], timeout

// ### $.fn.remove
//
// Remove element from DOM
//
// *Example:*
//
// $('#projects, .comments').remove();
//
$.fn.remove = function(){
return this.each(function(){
if(this.parentNode){
if(this.tagName === 'IMG'){
cache.push(this);
this.src = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=';
if (timeout) clearTimeout(timeout);
timeout = setTimeout(function(){ cache = [] }, 60000);
cache.push(this)
this.src = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='
if (timeout) clearTimeout(timeout)
timeout = setTimeout(function(){ cache = [] }, 60000)
}
this.parentNode.removeChild(this);
this.parentNode.removeChild(this)
}
});
})
}
})(Zepto);
})(Zepto)
24 changes: 12 additions & 12 deletions src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@

// The following code is heavily inspired by jQuery's $.fn.data()

(function($) {
;(function($) {
var data = {}, dataAttr = $.fn.data,
uuid = $.uuid = +new Date(),
exp = $.expando = 'Zepto' + uuid;
exp = $.expando = 'Zepto' + uuid

function getData(node, name) {
var id = node[exp], store = id && data[id];
var id = node[exp], store = id && data[id]
return name === undefined ? store || setData(node) :
(store && store[name]) || dataAttr.call($(node), name);
(store && store[name]) || dataAttr.call($(node), name)
}

function setData(node, name, value) {
var id = node[exp] || (node[exp] = ++uuid),
store = data[id] || (data[id] = {});
if (name !== undefined) store[name] = value;
return store;
};
store = data[id] || (data[id] = {})
if (name !== undefined) store[name] = value
return store
}

$.fn.data = function(name, value) {
return value === undefined ?
this.length == 0 ? undefined : getData(this[0], name) :
this.each(function(idx){
setData(this, name, $.isFunction(value) ?
value.call(this, idx, getData(this, name)) : value);
});
};
})(Zepto);
value.call(this, idx, getData(this, name)) : value)
})
}
})(Zepto)
47 changes: 12 additions & 35 deletions src/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// (c) 2010-2012 Thomas Fuchs
// Zepto.js may be freely distributed under the MIT license.

(function($){
;(function($){
function detect(ua){
var os = this.os = {}, browser = this.browser = {},
webkit = ua.match(/WebKit\/([\d.]+)/),
Expand All @@ -11,43 +11,20 @@
iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/),
touchpad = webos && ua.match(/TouchPad/),
blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/)

if (browser.webkit = !!webkit) browser.version = webkit[1];
if (browser.webkit = !!webkit) browser.version = webkit[1]

if (android) os.android = true, os.version = android[2];
if (iphone) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');
if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');
if (webos) os.webos = true, os.version = webos[2];
if (touchpad) os.touchpad = true;
if (blackberry) os.blackberry = true, os.version = blackberry[2];
if (android) os.android = true, os.version = android[2]
if (iphone) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.')
if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.')
if (webos) os.webos = true, os.version = webos[2]
if (touchpad) os.touchpad = true
if (blackberry) os.blackberry = true, os.version = blackberry[2]
}

// ### $.os
//
// Object containing information about browser platform
//
// *Example:*
//
// $.os.ios // => true if running on Apple iOS
// $.os.android // => true if running on Android
// $.os.webos // => true if running on HP/Palm WebOS
// $.os.touchpad // => true if running on a HP TouchPad
// $.os.version // => string with a version number, e.g.
// "4.0", "3.1.1", "2.1", etc.
// $.os.iphone // => true if running on iPhone
// $.os.ipad // => true if running on iPad
// $.os.blackberry // => true if running on BlackBerry
//
// ### $.browser
//
// *Example:*
//
// $.browser.webkit // => true if the browser is WebKit-based
// $.browser.version // => WebKit version string
detect.call($, navigator.userAgent);

detect.call($, navigator.userAgent)
// make available to unit tests
$.__detect = detect;
$.__detect = detect

})(Zepto);
})(Zepto)
Loading

10 comments on commit 68cbe1f

@indutny
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just... why?

@manuelkiessling
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOOOOOOOOOOOO!!!!!

@oslego
Copy link

@oslego oslego commented on 68cbe1f Mar 28, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zepto is experiencing a drastic diet! :)
@madrobby Could you please explain some of the reasoning for this?

@bartzon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

;+1 on this commit

@LinusU
Copy link
Contributor

@LinusU LinusU commented on 68cbe1f Mar 28, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, but, but... why? To decrease file size? That should be a job for the minifier!

@madrobby
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see http://mislav.uniqpath.com/2010/05/semicolons/ for why we're doing this. It's purely a stylistic issue, with less typing for us and the core team prefers this style.

@cristibalan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What Thomas said.

Also, I really really hate all the uglifiers and minifiers. They make source viewing and poking very difficult and I hope the trend of taking out semicolons encourages people to leave their code readable to humans.

I learned a ton while I was starting out by viewing the source and looking at how things were made. Won't you please think of the children?

@mislav
Copy link
Collaborator

@mislav mislav commented on 68cbe1f Mar 28, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to the following flowchart when making decisions about semicolons.

semicolons decision

@victor-baumann
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like it! :)
Why not get rid of the semicolon in ;(function($){...})(Zepto) by using !function($){...}(Zepto)?

@madrobby
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smolotov It's purely stylistic and we want simple rules, so it's easier to do the same before any statement that starts with ( or [. We leave more optimizations to UglifyJS.

Please sign in to comment.