sudo-js-rails 0.0.2

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