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