]>
Commit | Line | Data |
---|---|---|
f4e194ef | 1 | /* Zepto v1.1.4-80-ga9184b2 - zepto event data ie - zeptojs.com/license */ |
eef56f7a MG |
2 | |
3 | var Zepto = (function() { | |
514df99c | 4 | var undefined, key, $, classList, emptyArray = [], concat = emptyArray.concat, filter = emptyArray.filter, slice = emptyArray.slice, |
eef56f7a MG |
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/, | |
eef56f7a MG |
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 | ||
514df99c MG |
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 | ||
eef56f7a MG |
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 | |
514df99c | 160 | // to the array. This method can be overriden in plugins. |
eef56f7a | 161 | zepto.Z = function(dom, selector) { |
514df99c | 162 | return new Z(dom, selector) |
eef56f7a MG |
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) | |
f4e194ef | 257 | return (element.getElementById && isSimple && maybeID) ? // Safari DocumentFragment doesn't have getElementById |
eef56f7a | 258 | ( (found = element.getElementById(nameOnly)) ? [found] : [] ) : |
f4e194ef | 259 | (element.nodeType !== 1 && element.nodeType !== 9 && element.nodeType !== 11) ? [] : |
eef56f7a | 260 | slice.call( |
f4e194ef | 261 | isSimple && !maybeID && element.getElementsByClassName ? // DocumentFragment doesn't have getElementsByClassName/TagName |
eef56f7a MG |
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 | ||
514df99c MG |
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 | } | |
eef56f7a MG |
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){ | |
514df99c | 292 | var klass = node.className || '', |
eef56f7a MG |
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) { | |
eef56f7a MG |
308 | try { |
309 | return value ? | |
310 | value == "true" || | |
311 | ( value == "false" ? false : | |
312 | value == "null" ? null : | |
f4e194ef | 313 | +value + "" == value ? +value : |
eef56f7a MG |
314 | /^[\[\{]/.test(value) ? $.parseJSON(value) : |
315 | value ) | |
316 | : value | |
317 | } catch(e) { | |
318 | return value | |
319 | } | |
320 | } | |
321 | ||
322 | $.type = type | |
323 | $.isFunction = isFunction | |
324 | $.isWindow = isWindow | |
325 | $.isArray = isArray | |
326 | $.isPlainObject = isPlainObject | |
327 | ||
328 | $.isEmptyObject = function(obj) { | |
329 | var name | |
330 | for (name in obj) return false | |
331 | return true | |
332 | } | |
333 | ||
334 | $.inArray = function(elem, array, i){ | |
335 | return emptyArray.indexOf.call(array, elem, i) | |
336 | } | |
337 | ||
338 | $.camelCase = camelize | |
339 | $.trim = function(str) { | |
340 | return str == null ? "" : String.prototype.trim.call(str) | |
341 | } | |
342 | ||
343 | // plugin compatibility | |
344 | $.uuid = 0 | |
345 | $.support = { } | |
346 | $.expr = { } | |
f4e194ef | 347 | $.noop = function() {} |
eef56f7a MG |
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 = { | |
514df99c MG |
391 | constructor: zepto.Z, |
392 | length: 0, | |
393 | ||
eef56f7a MG |
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, | |
514df99c | 400 | splice: emptyArray.splice, |
eef56f7a | 401 | indexOf: emptyArray.indexOf, |
514df99c MG |
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 | }, | |
eef56f7a MG |
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 | |
f4e194ef | 493 | if (!selector) result = $() |
514df99c | 494 | else if (typeof selector == 'object') |
eef56f7a MG |
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() { | |
f4e194ef | 530 | return this.map(function() { return this.contentDocument || slice.call(this.childNodes) }) |
eef56f7a MG |
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){ | |
514df99c | 606 | return 0 in arguments ? |
eef56f7a MG |
607 | this.each(function(idx){ |
608 | var originHtml = this.innerHTML | |
609 | $(this).empty().append( funcArg(this, html, idx, originHtml) ) | |
514df99c MG |
610 | }) : |
611 | (0 in this ? this[0].innerHTML : null) | |
eef56f7a MG |
612 | }, |
613 | text: function(text){ | |
514df99c MG |
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) | |
eef56f7a MG |
620 | }, |
621 | attr: function(name, value){ | |
622 | var result | |
514df99c MG |
623 | return (typeof name == 'string' && !(1 in arguments)) ? |
624 | (!this.length || this[0].nodeType !== 1 ? undefined : | |
eef56f7a MG |
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){ | |
514df99c MG |
634 | return this.each(function(){ this.nodeType === 1 && name.split(' ').forEach(function(attribute){ |
635 | setAttribute(this, attribute) | |
636 | }, this)}) | |
eef56f7a MG |
637 | }, |
638 | prop: function(name, value){ | |
639 | name = propMap[name] || name | |
514df99c | 640 | return (1 in arguments) ? |
eef56f7a MG |
641 | this.each(function(idx){ |
642 | this[name] = funcArg(this, value, idx, this[name]) | |
514df99c MG |
643 | }) : |
644 | (this[0] && this[0][name]) | |
eef56f7a MG |
645 | }, |
646 | data: function(name, value){ | |
514df99c MG |
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 | ||
eef56f7a MG |
653 | return data !== null ? deserializeValue(data) : undefined |
654 | }, | |
655 | val: function(value){ | |
514df99c MG |
656 | return 0 in arguments ? |
657 | this.each(function(idx){ | |
658 | this.value = funcArg(this, value, idx, this.value) | |
659 | }) : | |
eef56f7a MG |
660 | (this[0] && (this[0].multiple ? |
661 | $(this[0]).find('option').filter(function(){ return this.selected }).pluck('value') : | |
662 | this[0].value) | |
514df99c | 663 | ) |
eef56f7a MG |
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 | }) | |
514df99c | 678 | if (!this.length) return null |
f4e194ef MG |
679 | if (!$.contains(document.documentElement, this[0])) |
680 | return {top: 0, left: 0} | |
eef56f7a MG |
681 | var obj = this[0].getBoundingClientRect() |
682 | return { | |
683 | left: obj.left + window.pageXOffset, | |
684 | top: obj.top + window.pageYOffset, | |
685 | width: Math.round(obj.width), | |
686 | height: Math.round(obj.height) | |
687 | } | |
688 | }, | |
689 | css: function(property, value){ | |
690 | if (arguments.length < 2) { | |
f4e194ef | 691 | var computedStyle, element = this[0] |
eef56f7a | 692 | if(!element) return |
f4e194ef | 693 | computedStyle = getComputedStyle(element, '') |
eef56f7a MG |
694 | if (typeof property == 'string') |
695 | return element.style[camelize(property)] || computedStyle.getPropertyValue(property) | |
696 | else if (isArray(property)) { | |
697 | var props = {} | |
514df99c | 698 | $.each(property, function(_, prop){ |
eef56f7a MG |
699 | props[prop] = (element.style[camelize(prop)] || computedStyle.getPropertyValue(prop)) |
700 | }) | |
701 | return props | |
702 | } | |
703 | } | |
704 | ||
705 | var css = '' | |
706 | if (type(property) == 'string') { | |
707 | if (!value && value !== 0) | |
708 | this.each(function(){ this.style.removeProperty(dasherize(property)) }) | |
709 | else | |
710 | css = dasherize(property) + ":" + maybeAddPx(property, value) | |
711 | } else { | |
712 | for (key in property) | |
713 | if (!property[key] && property[key] !== 0) | |
714 | this.each(function(){ this.style.removeProperty(dasherize(key)) }) | |
715 | else | |
716 | css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';' | |
717 | } | |
718 | ||
719 | return this.each(function(){ this.style.cssText += ';' + css }) | |
720 | }, | |
721 | index: function(element){ | |
722 | return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0]) | |
723 | }, | |
724 | hasClass: function(name){ | |
725 | if (!name) return false | |
726 | return emptyArray.some.call(this, function(el){ | |
727 | return this.test(className(el)) | |
728 | }, classRE(name)) | |
729 | }, | |
730 | addClass: function(name){ | |
731 | if (!name) return this | |
732 | return this.each(function(idx){ | |
514df99c | 733 | if (!('className' in this)) return |
eef56f7a MG |
734 | classList = [] |
735 | var cls = className(this), newName = funcArg(this, name, idx, cls) | |
736 | newName.split(/\s+/g).forEach(function(klass){ | |
737 | if (!$(this).hasClass(klass)) classList.push(klass) | |
738 | }, this) | |
739 | classList.length && className(this, cls + (cls ? " " : "") + classList.join(" ")) | |
740 | }) | |
741 | }, | |
742 | removeClass: function(name){ | |
743 | return this.each(function(idx){ | |
514df99c | 744 | if (!('className' in this)) return |
eef56f7a MG |
745 | if (name === undefined) return className(this, '') |
746 | classList = className(this) | |
747 | funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass){ | |
748 | classList = classList.replace(classRE(klass), " ") | |
749 | }) | |
750 | className(this, classList.trim()) | |
751 | }) | |
752 | }, | |
753 | toggleClass: function(name, when){ | |
754 | if (!name) return this | |
755 | return this.each(function(idx){ | |
756 | var $this = $(this), names = funcArg(this, name, idx, className(this)) | |
757 | names.split(/\s+/g).forEach(function(klass){ | |
758 | (when === undefined ? !$this.hasClass(klass) : when) ? | |
759 | $this.addClass(klass) : $this.removeClass(klass) | |
760 | }) | |
761 | }) | |
762 | }, | |
763 | scrollTop: function(value){ | |
764 | if (!this.length) return | |
765 | var hasScrollTop = 'scrollTop' in this[0] | |
766 | if (value === undefined) return hasScrollTop ? this[0].scrollTop : this[0].pageYOffset | |
767 | return this.each(hasScrollTop ? | |
768 | function(){ this.scrollTop = value } : | |
769 | function(){ this.scrollTo(this.scrollX, value) }) | |
770 | }, | |
771 | scrollLeft: function(value){ | |
772 | if (!this.length) return | |
773 | var hasScrollLeft = 'scrollLeft' in this[0] | |
774 | if (value === undefined) return hasScrollLeft ? this[0].scrollLeft : this[0].pageXOffset | |
775 | return this.each(hasScrollLeft ? | |
776 | function(){ this.scrollLeft = value } : | |
777 | function(){ this.scrollTo(value, this.scrollY) }) | |
778 | }, | |
779 | position: function() { | |
780 | if (!this.length) return | |
781 | ||
782 | var elem = this[0], | |
783 | // Get *real* offsetParent | |
784 | offsetParent = this.offsetParent(), | |
785 | // Get correct offsets | |
786 | offset = this.offset(), | |
787 | parentOffset = rootNodeRE.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset() | |
788 | ||
789 | // Subtract element margins | |
790 | // note: when an element has margin: auto the offsetLeft and marginLeft | |
791 | // are the same in Safari causing offset.left to incorrectly be 0 | |
792 | offset.top -= parseFloat( $(elem).css('margin-top') ) || 0 | |
793 | offset.left -= parseFloat( $(elem).css('margin-left') ) || 0 | |
794 | ||
795 | // Add offsetParent borders | |
796 | parentOffset.top += parseFloat( $(offsetParent[0]).css('border-top-width') ) || 0 | |
797 | parentOffset.left += parseFloat( $(offsetParent[0]).css('border-left-width') ) || 0 | |
798 | ||
799 | // Subtract the two offsets | |
800 | return { | |
801 | top: offset.top - parentOffset.top, | |
802 | left: offset.left - parentOffset.left | |
803 | } | |
804 | }, | |
805 | offsetParent: function() { | |
806 | return this.map(function(){ | |
807 | var parent = this.offsetParent || document.body | |
808 | while (parent && !rootNodeRE.test(parent.nodeName) && $(parent).css("position") == "static") | |
809 | parent = parent.offsetParent | |
810 | return parent | |
811 | }) | |
812 | } | |
813 | } | |
814 | ||
815 | // for now | |
816 | $.fn.detach = $.fn.remove | |
817 | ||
818 | // Generate the `width` and `height` functions | |
819 | ;['width', 'height'].forEach(function(dimension){ | |
820 | var dimensionProperty = | |
821 | dimension.replace(/./, function(m){ return m[0].toUpperCase() }) | |
822 | ||
823 | $.fn[dimension] = function(value){ | |
824 | var offset, el = this[0] | |
825 | if (value === undefined) return isWindow(el) ? el['inner' + dimensionProperty] : | |
826 | isDocument(el) ? el.documentElement['scroll' + dimensionProperty] : | |
827 | (offset = this.offset()) && offset[dimension] | |
828 | else return this.each(function(idx){ | |
829 | el = $(this) | |
830 | el.css(dimension, funcArg(this, value, idx, el[dimension]())) | |
831 | }) | |
832 | } | |
833 | }) | |
834 | ||
835 | function traverseNode(node, fun) { | |
836 | fun(node) | |
514df99c MG |
837 | for (var i = 0, len = node.childNodes.length; i < len; i++) |
838 | traverseNode(node.childNodes[i], fun) | |
eef56f7a MG |
839 | } |
840 | ||
841 | // Generate the `after`, `prepend`, `before`, `append`, | |
842 | // `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods. | |
843 | adjacencyOperators.forEach(function(operator, operatorIndex) { | |
844 | var inside = operatorIndex % 2 //=> prepend, append | |
845 | ||
846 | $.fn[operator] = function(){ | |
847 | // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings | |
848 | var argType, nodes = $.map(arguments, function(arg) { | |
849 | argType = type(arg) | |
850 | return argType == "object" || argType == "array" || arg == null ? | |
851 | arg : zepto.fragment(arg) | |
852 | }), | |
853 | parent, copyByClone = this.length > 1 | |
854 | if (nodes.length < 1) return this | |
855 | ||
856 | return this.each(function(_, target){ | |
857 | parent = inside ? target : target.parentNode | |
858 | ||
859 | // convert all methods to a "before" operation | |
860 | target = operatorIndex == 0 ? target.nextSibling : | |
861 | operatorIndex == 1 ? target.firstChild : | |
862 | operatorIndex == 2 ? target : | |
863 | null | |
864 | ||
514df99c MG |
865 | var parentInDocument = $.contains(document.documentElement, parent) |
866 | ||
eef56f7a MG |
867 | nodes.forEach(function(node){ |
868 | if (copyByClone) node = node.cloneNode(true) | |
869 | else if (!parent) return $(node).remove() | |
870 | ||
514df99c MG |
871 | parent.insertBefore(node, target) |
872 | if (parentInDocument) traverseNode(node, function(el){ | |
eef56f7a MG |
873 | if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' && |
874 | (!el.type || el.type === 'text/javascript') && !el.src) | |
875 | window['eval'].call(window, el.innerHTML) | |
876 | }) | |
877 | }) | |
878 | }) | |
879 | } | |
880 | ||
881 | // after => insertAfter | |
882 | // prepend => prependTo | |
883 | // before => insertBefore | |
884 | // append => appendTo | |
885 | $.fn[inside ? operator+'To' : 'insert'+(operatorIndex ? 'Before' : 'After')] = function(html){ | |
886 | $(html)[operator](this) | |
887 | return this | |
888 | } | |
889 | }) | |
890 | ||
514df99c | 891 | zepto.Z.prototype = Z.prototype = $.fn |
eef56f7a MG |
892 | |
893 | // Export internal API functions in the `$.zepto` namespace | |
894 | zepto.uniq = uniq | |
895 | zepto.deserializeValue = deserializeValue | |
896 | $.zepto = zepto | |
897 | ||
898 | return $ | |
899 | })() | |
900 | ||
901 | window.Zepto = Zepto | |
902 | window.$ === undefined && (window.$ = Zepto) | |
903 | ||
904 | ;(function($){ | |
514df99c | 905 | var _zid = 1, undefined, |
eef56f7a MG |
906 | slice = Array.prototype.slice, |
907 | isFunction = $.isFunction, | |
908 | isString = function(obj){ return typeof obj == 'string' }, | |
909 | handlers = {}, | |
910 | specialEvents={}, | |
911 | focusinSupported = 'onfocusin' in window, | |
912 | focus = { focus: 'focusin', blur: 'focusout' }, | |
913 | hover = { mouseenter: 'mouseover', mouseleave: 'mouseout' } | |
914 | ||
915 | specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents' | |
916 | ||
917 | function zid(element) { | |
918 | return element._zid || (element._zid = _zid++) | |
919 | } | |
920 | function findHandlers(element, event, fn, selector) { | |
921 | event = parse(event) | |
922 | if (event.ns) var matcher = matcherFor(event.ns) | |
923 | return (handlers[zid(element)] || []).filter(function(handler) { | |
924 | return handler | |
925 | && (!event.e || handler.e == event.e) | |
926 | && (!event.ns || matcher.test(handler.ns)) | |
927 | && (!fn || zid(handler.fn) === zid(fn)) | |
928 | && (!selector || handler.sel == selector) | |
929 | }) | |
930 | } | |
931 | function parse(event) { | |
932 | var parts = ('' + event).split('.') | |
933 | return {e: parts[0], ns: parts.slice(1).sort().join(' ')} | |
934 | } | |
935 | function matcherFor(ns) { | |
936 | return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)') | |
937 | } | |
938 | ||
939 | function eventCapture(handler, captureSetting) { | |
940 | return handler.del && | |
941 | (!focusinSupported && (handler.e in focus)) || | |
942 | !!captureSetting | |
943 | } | |
944 | ||
945 | function realEvent(type) { | |
946 | return hover[type] || (focusinSupported && focus[type]) || type | |
947 | } | |
948 | ||
949 | function add(element, events, fn, data, selector, delegator, capture){ | |
950 | var id = zid(element), set = (handlers[id] || (handlers[id] = [])) | |
951 | events.split(/\s/).forEach(function(event){ | |
952 | if (event == 'ready') return $(document).ready(fn) | |
953 | var handler = parse(event) | |
954 | handler.fn = fn | |
955 | handler.sel = selector | |
956 | // emulate mouseenter, mouseleave | |
957 | if (handler.e in hover) fn = function(e){ | |
958 | var related = e.relatedTarget | |
959 | if (!related || (related !== this && !$.contains(this, related))) | |
960 | return handler.fn.apply(this, arguments) | |
961 | } | |
962 | handler.del = delegator | |
963 | var callback = delegator || fn | |
964 | handler.proxy = function(e){ | |
965 | e = compatible(e) | |
966 | if (e.isImmediatePropagationStopped()) return | |
967 | e.data = data | |
968 | var result = callback.apply(element, e._args == undefined ? [e] : [e].concat(e._args)) | |
969 | if (result === false) e.preventDefault(), e.stopPropagation() | |
970 | return result | |
971 | } | |
972 | handler.i = set.length | |
973 | set.push(handler) | |
974 | if ('addEventListener' in element) | |
975 | element.addEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) | |
976 | }) | |
977 | } | |
978 | function remove(element, events, fn, selector, capture){ | |
979 | var id = zid(element) | |
980 | ;(events || '').split(/\s/).forEach(function(event){ | |
981 | findHandlers(element, event, fn, selector).forEach(function(handler){ | |
982 | delete handlers[id][handler.i] | |
983 | if ('removeEventListener' in element) | |
984 | element.removeEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) | |
985 | }) | |
986 | }) | |
987 | } | |
988 | ||
989 | $.event = { add: add, remove: remove } | |
990 | ||
991 | $.proxy = function(fn, context) { | |
514df99c | 992 | var args = (2 in arguments) && slice.call(arguments, 2) |
eef56f7a | 993 | if (isFunction(fn)) { |
514df99c | 994 | var proxyFn = function(){ return fn.apply(context, args ? args.concat(slice.call(arguments)) : arguments) } |
eef56f7a MG |
995 | proxyFn._zid = zid(fn) |
996 | return proxyFn | |
997 | } else if (isString(context)) { | |
514df99c MG |
998 | if (args) { |
999 | args.unshift(fn[context], fn) | |
1000 | return $.proxy.apply(null, args) | |
1001 | } else { | |
1002 | return $.proxy(fn[context], fn) | |
1003 | } | |
eef56f7a MG |
1004 | } else { |
1005 | throw new TypeError("expected function") | |
1006 | } | |
1007 | } | |
1008 | ||
1009 | $.fn.bind = function(event, data, callback){ | |
1010 | return this.on(event, data, callback) | |
1011 | } | |
1012 | $.fn.unbind = function(event, callback){ | |
1013 | return this.off(event, callback) | |
1014 | } | |
1015 | $.fn.one = function(event, selector, data, callback){ | |
1016 | return this.on(event, selector, data, callback, 1) | |
1017 | } | |
1018 | ||
1019 | var returnTrue = function(){return true}, | |
1020 | returnFalse = function(){return false}, | |
1021 | ignoreProperties = /^([A-Z]|returnValue$|layer[XY]$)/, | |
1022 | eventMethods = { | |
1023 | preventDefault: 'isDefaultPrevented', | |
1024 | stopImmediatePropagation: 'isImmediatePropagationStopped', | |
1025 | stopPropagation: 'isPropagationStopped' | |
1026 | } | |
1027 | ||
1028 | function compatible(event, source) { | |
1029 | if (source || !event.isDefaultPrevented) { | |
1030 | source || (source = event) | |
1031 | ||
1032 | $.each(eventMethods, function(name, predicate) { | |
1033 | var sourceMethod = source[name] | |
1034 | event[name] = function(){ | |
1035 | this[predicate] = returnTrue | |
1036 | return sourceMethod && sourceMethod.apply(source, arguments) | |
1037 | } | |
1038 | event[predicate] = returnFalse | |
1039 | }) | |
1040 | ||
1041 | if (source.defaultPrevented !== undefined ? source.defaultPrevented : | |
1042 | 'returnValue' in source ? source.returnValue === false : | |
1043 | source.getPreventDefault && source.getPreventDefault()) | |
1044 | event.isDefaultPrevented = returnTrue | |
1045 | } | |
1046 | return event | |
1047 | } | |
1048 | ||
1049 | function createProxy(event) { | |
1050 | var key, proxy = { originalEvent: event } | |
1051 | for (key in event) | |
1052 | if (!ignoreProperties.test(key) && event[key] !== undefined) proxy[key] = event[key] | |
1053 | ||
1054 | return compatible(proxy, event) | |
1055 | } | |
1056 | ||
1057 | $.fn.delegate = function(selector, event, callback){ | |
1058 | return this.on(event, selector, callback) | |
1059 | } | |
1060 | $.fn.undelegate = function(selector, event, callback){ | |
1061 | return this.off(event, selector, callback) | |
1062 | } | |
1063 | ||
1064 | $.fn.live = function(event, callback){ | |
1065 | $(document.body).delegate(this.selector, event, callback) | |
1066 | return this | |
1067 | } | |
1068 | $.fn.die = function(event, callback){ | |
1069 | $(document.body).undelegate(this.selector, event, callback) | |
1070 | return this | |
1071 | } | |
1072 | ||
1073 | $.fn.on = function(event, selector, data, callback, one){ | |
1074 | var autoRemove, delegator, $this = this | |
1075 | if (event && !isString(event)) { | |
1076 | $.each(event, function(type, fn){ | |
1077 | $this.on(type, selector, data, fn, one) | |
1078 | }) | |
1079 | return $this | |
1080 | } | |
1081 | ||
1082 | if (!isString(selector) && !isFunction(callback) && callback !== false) | |
1083 | callback = data, data = selector, selector = undefined | |
f4e194ef | 1084 | if (callback === undefined || data === false) |
eef56f7a MG |
1085 | callback = data, data = undefined |
1086 | ||
1087 | if (callback === false) callback = returnFalse | |
1088 | ||
1089 | return $this.each(function(_, element){ | |
1090 | if (one) autoRemove = function(e){ | |
1091 | remove(element, e.type, callback) | |
1092 | return callback.apply(this, arguments) | |
1093 | } | |
1094 | ||
1095 | if (selector) delegator = function(e){ | |
1096 | var evt, match = $(e.target).closest(selector, element).get(0) | |
1097 | if (match && match !== element) { | |
1098 | evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element}) | |
1099 | return (autoRemove || callback).apply(match, [evt].concat(slice.call(arguments, 1))) | |
1100 | } | |
1101 | } | |
1102 | ||
1103 | add(element, event, callback, data, selector, delegator || autoRemove) | |
1104 | }) | |
1105 | } | |
1106 | $.fn.off = function(event, selector, callback){ | |
1107 | var $this = this | |
1108 | if (event && !isString(event)) { | |
1109 | $.each(event, function(type, fn){ | |
1110 | $this.off(type, selector, fn) | |
1111 | }) | |
1112 | return $this | |
1113 | } | |
1114 | ||
1115 | if (!isString(selector) && !isFunction(callback) && callback !== false) | |
1116 | callback = selector, selector = undefined | |
1117 | ||
1118 | if (callback === false) callback = returnFalse | |
1119 | ||
1120 | return $this.each(function(){ | |
1121 | remove(this, event, callback, selector) | |
1122 | }) | |
1123 | } | |
1124 | ||
1125 | $.fn.trigger = function(event, args){ | |
1126 | event = (isString(event) || $.isPlainObject(event)) ? $.Event(event) : compatible(event) | |
1127 | event._args = args | |
1128 | return this.each(function(){ | |
f4e194ef MG |
1129 | // handle focus(), blur() by calling them directly |
1130 | if (event.type in focus && typeof this[event.type] == "function") this[event.type]() | |
eef56f7a | 1131 | // items in the collection might not be DOM elements |
f4e194ef | 1132 | else if ('dispatchEvent' in this) this.dispatchEvent(event) |
eef56f7a MG |
1133 | else $(this).triggerHandler(event, args) |
1134 | }) | |
1135 | } | |
1136 | ||
1137 | // triggers event handlers on current element just as if an event occurred, | |
1138 | // doesn't trigger an actual event, doesn't bubble | |
1139 | $.fn.triggerHandler = function(event, args){ | |
1140 | var e, result | |
1141 | this.each(function(i, element){ | |
1142 | e = createProxy(isString(event) ? $.Event(event) : event) | |
1143 | e._args = args | |
1144 | e.target = element | |
1145 | $.each(findHandlers(element, event.type || event), function(i, handler){ | |
1146 | result = handler.proxy(e) | |
1147 | if (e.isImmediatePropagationStopped()) return false | |
1148 | }) | |
1149 | }) | |
1150 | return result | |
1151 | } | |
1152 | ||
1153 | // shortcut methods for `.bind(event, fn)` for each event type | |
f4e194ef | 1154 | ;('focusin focusout focus blur load resize scroll unload click dblclick '+ |
eef56f7a MG |
1155 | 'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave '+ |
1156 | 'change select keydown keypress keyup error').split(' ').forEach(function(event) { | |
1157 | $.fn[event] = function(callback) { | |
f4e194ef | 1158 | return (0 in arguments) ? |
eef56f7a MG |
1159 | this.bind(event, callback) : |
1160 | this.trigger(event) | |
1161 | } | |
1162 | }) | |
1163 | ||
eef56f7a MG |
1164 | $.Event = function(type, props) { |
1165 | if (!isString(type)) props = type, type = props.type | |
1166 | var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true | |
1167 | if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name]) | |
1168 | event.initEvent(type, bubbles, true) | |
1169 | return compatible(event) | |
1170 | } | |
1171 | ||
1172 | })(Zepto) | |
1173 | ||
1174 | ;(function($){ | |
514df99c MG |
1175 | var data = {}, dataAttr = $.fn.data, camelize = $.camelCase, |
1176 | exp = $.expando = 'Zepto' + (+new Date()), emptyArray = [] | |
1177 | ||
1178 | // Get value from node: | |
1179 | // 1. first try key as given, | |
1180 | // 2. then try camelized key, | |
1181 | // 3. fall back to reading "data-*" attribute. | |
1182 | function getData(node, name) { | |
1183 | var id = node[exp], store = id && data[id] | |
1184 | if (name === undefined) return store || setData(node) | |
1185 | else { | |
1186 | if (store) { | |
1187 | if (name in store) return store[name] | |
1188 | var camelName = camelize(name) | |
1189 | if (camelName in store) return store[camelName] | |
eef56f7a | 1190 | } |
514df99c MG |
1191 | return dataAttr.call($(node), name) |
1192 | } | |
1193 | } | |
1194 | ||
1195 | // Store value under camelized key on node | |
1196 | function setData(node, name, value) { | |
1197 | var id = node[exp] || (node[exp] = ++$.uuid), | |
1198 | store = data[id] || (data[id] = attributeData(node)) | |
1199 | if (name !== undefined) store[camelize(name)] = value | |
1200 | return store | |
1201 | } | |
1202 | ||
1203 | // Read all "data-*" attributes from a node | |
1204 | function attributeData(node) { | |
1205 | var store = {} | |
1206 | $.each(node.attributes || emptyArray, function(i, attr){ | |
1207 | if (attr.name.indexOf('data-') == 0) | |
1208 | store[camelize(attr.name.replace('data-', ''))] = | |
1209 | $.zepto.deserializeValue(attr.value) | |
eef56f7a | 1210 | }) |
514df99c | 1211 | return store |
eef56f7a MG |
1212 | } |
1213 | ||
514df99c MG |
1214 | $.fn.data = function(name, value) { |
1215 | return value === undefined ? | |
1216 | // set multiple values via object | |
1217 | $.isPlainObject(name) ? | |
1218 | this.each(function(i, node){ | |
1219 | $.each(name, function(key, value){ setData(node, key, value) }) | |
1220 | }) : | |
1221 | // get value from first element | |
1222 | (0 in this ? getData(this[0], name) : undefined) : | |
1223 | // set value on all elements | |
1224 | this.each(function(){ setData(this, name, value) }) | |
1225 | } | |
1226 | ||
1227 | $.fn.removeData = function(names) { | |
1228 | if (typeof names == 'string') names = names.split(/\s+/) | |
1229 | return this.each(function(){ | |
1230 | var id = this[exp], store = id && data[id] | |
1231 | if (store) $.each(names || store, function(key){ | |
1232 | delete store[names ? camelize(this) : key] | |
1233 | }) | |
1234 | }) | |
1235 | } | |
1236 | ||
1237 | // Generate extended `remove` and `empty` functions | |
1238 | ;['remove', 'empty'].forEach(function(methodName){ | |
1239 | var origFn = $.fn[methodName] | |
1240 | $.fn[methodName] = function() { | |
1241 | var elements = this.find('*') | |
1242 | if (methodName === 'remove') elements = elements.add(this) | |
1243 | elements.removeData() | |
1244 | return origFn.call(this) | |
1245 | } | |
1246 | }) | |
1247 | })(Zepto) | |
1248 | ||
1249 | ;(function(){ | |
eef56f7a MG |
1250 | // getComputedStyle shouldn't freak out when called |
1251 | // without a valid element as argument | |
1252 | try { | |
1253 | getComputedStyle(undefined) | |
1254 | } catch(e) { | |
1255 | var nativeGetComputedStyle = getComputedStyle; | |
1256 | window.getComputedStyle = function(element){ | |
1257 | try { | |
1258 | return nativeGetComputedStyle(element) | |
1259 | } catch(e) { | |
1260 | return null | |
1261 | } | |
1262 | } | |
1263 | } | |
514df99c | 1264 | })() |