sprockets_zeptojs 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sprockets_zeptojs/version.rb +1 -1
- data/vendor/assets/javascripts/zepto/ajax.js +314 -0
- data/vendor/assets/javascripts/zepto/assets.js +21 -0
- data/vendor/assets/javascripts/zepto/data.js +67 -0
- data/vendor/assets/javascripts/zepto/detect.js +55 -0
- data/vendor/assets/javascripts/zepto/event.js +248 -0
- data/vendor/assets/javascripts/zepto/form.js +40 -0
- data/vendor/assets/javascripts/zepto/fx.js +102 -0
- data/vendor/assets/javascripts/zepto/fx_methods.js +71 -0
- data/vendor/assets/javascripts/zepto/gesture.js +35 -0
- data/vendor/assets/javascripts/zepto/index.js +6 -0
- data/vendor/assets/javascripts/zepto/polyfill.js +36 -0
- data/vendor/assets/javascripts/zepto/selector.js +81 -0
- data/vendor/assets/javascripts/zepto/stack.js +22 -0
- data/vendor/assets/javascripts/zepto/touch.js +115 -0
- data/vendor/assets/javascripts/zepto/zepto.js +790 -0
- metadata +16 -1
@@ -0,0 +1,35 @@
|
|
1
|
+
// Zepto.js
|
2
|
+
// (c) 2010-2012 Thomas Fuchs
|
3
|
+
// Zepto.js may be freely distributed under the MIT license.
|
4
|
+
|
5
|
+
;(function($){
|
6
|
+
if ($.os.ios) {
|
7
|
+
var gesture = {}, gestureTimeout
|
8
|
+
|
9
|
+
function parentIfText(node){
|
10
|
+
return 'tagName' in node ? node : node.parentNode
|
11
|
+
}
|
12
|
+
|
13
|
+
$(document).bind('gesturestart', function(e){
|
14
|
+
var now = Date.now(), delta = now - (gesture.last || now)
|
15
|
+
gesture.target = parentIfText(e.target)
|
16
|
+
gestureTimeout && clearTimeout(gestureTimeout)
|
17
|
+
gesture.e1 = e.scale
|
18
|
+
gesture.last = now
|
19
|
+
}).bind('gesturechange', function(e){
|
20
|
+
gesture.e2 = e.scale
|
21
|
+
}).bind('gestureend', function(e){
|
22
|
+
if (gesture.e2 > 0) {
|
23
|
+
Math.abs(gesture.e1 - gesture.e2) != 0 && $(gesture.target).trigger('pinch') &&
|
24
|
+
$(gesture.target).trigger('pinch' + (gesture.e1 - gesture.e2 > 0 ? 'In' : 'Out'))
|
25
|
+
gesture.e1 = gesture.e2 = gesture.last = 0
|
26
|
+
} else if ('last' in gesture) {
|
27
|
+
gesture = {}
|
28
|
+
}
|
29
|
+
})
|
30
|
+
|
31
|
+
;['pinch', 'pinchIn', 'pinchOut'].forEach(function(m){
|
32
|
+
$.fn[m] = function(callback){ return this.bind(m, callback) }
|
33
|
+
})
|
34
|
+
}
|
35
|
+
})(Zepto)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
// Zepto.js
|
2
|
+
// (c) 2010-2012 Thomas Fuchs
|
3
|
+
// Zepto.js may be freely distributed under the MIT license.
|
4
|
+
|
5
|
+
;(function(undefined){
|
6
|
+
if (String.prototype.trim === undefined) // fix for iOS 3.2
|
7
|
+
String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g, '') }
|
8
|
+
|
9
|
+
// For iOS 3.x
|
10
|
+
// from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduce
|
11
|
+
if (Array.prototype.reduce === undefined)
|
12
|
+
Array.prototype.reduce = function(fun){
|
13
|
+
if(this === void 0 || this === null) throw new TypeError()
|
14
|
+
var t = Object(this), len = t.length >>> 0, k = 0, accumulator
|
15
|
+
if(typeof fun != 'function') throw new TypeError()
|
16
|
+
if(len == 0 && arguments.length == 1) throw new TypeError()
|
17
|
+
|
18
|
+
if(arguments.length >= 2)
|
19
|
+
accumulator = arguments[1]
|
20
|
+
else
|
21
|
+
do{
|
22
|
+
if(k in t){
|
23
|
+
accumulator = t[k++]
|
24
|
+
break
|
25
|
+
}
|
26
|
+
if(++k >= len) throw new TypeError()
|
27
|
+
} while (true)
|
28
|
+
|
29
|
+
while (k < len){
|
30
|
+
if(k in t) accumulator = fun.call(undefined, accumulator, t[k], k, t)
|
31
|
+
k++
|
32
|
+
}
|
33
|
+
return accumulator
|
34
|
+
}
|
35
|
+
|
36
|
+
})()
|
@@ -0,0 +1,81 @@
|
|
1
|
+
;(function($){
|
2
|
+
var zepto = $.zepto, oldQsa = zepto.qsa, oldMatches = zepto.matches
|
3
|
+
|
4
|
+
function visible(elem){
|
5
|
+
elem = $(elem)
|
6
|
+
return !!(elem.width() || elem.height()) && elem.css("display") !== "none"
|
7
|
+
}
|
8
|
+
|
9
|
+
// Implements a subset from:
|
10
|
+
// http://api.jquery.com/category/selectors/jquery-selector-extensions/
|
11
|
+
//
|
12
|
+
// Each filter function receives the current index, all nodes in the
|
13
|
+
// considered set, and a value if there were parentheses. The value
|
14
|
+
// of `this` is the node currently being considered. The function returns the
|
15
|
+
// resulting node(s), null, or undefined.
|
16
|
+
//
|
17
|
+
// Complex selectors are not supported:
|
18
|
+
// li:has(label:contains("foo")) + li:has(label:contains("bar"))
|
19
|
+
// ul.inner:first > li
|
20
|
+
var filters = $.expr[':'] = {
|
21
|
+
visible: function(){ if (visible(this)) return this },
|
22
|
+
hidden: function(){ if (!visible(this)) return this },
|
23
|
+
selected: function(){ if (this.selected) return this },
|
24
|
+
checked: function(){ if (this.checked) return this },
|
25
|
+
parent: function(){ return this.parentNode },
|
26
|
+
first: function(idx){ if (idx === 0) return this },
|
27
|
+
last: function(idx, nodes){ if (idx === nodes.length - 1) return this },
|
28
|
+
eq: function(idx, _, value){ if (idx === value) return this },
|
29
|
+
contains: function(idx, _, text){ if ($(this).text().indexOf(text) > -1) return this },
|
30
|
+
has: function(idx, _, sel){ if (zepto.qsa(this, sel).length) return this }
|
31
|
+
}
|
32
|
+
|
33
|
+
var filterRe = new RegExp('(.*):(\\w+)(?:\\(([^)]+)\\))?$\\s*'),
|
34
|
+
childRe = /^\s*>/,
|
35
|
+
classTag = 'Zepto' + (+new Date())
|
36
|
+
|
37
|
+
function process(sel, fn) {
|
38
|
+
// quote the hash in `a[href^=#]` expression
|
39
|
+
sel = sel.replace(/=#\]/g, '="#"]')
|
40
|
+
var filter, arg, match = filterRe.exec(sel)
|
41
|
+
if (match && match[2] in filters) {
|
42
|
+
filter = filters[match[2]], arg = match[3]
|
43
|
+
sel = match[1]
|
44
|
+
if (arg) {
|
45
|
+
var num = Number(arg)
|
46
|
+
if (isNaN(num)) arg = arg.replace(/^["']|["']$/g, '')
|
47
|
+
else arg = num
|
48
|
+
}
|
49
|
+
}
|
50
|
+
return fn(sel, filter, arg)
|
51
|
+
}
|
52
|
+
|
53
|
+
zepto.qsa = function(node, selector) {
|
54
|
+
return process(selector, function(sel, filter, arg){
|
55
|
+
try {
|
56
|
+
var taggedParent
|
57
|
+
if (!sel && filter) sel = '*'
|
58
|
+
else if (childRe.test(sel))
|
59
|
+
// support "> *" child queries by tagging the parent node with a
|
60
|
+
// unique class and prepending that classname onto the selector
|
61
|
+
taggedParent = $(node).addClass(classTag), sel = '.'+classTag+' '+sel
|
62
|
+
|
63
|
+
var nodes = oldQsa(node, sel)
|
64
|
+
} catch(e) {
|
65
|
+
console.error('error performing selector: %o', selector)
|
66
|
+
throw e
|
67
|
+
} finally {
|
68
|
+
if (taggedParent) taggedParent.removeClass(classTag)
|
69
|
+
}
|
70
|
+
return !filter ? nodes :
|
71
|
+
zepto.uniq($.map(nodes, function(n, i){ return filter.call(n, i, nodes, arg) }))
|
72
|
+
})
|
73
|
+
}
|
74
|
+
|
75
|
+
zepto.matches = function(node, selector){
|
76
|
+
return process(selector, function(sel, filter, arg){
|
77
|
+
return (!sel || oldMatches(node, sel)) &&
|
78
|
+
(!filter || filter.call(node, null, arg) === node)
|
79
|
+
})
|
80
|
+
}
|
81
|
+
})(Zepto)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
// Zepto.js
|
2
|
+
// (c) 2010-2012 Thomas Fuchs
|
3
|
+
// Zepto.js may be freely distributed under the MIT license.
|
4
|
+
|
5
|
+
;(function($){
|
6
|
+
$.fn.end = function(){
|
7
|
+
return this.prevObject || $()
|
8
|
+
}
|
9
|
+
|
10
|
+
$.fn.andSelf = function(){
|
11
|
+
return this.add(this.prevObject || $())
|
12
|
+
}
|
13
|
+
|
14
|
+
'filter,add,not,eq,first,last,find,closest,parents,parent,children,siblings'.split(',').forEach(function(property){
|
15
|
+
var fn = $.fn[property]
|
16
|
+
$.fn[property] = function(){
|
17
|
+
var ret = fn.apply(this, arguments)
|
18
|
+
ret.prevObject = this
|
19
|
+
return ret
|
20
|
+
}
|
21
|
+
})
|
22
|
+
})(Zepto)
|
@@ -0,0 +1,115 @@
|
|
1
|
+
// Zepto.js
|
2
|
+
// (c) 2010-2012 Thomas Fuchs
|
3
|
+
// Zepto.js may be freely distributed under the MIT license.
|
4
|
+
|
5
|
+
;(function($){
|
6
|
+
var touch = {},
|
7
|
+
touchTimeout, tapTimeout, swipeTimeout,
|
8
|
+
longTapDelay = 750, longTapTimeout
|
9
|
+
|
10
|
+
function parentIfText(node) {
|
11
|
+
return 'tagName' in node ? node : node.parentNode
|
12
|
+
}
|
13
|
+
|
14
|
+
function swipeDirection(x1, x2, y1, y2) {
|
15
|
+
var xDelta = Math.abs(x1 - x2), yDelta = Math.abs(y1 - y2)
|
16
|
+
return xDelta >= yDelta ? (x1 - x2 > 0 ? 'Left' : 'Right') : (y1 - y2 > 0 ? 'Up' : 'Down')
|
17
|
+
}
|
18
|
+
|
19
|
+
function longTap() {
|
20
|
+
longTapTimeout = null
|
21
|
+
if (touch.last) {
|
22
|
+
touch.el.trigger('longTap')
|
23
|
+
touch = {}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
function cancelLongTap() {
|
28
|
+
if (longTapTimeout) clearTimeout(longTapTimeout)
|
29
|
+
longTapTimeout = null
|
30
|
+
}
|
31
|
+
|
32
|
+
function cancelAll() {
|
33
|
+
if (touchTimeout) clearTimeout(touchTimeout)
|
34
|
+
if (tapTimeout) clearTimeout(tapTimeout)
|
35
|
+
if (swipeTimeout) clearTimeout(swipeTimeout)
|
36
|
+
if (longTapTimeout) clearTimeout(longTapTimeout)
|
37
|
+
touchTimeout = tapTimeout = swipeTimeout = longTapTimeout = null
|
38
|
+
touch = {}
|
39
|
+
}
|
40
|
+
|
41
|
+
$(document).ready(function(){
|
42
|
+
var now, delta
|
43
|
+
|
44
|
+
$(document.body)
|
45
|
+
.bind('touchstart', function(e){
|
46
|
+
now = Date.now()
|
47
|
+
delta = now - (touch.last || now)
|
48
|
+
touch.el = $(parentIfText(e.touches[0].target))
|
49
|
+
touchTimeout && clearTimeout(touchTimeout)
|
50
|
+
touch.x1 = e.touches[0].pageX
|
51
|
+
touch.y1 = e.touches[0].pageY
|
52
|
+
if (delta > 0 && delta <= 250) touch.isDoubleTap = true
|
53
|
+
touch.last = now
|
54
|
+
longTapTimeout = setTimeout(longTap, longTapDelay)
|
55
|
+
})
|
56
|
+
.bind('touchmove', function(e){
|
57
|
+
cancelLongTap()
|
58
|
+
touch.x2 = e.touches[0].pageX
|
59
|
+
touch.y2 = e.touches[0].pageY
|
60
|
+
if (Math.abs(touch.x1 - touch.x2) > 10)
|
61
|
+
e.preventDefault()
|
62
|
+
})
|
63
|
+
.bind('touchend', function(e){
|
64
|
+
cancelLongTap()
|
65
|
+
|
66
|
+
// swipe
|
67
|
+
if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) ||
|
68
|
+
(touch.y2 && Math.abs(touch.y1 - touch.y2) > 30))
|
69
|
+
|
70
|
+
swipeTimeout = setTimeout(function() {
|
71
|
+
touch.el.trigger('swipe')
|
72
|
+
touch.el.trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2)))
|
73
|
+
touch = {}
|
74
|
+
}, 0)
|
75
|
+
|
76
|
+
// normal tap
|
77
|
+
else if ('last' in touch)
|
78
|
+
|
79
|
+
// delay by one tick so we can cancel the 'tap' event if 'scroll' fires
|
80
|
+
// ('tap' fires before 'scroll')
|
81
|
+
tapTimeout = setTimeout(function() {
|
82
|
+
|
83
|
+
// trigger universal 'tap' with the option to cancelTouch()
|
84
|
+
// (cancelTouch cancels processing of single vs double taps for faster 'tap' response)
|
85
|
+
var event = $.Event('tap')
|
86
|
+
event.cancelTouch = cancelAll
|
87
|
+
touch.el.trigger(event)
|
88
|
+
|
89
|
+
// trigger double tap immediately
|
90
|
+
if (touch.isDoubleTap) {
|
91
|
+
touch.el.trigger('doubleTap')
|
92
|
+
touch = {}
|
93
|
+
}
|
94
|
+
|
95
|
+
// trigger single tap after 250ms of inactivity
|
96
|
+
else {
|
97
|
+
touchTimeout = setTimeout(function(){
|
98
|
+
touchTimeout = null
|
99
|
+
touch.el.trigger('singleTap')
|
100
|
+
touch = {}
|
101
|
+
}, 250)
|
102
|
+
}
|
103
|
+
|
104
|
+
}, 0)
|
105
|
+
|
106
|
+
})
|
107
|
+
.bind('touchcancel', cancelAll)
|
108
|
+
|
109
|
+
$(window).bind('scroll', cancelAll)
|
110
|
+
})
|
111
|
+
|
112
|
+
;['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(m){
|
113
|
+
$.fn[m] = function(callback){ return this.bind(m, callback) }
|
114
|
+
})
|
115
|
+
})(Zepto)
|
@@ -0,0 +1,790 @@
|
|
1
|
+
// Zepto.js
|
2
|
+
// (c) 2010-2012 Thomas Fuchs
|
3
|
+
// Zepto.js may be freely distributed under the MIT license.
|
4
|
+
|
5
|
+
var Zepto = (function() {
|
6
|
+
var undefined, key, $, classList, emptyArray = [], slice = emptyArray.slice, filter = emptyArray.filter,
|
7
|
+
document = window.document,
|
8
|
+
elementDisplay = {}, classCache = {},
|
9
|
+
getComputedStyle = document.defaultView.getComputedStyle,
|
10
|
+
cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 },
|
11
|
+
fragmentRE = /^\s*<(\w+|!)[^>]*>/,
|
12
|
+
tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,
|
13
|
+
rootNodeRE = /^(?:body|html)$/i,
|
14
|
+
|
15
|
+
// special attributes that should be get/set via method calls
|
16
|
+
methodAttributes = ['val', 'css', 'html', 'text', 'data', 'width', 'height', 'offset'],
|
17
|
+
|
18
|
+
adjacencyOperators = [ 'after', 'prepend', 'before', 'append' ],
|
19
|
+
table = document.createElement('table'),
|
20
|
+
tableRow = document.createElement('tr'),
|
21
|
+
containers = {
|
22
|
+
'tr': document.createElement('tbody'),
|
23
|
+
'tbody': table, 'thead': table, 'tfoot': table,
|
24
|
+
'td': tableRow, 'th': tableRow,
|
25
|
+
'*': document.createElement('div')
|
26
|
+
},
|
27
|
+
readyRE = /complete|loaded|interactive/,
|
28
|
+
classSelectorRE = /^\.([\w-]+)$/,
|
29
|
+
idSelectorRE = /^#([\w-]*)$/,
|
30
|
+
tagSelectorRE = /^[\w-]+$/,
|
31
|
+
class2type = {},
|
32
|
+
toString = class2type.toString,
|
33
|
+
zepto = {},
|
34
|
+
camelize, uniq,
|
35
|
+
tempParent = document.createElement('div')
|
36
|
+
|
37
|
+
zepto.matches = function(element, selector) {
|
38
|
+
if (!element || element.nodeType !== 1) return false
|
39
|
+
var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector ||
|
40
|
+
element.oMatchesSelector || element.matchesSelector
|
41
|
+
if (matchesSelector) return matchesSelector.call(element, selector)
|
42
|
+
// fall back to performing a selector:
|
43
|
+
var match, parent = element.parentNode, temp = !parent
|
44
|
+
if (temp) (parent = tempParent).appendChild(element)
|
45
|
+
match = ~zepto.qsa(parent, selector).indexOf(element)
|
46
|
+
temp && tempParent.removeChild(element)
|
47
|
+
return match
|
48
|
+
}
|
49
|
+
|
50
|
+
function type(obj) {
|
51
|
+
return obj == null ? String(obj) :
|
52
|
+
class2type[toString.call(obj)] || "object"
|
53
|
+
}
|
54
|
+
|
55
|
+
function isFunction(value) { return type(value) == "function" }
|
56
|
+
function isWindow(obj) { return obj != null && obj == obj.window }
|
57
|
+
function isDocument(obj) { return obj != null && obj.nodeType == obj.DOCUMENT_NODE }
|
58
|
+
function isObject(obj) { return type(obj) == "object" }
|
59
|
+
function isPlainObject(obj) {
|
60
|
+
return isObject(obj) && !isWindow(obj) && obj.__proto__ == Object.prototype
|
61
|
+
}
|
62
|
+
function isArray(value) { return value instanceof Array }
|
63
|
+
function likeArray(obj) { return typeof obj.length == 'number' }
|
64
|
+
|
65
|
+
function compact(array) { return filter.call(array, function(item){ return item != null }) }
|
66
|
+
function flatten(array) { return array.length > 0 ? $.fn.concat.apply([], array) : array }
|
67
|
+
camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) }
|
68
|
+
function dasherize(str) {
|
69
|
+
return str.replace(/::/g, '/')
|
70
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
|
71
|
+
.replace(/([a-z\d])([A-Z])/g, '$1_$2')
|
72
|
+
.replace(/_/g, '-')
|
73
|
+
.toLowerCase()
|
74
|
+
}
|
75
|
+
uniq = function(array){ return filter.call(array, function(item, idx){ return array.indexOf(item) == idx }) }
|
76
|
+
|
77
|
+
function classRE(name) {
|
78
|
+
return name in classCache ?
|
79
|
+
classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)'))
|
80
|
+
}
|
81
|
+
|
82
|
+
function maybeAddPx(name, value) {
|
83
|
+
return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value
|
84
|
+
}
|
85
|
+
|
86
|
+
function defaultDisplay(nodeName) {
|
87
|
+
var element, display
|
88
|
+
if (!elementDisplay[nodeName]) {
|
89
|
+
element = document.createElement(nodeName)
|
90
|
+
document.body.appendChild(element)
|
91
|
+
display = getComputedStyle(element, '').getPropertyValue("display")
|
92
|
+
element.parentNode.removeChild(element)
|
93
|
+
display == "none" && (display = "block")
|
94
|
+
elementDisplay[nodeName] = display
|
95
|
+
}
|
96
|
+
return elementDisplay[nodeName]
|
97
|
+
}
|
98
|
+
|
99
|
+
function children(element) {
|
100
|
+
return 'children' in element ?
|
101
|
+
slice.call(element.children) :
|
102
|
+
$.map(element.childNodes, function(node){ if (node.nodeType == 1) return node })
|
103
|
+
}
|
104
|
+
|
105
|
+
// `$.zepto.fragment` takes a html string and an optional tag name
|
106
|
+
// to generate DOM nodes nodes from the given html string.
|
107
|
+
// The generated DOM nodes are returned as an array.
|
108
|
+
// This function can be overriden in plugins for example to make
|
109
|
+
// it compatible with browsers that don't support the DOM fully.
|
110
|
+
zepto.fragment = function(html, name, properties) {
|
111
|
+
if (html.replace) html = html.replace(tagExpanderRE, "<$1></$2>")
|
112
|
+
if (name === undefined) name = fragmentRE.test(html) && RegExp.$1
|
113
|
+
if (!(name in containers)) name = '*'
|
114
|
+
|
115
|
+
var nodes, dom, container = containers[name]
|
116
|
+
container.innerHTML = '' + html
|
117
|
+
dom = $.each(slice.call(container.childNodes), function(){
|
118
|
+
container.removeChild(this)
|
119
|
+
})
|
120
|
+
if (isPlainObject(properties)) {
|
121
|
+
nodes = $(dom)
|
122
|
+
$.each(properties, function(key, value) {
|
123
|
+
if (methodAttributes.indexOf(key) > -1) nodes[key](value)
|
124
|
+
else nodes.attr(key, value)
|
125
|
+
})
|
126
|
+
}
|
127
|
+
return dom
|
128
|
+
}
|
129
|
+
|
130
|
+
// `$.zepto.Z` swaps out the prototype of the given `dom` array
|
131
|
+
// of nodes with `$.fn` and thus supplying all the Zepto functions
|
132
|
+
// to the array. Note that `__proto__` is not supported on Internet
|
133
|
+
// Explorer. This method can be overriden in plugins.
|
134
|
+
zepto.Z = function(dom, selector) {
|
135
|
+
dom = dom || []
|
136
|
+
dom.__proto__ = $.fn
|
137
|
+
dom.selector = selector || ''
|
138
|
+
return dom
|
139
|
+
}
|
140
|
+
|
141
|
+
// `$.zepto.isZ` should return `true` if the given object is a Zepto
|
142
|
+
// collection. This method can be overriden in plugins.
|
143
|
+
zepto.isZ = function(object) {
|
144
|
+
return object instanceof zepto.Z
|
145
|
+
}
|
146
|
+
|
147
|
+
// `$.zepto.init` is Zepto's counterpart to jQuery's `$.fn.init` and
|
148
|
+
// takes a CSS selector and an optional context (and handles various
|
149
|
+
// special cases).
|
150
|
+
// This method can be overriden in plugins.
|
151
|
+
zepto.init = function(selector, context) {
|
152
|
+
// If nothing given, return an empty Zepto collection
|
153
|
+
if (!selector) return zepto.Z()
|
154
|
+
// If a function is given, call it when the DOM is ready
|
155
|
+
else if (isFunction(selector)) return $(document).ready(selector)
|
156
|
+
// If a Zepto collection is given, juts return it
|
157
|
+
else if (zepto.isZ(selector)) return selector
|
158
|
+
else {
|
159
|
+
var dom
|
160
|
+
// normalize array if an array of nodes is given
|
161
|
+
if (isArray(selector)) dom = compact(selector)
|
162
|
+
// Wrap DOM nodes. If a plain object is given, duplicate it.
|
163
|
+
else if (isObject(selector))
|
164
|
+
dom = [isPlainObject(selector) ? $.extend({}, selector) : selector], selector = null
|
165
|
+
// If it's a html fragment, create nodes from it
|
166
|
+
else if (fragmentRE.test(selector))
|
167
|
+
dom = zepto.fragment(selector.trim(), RegExp.$1, context), selector = null
|
168
|
+
// If there's a context, create a collection on that context first, and select
|
169
|
+
// nodes from there
|
170
|
+
else if (context !== undefined) return $(context).find(selector)
|
171
|
+
// And last but no least, if it's a CSS selector, use it to select nodes.
|
172
|
+
else dom = zepto.qsa(document, selector)
|
173
|
+
// create a new Zepto collection from the nodes found
|
174
|
+
return zepto.Z(dom, selector)
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
// `$` will be the base `Zepto` object. When calling this
|
179
|
+
// function just call `$.zepto.init, which makes the implementation
|
180
|
+
// details of selecting nodes and creating Zepto collections
|
181
|
+
// patchable in plugins.
|
182
|
+
$ = function(selector, context){
|
183
|
+
return zepto.init(selector, context)
|
184
|
+
}
|
185
|
+
|
186
|
+
function extend(target, source, deep) {
|
187
|
+
for (key in source)
|
188
|
+
if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
|
189
|
+
if (isPlainObject(source[key]) && !isPlainObject(target[key]))
|
190
|
+
target[key] = {}
|
191
|
+
if (isArray(source[key]) && !isArray(target[key]))
|
192
|
+
target[key] = []
|
193
|
+
extend(target[key], source[key], deep)
|
194
|
+
}
|
195
|
+
else if (source[key] !== undefined) target[key] = source[key]
|
196
|
+
}
|
197
|
+
|
198
|
+
// Copy all but undefined properties from one or more
|
199
|
+
// objects to the `target` object.
|
200
|
+
$.extend = function(target){
|
201
|
+
var deep, args = slice.call(arguments, 1)
|
202
|
+
if (typeof target == 'boolean') {
|
203
|
+
deep = target
|
204
|
+
target = args.shift()
|
205
|
+
}
|
206
|
+
args.forEach(function(arg){ extend(target, arg, deep) })
|
207
|
+
return target
|
208
|
+
}
|
209
|
+
|
210
|
+
// `$.zepto.qsa` is Zepto's CSS selector implementation which
|
211
|
+
// uses `document.querySelectorAll` and optimizes for some special cases, like `#id`.
|
212
|
+
// This method can be overriden in plugins.
|
213
|
+
zepto.qsa = function(element, selector){
|
214
|
+
var found
|
215
|
+
return (isDocument(element) && idSelectorRE.test(selector)) ?
|
216
|
+
( (found = element.getElementById(RegExp.$1)) ? [found] : [] ) :
|
217
|
+
(element.nodeType !== 1 && element.nodeType !== 9) ? [] :
|
218
|
+
slice.call(
|
219
|
+
classSelectorRE.test(selector) ? element.getElementsByClassName(RegExp.$1) :
|
220
|
+
tagSelectorRE.test(selector) ? element.getElementsByTagName(selector) :
|
221
|
+
element.querySelectorAll(selector)
|
222
|
+
)
|
223
|
+
}
|
224
|
+
|
225
|
+
function filtered(nodes, selector) {
|
226
|
+
return selector === undefined ? $(nodes) : $(nodes).filter(selector)
|
227
|
+
}
|
228
|
+
|
229
|
+
$.contains = function(parent, node) {
|
230
|
+
return parent !== node && parent.contains(node)
|
231
|
+
}
|
232
|
+
|
233
|
+
function funcArg(context, arg, idx, payload) {
|
234
|
+
return isFunction(arg) ? arg.call(context, idx, payload) : arg
|
235
|
+
}
|
236
|
+
|
237
|
+
function setAttribute(node, name, value) {
|
238
|
+
value == null ? node.removeAttribute(name) : node.setAttribute(name, value)
|
239
|
+
}
|
240
|
+
|
241
|
+
// access className property while respecting SVGAnimatedString
|
242
|
+
function className(node, value){
|
243
|
+
var klass = node.className,
|
244
|
+
svg = klass && klass.baseVal !== undefined
|
245
|
+
|
246
|
+
if (value === undefined) return svg ? klass.baseVal : klass
|
247
|
+
svg ? (klass.baseVal = value) : (node.className = value)
|
248
|
+
}
|
249
|
+
|
250
|
+
// "true" => true
|
251
|
+
// "false" => false
|
252
|
+
// "null" => null
|
253
|
+
// "42" => 42
|
254
|
+
// "42.5" => 42.5
|
255
|
+
// JSON => parse if valid
|
256
|
+
// String => self
|
257
|
+
function deserializeValue(value) {
|
258
|
+
var num
|
259
|
+
try {
|
260
|
+
return value ?
|
261
|
+
value == "true" ||
|
262
|
+
( value == "false" ? false :
|
263
|
+
value == "null" ? null :
|
264
|
+
!isNaN(num = Number(value)) ? num :
|
265
|
+
/^[\[\{]/.test(value) ? $.parseJSON(value) :
|
266
|
+
value )
|
267
|
+
: value
|
268
|
+
} catch(e) {
|
269
|
+
return value
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
$.type = type
|
274
|
+
$.isFunction = isFunction
|
275
|
+
$.isWindow = isWindow
|
276
|
+
$.isArray = isArray
|
277
|
+
$.isPlainObject = isPlainObject
|
278
|
+
|
279
|
+
$.isEmptyObject = function(obj) {
|
280
|
+
var name
|
281
|
+
for (name in obj) return false
|
282
|
+
return true
|
283
|
+
}
|
284
|
+
|
285
|
+
$.inArray = function(elem, array, i){
|
286
|
+
return emptyArray.indexOf.call(array, elem, i)
|
287
|
+
}
|
288
|
+
|
289
|
+
$.camelCase = camelize
|
290
|
+
$.trim = function(str) { return str.trim() }
|
291
|
+
|
292
|
+
// plugin compatibility
|
293
|
+
$.uuid = 0
|
294
|
+
$.support = { }
|
295
|
+
$.expr = { }
|
296
|
+
|
297
|
+
$.map = function(elements, callback){
|
298
|
+
var value, values = [], i, key
|
299
|
+
if (likeArray(elements))
|
300
|
+
for (i = 0; i < elements.length; i++) {
|
301
|
+
value = callback(elements[i], i)
|
302
|
+
if (value != null) values.push(value)
|
303
|
+
}
|
304
|
+
else
|
305
|
+
for (key in elements) {
|
306
|
+
value = callback(elements[key], key)
|
307
|
+
if (value != null) values.push(value)
|
308
|
+
}
|
309
|
+
return flatten(values)
|
310
|
+
}
|
311
|
+
|
312
|
+
$.each = function(elements, callback){
|
313
|
+
var i, key
|
314
|
+
if (likeArray(elements)) {
|
315
|
+
for (i = 0; i < elements.length; i++)
|
316
|
+
if (callback.call(elements[i], i, elements[i]) === false) return elements
|
317
|
+
} else {
|
318
|
+
for (key in elements)
|
319
|
+
if (callback.call(elements[key], key, elements[key]) === false) return elements
|
320
|
+
}
|
321
|
+
|
322
|
+
return elements
|
323
|
+
}
|
324
|
+
|
325
|
+
$.grep = function(elements, callback){
|
326
|
+
return filter.call(elements, callback)
|
327
|
+
}
|
328
|
+
|
329
|
+
if (window.JSON) $.parseJSON = JSON.parse
|
330
|
+
|
331
|
+
// Populate the class2type map
|
332
|
+
$.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
|
333
|
+
class2type[ "[object " + name + "]" ] = name.toLowerCase()
|
334
|
+
})
|
335
|
+
|
336
|
+
// Define methods that will be available on all
|
337
|
+
// Zepto collections
|
338
|
+
$.fn = {
|
339
|
+
// Because a collection acts like an array
|
340
|
+
// copy over these useful array functions.
|
341
|
+
forEach: emptyArray.forEach,
|
342
|
+
reduce: emptyArray.reduce,
|
343
|
+
push: emptyArray.push,
|
344
|
+
sort: emptyArray.sort,
|
345
|
+
indexOf: emptyArray.indexOf,
|
346
|
+
concat: emptyArray.concat,
|
347
|
+
|
348
|
+
// `map` and `slice` in the jQuery API work differently
|
349
|
+
// from their array counterparts
|
350
|
+
map: function(fn){
|
351
|
+
return $($.map(this, function(el, i){ return fn.call(el, i, el) }))
|
352
|
+
},
|
353
|
+
slice: function(){
|
354
|
+
return $(slice.apply(this, arguments))
|
355
|
+
},
|
356
|
+
|
357
|
+
ready: function(callback){
|
358
|
+
if (readyRE.test(document.readyState)) callback($)
|
359
|
+
else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false)
|
360
|
+
return this
|
361
|
+
},
|
362
|
+
get: function(idx){
|
363
|
+
return idx === undefined ? slice.call(this) : this[idx >= 0 ? idx : idx + this.length]
|
364
|
+
},
|
365
|
+
toArray: function(){ return this.get() },
|
366
|
+
size: function(){
|
367
|
+
return this.length
|
368
|
+
},
|
369
|
+
remove: function(){
|
370
|
+
return this.each(function(){
|
371
|
+
if (this.parentNode != null)
|
372
|
+
this.parentNode.removeChild(this)
|
373
|
+
})
|
374
|
+
},
|
375
|
+
each: function(callback){
|
376
|
+
emptyArray.every.call(this, function(el, idx){
|
377
|
+
return callback.call(el, idx, el) !== false
|
378
|
+
})
|
379
|
+
return this
|
380
|
+
},
|
381
|
+
filter: function(selector){
|
382
|
+
if (isFunction(selector)) return this.not(this.not(selector))
|
383
|
+
return $(filter.call(this, function(element){
|
384
|
+
return zepto.matches(element, selector)
|
385
|
+
}))
|
386
|
+
},
|
387
|
+
add: function(selector,context){
|
388
|
+
return $(uniq(this.concat($(selector,context))))
|
389
|
+
},
|
390
|
+
is: function(selector){
|
391
|
+
return this.length > 0 && zepto.matches(this[0], selector)
|
392
|
+
},
|
393
|
+
not: function(selector){
|
394
|
+
var nodes=[]
|
395
|
+
if (isFunction(selector) && selector.call !== undefined)
|
396
|
+
this.each(function(idx){
|
397
|
+
if (!selector.call(this,idx)) nodes.push(this)
|
398
|
+
})
|
399
|
+
else {
|
400
|
+
var excludes = typeof selector == 'string' ? this.filter(selector) :
|
401
|
+
(likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector)
|
402
|
+
this.forEach(function(el){
|
403
|
+
if (excludes.indexOf(el) < 0) nodes.push(el)
|
404
|
+
})
|
405
|
+
}
|
406
|
+
return $(nodes)
|
407
|
+
},
|
408
|
+
has: function(selector){
|
409
|
+
return this.filter(function(){
|
410
|
+
return isObject(selector) ?
|
411
|
+
$.contains(this, selector) :
|
412
|
+
$(this).find(selector).size()
|
413
|
+
})
|
414
|
+
},
|
415
|
+
eq: function(idx){
|
416
|
+
return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1)
|
417
|
+
},
|
418
|
+
first: function(){
|
419
|
+
var el = this[0]
|
420
|
+
return el && !isObject(el) ? el : $(el)
|
421
|
+
},
|
422
|
+
last: function(){
|
423
|
+
var el = this[this.length - 1]
|
424
|
+
return el && !isObject(el) ? el : $(el)
|
425
|
+
},
|
426
|
+
find: function(selector){
|
427
|
+
var result, $this = this
|
428
|
+
if (typeof selector == 'object')
|
429
|
+
result = $(selector).filter(function(){
|
430
|
+
var node = this
|
431
|
+
return emptyArray.some.call($this, function(parent){
|
432
|
+
return $.contains(parent, node)
|
433
|
+
})
|
434
|
+
})
|
435
|
+
else if (this.length == 1) result = $(zepto.qsa(this[0], selector))
|
436
|
+
else result = this.map(function(){ return zepto.qsa(this, selector) })
|
437
|
+
return result
|
438
|
+
},
|
439
|
+
closest: function(selector, context){
|
440
|
+
var node = this[0], collection = false
|
441
|
+
if (typeof selector == 'object') collection = $(selector)
|
442
|
+
while (node && !(collection ? collection.indexOf(node) >= 0 : zepto.matches(node, selector)))
|
443
|
+
node = node !== context && !isDocument(node) && node.parentNode
|
444
|
+
return $(node)
|
445
|
+
},
|
446
|
+
parents: function(selector){
|
447
|
+
var ancestors = [], nodes = this
|
448
|
+
while (nodes.length > 0)
|
449
|
+
nodes = $.map(nodes, function(node){
|
450
|
+
if ((node = node.parentNode) && !isDocument(node) && ancestors.indexOf(node) < 0) {
|
451
|
+
ancestors.push(node)
|
452
|
+
return node
|
453
|
+
}
|
454
|
+
})
|
455
|
+
return filtered(ancestors, selector)
|
456
|
+
},
|
457
|
+
parent: function(selector){
|
458
|
+
return filtered(uniq(this.pluck('parentNode')), selector)
|
459
|
+
},
|
460
|
+
children: function(selector){
|
461
|
+
return filtered(this.map(function(){ return children(this) }), selector)
|
462
|
+
},
|
463
|
+
contents: function() {
|
464
|
+
return this.map(function() { return slice.call(this.childNodes) })
|
465
|
+
},
|
466
|
+
siblings: function(selector){
|
467
|
+
return filtered(this.map(function(i, el){
|
468
|
+
return filter.call(children(el.parentNode), function(child){ return child!==el })
|
469
|
+
}), selector)
|
470
|
+
},
|
471
|
+
empty: function(){
|
472
|
+
return this.each(function(){ this.innerHTML = '' })
|
473
|
+
},
|
474
|
+
// `pluck` is borrowed from Prototype.js
|
475
|
+
pluck: function(property){
|
476
|
+
return $.map(this, function(el){ return el[property] })
|
477
|
+
},
|
478
|
+
show: function(){
|
479
|
+
return this.each(function(){
|
480
|
+
this.style.display == "none" && (this.style.display = null)
|
481
|
+
if (getComputedStyle(this, '').getPropertyValue("display") == "none")
|
482
|
+
this.style.display = defaultDisplay(this.nodeName)
|
483
|
+
})
|
484
|
+
},
|
485
|
+
replaceWith: function(newContent){
|
486
|
+
return this.before(newContent).remove()
|
487
|
+
},
|
488
|
+
wrap: function(structure){
|
489
|
+
var func = isFunction(structure)
|
490
|
+
if (this[0] && !func)
|
491
|
+
var dom = $(structure).get(0),
|
492
|
+
clone = dom.parentNode || this.length > 1
|
493
|
+
|
494
|
+
return this.each(function(index){
|
495
|
+
$(this).wrapAll(
|
496
|
+
func ? structure.call(this, index) :
|
497
|
+
clone ? dom.cloneNode(true) : dom
|
498
|
+
)
|
499
|
+
})
|
500
|
+
},
|
501
|
+
wrapAll: function(structure){
|
502
|
+
if (this[0]) {
|
503
|
+
$(this[0]).before(structure = $(structure))
|
504
|
+
var children
|
505
|
+
// drill down to the inmost element
|
506
|
+
while ((children = structure.children()).length) structure = children.first()
|
507
|
+
$(structure).append(this)
|
508
|
+
}
|
509
|
+
return this
|
510
|
+
},
|
511
|
+
wrapInner: function(structure){
|
512
|
+
var func = isFunction(structure)
|
513
|
+
return this.each(function(index){
|
514
|
+
var self = $(this), contents = self.contents(),
|
515
|
+
dom = func ? structure.call(this, index) : structure
|
516
|
+
contents.length ? contents.wrapAll(dom) : self.append(dom)
|
517
|
+
})
|
518
|
+
},
|
519
|
+
unwrap: function(){
|
520
|
+
this.parent().each(function(){
|
521
|
+
$(this).replaceWith($(this).children())
|
522
|
+
})
|
523
|
+
return this
|
524
|
+
},
|
525
|
+
clone: function(){
|
526
|
+
return this.map(function(){ return this.cloneNode(true) })
|
527
|
+
},
|
528
|
+
hide: function(){
|
529
|
+
return this.css("display", "none")
|
530
|
+
},
|
531
|
+
toggle: function(setting){
|
532
|
+
return this.each(function(){
|
533
|
+
var el = $(this)
|
534
|
+
;(setting === undefined ? el.css("display") == "none" : setting) ? el.show() : el.hide()
|
535
|
+
})
|
536
|
+
},
|
537
|
+
prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') },
|
538
|
+
next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') },
|
539
|
+
html: function(html){
|
540
|
+
return html === undefined ?
|
541
|
+
(this.length > 0 ? this[0].innerHTML : null) :
|
542
|
+
this.each(function(idx){
|
543
|
+
var originHtml = this.innerHTML
|
544
|
+
$(this).empty().append( funcArg(this, html, idx, originHtml) )
|
545
|
+
})
|
546
|
+
},
|
547
|
+
text: function(text){
|
548
|
+
return text === undefined ?
|
549
|
+
(this.length > 0 ? this[0].textContent : null) :
|
550
|
+
this.each(function(){ this.textContent = text })
|
551
|
+
},
|
552
|
+
attr: function(name, value){
|
553
|
+
var result
|
554
|
+
return (typeof name == 'string' && value === undefined) ?
|
555
|
+
(this.length == 0 || this[0].nodeType !== 1 ? undefined :
|
556
|
+
(name == 'value' && this[0].nodeName == 'INPUT') ? this.val() :
|
557
|
+
(!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result
|
558
|
+
) :
|
559
|
+
this.each(function(idx){
|
560
|
+
if (this.nodeType !== 1) return
|
561
|
+
if (isObject(name)) for (key in name) setAttribute(this, key, name[key])
|
562
|
+
else setAttribute(this, name, funcArg(this, value, idx, this.getAttribute(name)))
|
563
|
+
})
|
564
|
+
},
|
565
|
+
removeAttr: function(name){
|
566
|
+
return this.each(function(){ this.nodeType === 1 && setAttribute(this, name) })
|
567
|
+
},
|
568
|
+
prop: function(name, value){
|
569
|
+
return (value === undefined) ?
|
570
|
+
(this[0] && this[0][name]) :
|
571
|
+
this.each(function(idx){
|
572
|
+
this[name] = funcArg(this, value, idx, this[name])
|
573
|
+
})
|
574
|
+
},
|
575
|
+
data: function(name, value){
|
576
|
+
var data = this.attr('data-' + dasherize(name), value)
|
577
|
+
return data !== null ? deserializeValue(data) : undefined
|
578
|
+
},
|
579
|
+
val: function(value){
|
580
|
+
return (value === undefined) ?
|
581
|
+
(this[0] && (this[0].multiple ?
|
582
|
+
$(this[0]).find('option').filter(function(o){ return this.selected }).pluck('value') :
|
583
|
+
this[0].value)
|
584
|
+
) :
|
585
|
+
this.each(function(idx){
|
586
|
+
this.value = funcArg(this, value, idx, this.value)
|
587
|
+
})
|
588
|
+
},
|
589
|
+
offset: function(coordinates){
|
590
|
+
if (coordinates) return this.each(function(index){
|
591
|
+
var $this = $(this),
|
592
|
+
coords = funcArg(this, coordinates, index, $this.offset()),
|
593
|
+
parentOffset = $this.offsetParent().offset(),
|
594
|
+
props = {
|
595
|
+
top: coords.top - parentOffset.top,
|
596
|
+
left: coords.left - parentOffset.left
|
597
|
+
}
|
598
|
+
|
599
|
+
if ($this.css('position') == 'static') props['position'] = 'relative'
|
600
|
+
$this.css(props)
|
601
|
+
})
|
602
|
+
if (this.length==0) return null
|
603
|
+
var obj = this[0].getBoundingClientRect()
|
604
|
+
return {
|
605
|
+
left: obj.left + window.pageXOffset,
|
606
|
+
top: obj.top + window.pageYOffset,
|
607
|
+
width: Math.round(obj.width),
|
608
|
+
height: Math.round(obj.height)
|
609
|
+
}
|
610
|
+
},
|
611
|
+
css: function(property, value){
|
612
|
+
if (arguments.length < 2 && typeof property == 'string')
|
613
|
+
return this[0] && (this[0].style[camelize(property)] || getComputedStyle(this[0], '').getPropertyValue(property))
|
614
|
+
|
615
|
+
var css = ''
|
616
|
+
if (type(property) == 'string') {
|
617
|
+
if (!value && value !== 0)
|
618
|
+
this.each(function(){ this.style.removeProperty(dasherize(property)) })
|
619
|
+
else
|
620
|
+
css = dasherize(property) + ":" + maybeAddPx(property, value)
|
621
|
+
} else {
|
622
|
+
for (key in property)
|
623
|
+
if (!property[key] && property[key] !== 0)
|
624
|
+
this.each(function(){ this.style.removeProperty(dasherize(key)) })
|
625
|
+
else
|
626
|
+
css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';'
|
627
|
+
}
|
628
|
+
|
629
|
+
return this.each(function(){ this.style.cssText += ';' + css })
|
630
|
+
},
|
631
|
+
index: function(element){
|
632
|
+
return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0])
|
633
|
+
},
|
634
|
+
hasClass: function(name){
|
635
|
+
return emptyArray.some.call(this, function(el){
|
636
|
+
return this.test(className(el))
|
637
|
+
}, classRE(name))
|
638
|
+
},
|
639
|
+
addClass: function(name){
|
640
|
+
return this.each(function(idx){
|
641
|
+
classList = []
|
642
|
+
var cls = className(this), newName = funcArg(this, name, idx, cls)
|
643
|
+
newName.split(/\s+/g).forEach(function(klass){
|
644
|
+
if (!$(this).hasClass(klass)) classList.push(klass)
|
645
|
+
}, this)
|
646
|
+
classList.length && className(this, cls + (cls ? " " : "") + classList.join(" "))
|
647
|
+
})
|
648
|
+
},
|
649
|
+
removeClass: function(name){
|
650
|
+
return this.each(function(idx){
|
651
|
+
if (name === undefined) return className(this, '')
|
652
|
+
classList = className(this)
|
653
|
+
funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass){
|
654
|
+
classList = classList.replace(classRE(klass), " ")
|
655
|
+
})
|
656
|
+
className(this, classList.trim())
|
657
|
+
})
|
658
|
+
},
|
659
|
+
toggleClass: function(name, when){
|
660
|
+
return this.each(function(idx){
|
661
|
+
var $this = $(this), names = funcArg(this, name, idx, className(this))
|
662
|
+
names.split(/\s+/g).forEach(function(klass){
|
663
|
+
(when === undefined ? !$this.hasClass(klass) : when) ?
|
664
|
+
$this.addClass(klass) : $this.removeClass(klass)
|
665
|
+
})
|
666
|
+
})
|
667
|
+
},
|
668
|
+
scrollTop: function(){
|
669
|
+
if (!this.length) return
|
670
|
+
return ('scrollTop' in this[0]) ? this[0].scrollTop : this[0].scrollY
|
671
|
+
},
|
672
|
+
position: function() {
|
673
|
+
if (!this.length) return
|
674
|
+
|
675
|
+
var elem = this[0],
|
676
|
+
// Get *real* offsetParent
|
677
|
+
offsetParent = this.offsetParent(),
|
678
|
+
// Get correct offsets
|
679
|
+
offset = this.offset(),
|
680
|
+
parentOffset = rootNodeRE.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset()
|
681
|
+
|
682
|
+
// Subtract element margins
|
683
|
+
// note: when an element has margin: auto the offsetLeft and marginLeft
|
684
|
+
// are the same in Safari causing offset.left to incorrectly be 0
|
685
|
+
offset.top -= parseFloat( $(elem).css('margin-top') ) || 0
|
686
|
+
offset.left -= parseFloat( $(elem).css('margin-left') ) || 0
|
687
|
+
|
688
|
+
// Add offsetParent borders
|
689
|
+
parentOffset.top += parseFloat( $(offsetParent[0]).css('border-top-width') ) || 0
|
690
|
+
parentOffset.left += parseFloat( $(offsetParent[0]).css('border-left-width') ) || 0
|
691
|
+
|
692
|
+
// Subtract the two offsets
|
693
|
+
return {
|
694
|
+
top: offset.top - parentOffset.top,
|
695
|
+
left: offset.left - parentOffset.left
|
696
|
+
}
|
697
|
+
},
|
698
|
+
offsetParent: function() {
|
699
|
+
return this.map(function(){
|
700
|
+
var parent = this.offsetParent || document.body
|
701
|
+
while (parent && !rootNodeRE.test(parent.nodeName) && $(parent).css("position") == "static")
|
702
|
+
parent = parent.offsetParent
|
703
|
+
return parent
|
704
|
+
})
|
705
|
+
}
|
706
|
+
}
|
707
|
+
|
708
|
+
// for now
|
709
|
+
$.fn.detach = $.fn.remove
|
710
|
+
|
711
|
+
// Generate the `width` and `height` functions
|
712
|
+
;['width', 'height'].forEach(function(dimension){
|
713
|
+
$.fn[dimension] = function(value){
|
714
|
+
var offset, el = this[0],
|
715
|
+
Dimension = dimension.replace(/./, function(m){ return m[0].toUpperCase() })
|
716
|
+
if (value === undefined) return isWindow(el) ? el['inner' + Dimension] :
|
717
|
+
isDocument(el) ? el.documentElement['offset' + Dimension] :
|
718
|
+
(offset = this.offset()) && offset[dimension]
|
719
|
+
else return this.each(function(idx){
|
720
|
+
el = $(this)
|
721
|
+
el.css(dimension, funcArg(this, value, idx, el[dimension]()))
|
722
|
+
})
|
723
|
+
}
|
724
|
+
})
|
725
|
+
|
726
|
+
function traverseNode(node, fun) {
|
727
|
+
fun(node)
|
728
|
+
for (var key in node.childNodes) traverseNode(node.childNodes[key], fun)
|
729
|
+
}
|
730
|
+
|
731
|
+
// Generate the `after`, `prepend`, `before`, `append`,
|
732
|
+
// `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods.
|
733
|
+
adjacencyOperators.forEach(function(operator, operatorIndex) {
|
734
|
+
var inside = operatorIndex % 2 //=> prepend, append
|
735
|
+
|
736
|
+
$.fn[operator] = function(){
|
737
|
+
// arguments can be nodes, arrays of nodes, Zepto objects and HTML strings
|
738
|
+
var argType, nodes = $.map(arguments, function(arg) {
|
739
|
+
argType = type(arg)
|
740
|
+
return argType == "object" || argType == "array" || arg == null ?
|
741
|
+
arg : zepto.fragment(arg)
|
742
|
+
}),
|
743
|
+
parent, copyByClone = this.length > 1
|
744
|
+
if (nodes.length < 1) return this
|
745
|
+
|
746
|
+
return this.each(function(_, target){
|
747
|
+
parent = inside ? target : target.parentNode
|
748
|
+
|
749
|
+
// convert all methods to a "before" operation
|
750
|
+
target = operatorIndex == 0 ? target.nextSibling :
|
751
|
+
operatorIndex == 1 ? target.firstChild :
|
752
|
+
operatorIndex == 2 ? target :
|
753
|
+
null
|
754
|
+
|
755
|
+
nodes.forEach(function(node){
|
756
|
+
if (copyByClone) node = node.cloneNode(true)
|
757
|
+
else if (!parent) return $(node).remove()
|
758
|
+
|
759
|
+
traverseNode(parent.insertBefore(node, target), function(el){
|
760
|
+
if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' &&
|
761
|
+
(!el.type || el.type === 'text/javascript') && !el.src)
|
762
|
+
window['eval'].call(window, el.innerHTML)
|
763
|
+
})
|
764
|
+
})
|
765
|
+
})
|
766
|
+
}
|
767
|
+
|
768
|
+
// after => insertAfter
|
769
|
+
// prepend => prependTo
|
770
|
+
// before => insertBefore
|
771
|
+
// append => appendTo
|
772
|
+
$.fn[inside ? operator+'To' : 'insert'+(operatorIndex ? 'Before' : 'After')] = function(html){
|
773
|
+
$(html)[operator](this)
|
774
|
+
return this
|
775
|
+
}
|
776
|
+
})
|
777
|
+
|
778
|
+
zepto.Z.prototype = $.fn
|
779
|
+
|
780
|
+
// Export internal API functions in the `$.zepto` namespace
|
781
|
+
zepto.uniq = uniq
|
782
|
+
zepto.deserializeValue = deserializeValue
|
783
|
+
$.zepto = zepto
|
784
|
+
|
785
|
+
return $
|
786
|
+
})()
|
787
|
+
|
788
|
+
// If `$` is not yet defined, point it to `Zepto`
|
789
|
+
window.Zepto = Zepto
|
790
|
+
'$' in window || (window.$ = Zepto)
|