zepto_rails 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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)