]> iEval git - gruntmaster-page.git/blob - js/00-zepto.js
Declare charset in content-type header
[gruntmaster-page.git] / js / 00-zepto.js
1 /* Zepto v1.1.4-13-geba5344 - zepto event data ie - zeptojs.com/license */
2
3 var Zepto = (function() {
4 var undefined, key, $, classList, emptyArray = [], concat = emptyArray.concat, filter = emptyArray.filter, slice = emptyArray.slice,
5 document = window.document,
6 elementDisplay = {}, classCache = {},
7 cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 },
8 fragmentRE = /^\s*<(\w+|!)[^>]*>/,
9 singleTagRE = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,
10 tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,
11 rootNodeRE = /^(?:body|html)$/i,
12 capitalRE = /([A-Z])/g,
13
14 // special attributes that should be get/set via method calls
15 methodAttributes = ['val', 'css', 'html', 'text', 'data', 'width', 'height', 'offset'],
16
17 adjacencyOperators = [ 'after', 'prepend', 'before', 'append' ],
18 table = document.createElement('table'),
19 tableRow = document.createElement('tr'),
20 containers = {
21 'tr': document.createElement('tbody'),
22 'tbody': table, 'thead': table, 'tfoot': table,
23 'td': tableRow, 'th': tableRow,
24 '*': document.createElement('div')
25 },
26 readyRE = /complete|loaded|interactive/,
27 simpleSelectorRE = /^[\w-]*$/,
28 class2type = {},
29 toString = class2type.toString,
30 zepto = {},
31 camelize, uniq,
32 tempParent = document.createElement('div'),
33 propMap = {
34 'tabindex': 'tabIndex',
35 'readonly': 'readOnly',
36 'for': 'htmlFor',
37 'class': 'className',
38 'maxlength': 'maxLength',
39 'cellspacing': 'cellSpacing',
40 'cellpadding': 'cellPadding',
41 'rowspan': 'rowSpan',
42 'colspan': 'colSpan',
43 'usemap': 'useMap',
44 'frameborder': 'frameBorder',
45 'contenteditable': 'contentEditable'
46 },
47 isArray = Array.isArray ||
48 function(object){ return object instanceof Array }
49
50 zepto.matches = function(element, selector) {
51 if (!selector || !element || element.nodeType !== 1) return false
52 var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector ||
53 element.oMatchesSelector || element.matchesSelector
54 if (matchesSelector) return matchesSelector.call(element, selector)
55 // fall back to performing a selector:
56 var match, parent = element.parentNode, temp = !parent
57 if (temp) (parent = tempParent).appendChild(element)
58 match = ~zepto.qsa(parent, selector).indexOf(element)
59 temp && tempParent.removeChild(element)
60 return match
61 }
62
63 function type(obj) {
64 return obj == null ? String(obj) :
65 class2type[toString.call(obj)] || "object"
66 }
67
68 function isFunction(value) { return type(value) == "function" }
69 function isWindow(obj) { return obj != null && obj == obj.window }
70 function isDocument(obj) { return obj != null && obj.nodeType == obj.DOCUMENT_NODE }
71 function isObject(obj) { return type(obj) == "object" }
72 function isPlainObject(obj) {
73 return isObject(obj) && !isWindow(obj) && Object.getPrototypeOf(obj) == Object.prototype
74 }
75 function likeArray(obj) { return typeof obj.length == 'number' }
76
77 function compact(array) { return filter.call(array, function(item){ return item != null }) }
78 function flatten(array) { return array.length > 0 ? $.fn.concat.apply([], array) : array }
79 camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) }
80 function dasherize(str) {
81 return str.replace(/::/g, '/')
82 .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
83 .replace(/([a-z\d])([A-Z])/g, '$1_$2')
84 .replace(/_/g, '-')
85 .toLowerCase()
86 }
87 uniq = function(array){ return filter.call(array, function(item, idx){ return array.indexOf(item) == idx }) }
88
89 function classRE(name) {
90 return name in classCache ?
91 classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)'))
92 }
93
94 function maybeAddPx(name, value) {
95 return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value
96 }
97
98 function defaultDisplay(nodeName) {
99 var element, display
100 if (!elementDisplay[nodeName]) {
101 element = document.createElement(nodeName)
102 document.body.appendChild(element)
103 display = getComputedStyle(element, '').getPropertyValue("display")
104 element.parentNode.removeChild(element)
105 display == "none" && (display = "block")
106 elementDisplay[nodeName] = display
107 }
108 return elementDisplay[nodeName]
109 }
110
111 function children(element) {
112 return 'children' in element ?
113 slice.call(element.children) :
114 $.map(element.childNodes, function(node){ if (node.nodeType == 1) return node })
115 }
116
117 function Z(dom, selector) {
118 var i, len = dom ? dom.length : 0
119 for (i = 0; i < len; i++) this[i] = dom[i]
120 this.length = len
121 this.selector = selector || ''
122 }
123
124 // `$.zepto.fragment` takes a html string and an optional tag name
125 // to generate DOM nodes nodes from the given html string.
126 // The generated DOM nodes are returned as an array.
127 // This function can be overriden in plugins for example to make
128 // it compatible with browsers that don't support the DOM fully.
129 zepto.fragment = function(html, name, properties) {
130 var dom, nodes, container
131
132 // A special case optimization for a single tag
133 if (singleTagRE.test(html)) dom = $(document.createElement(RegExp.$1))
134
135 if (!dom) {
136 if (html.replace) html = html.replace(tagExpanderRE, "<$1></$2>")
137 if (name === undefined) name = fragmentRE.test(html) && RegExp.$1
138 if (!(name in containers)) name = '*'
139
140 container = containers[name]
141 container.innerHTML = '' + html
142 dom = $.each(slice.call(container.childNodes), function(){
143 container.removeChild(this)
144 })
145 }
146
147 if (isPlainObject(properties)) {
148 nodes = $(dom)
149 $.each(properties, function(key, value) {
150 if (methodAttributes.indexOf(key) > -1) nodes[key](value)
151 else nodes.attr(key, value)
152 })
153 }
154
155 return dom
156 }
157
158 // `$.zepto.Z` swaps out the prototype of the given `dom` array
159 // of nodes with `$.fn` and thus supplying all the Zepto functions
160 // to the array. This method can be overriden in plugins.
161 zepto.Z = function(dom, selector) {
162 return new Z(dom, selector)
163 }
164
165 // `$.zepto.isZ` should return `true` if the given object is a Zepto
166 // collection. This method can be overriden in plugins.
167 zepto.isZ = function(object) {
168 return object instanceof zepto.Z
169 }
170
171 // `$.zepto.init` is Zepto's counterpart to jQuery's `$.fn.init` and
172 // takes a CSS selector and an optional context (and handles various
173 // special cases).
174 // This method can be overriden in plugins.
175 zepto.init = function(selector, context) {
176 var dom
177 // If nothing given, return an empty Zepto collection
178 if (!selector) return zepto.Z()
179 // Optimize for string selectors
180 else if (typeof selector == 'string') {
181 selector = selector.trim()
182 // If it's a html fragment, create nodes from it
183 // Note: In both Chrome 21 and Firefox 15, DOM error 12
184 // is thrown if the fragment doesn't begin with <
185 if (selector[0] == '<' && fragmentRE.test(selector))
186 dom = zepto.fragment(selector, RegExp.$1, context), selector = null
187 // If there's a context, create a collection on that context first, and select
188 // nodes from there
189 else if (context !== undefined) return $(context).find(selector)
190 // If it's a CSS selector, use it to select nodes.
191 else dom = zepto.qsa(document, selector)
192 }
193 // If a function is given, call it when the DOM is ready
194 else if (isFunction(selector)) return $(document).ready(selector)
195 // If a Zepto collection is given, just return it
196 else if (zepto.isZ(selector)) return selector
197 else {
198 // normalize array if an array of nodes is given
199 if (isArray(selector)) dom = compact(selector)
200 // Wrap DOM nodes.
201 else if (isObject(selector))
202 dom = [selector], selector = null
203 // If it's a html fragment, create nodes from it
204 else if (fragmentRE.test(selector))
205 dom = zepto.fragment(selector.trim(), RegExp.$1, context), selector = null
206 // If there's a context, create a collection on that context first, and select
207 // nodes from there
208 else if (context !== undefined) return $(context).find(selector)
209 // And last but no least, if it's a CSS selector, use it to select nodes.
210 else dom = zepto.qsa(document, selector)
211 }
212 // create a new Zepto collection from the nodes found
213 return zepto.Z(dom, selector)
214 }
215
216 // `$` will be the base `Zepto` object. When calling this
217 // function just call `$.zepto.init, which makes the implementation
218 // details of selecting nodes and creating Zepto collections
219 // patchable in plugins.
220 $ = function(selector, context){
221 return zepto.init(selector, context)
222 }
223
224 function extend(target, source, deep) {
225 for (key in source)
226 if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
227 if (isPlainObject(source[key]) && !isPlainObject(target[key]))
228 target[key] = {}
229 if (isArray(source[key]) && !isArray(target[key]))
230 target[key] = []
231 extend(target[key], source[key], deep)
232 }
233 else if (source[key] !== undefined) target[key] = source[key]
234 }
235
236 // Copy all but undefined properties from one or more
237 // objects to the `target` object.
238 $.extend = function(target){
239 var deep, args = slice.call(arguments, 1)
240 if (typeof target == 'boolean') {
241 deep = target
242 target = args.shift()
243 }
244 args.forEach(function(arg){ extend(target, arg, deep) })
245 return target
246 }
247
248 // `$.zepto.qsa` is Zepto's CSS selector implementation which
249 // uses `document.querySelectorAll` and optimizes for some special cases, like `#id`.
250 // This method can be overriden in plugins.
251 zepto.qsa = function(element, selector){
252 var found,
253 maybeID = selector[0] == '#',
254 maybeClass = !maybeID && selector[0] == '.',
255 nameOnly = maybeID || maybeClass ? selector.slice(1) : selector, // Ensure that a 1 char tag name still gets checked
256 isSimple = simpleSelectorRE.test(nameOnly)
257 return (isDocument(element) && isSimple && maybeID) ?
258 ( (found = element.getElementById(nameOnly)) ? [found] : [] ) :
259 (element.nodeType !== 1 && element.nodeType !== 9) ? [] :
260 slice.call(
261 isSimple && !maybeID ?
262 maybeClass ? element.getElementsByClassName(nameOnly) : // If it's simple, it could be a class
263 element.getElementsByTagName(selector) : // Or a tag
264 element.querySelectorAll(selector) // Or it's not simple, and we need to query all
265 )
266 }
267
268 function filtered(nodes, selector) {
269 return selector == null ? $(nodes) : $(nodes).filter(selector)
270 }
271
272 $.contains = document.documentElement.contains ?
273 function(parent, node) {
274 return parent !== node && parent.contains(node)
275 } :
276 function(parent, node) {
277 while (node && (node = node.parentNode))
278 if (node === parent) return true
279 return false
280 }
281
282 function funcArg(context, arg, idx, payload) {
283 return isFunction(arg) ? arg.call(context, idx, payload) : arg
284 }
285
286 function setAttribute(node, name, value) {
287 value == null ? node.removeAttribute(name) : node.setAttribute(name, value)
288 }
289
290 // access className property while respecting SVGAnimatedString
291 function className(node, value){
292 var klass = node.className || '',
293 svg = klass && klass.baseVal !== undefined
294
295 if (value === undefined) return svg ? klass.baseVal : klass
296 svg ? (klass.baseVal = value) : (node.className = value)
297 }
298
299 // "true" => true
300 // "false" => false
301 // "null" => null
302 // "42" => 42
303 // "42.5" => 42.5
304 // "08" => "08"
305 // JSON => parse if valid
306 // String => self
307 function deserializeValue(value) {
308 var num
309 try {
310 return value ?
311 value == "true" ||
312 ( value == "false" ? false :
313 value == "null" ? null :
314 !/^0/.test(value) && !isNaN(num = Number(value)) ? num :
315 /^[\[\{]/.test(value) ? $.parseJSON(value) :
316 value )
317 : value
318 } catch(e) {
319 return value
320 }
321 }
322
323 $.type = type
324 $.isFunction = isFunction
325 $.isWindow = isWindow
326 $.isArray = isArray
327 $.isPlainObject = isPlainObject
328
329 $.isEmptyObject = function(obj) {
330 var name
331 for (name in obj) return false
332 return true
333 }
334
335 $.inArray = function(elem, array, i){
336 return emptyArray.indexOf.call(array, elem, i)
337 }
338
339 $.camelCase = camelize
340 $.trim = function(str) {
341 return str == null ? "" : String.prototype.trim.call(str)
342 }
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 constructor: zepto.Z,
392 length: 0,
393
394 // Because a collection acts like an array
395 // copy over these useful array functions.
396 forEach: emptyArray.forEach,
397 reduce: emptyArray.reduce,
398 push: emptyArray.push,
399 sort: emptyArray.sort,
400 splice: emptyArray.splice,
401 indexOf: emptyArray.indexOf,
402 concat: function(){
403 var i, value, args = []
404 for (i = 0; i < arguments.length; i++) {
405 value = arguments[i]
406 args[i] = zepto.isZ(value) ? value.toArray() : value
407 }
408 return concat.apply(zepto.isZ(this) ? this.toArray() : this, args)
409 },
410
411 // `map` and `slice` in the jQuery API work differently
412 // from their array counterparts
413 map: function(fn){
414 return $($.map(this, function(el, i){ return fn.call(el, i, el) }))
415 },
416 slice: function(){
417 return $(slice.apply(this, arguments))
418 },
419
420 ready: function(callback){
421 // need to check if document.body exists for IE as that browser reports
422 // document ready when it hasn't yet created the body element
423 if (readyRE.test(document.readyState) && document.body) callback($)
424 else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false)
425 return this
426 },
427 get: function(idx){
428 return idx === undefined ? slice.call(this) : this[idx >= 0 ? idx : idx + this.length]
429 },
430 toArray: function(){ return this.get() },
431 size: function(){
432 return this.length
433 },
434 remove: function(){
435 return this.each(function(){
436 if (this.parentNode != null)
437 this.parentNode.removeChild(this)
438 })
439 },
440 each: function(callback){
441 emptyArray.every.call(this, function(el, idx){
442 return callback.call(el, idx, el) !== false
443 })
444 return this
445 },
446 filter: function(selector){
447 if (isFunction(selector)) return this.not(this.not(selector))
448 return $(filter.call(this, function(element){
449 return zepto.matches(element, selector)
450 }))
451 },
452 add: function(selector,context){
453 return $(uniq(this.concat($(selector,context))))
454 },
455 is: function(selector){
456 return this.length > 0 && zepto.matches(this[0], selector)
457 },
458 not: function(selector){
459 var nodes=[]
460 if (isFunction(selector) && selector.call !== undefined)
461 this.each(function(idx){
462 if (!selector.call(this,idx)) nodes.push(this)
463 })
464 else {
465 var excludes = typeof selector == 'string' ? this.filter(selector) :
466 (likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector)
467 this.forEach(function(el){
468 if (excludes.indexOf(el) < 0) nodes.push(el)
469 })
470 }
471 return $(nodes)
472 },
473 has: function(selector){
474 return this.filter(function(){
475 return isObject(selector) ?
476 $.contains(this, selector) :
477 $(this).find(selector).size()
478 })
479 },
480 eq: function(idx){
481 return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1)
482 },
483 first: function(){
484 var el = this[0]
485 return el && !isObject(el) ? el : $(el)
486 },
487 last: function(){
488 var el = this[this.length - 1]
489 return el && !isObject(el) ? el : $(el)
490 },
491 find: function(selector){
492 var result, $this = this
493 if (!selector) result = []
494 else if (typeof selector == 'object')
495 result = $(selector).filter(function(){
496 var node = this
497 return emptyArray.some.call($this, function(parent){
498 return $.contains(parent, node)
499 })
500 })
501 else if (this.length == 1) result = $(zepto.qsa(this[0], selector))
502 else result = this.map(function(){ return zepto.qsa(this, selector) })
503 return result
504 },
505 closest: function(selector, context){
506 var node = this[0], collection = false
507 if (typeof selector == 'object') collection = $(selector)
508 while (node && !(collection ? collection.indexOf(node) >= 0 : zepto.matches(node, selector)))
509 node = node !== context && !isDocument(node) && node.parentNode
510 return $(node)
511 },
512 parents: function(selector){
513 var ancestors = [], nodes = this
514 while (nodes.length > 0)
515 nodes = $.map(nodes, function(node){
516 if ((node = node.parentNode) && !isDocument(node) && ancestors.indexOf(node) < 0) {
517 ancestors.push(node)
518 return node
519 }
520 })
521 return filtered(ancestors, selector)
522 },
523 parent: function(selector){
524 return filtered(uniq(this.pluck('parentNode')), selector)
525 },
526 children: function(selector){
527 return filtered(this.map(function(){ return children(this) }), selector)
528 },
529 contents: function() {
530 return this.map(function() { return slice.call(this.childNodes) })
531 },
532 siblings: function(selector){
533 return filtered(this.map(function(i, el){
534 return filter.call(children(el.parentNode), function(child){ return child!==el })
535 }), selector)
536 },
537 empty: function(){
538 return this.each(function(){ this.innerHTML = '' })
539 },
540 // `pluck` is borrowed from Prototype.js
541 pluck: function(property){
542 return $.map(this, function(el){ return el[property] })
543 },
544 show: function(){
545 return this.each(function(){
546 this.style.display == "none" && (this.style.display = '')
547 if (getComputedStyle(this, '').getPropertyValue("display") == "none")
548 this.style.display = defaultDisplay(this.nodeName)
549 })
550 },
551 replaceWith: function(newContent){
552 return this.before(newContent).remove()
553 },
554 wrap: function(structure){
555 var func = isFunction(structure)
556 if (this[0] && !func)
557 var dom = $(structure).get(0),
558 clone = dom.parentNode || this.length > 1
559
560 return this.each(function(index){
561 $(this).wrapAll(
562 func ? structure.call(this, index) :
563 clone ? dom.cloneNode(true) : dom
564 )
565 })
566 },
567 wrapAll: function(structure){
568 if (this[0]) {
569 $(this[0]).before(structure = $(structure))
570 var children
571 // drill down to the inmost element
572 while ((children = structure.children()).length) structure = children.first()
573 $(structure).append(this)
574 }
575 return this
576 },
577 wrapInner: function(structure){
578 var func = isFunction(structure)
579 return this.each(function(index){
580 var self = $(this), contents = self.contents(),
581 dom = func ? structure.call(this, index) : structure
582 contents.length ? contents.wrapAll(dom) : self.append(dom)
583 })
584 },
585 unwrap: function(){
586 this.parent().each(function(){
587 $(this).replaceWith($(this).children())
588 })
589 return this
590 },
591 clone: function(){
592 return this.map(function(){ return this.cloneNode(true) })
593 },
594 hide: function(){
595 return this.css("display", "none")
596 },
597 toggle: function(setting){
598 return this.each(function(){
599 var el = $(this)
600 ;(setting === undefined ? el.css("display") == "none" : setting) ? el.show() : el.hide()
601 })
602 },
603 prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') },
604 next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') },
605 html: function(html){
606 return 0 in arguments ?
607 this.each(function(idx){
608 var originHtml = this.innerHTML
609 $(this).empty().append( funcArg(this, html, idx, originHtml) )
610 }) :
611 (0 in this ? this[0].innerHTML : null)
612 },
613 text: function(text){
614 return 0 in arguments ?
615 this.each(function(idx){
616 var newText = funcArg(this, text, idx, this.textContent)
617 this.textContent = newText == null ? '' : ''+newText
618 }) :
619 (0 in this ? this[0].textContent : null)
620 },
621 attr: function(name, value){
622 var result
623 return (typeof name == 'string' && !(1 in arguments)) ?
624 (!this.length || this[0].nodeType !== 1 ? undefined :
625 (!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result
626 ) :
627 this.each(function(idx){
628 if (this.nodeType !== 1) return
629 if (isObject(name)) for (key in name) setAttribute(this, key, name[key])
630 else setAttribute(this, name, funcArg(this, value, idx, this.getAttribute(name)))
631 })
632 },
633 removeAttr: function(name){
634 return this.each(function(){ this.nodeType === 1 && name.split(' ').forEach(function(attribute){
635 setAttribute(this, attribute)
636 }, this)})
637 },
638 prop: function(name, value){
639 name = propMap[name] || name
640 return (1 in arguments) ?
641 this.each(function(idx){
642 this[name] = funcArg(this, value, idx, this[name])
643 }) :
644 (this[0] && this[0][name])
645 },
646 data: function(name, value){
647 var attrName = 'data-' + name.replace(capitalRE, '-$1').toLowerCase()
648
649 var data = (1 in arguments) ?
650 this.attr(attrName, value) :
651 this.attr(attrName)
652
653 return data !== null ? deserializeValue(data) : undefined
654 },
655 val: function(value){
656 return 0 in arguments ?
657 this.each(function(idx){
658 this.value = funcArg(this, value, idx, this.value)
659 }) :
660 (this[0] && (this[0].multiple ?
661 $(this[0]).find('option').filter(function(){ return this.selected }).pluck('value') :
662 this[0].value)
663 )
664 },
665 offset: function(coordinates){
666 if (coordinates) return this.each(function(index){
667 var $this = $(this),
668 coords = funcArg(this, coordinates, index, $this.offset()),
669 parentOffset = $this.offsetParent().offset(),
670 props = {
671 top: coords.top - parentOffset.top,
672 left: coords.left - parentOffset.left
673 }
674
675 if ($this.css('position') == 'static') props['position'] = 'relative'
676 $this.css(props)
677 })
678 if (!this.length) return null
679 var obj = this[0].getBoundingClientRect()
680 return {
681 left: obj.left + window.pageXOffset,
682 top: obj.top + window.pageYOffset,
683 width: Math.round(obj.width),
684 height: Math.round(obj.height)
685 }
686 },
687 css: function(property, value){
688 if (arguments.length < 2) {
689 var element = this[0], computedStyle = getComputedStyle(element, '')
690 if(!element) return
691 if (typeof property == 'string')
692 return element.style[camelize(property)] || computedStyle.getPropertyValue(property)
693 else if (isArray(property)) {
694 var props = {}
695 $.each(property, function(_, prop){
696 props[prop] = (element.style[camelize(prop)] || computedStyle.getPropertyValue(prop))
697 })
698 return props
699 }
700 }
701
702 var css = ''
703 if (type(property) == 'string') {
704 if (!value && value !== 0)
705 this.each(function(){ this.style.removeProperty(dasherize(property)) })
706 else
707 css = dasherize(property) + ":" + maybeAddPx(property, value)
708 } else {
709 for (key in property)
710 if (!property[key] && property[key] !== 0)
711 this.each(function(){ this.style.removeProperty(dasherize(key)) })
712 else
713 css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';'
714 }
715
716 return this.each(function(){ this.style.cssText += ';' + css })
717 },
718 index: function(element){
719 return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0])
720 },
721 hasClass: function(name){
722 if (!name) return false
723 return emptyArray.some.call(this, function(el){
724 return this.test(className(el))
725 }, classRE(name))
726 },
727 addClass: function(name){
728 if (!name) return this
729 return this.each(function(idx){
730 if (!('className' in this)) return
731 classList = []
732 var cls = className(this), newName = funcArg(this, name, idx, cls)
733 newName.split(/\s+/g).forEach(function(klass){
734 if (!$(this).hasClass(klass)) classList.push(klass)
735 }, this)
736 classList.length && className(this, cls + (cls ? " " : "") + classList.join(" "))
737 })
738 },
739 removeClass: function(name){
740 return this.each(function(idx){
741 if (!('className' in this)) return
742 if (name === undefined) return className(this, '')
743 classList = className(this)
744 funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass){
745 classList = classList.replace(classRE(klass), " ")
746 })
747 className(this, classList.trim())
748 })
749 },
750 toggleClass: function(name, when){
751 if (!name) return this
752 return this.each(function(idx){
753 var $this = $(this), names = funcArg(this, name, idx, className(this))
754 names.split(/\s+/g).forEach(function(klass){
755 (when === undefined ? !$this.hasClass(klass) : when) ?
756 $this.addClass(klass) : $this.removeClass(klass)
757 })
758 })
759 },
760 scrollTop: function(value){
761 if (!this.length) return
762 var hasScrollTop = 'scrollTop' in this[0]
763 if (value === undefined) return hasScrollTop ? this[0].scrollTop : this[0].pageYOffset
764 return this.each(hasScrollTop ?
765 function(){ this.scrollTop = value } :
766 function(){ this.scrollTo(this.scrollX, value) })
767 },
768 scrollLeft: function(value){
769 if (!this.length) return
770 var hasScrollLeft = 'scrollLeft' in this[0]
771 if (value === undefined) return hasScrollLeft ? this[0].scrollLeft : this[0].pageXOffset
772 return this.each(hasScrollLeft ?
773 function(){ this.scrollLeft = value } :
774 function(){ this.scrollTo(value, this.scrollY) })
775 },
776 position: function() {
777 if (!this.length) return
778
779 var elem = this[0],
780 // Get *real* offsetParent
781 offsetParent = this.offsetParent(),
782 // Get correct offsets
783 offset = this.offset(),
784 parentOffset = rootNodeRE.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset()
785
786 // Subtract element margins
787 // note: when an element has margin: auto the offsetLeft and marginLeft
788 // are the same in Safari causing offset.left to incorrectly be 0
789 offset.top -= parseFloat( $(elem).css('margin-top') ) || 0
790 offset.left -= parseFloat( $(elem).css('margin-left') ) || 0
791
792 // Add offsetParent borders
793 parentOffset.top += parseFloat( $(offsetParent[0]).css('border-top-width') ) || 0
794 parentOffset.left += parseFloat( $(offsetParent[0]).css('border-left-width') ) || 0
795
796 // Subtract the two offsets
797 return {
798 top: offset.top - parentOffset.top,
799 left: offset.left - parentOffset.left
800 }
801 },
802 offsetParent: function() {
803 return this.map(function(){
804 var parent = this.offsetParent || document.body
805 while (parent && !rootNodeRE.test(parent.nodeName) && $(parent).css("position") == "static")
806 parent = parent.offsetParent
807 return parent
808 })
809 }
810 }
811
812 // for now
813 $.fn.detach = $.fn.remove
814
815 // Generate the `width` and `height` functions
816 ;['width', 'height'].forEach(function(dimension){
817 var dimensionProperty =
818 dimension.replace(/./, function(m){ return m[0].toUpperCase() })
819
820 $.fn[dimension] = function(value){
821 var offset, el = this[0]
822 if (value === undefined) return isWindow(el) ? el['inner' + dimensionProperty] :
823 isDocument(el) ? el.documentElement['scroll' + dimensionProperty] :
824 (offset = this.offset()) && offset[dimension]
825 else return this.each(function(idx){
826 el = $(this)
827 el.css(dimension, funcArg(this, value, idx, el[dimension]()))
828 })
829 }
830 })
831
832 function traverseNode(node, fun) {
833 fun(node)
834 for (var i = 0, len = node.childNodes.length; i < len; i++)
835 traverseNode(node.childNodes[i], fun)
836 }
837
838 // Generate the `after`, `prepend`, `before`, `append`,
839 // `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods.
840 adjacencyOperators.forEach(function(operator, operatorIndex) {
841 var inside = operatorIndex % 2 //=> prepend, append
842
843 $.fn[operator] = function(){
844 // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings
845 var argType, nodes = $.map(arguments, function(arg) {
846 argType = type(arg)
847 return argType == "object" || argType == "array" || arg == null ?
848 arg : zepto.fragment(arg)
849 }),
850 parent, copyByClone = this.length > 1
851 if (nodes.length < 1) return this
852
853 return this.each(function(_, target){
854 parent = inside ? target : target.parentNode
855
856 // convert all methods to a "before" operation
857 target = operatorIndex == 0 ? target.nextSibling :
858 operatorIndex == 1 ? target.firstChild :
859 operatorIndex == 2 ? target :
860 null
861
862 var parentInDocument = $.contains(document.documentElement, parent)
863
864 nodes.forEach(function(node){
865 if (copyByClone) node = node.cloneNode(true)
866 else if (!parent) return $(node).remove()
867
868 parent.insertBefore(node, target)
869 if (parentInDocument) traverseNode(node, function(el){
870 if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' &&
871 (!el.type || el.type === 'text/javascript') && !el.src)
872 window['eval'].call(window, el.innerHTML)
873 })
874 })
875 })
876 }
877
878 // after => insertAfter
879 // prepend => prependTo
880 // before => insertBefore
881 // append => appendTo
882 $.fn[inside ? operator+'To' : 'insert'+(operatorIndex ? 'Before' : 'After')] = function(html){
883 $(html)[operator](this)
884 return this
885 }
886 })
887
888 zepto.Z.prototype = Z.prototype = $.fn
889
890 // Export internal API functions in the `$.zepto` namespace
891 zepto.uniq = uniq
892 zepto.deserializeValue = deserializeValue
893 $.zepto = zepto
894
895 return $
896 })()
897
898 window.Zepto = Zepto
899 window.$ === undefined && (window.$ = Zepto)
900
901 ;(function($){
902 var _zid = 1, undefined,
903 slice = Array.prototype.slice,
904 isFunction = $.isFunction,
905 isString = function(obj){ return typeof obj == 'string' },
906 handlers = {},
907 specialEvents={},
908 focusinSupported = 'onfocusin' in window,
909 focus = { focus: 'focusin', blur: 'focusout' },
910 hover = { mouseenter: 'mouseover', mouseleave: 'mouseout' }
911
912 specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents'
913
914 function zid(element) {
915 return element._zid || (element._zid = _zid++)
916 }
917 function findHandlers(element, event, fn, selector) {
918 event = parse(event)
919 if (event.ns) var matcher = matcherFor(event.ns)
920 return (handlers[zid(element)] || []).filter(function(handler) {
921 return handler
922 && (!event.e || handler.e == event.e)
923 && (!event.ns || matcher.test(handler.ns))
924 && (!fn || zid(handler.fn) === zid(fn))
925 && (!selector || handler.sel == selector)
926 })
927 }
928 function parse(event) {
929 var parts = ('' + event).split('.')
930 return {e: parts[0], ns: parts.slice(1).sort().join(' ')}
931 }
932 function matcherFor(ns) {
933 return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)')
934 }
935
936 function eventCapture(handler, captureSetting) {
937 return handler.del &&
938 (!focusinSupported && (handler.e in focus)) ||
939 !!captureSetting
940 }
941
942 function realEvent(type) {
943 return hover[type] || (focusinSupported && focus[type]) || type
944 }
945
946 function add(element, events, fn, data, selector, delegator, capture){
947 var id = zid(element), set = (handlers[id] || (handlers[id] = []))
948 events.split(/\s/).forEach(function(event){
949 if (event == 'ready') return $(document).ready(fn)
950 var handler = parse(event)
951 handler.fn = fn
952 handler.sel = selector
953 // emulate mouseenter, mouseleave
954 if (handler.e in hover) fn = function(e){
955 var related = e.relatedTarget
956 if (!related || (related !== this && !$.contains(this, related)))
957 return handler.fn.apply(this, arguments)
958 }
959 handler.del = delegator
960 var callback = delegator || fn
961 handler.proxy = function(e){
962 e = compatible(e)
963 if (e.isImmediatePropagationStopped()) return
964 e.data = data
965 var result = callback.apply(element, e._args == undefined ? [e] : [e].concat(e._args))
966 if (result === false) e.preventDefault(), e.stopPropagation()
967 return result
968 }
969 handler.i = set.length
970 set.push(handler)
971 if ('addEventListener' in element)
972 element.addEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture))
973 })
974 }
975 function remove(element, events, fn, selector, capture){
976 var id = zid(element)
977 ;(events || '').split(/\s/).forEach(function(event){
978 findHandlers(element, event, fn, selector).forEach(function(handler){
979 delete handlers[id][handler.i]
980 if ('removeEventListener' in element)
981 element.removeEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture))
982 })
983 })
984 }
985
986 $.event = { add: add, remove: remove }
987
988 $.proxy = function(fn, context) {
989 var args = (2 in arguments) && slice.call(arguments, 2)
990 if (isFunction(fn)) {
991 var proxyFn = function(){ return fn.apply(context, args ? args.concat(slice.call(arguments)) : arguments) }
992 proxyFn._zid = zid(fn)
993 return proxyFn
994 } else if (isString(context)) {
995 if (args) {
996 args.unshift(fn[context], fn)
997 return $.proxy.apply(null, args)
998 } else {
999 return $.proxy(fn[context], fn)
1000 }
1001 } else {
1002 throw new TypeError("expected function")
1003 }
1004 }
1005
1006 $.fn.bind = function(event, data, callback){
1007 return this.on(event, data, callback)
1008 }
1009 $.fn.unbind = function(event, callback){
1010 return this.off(event, callback)
1011 }
1012 $.fn.one = function(event, selector, data, callback){
1013 return this.on(event, selector, data, callback, 1)
1014 }
1015
1016 var returnTrue = function(){return true},
1017 returnFalse = function(){return false},
1018 ignoreProperties = /^([A-Z]|returnValue$|layer[XY]$)/,
1019 eventMethods = {
1020 preventDefault: 'isDefaultPrevented',
1021 stopImmediatePropagation: 'isImmediatePropagationStopped',
1022 stopPropagation: 'isPropagationStopped'
1023 }
1024
1025 function compatible(event, source) {
1026 if (source || !event.isDefaultPrevented) {
1027 source || (source = event)
1028
1029 $.each(eventMethods, function(name, predicate) {
1030 var sourceMethod = source[name]
1031 event[name] = function(){
1032 this[predicate] = returnTrue
1033 return sourceMethod && sourceMethod.apply(source, arguments)
1034 }
1035 event[predicate] = returnFalse
1036 })
1037
1038 if (source.defaultPrevented !== undefined ? source.defaultPrevented :
1039 'returnValue' in source ? source.returnValue === false :
1040 source.getPreventDefault && source.getPreventDefault())
1041 event.isDefaultPrevented = returnTrue
1042 }
1043 return event
1044 }
1045
1046 function createProxy(event) {
1047 var key, proxy = { originalEvent: event }
1048 for (key in event)
1049 if (!ignoreProperties.test(key) && event[key] !== undefined) proxy[key] = event[key]
1050
1051 return compatible(proxy, event)
1052 }
1053
1054 $.fn.delegate = function(selector, event, callback){
1055 return this.on(event, selector, callback)
1056 }
1057 $.fn.undelegate = function(selector, event, callback){
1058 return this.off(event, selector, callback)
1059 }
1060
1061 $.fn.live = function(event, callback){
1062 $(document.body).delegate(this.selector, event, callback)
1063 return this
1064 }
1065 $.fn.die = function(event, callback){
1066 $(document.body).undelegate(this.selector, event, callback)
1067 return this
1068 }
1069
1070 $.fn.on = function(event, selector, data, callback, one){
1071 var autoRemove, delegator, $this = this
1072 if (event && !isString(event)) {
1073 $.each(event, function(type, fn){
1074 $this.on(type, selector, data, fn, one)
1075 })
1076 return $this
1077 }
1078
1079 if (!isString(selector) && !isFunction(callback) && callback !== false)
1080 callback = data, data = selector, selector = undefined
1081 if (isFunction(data) || data === false)
1082 callback = data, data = undefined
1083
1084 if (callback === false) callback = returnFalse
1085
1086 return $this.each(function(_, element){
1087 if (one) autoRemove = function(e){
1088 remove(element, e.type, callback)
1089 return callback.apply(this, arguments)
1090 }
1091
1092 if (selector) delegator = function(e){
1093 var evt, match = $(e.target).closest(selector, element).get(0)
1094 if (match && match !== element) {
1095 evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element})
1096 return (autoRemove || callback).apply(match, [evt].concat(slice.call(arguments, 1)))
1097 }
1098 }
1099
1100 add(element, event, callback, data, selector, delegator || autoRemove)
1101 })
1102 }
1103 $.fn.off = function(event, selector, callback){
1104 var $this = this
1105 if (event && !isString(event)) {
1106 $.each(event, function(type, fn){
1107 $this.off(type, selector, fn)
1108 })
1109 return $this
1110 }
1111
1112 if (!isString(selector) && !isFunction(callback) && callback !== false)
1113 callback = selector, selector = undefined
1114
1115 if (callback === false) callback = returnFalse
1116
1117 return $this.each(function(){
1118 remove(this, event, callback, selector)
1119 })
1120 }
1121
1122 $.fn.trigger = function(event, args){
1123 event = (isString(event) || $.isPlainObject(event)) ? $.Event(event) : compatible(event)
1124 event._args = args
1125 return this.each(function(){
1126 // items in the collection might not be DOM elements
1127 if('dispatchEvent' in this) this.dispatchEvent(event)
1128 else $(this).triggerHandler(event, args)
1129 })
1130 }
1131
1132 // triggers event handlers on current element just as if an event occurred,
1133 // doesn't trigger an actual event, doesn't bubble
1134 $.fn.triggerHandler = function(event, args){
1135 var e, result
1136 this.each(function(i, element){
1137 e = createProxy(isString(event) ? $.Event(event) : event)
1138 e._args = args
1139 e.target = element
1140 $.each(findHandlers(element, event.type || event), function(i, handler){
1141 result = handler.proxy(e)
1142 if (e.isImmediatePropagationStopped()) return false
1143 })
1144 })
1145 return result
1146 }
1147
1148 // shortcut methods for `.bind(event, fn)` for each event type
1149 ;('focusin focusout load resize scroll unload click dblclick '+
1150 'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave '+
1151 'change select keydown keypress keyup error').split(' ').forEach(function(event) {
1152 $.fn[event] = function(callback) {
1153 return callback ?
1154 this.bind(event, callback) :
1155 this.trigger(event)
1156 }
1157 })
1158
1159 ;['focus', 'blur'].forEach(function(name) {
1160 $.fn[name] = function(callback) {
1161 if (callback) this.bind(name, callback)
1162 else this.each(function(){
1163 try { this[name]() }
1164 catch(e) {}
1165 })
1166 return this
1167 }
1168 })
1169
1170 $.Event = function(type, props) {
1171 if (!isString(type)) props = type, type = props.type
1172 var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true
1173 if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name])
1174 event.initEvent(type, bubbles, true)
1175 return compatible(event)
1176 }
1177
1178 })(Zepto)
1179
1180 ;(function($){
1181 var data = {}, dataAttr = $.fn.data, camelize = $.camelCase,
1182 exp = $.expando = 'Zepto' + (+new Date()), emptyArray = []
1183
1184 // Get value from node:
1185 // 1. first try key as given,
1186 // 2. then try camelized key,
1187 // 3. fall back to reading "data-*" attribute.
1188 function getData(node, name) {
1189 var id = node[exp], store = id && data[id]
1190 if (name === undefined) return store || setData(node)
1191 else {
1192 if (store) {
1193 if (name in store) return store[name]
1194 var camelName = camelize(name)
1195 if (camelName in store) return store[camelName]
1196 }
1197 return dataAttr.call($(node), name)
1198 }
1199 }
1200
1201 // Store value under camelized key on node
1202 function setData(node, name, value) {
1203 var id = node[exp] || (node[exp] = ++$.uuid),
1204 store = data[id] || (data[id] = attributeData(node))
1205 if (name !== undefined) store[camelize(name)] = value
1206 return store
1207 }
1208
1209 // Read all "data-*" attributes from a node
1210 function attributeData(node) {
1211 var store = {}
1212 $.each(node.attributes || emptyArray, function(i, attr){
1213 if (attr.name.indexOf('data-') == 0)
1214 store[camelize(attr.name.replace('data-', ''))] =
1215 $.zepto.deserializeValue(attr.value)
1216 })
1217 return store
1218 }
1219
1220 $.fn.data = function(name, value) {
1221 return value === undefined ?
1222 // set multiple values via object
1223 $.isPlainObject(name) ?
1224 this.each(function(i, node){
1225 $.each(name, function(key, value){ setData(node, key, value) })
1226 }) :
1227 // get value from first element
1228 (0 in this ? getData(this[0], name) : undefined) :
1229 // set value on all elements
1230 this.each(function(){ setData(this, name, value) })
1231 }
1232
1233 $.fn.removeData = function(names) {
1234 if (typeof names == 'string') names = names.split(/\s+/)
1235 return this.each(function(){
1236 var id = this[exp], store = id && data[id]
1237 if (store) $.each(names || store, function(key){
1238 delete store[names ? camelize(this) : key]
1239 })
1240 })
1241 }
1242
1243 // Generate extended `remove` and `empty` functions
1244 ;['remove', 'empty'].forEach(function(methodName){
1245 var origFn = $.fn[methodName]
1246 $.fn[methodName] = function() {
1247 var elements = this.find('*')
1248 if (methodName === 'remove') elements = elements.add(this)
1249 elements.removeData()
1250 return origFn.call(this)
1251 }
1252 })
1253 })(Zepto)
1254
1255 ;(function(){
1256 // getComputedStyle shouldn't freak out when called
1257 // without a valid element as argument
1258 try {
1259 getComputedStyle(undefined)
1260 } catch(e) {
1261 var nativeGetComputedStyle = getComputedStyle;
1262 window.getComputedStyle = function(element){
1263 try {
1264 return nativeGetComputedStyle(element)
1265 } catch(e) {
1266 return null
1267 }
1268 }
1269 }
1270 })()
This page took 0.266242 seconds and 4 git commands to generate.