zepto-for-rails 0.1

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,1550 @@
1
+ /* Zepto v1.1.2 - zepto event ajax form ie - zeptojs.com/license */
2
+
3
+
4
+ var Zepto = (function() {
5
+ var undefined, key, $, classList, emptyArray = [], slice = emptyArray.slice, filter = emptyArray.filter,
6
+ document = window.document,
7
+ elementDisplay = {}, classCache = {},
8
+ cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 },
9
+ fragmentRE = /^\s*<(\w+|!)[^>]*>/,
10
+ singleTagRE = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,
11
+ tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,
12
+ rootNodeRE = /^(?:body|html)$/i,
13
+ capitalRE = /([A-Z])/g,
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
+ simpleSelectorRE = /^[\w-]*$/,
31
+ class2type = {},
32
+ toString = class2type.toString,
33
+ zepto = {},
34
+ camelize, uniq,
35
+ tempParent = document.createElement('div'),
36
+ propMap = {
37
+ 'tabindex': 'tabIndex',
38
+ 'readonly': 'readOnly',
39
+ 'for': 'htmlFor',
40
+ 'class': 'className',
41
+ 'maxlength': 'maxLength',
42
+ 'cellspacing': 'cellSpacing',
43
+ 'cellpadding': 'cellPadding',
44
+ 'rowspan': 'rowSpan',
45
+ 'colspan': 'colSpan',
46
+ 'usemap': 'useMap',
47
+ 'frameborder': 'frameBorder',
48
+ 'contenteditable': 'contentEditable'
49
+ }
50
+
51
+ zepto.matches = function(element, selector) {
52
+ if (!selector || !element || element.nodeType !== 1) return false
53
+ var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector ||
54
+ element.oMatchesSelector || element.matchesSelector
55
+ if (matchesSelector) return matchesSelector.call(element, selector)
56
+ // fall back to performing a selector:
57
+ var match, parent = element.parentNode, temp = !parent
58
+ if (temp) (parent = tempParent).appendChild(element)
59
+ match = ~zepto.qsa(parent, selector).indexOf(element)
60
+ temp && tempParent.removeChild(element)
61
+ return match
62
+ }
63
+
64
+ function type(obj) {
65
+ return obj == null ? String(obj) :
66
+ class2type[toString.call(obj)] || "object"
67
+ }
68
+
69
+ function isFunction(value) { return type(value) == "function" }
70
+ function isWindow(obj) { return obj != null && obj == obj.window }
71
+ function isDocument(obj) { return obj != null && obj.nodeType == obj.DOCUMENT_NODE }
72
+ function isObject(obj) { return type(obj) == "object" }
73
+ function isPlainObject(obj) {
74
+ return isObject(obj) && !isWindow(obj) && Object.getPrototypeOf(obj) == Object.prototype
75
+ }
76
+ function isArray(value) { return value instanceof Array }
77
+ function likeArray(obj) { return typeof obj.length == 'number' }
78
+
79
+ function compact(array) { return filter.call(array, function(item){ return item != null }) }
80
+ function flatten(array) { return array.length > 0 ? $.fn.concat.apply([], array) : array }
81
+ camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) }
82
+ function dasherize(str) {
83
+ return str.replace(/::/g, '/')
84
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
85
+ .replace(/([a-z\d])([A-Z])/g, '$1_$2')
86
+ .replace(/_/g, '-')
87
+ .toLowerCase()
88
+ }
89
+ uniq = function(array){ return filter.call(array, function(item, idx){ return array.indexOf(item) == idx }) }
90
+
91
+ function classRE(name) {
92
+ return name in classCache ?
93
+ classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)'))
94
+ }
95
+
96
+ function maybeAddPx(name, value) {
97
+ return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value
98
+ }
99
+
100
+ function defaultDisplay(nodeName) {
101
+ var element, display
102
+ if (!elementDisplay[nodeName]) {
103
+ element = document.createElement(nodeName)
104
+ document.body.appendChild(element)
105
+ display = getComputedStyle(element, '').getPropertyValue("display")
106
+ element.parentNode.removeChild(element)
107
+ display == "none" && (display = "block")
108
+ elementDisplay[nodeName] = display
109
+ }
110
+ return elementDisplay[nodeName]
111
+ }
112
+
113
+ function children(element) {
114
+ return 'children' in element ?
115
+ slice.call(element.children) :
116
+ $.map(element.childNodes, function(node){ if (node.nodeType == 1) return node })
117
+ }
118
+
119
+ // `$.zepto.fragment` takes a html string and an optional tag name
120
+ // to generate DOM nodes nodes from the given html string.
121
+ // The generated DOM nodes are returned as an array.
122
+ // This function can be overriden in plugins for example to make
123
+ // it compatible with browsers that don't support the DOM fully.
124
+ zepto.fragment = function(html, name, properties) {
125
+ var dom, nodes, container
126
+
127
+ // A special case optimization for a single tag
128
+ if (singleTagRE.test(html)) dom = $(document.createElement(RegExp.$1))
129
+
130
+ if (!dom) {
131
+ if (html.replace) html = html.replace(tagExpanderRE, "<$1></$2>")
132
+ if (name === undefined) name = fragmentRE.test(html) && RegExp.$1
133
+ if (!(name in containers)) name = '*'
134
+
135
+ container = containers[name]
136
+ container.innerHTML = '' + html
137
+ dom = $.each(slice.call(container.childNodes), function(){
138
+ container.removeChild(this)
139
+ })
140
+ }
141
+
142
+ if (isPlainObject(properties)) {
143
+ nodes = $(dom)
144
+ $.each(properties, function(key, value) {
145
+ if (methodAttributes.indexOf(key) > -1) nodes[key](value)
146
+ else nodes.attr(key, value)
147
+ })
148
+ }
149
+
150
+ return dom
151
+ }
152
+
153
+ // `$.zepto.Z` swaps out the prototype of the given `dom` array
154
+ // of nodes with `$.fn` and thus supplying all the Zepto functions
155
+ // to the array. Note that `__proto__` is not supported on Internet
156
+ // Explorer. This method can be overriden in plugins.
157
+ zepto.Z = function(dom, selector) {
158
+ dom = dom || []
159
+ dom.__proto__ = $.fn
160
+ dom.selector = selector || ''
161
+ return dom
162
+ }
163
+
164
+ // `$.zepto.isZ` should return `true` if the given object is a Zepto
165
+ // collection. This method can be overriden in plugins.
166
+ zepto.isZ = function(object) {
167
+ return object instanceof zepto.Z
168
+ }
169
+
170
+ // `$.zepto.init` is Zepto's counterpart to jQuery's `$.fn.init` and
171
+ // takes a CSS selector and an optional context (and handles various
172
+ // special cases).
173
+ // This method can be overriden in plugins.
174
+ zepto.init = function(selector, context) {
175
+ var dom
176
+ // If nothing given, return an empty Zepto collection
177
+ if (!selector) return zepto.Z()
178
+ // Optimize for string selectors
179
+ else if (typeof selector == 'string') {
180
+ selector = selector.trim()
181
+ // If it's a html fragment, create nodes from it
182
+ // Note: In both Chrome 21 and Firefox 15, DOM error 12
183
+ // is thrown if the fragment doesn't begin with <
184
+ if (selector[0] == '<' && fragmentRE.test(selector))
185
+ dom = zepto.fragment(selector, RegExp.$1, context), selector = null
186
+ // If there's a context, create a collection on that context first, and select
187
+ // nodes from there
188
+ else if (context !== undefined) return $(context).find(selector)
189
+ // If it's a CSS selector, use it to select nodes.
190
+ else dom = zepto.qsa(document, selector)
191
+ }
192
+ // If a function is given, call it when the DOM is ready
193
+ else if (isFunction(selector)) return $(document).ready(selector)
194
+ // If a Zepto collection is given, just return it
195
+ else if (zepto.isZ(selector)) return selector
196
+ else {
197
+ // normalize array if an array of nodes is given
198
+ if (isArray(selector)) dom = compact(selector)
199
+ // Wrap DOM nodes.
200
+ else if (isObject(selector))
201
+ dom = [selector], selector = null
202
+ // If it's a html fragment, create nodes from it
203
+ else if (fragmentRE.test(selector))
204
+ dom = zepto.fragment(selector.trim(), RegExp.$1, context), selector = null
205
+ // If there's a context, create a collection on that context first, and select
206
+ // nodes from there
207
+ else if (context !== undefined) return $(context).find(selector)
208
+ // And last but no least, if it's a CSS selector, use it to select nodes.
209
+ else dom = zepto.qsa(document, selector)
210
+ }
211
+ // create a new Zepto collection from the nodes found
212
+ return zepto.Z(dom, selector)
213
+ }
214
+
215
+ // `$` will be the base `Zepto` object. When calling this
216
+ // function just call `$.zepto.init, which makes the implementation
217
+ // details of selecting nodes and creating Zepto collections
218
+ // patchable in plugins.
219
+ $ = function(selector, context){
220
+ return zepto.init(selector, context)
221
+ }
222
+
223
+ function extend(target, source, deep) {
224
+ for (key in source)
225
+ if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
226
+ if (isPlainObject(source[key]) && !isPlainObject(target[key]))
227
+ target[key] = {}
228
+ if (isArray(source[key]) && !isArray(target[key]))
229
+ target[key] = []
230
+ extend(target[key], source[key], deep)
231
+ }
232
+ else if (source[key] !== undefined) target[key] = source[key]
233
+ }
234
+
235
+ // Copy all but undefined properties from one or more
236
+ // objects to the `target` object.
237
+ $.extend = function(target){
238
+ var deep, args = slice.call(arguments, 1)
239
+ if (typeof target == 'boolean') {
240
+ deep = target
241
+ target = args.shift()
242
+ }
243
+ args.forEach(function(arg){ extend(target, arg, deep) })
244
+ return target
245
+ }
246
+
247
+ // `$.zepto.qsa` is Zepto's CSS selector implementation which
248
+ // uses `document.querySelectorAll` and optimizes for some special cases, like `#id`.
249
+ // This method can be overriden in plugins.
250
+ zepto.qsa = function(element, selector){
251
+ var found,
252
+ maybeID = selector[0] == '#',
253
+ maybeClass = !maybeID && selector[0] == '.',
254
+ nameOnly = maybeID || maybeClass ? selector.slice(1) : selector, // Ensure that a 1 char tag name still gets checked
255
+ isSimple = simpleSelectorRE.test(nameOnly)
256
+ return (isDocument(element) && isSimple && maybeID) ?
257
+ ( (found = element.getElementById(nameOnly)) ? [found] : [] ) :
258
+ (element.nodeType !== 1 && element.nodeType !== 9) ? [] :
259
+ slice.call(
260
+ isSimple && !maybeID ?
261
+ maybeClass ? element.getElementsByClassName(nameOnly) : // If it's simple, it could be a class
262
+ element.getElementsByTagName(selector) : // Or a tag
263
+ element.querySelectorAll(selector) // Or it's not simple, and we need to query all
264
+ )
265
+ }
266
+
267
+ function filtered(nodes, selector) {
268
+ return selector == null ? $(nodes) : $(nodes).filter(selector)
269
+ }
270
+
271
+ $.contains = function(parent, node) {
272
+ return parent !== node && parent.contains(node)
273
+ }
274
+
275
+ function funcArg(context, arg, idx, payload) {
276
+ return isFunction(arg) ? arg.call(context, idx, payload) : arg
277
+ }
278
+
279
+ function setAttribute(node, name, value) {
280
+ value == null ? node.removeAttribute(name) : node.setAttribute(name, value)
281
+ }
282
+
283
+ // access className property while respecting SVGAnimatedString
284
+ function className(node, value){
285
+ var klass = node.className,
286
+ svg = klass && klass.baseVal !== undefined
287
+
288
+ if (value === undefined) return svg ? klass.baseVal : klass
289
+ svg ? (klass.baseVal = value) : (node.className = value)
290
+ }
291
+
292
+ // "true" => true
293
+ // "false" => false
294
+ // "null" => null
295
+ // "42" => 42
296
+ // "42.5" => 42.5
297
+ // "08" => "08"
298
+ // JSON => parse if valid
299
+ // String => self
300
+ function deserializeValue(value) {
301
+ var num
302
+ try {
303
+ return value ?
304
+ value == "true" ||
305
+ ( value == "false" ? false :
306
+ value == "null" ? null :
307
+ !/^0/.test(value) && !isNaN(num = Number(value)) ? num :
308
+ /^[\[\{]/.test(value) ? $.parseJSON(value) :
309
+ value )
310
+ : value
311
+ } catch(e) {
312
+ return value
313
+ }
314
+ }
315
+
316
+ $.type = type
317
+ $.isFunction = isFunction
318
+ $.isWindow = isWindow
319
+ $.isArray = isArray
320
+ $.isPlainObject = isPlainObject
321
+
322
+ $.isEmptyObject = function(obj) {
323
+ var name
324
+ for (name in obj) return false
325
+ return true
326
+ }
327
+
328
+ $.inArray = function(elem, array, i){
329
+ return emptyArray.indexOf.call(array, elem, i)
330
+ }
331
+
332
+ $.camelCase = camelize
333
+ $.trim = function(str) {
334
+ return str == null ? "" : String.prototype.trim.call(str)
335
+ }
336
+
337
+ // plugin compatibility
338
+ $.uuid = 0
339
+ $.support = { }
340
+ $.expr = { }
341
+
342
+ $.map = function(elements, callback){
343
+ var value, values = [], i, key
344
+ if (likeArray(elements))
345
+ for (i = 0; i < elements.length; i++) {
346
+ value = callback(elements[i], i)
347
+ if (value != null) values.push(value)
348
+ }
349
+ else
350
+ for (key in elements) {
351
+ value = callback(elements[key], key)
352
+ if (value != null) values.push(value)
353
+ }
354
+ return flatten(values)
355
+ }
356
+
357
+ $.each = function(elements, callback){
358
+ var i, key
359
+ if (likeArray(elements)) {
360
+ for (i = 0; i < elements.length; i++)
361
+ if (callback.call(elements[i], i, elements[i]) === false) return elements
362
+ } else {
363
+ for (key in elements)
364
+ if (callback.call(elements[key], key, elements[key]) === false) return elements
365
+ }
366
+
367
+ return elements
368
+ }
369
+
370
+ $.grep = function(elements, callback){
371
+ return filter.call(elements, callback)
372
+ }
373
+
374
+ if (window.JSON) $.parseJSON = JSON.parse
375
+
376
+ // Populate the class2type map
377
+ $.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
378
+ class2type[ "[object " + name + "]" ] = name.toLowerCase()
379
+ })
380
+
381
+ // Define methods that will be available on all
382
+ // Zepto collections
383
+ $.fn = {
384
+ // Because a collection acts like an array
385
+ // copy over these useful array functions.
386
+ forEach: emptyArray.forEach,
387
+ reduce: emptyArray.reduce,
388
+ push: emptyArray.push,
389
+ sort: emptyArray.sort,
390
+ indexOf: emptyArray.indexOf,
391
+ concat: emptyArray.concat,
392
+
393
+ // `map` and `slice` in the jQuery API work differently
394
+ // from their array counterparts
395
+ map: function(fn){
396
+ return $($.map(this, function(el, i){ return fn.call(el, i, el) }))
397
+ },
398
+ slice: function(){
399
+ return $(slice.apply(this, arguments))
400
+ },
401
+
402
+ ready: function(callback){
403
+ // need to check if document.body exists for IE as that browser reports
404
+ // document ready when it hasn't yet created the body element
405
+ if (readyRE.test(document.readyState) && document.body) callback($)
406
+ else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false)
407
+ return this
408
+ },
409
+ get: function(idx){
410
+ return idx === undefined ? slice.call(this) : this[idx >= 0 ? idx : idx + this.length]
411
+ },
412
+ toArray: function(){ return this.get() },
413
+ size: function(){
414
+ return this.length
415
+ },
416
+ remove: function(){
417
+ return this.each(function(){
418
+ if (this.parentNode != null)
419
+ this.parentNode.removeChild(this)
420
+ })
421
+ },
422
+ each: function(callback){
423
+ emptyArray.every.call(this, function(el, idx){
424
+ return callback.call(el, idx, el) !== false
425
+ })
426
+ return this
427
+ },
428
+ filter: function(selector){
429
+ if (isFunction(selector)) return this.not(this.not(selector))
430
+ return $(filter.call(this, function(element){
431
+ return zepto.matches(element, selector)
432
+ }))
433
+ },
434
+ add: function(selector,context){
435
+ return $(uniq(this.concat($(selector,context))))
436
+ },
437
+ is: function(selector){
438
+ return this.length > 0 && zepto.matches(this[0], selector)
439
+ },
440
+ not: function(selector){
441
+ var nodes=[]
442
+ if (isFunction(selector) && selector.call !== undefined)
443
+ this.each(function(idx){
444
+ if (!selector.call(this,idx)) nodes.push(this)
445
+ })
446
+ else {
447
+ var excludes = typeof selector == 'string' ? this.filter(selector) :
448
+ (likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector)
449
+ this.forEach(function(el){
450
+ if (excludes.indexOf(el) < 0) nodes.push(el)
451
+ })
452
+ }
453
+ return $(nodes)
454
+ },
455
+ has: function(selector){
456
+ return this.filter(function(){
457
+ return isObject(selector) ?
458
+ $.contains(this, selector) :
459
+ $(this).find(selector).size()
460
+ })
461
+ },
462
+ eq: function(idx){
463
+ return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1)
464
+ },
465
+ first: function(){
466
+ var el = this[0]
467
+ return el && !isObject(el) ? el : $(el)
468
+ },
469
+ last: function(){
470
+ var el = this[this.length - 1]
471
+ return el && !isObject(el) ? el : $(el)
472
+ },
473
+ find: function(selector){
474
+ var result, $this = this
475
+ if (typeof selector == 'object')
476
+ result = $(selector).filter(function(){
477
+ var node = this
478
+ return emptyArray.some.call($this, function(parent){
479
+ return $.contains(parent, node)
480
+ })
481
+ })
482
+ else if (this.length == 1) result = $(zepto.qsa(this[0], selector))
483
+ else result = this.map(function(){ return zepto.qsa(this, selector) })
484
+ return result
485
+ },
486
+ closest: function(selector, context){
487
+ var node = this[0], collection = false
488
+ if (typeof selector == 'object') collection = $(selector)
489
+ while (node && !(collection ? collection.indexOf(node) >= 0 : zepto.matches(node, selector)))
490
+ node = node !== context && !isDocument(node) && node.parentNode
491
+ return $(node)
492
+ },
493
+ parents: function(selector){
494
+ var ancestors = [], nodes = this
495
+ while (nodes.length > 0)
496
+ nodes = $.map(nodes, function(node){
497
+ if ((node = node.parentNode) && !isDocument(node) && ancestors.indexOf(node) < 0) {
498
+ ancestors.push(node)
499
+ return node
500
+ }
501
+ })
502
+ return filtered(ancestors, selector)
503
+ },
504
+ parent: function(selector){
505
+ return filtered(uniq(this.pluck('parentNode')), selector)
506
+ },
507
+ children: function(selector){
508
+ return filtered(this.map(function(){ return children(this) }), selector)
509
+ },
510
+ contents: function() {
511
+ return this.map(function() { return slice.call(this.childNodes) })
512
+ },
513
+ siblings: function(selector){
514
+ return filtered(this.map(function(i, el){
515
+ return filter.call(children(el.parentNode), function(child){ return child!==el })
516
+ }), selector)
517
+ },
518
+ empty: function(){
519
+ return this.each(function(){ this.innerHTML = '' })
520
+ },
521
+ // `pluck` is borrowed from Prototype.js
522
+ pluck: function(property){
523
+ return $.map(this, function(el){ return el[property] })
524
+ },
525
+ show: function(){
526
+ return this.each(function(){
527
+ this.style.display == "none" && (this.style.display = '')
528
+ if (getComputedStyle(this, '').getPropertyValue("display") == "none")
529
+ this.style.display = defaultDisplay(this.nodeName)
530
+ })
531
+ },
532
+ replaceWith: function(newContent){
533
+ return this.before(newContent).remove()
534
+ },
535
+ wrap: function(structure){
536
+ var func = isFunction(structure)
537
+ if (this[0] && !func)
538
+ var dom = $(structure).get(0),
539
+ clone = dom.parentNode || this.length > 1
540
+
541
+ return this.each(function(index){
542
+ $(this).wrapAll(
543
+ func ? structure.call(this, index) :
544
+ clone ? dom.cloneNode(true) : dom
545
+ )
546
+ })
547
+ },
548
+ wrapAll: function(structure){
549
+ if (this[0]) {
550
+ $(this[0]).before(structure = $(structure))
551
+ var children
552
+ // drill down to the inmost element
553
+ while ((children = structure.children()).length) structure = children.first()
554
+ $(structure).append(this)
555
+ }
556
+ return this
557
+ },
558
+ wrapInner: function(structure){
559
+ var func = isFunction(structure)
560
+ return this.each(function(index){
561
+ var self = $(this), contents = self.contents(),
562
+ dom = func ? structure.call(this, index) : structure
563
+ contents.length ? contents.wrapAll(dom) : self.append(dom)
564
+ })
565
+ },
566
+ unwrap: function(){
567
+ this.parent().each(function(){
568
+ $(this).replaceWith($(this).children())
569
+ })
570
+ return this
571
+ },
572
+ clone: function(){
573
+ return this.map(function(){ return this.cloneNode(true) })
574
+ },
575
+ hide: function(){
576
+ return this.css("display", "none")
577
+ },
578
+ toggle: function(setting){
579
+ return this.each(function(){
580
+ var el = $(this)
581
+ ;(setting === undefined ? el.css("display") == "none" : setting) ? el.show() : el.hide()
582
+ })
583
+ },
584
+ prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') },
585
+ next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') },
586
+ html: function(html){
587
+ return arguments.length === 0 ?
588
+ (this.length > 0 ? this[0].innerHTML : null) :
589
+ this.each(function(idx){
590
+ var originHtml = this.innerHTML
591
+ $(this).empty().append( funcArg(this, html, idx, originHtml) )
592
+ })
593
+ },
594
+ text: function(text){
595
+ return arguments.length === 0 ?
596
+ (this.length > 0 ? this[0].textContent : null) :
597
+ this.each(function(){ this.textContent = (text === undefined) ? '' : ''+text })
598
+ },
599
+ attr: function(name, value){
600
+ var result
601
+ return (typeof name == 'string' && value === undefined) ?
602
+ (this.length == 0 || this[0].nodeType !== 1 ? undefined :
603
+ (name == 'value' && this[0].nodeName == 'INPUT') ? this.val() :
604
+ (!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result
605
+ ) :
606
+ this.each(function(idx){
607
+ if (this.nodeType !== 1) return
608
+ if (isObject(name)) for (key in name) setAttribute(this, key, name[key])
609
+ else setAttribute(this, name, funcArg(this, value, idx, this.getAttribute(name)))
610
+ })
611
+ },
612
+ removeAttr: function(name){
613
+ return this.each(function(){ this.nodeType === 1 && setAttribute(this, name) })
614
+ },
615
+ prop: function(name, value){
616
+ name = propMap[name] || name
617
+ return (value === undefined) ?
618
+ (this[0] && this[0][name]) :
619
+ this.each(function(idx){
620
+ this[name] = funcArg(this, value, idx, this[name])
621
+ })
622
+ },
623
+ data: function(name, value){
624
+ var data = this.attr('data-' + name.replace(capitalRE, '-$1').toLowerCase(), value)
625
+ return data !== null ? deserializeValue(data) : undefined
626
+ },
627
+ val: function(value){
628
+ return arguments.length === 0 ?
629
+ (this[0] && (this[0].multiple ?
630
+ $(this[0]).find('option').filter(function(){ return this.selected }).pluck('value') :
631
+ this[0].value)
632
+ ) :
633
+ this.each(function(idx){
634
+ this.value = funcArg(this, value, idx, this.value)
635
+ })
636
+ },
637
+ offset: function(coordinates){
638
+ if (coordinates) return this.each(function(index){
639
+ var $this = $(this),
640
+ coords = funcArg(this, coordinates, index, $this.offset()),
641
+ parentOffset = $this.offsetParent().offset(),
642
+ props = {
643
+ top: coords.top - parentOffset.top,
644
+ left: coords.left - parentOffset.left
645
+ }
646
+
647
+ if ($this.css('position') == 'static') props['position'] = 'relative'
648
+ $this.css(props)
649
+ })
650
+ if (this.length==0) return null
651
+ var obj = this[0].getBoundingClientRect()
652
+ return {
653
+ left: obj.left + window.pageXOffset,
654
+ top: obj.top + window.pageYOffset,
655
+ width: Math.round(obj.width),
656
+ height: Math.round(obj.height)
657
+ }
658
+ },
659
+ css: function(property, value){
660
+ if (arguments.length < 2) {
661
+ var element = this[0], computedStyle = getComputedStyle(element, '')
662
+ if(!element) return
663
+ if (typeof property == 'string')
664
+ return element.style[camelize(property)] || computedStyle.getPropertyValue(property)
665
+ else if (isArray(property)) {
666
+ var props = {}
667
+ $.each(isArray(property) ? property: [property], function(_, prop){
668
+ props[prop] = (element.style[camelize(prop)] || computedStyle.getPropertyValue(prop))
669
+ })
670
+ return props
671
+ }
672
+ }
673
+
674
+ var css = ''
675
+ if (type(property) == 'string') {
676
+ if (!value && value !== 0)
677
+ this.each(function(){ this.style.removeProperty(dasherize(property)) })
678
+ else
679
+ css = dasherize(property) + ":" + maybeAddPx(property, value)
680
+ } else {
681
+ for (key in property)
682
+ if (!property[key] && property[key] !== 0)
683
+ this.each(function(){ this.style.removeProperty(dasherize(key)) })
684
+ else
685
+ css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';'
686
+ }
687
+
688
+ return this.each(function(){ this.style.cssText += ';' + css })
689
+ },
690
+ index: function(element){
691
+ return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0])
692
+ },
693
+ hasClass: function(name){
694
+ if (!name) return false
695
+ return emptyArray.some.call(this, function(el){
696
+ return this.test(className(el))
697
+ }, classRE(name))
698
+ },
699
+ addClass: function(name){
700
+ if (!name) return this
701
+ return this.each(function(idx){
702
+ classList = []
703
+ var cls = className(this), newName = funcArg(this, name, idx, cls)
704
+ newName.split(/\s+/g).forEach(function(klass){
705
+ if (!$(this).hasClass(klass)) classList.push(klass)
706
+ }, this)
707
+ classList.length && className(this, cls + (cls ? " " : "") + classList.join(" "))
708
+ })
709
+ },
710
+ removeClass: function(name){
711
+ return this.each(function(idx){
712
+ if (name === undefined) return className(this, '')
713
+ classList = className(this)
714
+ funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass){
715
+ classList = classList.replace(classRE(klass), " ")
716
+ })
717
+ className(this, classList.trim())
718
+ })
719
+ },
720
+ toggleClass: function(name, when){
721
+ if (!name) return this
722
+ return this.each(function(idx){
723
+ var $this = $(this), names = funcArg(this, name, idx, className(this))
724
+ names.split(/\s+/g).forEach(function(klass){
725
+ (when === undefined ? !$this.hasClass(klass) : when) ?
726
+ $this.addClass(klass) : $this.removeClass(klass)
727
+ })
728
+ })
729
+ },
730
+ scrollTop: function(value){
731
+ if (!this.length) return
732
+ var hasScrollTop = 'scrollTop' in this[0]
733
+ if (value === undefined) return hasScrollTop ? this[0].scrollTop : this[0].pageYOffset
734
+ return this.each(hasScrollTop ?
735
+ function(){ this.scrollTop = value } :
736
+ function(){ this.scrollTo(this.scrollX, value) })
737
+ },
738
+ scrollLeft: function(value){
739
+ if (!this.length) return
740
+ var hasScrollLeft = 'scrollLeft' in this[0]
741
+ if (value === undefined) return hasScrollLeft ? this[0].scrollLeft : this[0].pageXOffset
742
+ return this.each(hasScrollLeft ?
743
+ function(){ this.scrollLeft = value } :
744
+ function(){ this.scrollTo(value, this.scrollY) })
745
+ },
746
+ position: function() {
747
+ if (!this.length) return
748
+
749
+ var elem = this[0],
750
+ // Get *real* offsetParent
751
+ offsetParent = this.offsetParent(),
752
+ // Get correct offsets
753
+ offset = this.offset(),
754
+ parentOffset = rootNodeRE.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset()
755
+
756
+ // Subtract element margins
757
+ // note: when an element has margin: auto the offsetLeft and marginLeft
758
+ // are the same in Safari causing offset.left to incorrectly be 0
759
+ offset.top -= parseFloat( $(elem).css('margin-top') ) || 0
760
+ offset.left -= parseFloat( $(elem).css('margin-left') ) || 0
761
+
762
+ // Add offsetParent borders
763
+ parentOffset.top += parseFloat( $(offsetParent[0]).css('border-top-width') ) || 0
764
+ parentOffset.left += parseFloat( $(offsetParent[0]).css('border-left-width') ) || 0
765
+
766
+ // Subtract the two offsets
767
+ return {
768
+ top: offset.top - parentOffset.top,
769
+ left: offset.left - parentOffset.left
770
+ }
771
+ },
772
+ offsetParent: function() {
773
+ return this.map(function(){
774
+ var parent = this.offsetParent || document.body
775
+ while (parent && !rootNodeRE.test(parent.nodeName) && $(parent).css("position") == "static")
776
+ parent = parent.offsetParent
777
+ return parent
778
+ })
779
+ }
780
+ }
781
+
782
+ // for now
783
+ $.fn.detach = $.fn.remove
784
+
785
+ // Generate the `width` and `height` functions
786
+ ;['width', 'height'].forEach(function(dimension){
787
+ var dimensionProperty =
788
+ dimension.replace(/./, function(m){ return m[0].toUpperCase() })
789
+
790
+ $.fn[dimension] = function(value){
791
+ var offset, el = this[0]
792
+ if (value === undefined) return isWindow(el) ? el['inner' + dimensionProperty] :
793
+ isDocument(el) ? el.documentElement['scroll' + dimensionProperty] :
794
+ (offset = this.offset()) && offset[dimension]
795
+ else return this.each(function(idx){
796
+ el = $(this)
797
+ el.css(dimension, funcArg(this, value, idx, el[dimension]()))
798
+ })
799
+ }
800
+ })
801
+
802
+ function traverseNode(node, fun) {
803
+ fun(node)
804
+ for (var key in node.childNodes) traverseNode(node.childNodes[key], fun)
805
+ }
806
+
807
+ // Generate the `after`, `prepend`, `before`, `append`,
808
+ // `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods.
809
+ adjacencyOperators.forEach(function(operator, operatorIndex) {
810
+ var inside = operatorIndex % 2 //=> prepend, append
811
+
812
+ $.fn[operator] = function(){
813
+ // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings
814
+ var argType, nodes = $.map(arguments, function(arg) {
815
+ argType = type(arg)
816
+ return argType == "object" || argType == "array" || arg == null ?
817
+ arg : zepto.fragment(arg)
818
+ }),
819
+ parent, copyByClone = this.length > 1
820
+ if (nodes.length < 1) return this
821
+
822
+ return this.each(function(_, target){
823
+ parent = inside ? target : target.parentNode
824
+
825
+ // convert all methods to a "before" operation
826
+ target = operatorIndex == 0 ? target.nextSibling :
827
+ operatorIndex == 1 ? target.firstChild :
828
+ operatorIndex == 2 ? target :
829
+ null
830
+
831
+ nodes.forEach(function(node){
832
+ if (copyByClone) node = node.cloneNode(true)
833
+ else if (!parent) return $(node).remove()
834
+
835
+ traverseNode(parent.insertBefore(node, target), function(el){
836
+ if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' &&
837
+ (!el.type || el.type === 'text/javascript') && !el.src)
838
+ window['eval'].call(window, el.innerHTML)
839
+ })
840
+ })
841
+ })
842
+ }
843
+
844
+ // after => insertAfter
845
+ // prepend => prependTo
846
+ // before => insertBefore
847
+ // append => appendTo
848
+ $.fn[inside ? operator+'To' : 'insert'+(operatorIndex ? 'Before' : 'After')] = function(html){
849
+ $(html)[operator](this)
850
+ return this
851
+ }
852
+ })
853
+
854
+ zepto.Z.prototype = $.fn
855
+
856
+ // Export internal API functions in the `$.zepto` namespace
857
+ zepto.uniq = uniq
858
+ zepto.deserializeValue = deserializeValue
859
+ $.zepto = zepto
860
+
861
+ return $
862
+ })()
863
+
864
+ window.Zepto = Zepto
865
+ window.$ === undefined && (window.$ = Zepto)
866
+
867
+ ;(function($){
868
+ var $$ = $.zepto.qsa, _zid = 1, undefined,
869
+ slice = Array.prototype.slice,
870
+ isFunction = $.isFunction,
871
+ isString = function(obj){ return typeof obj == 'string' },
872
+ handlers = {},
873
+ specialEvents={},
874
+ focusinSupported = 'onfocusin' in window,
875
+ focus = { focus: 'focusin', blur: 'focusout' },
876
+ hover = { mouseenter: 'mouseover', mouseleave: 'mouseout' }
877
+
878
+ specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents'
879
+
880
+ function zid(element) {
881
+ return element._zid || (element._zid = _zid++)
882
+ }
883
+ function findHandlers(element, event, fn, selector) {
884
+ event = parse(event)
885
+ if (event.ns) var matcher = matcherFor(event.ns)
886
+ return (handlers[zid(element)] || []).filter(function(handler) {
887
+ return handler
888
+ && (!event.e || handler.e == event.e)
889
+ && (!event.ns || matcher.test(handler.ns))
890
+ && (!fn || zid(handler.fn) === zid(fn))
891
+ && (!selector || handler.sel == selector)
892
+ })
893
+ }
894
+ function parse(event) {
895
+ var parts = ('' + event).split('.')
896
+ return {e: parts[0], ns: parts.slice(1).sort().join(' ')}
897
+ }
898
+ function matcherFor(ns) {
899
+ return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)')
900
+ }
901
+
902
+ function eventCapture(handler, captureSetting) {
903
+ return handler.del &&
904
+ (!focusinSupported && (handler.e in focus)) ||
905
+ !!captureSetting
906
+ }
907
+
908
+ function realEvent(type) {
909
+ return hover[type] || (focusinSupported && focus[type]) || type
910
+ }
911
+
912
+ function add(element, events, fn, data, selector, delegator, capture){
913
+ var id = zid(element), set = (handlers[id] || (handlers[id] = []))
914
+ events.split(/\s/).forEach(function(event){
915
+ if (event == 'ready') return $(document).ready(fn)
916
+ var handler = parse(event)
917
+ handler.fn = fn
918
+ handler.sel = selector
919
+ // emulate mouseenter, mouseleave
920
+ if (handler.e in hover) fn = function(e){
921
+ var related = e.relatedTarget
922
+ if (!related || (related !== this && !$.contains(this, related)))
923
+ return handler.fn.apply(this, arguments)
924
+ }
925
+ handler.del = delegator
926
+ var callback = delegator || fn
927
+ handler.proxy = function(e){
928
+ e = compatible(e)
929
+ if (e.isImmediatePropagationStopped()) return
930
+ e.data = data
931
+ var result = callback.apply(element, e._args == undefined ? [e] : [e].concat(e._args))
932
+ if (result === false) e.preventDefault(), e.stopPropagation()
933
+ return result
934
+ }
935
+ handler.i = set.length
936
+ set.push(handler)
937
+ if ('addEventListener' in element)
938
+ element.addEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture))
939
+ })
940
+ }
941
+ function remove(element, events, fn, selector, capture){
942
+ var id = zid(element)
943
+ ;(events || '').split(/\s/).forEach(function(event){
944
+ findHandlers(element, event, fn, selector).forEach(function(handler){
945
+ delete handlers[id][handler.i]
946
+ if ('removeEventListener' in element)
947
+ element.removeEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture))
948
+ })
949
+ })
950
+ }
951
+
952
+ $.event = { add: add, remove: remove }
953
+
954
+ $.proxy = function(fn, context) {
955
+ if (isFunction(fn)) {
956
+ var proxyFn = function(){ return fn.apply(context, arguments) }
957
+ proxyFn._zid = zid(fn)
958
+ return proxyFn
959
+ } else if (isString(context)) {
960
+ return $.proxy(fn[context], fn)
961
+ } else {
962
+ throw new TypeError("expected function")
963
+ }
964
+ }
965
+
966
+ $.fn.bind = function(event, data, callback){
967
+ return this.on(event, data, callback)
968
+ }
969
+ $.fn.unbind = function(event, callback){
970
+ return this.off(event, callback)
971
+ }
972
+ $.fn.one = function(event, selector, data, callback){
973
+ return this.on(event, selector, data, callback, 1)
974
+ }
975
+
976
+ var returnTrue = function(){return true},
977
+ returnFalse = function(){return false},
978
+ ignoreProperties = /^([A-Z]|returnValue$|layer[XY]$)/,
979
+ eventMethods = {
980
+ preventDefault: 'isDefaultPrevented',
981
+ stopImmediatePropagation: 'isImmediatePropagationStopped',
982
+ stopPropagation: 'isPropagationStopped'
983
+ }
984
+
985
+ function compatible(event, source) {
986
+ if (source || !event.isDefaultPrevented) {
987
+ source || (source = event)
988
+
989
+ $.each(eventMethods, function(name, predicate) {
990
+ var sourceMethod = source[name]
991
+ event[name] = function(){
992
+ this[predicate] = returnTrue
993
+ return sourceMethod && sourceMethod.apply(source, arguments)
994
+ }
995
+ event[predicate] = returnFalse
996
+ })
997
+
998
+ if (source.defaultPrevented !== undefined ? source.defaultPrevented :
999
+ 'returnValue' in source ? source.returnValue === false :
1000
+ source.getPreventDefault && source.getPreventDefault())
1001
+ event.isDefaultPrevented = returnTrue
1002
+ }
1003
+ return event
1004
+ }
1005
+
1006
+ function createProxy(event) {
1007
+ var key, proxy = { originalEvent: event }
1008
+ for (key in event)
1009
+ if (!ignoreProperties.test(key) && event[key] !== undefined) proxy[key] = event[key]
1010
+
1011
+ return compatible(proxy, event)
1012
+ }
1013
+
1014
+ $.fn.delegate = function(selector, event, callback){
1015
+ return this.on(event, selector, callback)
1016
+ }
1017
+ $.fn.undelegate = function(selector, event, callback){
1018
+ return this.off(event, selector, callback)
1019
+ }
1020
+
1021
+ $.fn.live = function(event, callback){
1022
+ $(document.body).delegate(this.selector, event, callback)
1023
+ return this
1024
+ }
1025
+ $.fn.die = function(event, callback){
1026
+ $(document.body).undelegate(this.selector, event, callback)
1027
+ return this
1028
+ }
1029
+
1030
+ $.fn.on = function(event, selector, data, callback, one){
1031
+ var autoRemove, delegator, $this = this
1032
+ if (event && !isString(event)) {
1033
+ $.each(event, function(type, fn){
1034
+ $this.on(type, selector, data, fn, one)
1035
+ })
1036
+ return $this
1037
+ }
1038
+
1039
+ if (!isString(selector) && !isFunction(callback) && callback !== false)
1040
+ callback = data, data = selector, selector = undefined
1041
+ if (isFunction(data) || data === false)
1042
+ callback = data, data = undefined
1043
+
1044
+ if (callback === false) callback = returnFalse
1045
+
1046
+ return $this.each(function(_, element){
1047
+ if (one) autoRemove = function(e){
1048
+ remove(element, e.type, callback)
1049
+ return callback.apply(this, arguments)
1050
+ }
1051
+
1052
+ if (selector) delegator = function(e){
1053
+ var evt, match = $(e.target).closest(selector, element).get(0)
1054
+ if (match && match !== element) {
1055
+ evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element})
1056
+ return (autoRemove || callback).apply(match, [evt].concat(slice.call(arguments, 1)))
1057
+ }
1058
+ }
1059
+
1060
+ add(element, event, callback, data, selector, delegator || autoRemove)
1061
+ })
1062
+ }
1063
+ $.fn.off = function(event, selector, callback){
1064
+ var $this = this
1065
+ if (event && !isString(event)) {
1066
+ $.each(event, function(type, fn){
1067
+ $this.off(type, selector, fn)
1068
+ })
1069
+ return $this
1070
+ }
1071
+
1072
+ if (!isString(selector) && !isFunction(callback) && callback !== false)
1073
+ callback = selector, selector = undefined
1074
+
1075
+ if (callback === false) callback = returnFalse
1076
+
1077
+ return $this.each(function(){
1078
+ remove(this, event, callback, selector)
1079
+ })
1080
+ }
1081
+
1082
+ $.fn.trigger = function(event, args){
1083
+ event = (isString(event) || $.isPlainObject(event)) ? $.Event(event) : compatible(event)
1084
+ event._args = args
1085
+ return this.each(function(){
1086
+ // items in the collection might not be DOM elements
1087
+ if('dispatchEvent' in this) this.dispatchEvent(event)
1088
+ else $(this).triggerHandler(event, args)
1089
+ })
1090
+ }
1091
+
1092
+ // triggers event handlers on current element just as if an event occurred,
1093
+ // doesn't trigger an actual event, doesn't bubble
1094
+ $.fn.triggerHandler = function(event, args){
1095
+ var e, result
1096
+ this.each(function(i, element){
1097
+ e = createProxy(isString(event) ? $.Event(event) : event)
1098
+ e._args = args
1099
+ e.target = element
1100
+ $.each(findHandlers(element, event.type || event), function(i, handler){
1101
+ result = handler.proxy(e)
1102
+ if (e.isImmediatePropagationStopped()) return false
1103
+ })
1104
+ })
1105
+ return result
1106
+ }
1107
+
1108
+ // shortcut methods for `.bind(event, fn)` for each event type
1109
+ ;('focusin focusout load resize scroll unload click dblclick '+
1110
+ 'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave '+
1111
+ 'change select keydown keypress keyup error').split(' ').forEach(function(event) {
1112
+ $.fn[event] = function(callback) {
1113
+ return callback ?
1114
+ this.bind(event, callback) :
1115
+ this.trigger(event)
1116
+ }
1117
+ })
1118
+
1119
+ ;['focus', 'blur'].forEach(function(name) {
1120
+ $.fn[name] = function(callback) {
1121
+ if (callback) this.bind(name, callback)
1122
+ else this.each(function(){
1123
+ try { this[name]() }
1124
+ catch(e) {}
1125
+ })
1126
+ return this
1127
+ }
1128
+ })
1129
+
1130
+ $.Event = function(type, props) {
1131
+ if (!isString(type)) props = type, type = props.type
1132
+ var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true
1133
+ if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name])
1134
+ event.initEvent(type, bubbles, true)
1135
+ return compatible(event)
1136
+ }
1137
+
1138
+ })(Zepto)
1139
+
1140
+ ;(function($){
1141
+ var jsonpID = 0,
1142
+ document = window.document,
1143
+ key,
1144
+ name,
1145
+ rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
1146
+ scriptTypeRE = /^(?:text|application)\/javascript/i,
1147
+ xmlTypeRE = /^(?:text|application)\/xml/i,
1148
+ jsonType = 'application/json',
1149
+ htmlType = 'text/html',
1150
+ blankRE = /^\s*$/
1151
+
1152
+ // trigger a custom event and return false if it was cancelled
1153
+ function triggerAndReturn(context, eventName, data) {
1154
+ var event = $.Event(eventName)
1155
+ $(context).trigger(event, data)
1156
+ return !event.isDefaultPrevented()
1157
+ }
1158
+
1159
+ // trigger an Ajax "global" event
1160
+ function triggerGlobal(settings, context, eventName, data) {
1161
+ if (settings.global) return triggerAndReturn(context || document, eventName, data)
1162
+ }
1163
+
1164
+ // Number of active Ajax requests
1165
+ $.active = 0
1166
+
1167
+ function ajaxStart(settings) {
1168
+ if (settings.global && $.active++ === 0) triggerGlobal(settings, null, 'ajaxStart')
1169
+ }
1170
+ function ajaxStop(settings) {
1171
+ if (settings.global && !(--$.active)) triggerGlobal(settings, null, 'ajaxStop')
1172
+ }
1173
+
1174
+ // triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable
1175
+ function ajaxBeforeSend(xhr, settings) {
1176
+ var context = settings.context
1177
+ if (settings.beforeSend.call(context, xhr, settings) === false ||
1178
+ triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false)
1179
+ return false
1180
+
1181
+ triggerGlobal(settings, context, 'ajaxSend', [xhr, settings])
1182
+ }
1183
+ function ajaxSuccess(data, xhr, settings, deferred) {
1184
+ var context = settings.context, status = 'success'
1185
+ settings.success.call(context, data, status, xhr)
1186
+ if (deferred) deferred.resolveWith(context, [data, status, xhr])
1187
+ triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data])
1188
+ ajaxComplete(status, xhr, settings)
1189
+ }
1190
+ // type: "timeout", "error", "abort", "parsererror"
1191
+ function ajaxError(error, type, xhr, settings, deferred) {
1192
+ var context = settings.context
1193
+ settings.error.call(context, xhr, type, error)
1194
+ if (deferred) deferred.rejectWith(context, [xhr, type, error])
1195
+ triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error || type])
1196
+ ajaxComplete(type, xhr, settings)
1197
+ }
1198
+ // status: "success", "notmodified", "error", "timeout", "abort", "parsererror"
1199
+ function ajaxComplete(status, xhr, settings) {
1200
+ var context = settings.context
1201
+ settings.complete.call(context, xhr, status)
1202
+ triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings])
1203
+ ajaxStop(settings)
1204
+ }
1205
+
1206
+ // Empty function, used as default callback
1207
+ function empty() {}
1208
+
1209
+ $.ajaxJSONP = function(options, deferred){
1210
+ if (!('type' in options)) return $.ajax(options)
1211
+
1212
+ var _callbackName = options.jsonpCallback,
1213
+ callbackName = ($.isFunction(_callbackName) ?
1214
+ _callbackName() : _callbackName) || ('jsonp' + (++jsonpID)),
1215
+ script = document.createElement('script'),
1216
+ originalCallback = window[callbackName],
1217
+ responseData,
1218
+ abort = function(errorType) {
1219
+ $(script).triggerHandler('error', errorType || 'abort')
1220
+ },
1221
+ xhr = { abort: abort }, abortTimeout
1222
+
1223
+ if (deferred) deferred.promise(xhr)
1224
+
1225
+ $(script).on('load error', function(e, errorType){
1226
+ clearTimeout(abortTimeout)
1227
+ $(script).off().remove()
1228
+
1229
+ if (e.type == 'error' || !responseData) {
1230
+ ajaxError(null, errorType || 'error', xhr, options, deferred)
1231
+ } else {
1232
+ ajaxSuccess(responseData[0], xhr, options, deferred)
1233
+ }
1234
+
1235
+ window[callbackName] = originalCallback
1236
+ if (responseData && $.isFunction(originalCallback))
1237
+ originalCallback(responseData[0])
1238
+
1239
+ originalCallback = responseData = undefined
1240
+ })
1241
+
1242
+ if (ajaxBeforeSend(xhr, options) === false) {
1243
+ abort('abort')
1244
+ return xhr
1245
+ }
1246
+
1247
+ window[callbackName] = function(){
1248
+ responseData = arguments
1249
+ }
1250
+
1251
+ script.src = options.url.replace(/=\?/, '=' + callbackName)
1252
+ document.head.appendChild(script)
1253
+
1254
+ if (options.timeout > 0) abortTimeout = setTimeout(function(){
1255
+ abort('timeout')
1256
+ }, options.timeout)
1257
+
1258
+ return xhr
1259
+ }
1260
+
1261
+ $.ajaxSettings = {
1262
+ // Default type of request
1263
+ type: 'GET',
1264
+ // Callback that is executed before request
1265
+ beforeSend: empty,
1266
+ // Callback that is executed if the request succeeds
1267
+ success: empty,
1268
+ // Callback that is executed the the server drops error
1269
+ error: empty,
1270
+ // Callback that is executed on request complete (both: error and success)
1271
+ complete: empty,
1272
+ // The context for the callbacks
1273
+ context: null,
1274
+ // Whether to trigger "global" Ajax events
1275
+ global: true,
1276
+ // Transport
1277
+ xhr: function () {
1278
+ return new window.XMLHttpRequest()
1279
+ },
1280
+ // MIME types mapping
1281
+ // IIS returns Javascript as "application/x-javascript"
1282
+ accepts: {
1283
+ script: 'text/javascript, application/javascript, application/x-javascript',
1284
+ json: jsonType,
1285
+ xml: 'application/xml, text/xml',
1286
+ html: htmlType,
1287
+ text: 'text/plain'
1288
+ },
1289
+ // Whether the request is to another domain
1290
+ crossDomain: false,
1291
+ // Default timeout
1292
+ timeout: 0,
1293
+ // Whether data should be serialized to string
1294
+ processData: true,
1295
+ // Whether the browser should be allowed to cache GET responses
1296
+ cache: true
1297
+ }
1298
+
1299
+ function mimeToDataType(mime) {
1300
+ if (mime) mime = mime.split(';', 2)[0]
1301
+ return mime && ( mime == htmlType ? 'html' :
1302
+ mime == jsonType ? 'json' :
1303
+ scriptTypeRE.test(mime) ? 'script' :
1304
+ xmlTypeRE.test(mime) && 'xml' ) || 'text'
1305
+ }
1306
+
1307
+ function appendQuery(url, query) {
1308
+ if (query == '') return url
1309
+ return (url + '&' + query).replace(/[&?]{1,2}/, '?')
1310
+ }
1311
+
1312
+ // serialize payload and append it to the URL for GET requests
1313
+ function serializeData(options) {
1314
+ if (options.processData && options.data && $.type(options.data) != "string")
1315
+ options.data = $.param(options.data, options.traditional)
1316
+ if (options.data && (!options.type || options.type.toUpperCase() == 'GET'))
1317
+ options.url = appendQuery(options.url, options.data), options.data = undefined
1318
+ }
1319
+
1320
+ $.ajax = function(options){
1321
+ var settings = $.extend({}, options || {}),
1322
+ deferred = $.Deferred && $.Deferred()
1323
+ for (key in $.ajaxSettings) if (settings[key] === undefined) settings[key] = $.ajaxSettings[key]
1324
+
1325
+ ajaxStart(settings)
1326
+
1327
+ if (!settings.crossDomain) settings.crossDomain = /^([\w-]+:)?\/\/([^\/]+)/.test(settings.url) &&
1328
+ RegExp.$2 != window.location.host
1329
+
1330
+ if (!settings.url) settings.url = window.location.toString()
1331
+ serializeData(settings)
1332
+ if (settings.cache === false) settings.url = appendQuery(settings.url, '_=' + Date.now())
1333
+
1334
+ var dataType = settings.dataType, hasPlaceholder = /=\?/.test(settings.url)
1335
+ if (dataType == 'jsonp' || hasPlaceholder) {
1336
+ if (!hasPlaceholder)
1337
+ settings.url = appendQuery(settings.url,
1338
+ settings.jsonp ? (settings.jsonp + '=?') : settings.jsonp === false ? '' : 'callback=?')
1339
+ return $.ajaxJSONP(settings, deferred)
1340
+ }
1341
+
1342
+ var mime = settings.accepts[dataType],
1343
+ headers = { },
1344
+ setHeader = function(name, value) { headers[name.toLowerCase()] = [name, value] },
1345
+ protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol,
1346
+ xhr = settings.xhr(),
1347
+ nativeSetHeader = xhr.setRequestHeader,
1348
+ abortTimeout
1349
+
1350
+ if (deferred) deferred.promise(xhr)
1351
+
1352
+ if (!settings.crossDomain) setHeader('X-Requested-With', 'XMLHttpRequest')
1353
+ setHeader('Accept', mime || '*/*')
1354
+ if (mime = settings.mimeType || mime) {
1355
+ if (mime.indexOf(',') > -1) mime = mime.split(',', 2)[0]
1356
+ xhr.overrideMimeType && xhr.overrideMimeType(mime)
1357
+ }
1358
+ if (settings.contentType || (settings.contentType !== false && settings.data && settings.type.toUpperCase() != 'GET'))
1359
+ setHeader('Content-Type', settings.contentType || 'application/x-www-form-urlencoded')
1360
+
1361
+ if (settings.headers) for (name in settings.headers) setHeader(name, settings.headers[name])
1362
+ xhr.setRequestHeader = setHeader
1363
+
1364
+ xhr.onreadystatechange = function(){
1365
+ if (xhr.readyState == 4) {
1366
+ xhr.onreadystatechange = empty
1367
+ clearTimeout(abortTimeout)
1368
+ var result, error = false
1369
+ if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) {
1370
+ dataType = dataType || mimeToDataType(settings.mimeType || xhr.getResponseHeader('content-type'))
1371
+ result = xhr.responseText
1372
+
1373
+ try {
1374
+ // http://perfectionkills.com/global-eval-what-are-the-options/
1375
+ if (dataType == 'script') (1,eval)(result)
1376
+ else if (dataType == 'xml') result = xhr.responseXML
1377
+ else if (dataType == 'json') result = blankRE.test(result) ? null : $.parseJSON(result)
1378
+ } catch (e) { error = e }
1379
+
1380
+ if (error) ajaxError(error, 'parsererror', xhr, settings, deferred)
1381
+ else ajaxSuccess(result, xhr, settings, deferred)
1382
+ } else {
1383
+ ajaxError(xhr.statusText || null, xhr.status ? 'error' : 'abort', xhr, settings, deferred)
1384
+ }
1385
+ }
1386
+ }
1387
+
1388
+ if (ajaxBeforeSend(xhr, settings) === false) {
1389
+ xhr.abort()
1390
+ ajaxError(null, 'abort', xhr, settings, deferred)
1391
+ return xhr
1392
+ }
1393
+
1394
+ if (settings.xhrFields) for (name in settings.xhrFields) xhr[name] = settings.xhrFields[name]
1395
+
1396
+ var async = 'async' in settings ? settings.async : true
1397
+ xhr.open(settings.type, settings.url, async, settings.username, settings.password)
1398
+
1399
+ for (name in headers) nativeSetHeader.apply(xhr, headers[name])
1400
+
1401
+ if (settings.timeout > 0) abortTimeout = setTimeout(function(){
1402
+ xhr.onreadystatechange = empty
1403
+ xhr.abort()
1404
+ ajaxError(null, 'timeout', xhr, settings, deferred)
1405
+ }, settings.timeout)
1406
+
1407
+ // avoid sending empty string (#319)
1408
+ xhr.send(settings.data ? settings.data : null)
1409
+ return xhr
1410
+ }
1411
+
1412
+ // handle optional data/success arguments
1413
+ function parseArguments(url, data, success, dataType) {
1414
+ var hasData = !$.isFunction(data)
1415
+ return {
1416
+ url: url,
1417
+ data: hasData ? data : undefined,
1418
+ success: !hasData ? data : $.isFunction(success) ? success : undefined,
1419
+ dataType: hasData ? dataType || success : success
1420
+ }
1421
+ }
1422
+
1423
+ $.get = function(url, data, success, dataType){
1424
+ return $.ajax(parseArguments.apply(null, arguments))
1425
+ }
1426
+
1427
+ $.post = function(url, data, success, dataType){
1428
+ var options = parseArguments.apply(null, arguments)
1429
+ options.type = 'POST'
1430
+ return $.ajax(options)
1431
+ }
1432
+
1433
+ $.getJSON = function(url, data, success){
1434
+ var options = parseArguments.apply(null, arguments)
1435
+ options.dataType = 'json'
1436
+ return $.ajax(options)
1437
+ }
1438
+
1439
+ $.fn.load = function(url, data, success){
1440
+ if (!this.length) return this
1441
+ var self = this, parts = url.split(/\s/), selector,
1442
+ options = parseArguments(url, data, success),
1443
+ callback = options.success
1444
+ if (parts.length > 1) options.url = parts[0], selector = parts[1]
1445
+ options.success = function(response){
1446
+ self.html(selector ?
1447
+ $('<div>').html(response.replace(rscript, "")).find(selector)
1448
+ : response)
1449
+ callback && callback.apply(self, arguments)
1450
+ }
1451
+ $.ajax(options)
1452
+ return this
1453
+ }
1454
+
1455
+ var escape = encodeURIComponent
1456
+
1457
+ function serialize(params, obj, traditional, scope){
1458
+ var type, array = $.isArray(obj), hash = $.isPlainObject(obj)
1459
+ $.each(obj, function(key, value) {
1460
+ type = $.type(value)
1461
+ if (scope) key = traditional ? scope :
1462
+ scope + '[' + (hash || type == 'object' || type == 'array' ? key : '') + ']'
1463
+ // handle data in serializeArray() format
1464
+ if (!scope && array) params.add(value.name, value.value)
1465
+ // recurse into nested objects
1466
+ else if (type == "array" || (!traditional && type == "object"))
1467
+ serialize(params, value, traditional, key)
1468
+ else params.add(key, value)
1469
+ })
1470
+ }
1471
+
1472
+ $.param = function(obj, traditional){
1473
+ var params = []
1474
+ params.add = function(k, v){ this.push(escape(k) + '=' + escape(v)) }
1475
+ serialize(params, obj, traditional)
1476
+ return params.join('&').replace(/%20/g, '+')
1477
+ }
1478
+ })(Zepto)
1479
+
1480
+ ;(function($){
1481
+ $.fn.serializeArray = function() {
1482
+ var result = [], el
1483
+ $([].slice.call(this.get(0).elements)).each(function(){
1484
+ el = $(this)
1485
+ var type = el.attr('type')
1486
+ if (this.nodeName.toLowerCase() != 'fieldset' &&
1487
+ !this.disabled && type != 'submit' && type != 'reset' && type != 'button' &&
1488
+ ((type != 'radio' && type != 'checkbox') || this.checked))
1489
+ result.push({
1490
+ name: el.attr('name'),
1491
+ value: el.val()
1492
+ })
1493
+ })
1494
+ return result
1495
+ }
1496
+
1497
+ $.fn.serialize = function(){
1498
+ var result = []
1499
+ this.serializeArray().forEach(function(elm){
1500
+ result.push(encodeURIComponent(elm.name) + '=' + encodeURIComponent(elm.value))
1501
+ })
1502
+ return result.join('&')
1503
+ }
1504
+
1505
+ $.fn.submit = function(callback) {
1506
+ if (callback) this.bind('submit', callback)
1507
+ else if (this.length) {
1508
+ var event = $.Event('submit')
1509
+ this.eq(0).trigger(event)
1510
+ if (!event.isDefaultPrevented()) this.get(0).submit()
1511
+ }
1512
+ return this
1513
+ }
1514
+
1515
+ })(Zepto)
1516
+
1517
+ ;(function($){
1518
+ // __proto__ doesn't exist on IE<11, so redefine
1519
+ // the Z function to use object extension instead
1520
+ if (!('__proto__' in {})) {
1521
+ $.extend($.zepto, {
1522
+ Z: function(dom, selector){
1523
+ dom = dom || []
1524
+ $.extend(dom, $.fn)
1525
+ dom.selector = selector || ''
1526
+ dom.__Z = true
1527
+ return dom
1528
+ },
1529
+ // this is a kludge but works
1530
+ isZ: function(object){
1531
+ return $.type(object) === 'array' && '__Z' in object
1532
+ }
1533
+ })
1534
+ }
1535
+
1536
+ // getComputedStyle shouldn't freak out when called
1537
+ // without a valid element as argument
1538
+ try {
1539
+ getComputedStyle(undefined)
1540
+ } catch(e) {
1541
+ var nativeGetComputedStyle = getComputedStyle;
1542
+ window.getComputedStyle = function(element){
1543
+ try {
1544
+ return nativeGetComputedStyle(element)
1545
+ } catch(e) {
1546
+ return null
1547
+ }
1548
+ }
1549
+ }
1550
+ })(Zepto)