author | Clipperz <info@clipperz.com> | 2013-01-09 09:03:53 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-09 09:03:53 (UTC) |
commit | 644891059e1f37d0748bc34b9ca78c05fa748214 (patch) (unidiff) | |
tree | a746ee125d503088dc53dac823474e4295560947 /frontend/gamma/js/Zepto/zepto.js | |
parent | a9974c63bdcef65f009420dce095d1e39da7e3b8 (diff) | |
download | clipperz-644891059e1f37d0748bc34b9ca78c05fa748214.zip clipperz-644891059e1f37d0748bc34b9ca78c05fa748214.tar.gz clipperz-644891059e1f37d0748bc34b9ca78c05fa748214.tar.bz2 |
Added JQTouch and Zepto libraries
JQTouch and Zepto are tentatively used for the mobile version of Clipperz.
No final commitment has been made, though.
Diffstat (limited to 'frontend/gamma/js/Zepto/zepto.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Zepto/zepto.js | 751 |
1 files changed, 751 insertions, 0 deletions
diff --git a/frontend/gamma/js/Zepto/zepto.js b/frontend/gamma/js/Zepto/zepto.js new file mode 100644 index 0000000..e67b3a2 --- a/dev/null +++ b/frontend/gamma/js/Zepto/zepto.js | |||
@@ -0,0 +1,751 @@ | |||
1 | // Zepto.js | ||
2 | // (c) 2010-2012 Thomas Fuchs | ||
3 | // Zepto.js may be freely distributed under the MIT license. | ||
4 | |||
5 | var Zepto = (function() { | ||
6 | var undefined, key, $, classList, emptyArray = [], slice = emptyArray.slice, filter = emptyArray.filter, | ||
7 | document = window.document, | ||
8 | elementDisplay = {}, classCache = {}, | ||
9 | getComputedStyle = document.defaultView.getComputedStyle, | ||
10 | cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 }, | ||
11 | fragmentRE = /^\s*<(\w+|!)[^>]*>/, | ||
12 | tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig, | ||
13 | rootNodeRE = /^(?:body|html)$/i, | ||
14 | |||
15 | // special attributes that should be get/set via method calls | ||
16 | methodAttributes = ['val', 'css', 'html', 'text', 'data', 'width', 'height', 'offset'], | ||
17 | |||
18 | adjacencyOperators = [ 'after', 'prepend', 'before', 'append' ], | ||
19 | table = document.createElement('table'), | ||
20 | tableRow = document.createElement('tr'), | ||
21 | containers = { | ||
22 | 'tr': document.createElement('tbody'), | ||
23 | 'tbody': table, 'thead': table, 'tfoot': table, | ||
24 | 'td': tableRow, 'th': tableRow, | ||
25 | '*': document.createElement('div') | ||
26 | }, | ||
27 | readyRE = /complete|loaded|interactive/, | ||
28 | classSelectorRE = /^\.([\w-]+)$/, | ||
29 | idSelectorRE = /^#([\w-]*)$/, | ||
30 | tagSelectorRE = /^[\w-]+$/, | ||
31 | toString = {}.toString, | ||
32 | zepto = {}, | ||
33 | camelize, uniq, | ||
34 | tempParent = document.createElement('div') | ||
35 | |||
36 | zepto.matches = function(element, selector) { | ||
37 | if (!element || element.nodeType !== 1) return false | ||
38 | var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector || | ||
39 | element.oMatchesSelector || element.matchesSelector | ||
40 | if (matchesSelector) return matchesSelector.call(element, selector) | ||
41 | // fall back to performing a selector: | ||
42 | var match, parent = element.parentNode, temp = !parent | ||
43 | if (temp) (parent = tempParent).appendChild(element) | ||
44 | match = ~zepto.qsa(parent, selector).indexOf(element) | ||
45 | temp && tempParent.removeChild(element) | ||
46 | return match | ||
47 | } | ||
48 | |||
49 | function isFunction(value) { return toString.call(value) == "[object Function]" } | ||
50 | function isObject(value) { return value instanceof Object } | ||
51 | function isPlainObject(value) { | ||
52 | return isObject(value) && value != window && value.__proto__ == Object.prototype | ||
53 | } | ||
54 | function isArray(value) { return value instanceof Array } | ||
55 | function likeArray(obj) { return typeof obj.length == 'number' } | ||
56 | |||
57 | function compact(array) { return filter.call(array, function(item){ return item != null }) } | ||
58 | function flatten(array) { return array.length > 0 ? $.fn.concat.apply([], array) : array } | ||
59 | camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) } | ||
60 | function dasherize(str) { | ||
61 | return str.replace(/::/g, '/') | ||
62 | .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') | ||
63 | .replace(/([a-z\d])([A-Z])/g, '$1_$2') | ||
64 | .replace(/_/g, '-') | ||
65 | .toLowerCase() | ||
66 | } | ||
67 | uniq = function(array){ return filter.call(array, function(item, idx){ return array.indexOf(item) == idx }) } | ||
68 | |||
69 | function classRE(name) { | ||
70 | return name in classCache ? | ||
71 | classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)')) | ||
72 | } | ||
73 | |||
74 | function maybeAddPx(name, value) { | ||
75 | return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value | ||
76 | } | ||
77 | |||
78 | function defaultDisplay(nodeName) { | ||
79 | var element, display | ||
80 | if (!elementDisplay[nodeName]) { | ||
81 | element = document.createElement(nodeName) | ||
82 | document.body.appendChild(element) | ||
83 | display = getComputedStyle(element, '').getPropertyValue("display") | ||
84 | element.parentNode.removeChild(element) | ||
85 | display == "none" && (display = "block") | ||
86 | elementDisplay[nodeName] = display | ||
87 | } | ||
88 | return elementDisplay[nodeName] | ||
89 | } | ||
90 | |||
91 | function children(element) { | ||
92 | return 'children' in element ? | ||
93 | slice.call(element.children) : | ||
94 | $.map(element.childNodes, function(node){ if (node.nodeType == 1) return node }) | ||
95 | } | ||
96 | |||
97 | // `$.zepto.fragment` takes a html string and an optional tag name | ||
98 | // to generate DOM nodes nodes from the given html string. | ||
99 | // The generated DOM nodes are returned as an array. | ||
100 | // This function can be overriden in plugins for example to make | ||
101 | // it compatible with browsers that don't support the DOM fully. | ||
102 | zepto.fragment = function(html, name, properties) { | ||
103 | if (html.replace) html = html.replace(tagExpanderRE, "<$1></$2>") | ||
104 | if (name === undefined) name = fragmentRE.test(html) && RegExp.$1 | ||
105 | if (!(name in containers)) name = '*' | ||
106 | |||
107 | var nodes, dom, container = containers[name] | ||
108 | container.innerHTML = '' + html | ||
109 | dom = $.each(slice.call(container.childNodes), function(){ | ||
110 | container.removeChild(this) | ||
111 | }) | ||
112 | if (isPlainObject(properties)) { | ||
113 | nodes = $(dom) | ||
114 | $.each(properties, function(key, value) { | ||
115 | if (methodAttributes.indexOf(key) > -1) nodes[key](value) | ||
116 | else nodes.attr(key, value) | ||
117 | }) | ||
118 | } | ||
119 | return dom | ||
120 | } | ||
121 | |||
122 | // `$.zepto.Z` swaps out the prototype of the given `dom` array | ||
123 | // of nodes with `$.fn` and thus supplying all the Zepto functions | ||
124 | // to the array. Note that `__proto__` is not supported on Internet | ||
125 | // Explorer. This method can be overriden in plugins. | ||
126 | zepto.Z = function(dom, selector) { | ||
127 | dom = dom || [] | ||
128 | dom.__proto__ = arguments.callee.prototype | ||
129 | dom.selector = selector || '' | ||
130 | return dom | ||
131 | } | ||
132 | |||
133 | // `$.zepto.isZ` should return `true` if the given object is a Zepto | ||
134 | // collection. This method can be overriden in plugins. | ||
135 | zepto.isZ = function(object) { | ||
136 | return object instanceof zepto.Z | ||
137 | } | ||
138 | |||
139 | // `$.zepto.init` is Zepto's counterpart to jQuery's `$.fn.init` and | ||
140 | // takes a CSS selector and an optional context (and handles various | ||
141 | // special cases). | ||
142 | // This method can be overriden in plugins. | ||
143 | zepto.init = function(selector, context) { | ||
144 | // If nothing given, return an empty Zepto collection | ||
145 | if (!selector) return zepto.Z() | ||
146 | // If a function is given, call it when the DOM is ready | ||
147 | else if (isFunction(selector)) return $(document).ready(selector) | ||
148 | // If a Zepto collection is given, juts return it | ||
149 | else if (zepto.isZ(selector)) return selector | ||
150 | else { | ||
151 | var dom | ||
152 | // normalize array if an array of nodes is given | ||
153 | if (isArray(selector)) dom = compact(selector) | ||
154 | // Wrap DOM nodes. If a plain object is given, duplicate it. | ||
155 | else if (isObject(selector)) | ||
156 | dom = [isPlainObject(selector) ? $.extend({}, selector) : selector], selector = null | ||
157 | // If it's a html fragment, create nodes from it | ||
158 | else if (fragmentRE.test(selector)) | ||
159 | dom = zepto.fragment(selector.trim(), RegExp.$1, context), selector = null | ||
160 | // If there's a context, create a collection on that context first, and select | ||
161 | // nodes from there | ||
162 | else if (context !== undefined) return $(context).find(selector) | ||
163 | // And last but no least, if it's a CSS selector, use it to select nodes. | ||
164 | else dom = zepto.qsa(document, selector) | ||
165 | // create a new Zepto collection from the nodes found | ||
166 | return zepto.Z(dom, selector) | ||
167 | } | ||
168 | } | ||
169 | |||
170 | // `$` will be the base `Zepto` object. When calling this | ||
171 | // function just call `$.zepto.init, which makes the implementation | ||
172 | // details of selecting nodes and creating Zepto collections | ||
173 | // patchable in plugins. | ||
174 | $ = function(selector, context){ | ||
175 | return zepto.init(selector, context) | ||
176 | } | ||
177 | |||
178 | function extend(target, source, deep) { | ||
179 | for (key in source) | ||
180 | if (deep && isPlainObject(source[key])) { | ||
181 | if (!isPlainObject(target[key])) target[key] = {} | ||
182 | extend(target[key], source[key], deep) | ||
183 | } | ||
184 | else if (source[key] !== undefined) target[key] = source[key] | ||
185 | } | ||
186 | |||
187 | // Copy all but undefined properties from one or more | ||
188 | // objects to the `target` object. | ||
189 | $.extend = function(target){ | ||
190 | var deep, args = slice.call(arguments, 1) | ||
191 | if (typeof target == 'boolean') { | ||
192 | deep = target | ||
193 | target = args.shift() | ||
194 | } | ||
195 | args.forEach(function(arg){ extend(target, arg, deep) }) | ||
196 | return target | ||
197 | } | ||
198 | |||
199 | // `$.zepto.qsa` is Zepto's CSS selector implementation which | ||
200 | // uses `document.querySelectorAll` and optimizes for some special cases, like `#id`. | ||
201 | // This method can be overriden in plugins. | ||
202 | zepto.qsa = function(element, selector){ | ||
203 | var found | ||
204 | return (element === document && idSelectorRE.test(selector)) ? | ||
205 | ( (found = element.getElementById(RegExp.$1)) ? [found] : [] ) : | ||
206 | (element.nodeType !== 1 && element.nodeType !== 9) ? [] : | ||
207 | slice.call( | ||
208 | classSelectorRE.test(selector) ? element.getElementsByClassName(RegExp.$1) : | ||
209 | tagSelectorRE.test(selector) ? element.getElementsByTagName(selector) : | ||
210 | element.querySelectorAll(selector) | ||
211 | ) | ||
212 | } | ||
213 | |||
214 | function filtered(nodes, selector) { | ||
215 | return selector === undefined ? $(nodes) : $(nodes).filter(selector) | ||
216 | } | ||
217 | |||
218 | $.contains = function(parent, node) { | ||
219 | return parent !== node && parent.contains(node) | ||
220 | } | ||
221 | |||
222 | function funcArg(context, arg, idx, payload) { | ||
223 | return isFunction(arg) ? arg.call(context, idx, payload) : arg | ||
224 | } | ||
225 | |||
226 | function setAttribute(node, name, value) { | ||
227 | value == null ? node.removeAttribute(name) : node.setAttribute(name, value) | ||
228 | } | ||
229 | |||
230 | // access className property while respecting SVGAnimatedString | ||
231 | function className(node, value){ | ||
232 | var klass = node.className, | ||
233 | svg = klass && klass.baseVal !== undefined | ||
234 | |||
235 | if (value === undefined) return svg ? klass.baseVal : klass | ||
236 | svg ? (klass.baseVal = value) : (node.className = value) | ||
237 | } | ||
238 | |||
239 | // "true" => true | ||
240 | // "false" => false | ||
241 | // "null" => null | ||
242 | // "42" => 42 | ||
243 | // "42.5" => 42.5 | ||
244 | // JSON => parse if valid | ||
245 | // String => self | ||
246 | function deserializeValue(value) { | ||
247 | var num | ||
248 | try { | ||
249 | return value ? | ||
250 | value == "true" || | ||
251 | ( value == "false" ? false : | ||
252 | value == "null" ? null : | ||
253 | !isNaN(num = Number(value)) ? num : | ||
254 | /^[\[\{]/.test(value) ? $.parseJSON(value) : | ||
255 | value ) | ||
256 | : value | ||
257 | } catch(e) { | ||
258 | return value | ||
259 | } | ||
260 | } | ||
261 | |||
262 | $.isFunction = isFunction | ||
263 | $.isObject = isObject | ||
264 | $.isArray = isArray | ||
265 | $.isPlainObject = isPlainObject | ||
266 | |||
267 | $.inArray = function(elem, array, i){ | ||
268 | return emptyArray.indexOf.call(array, elem, i) | ||
269 | } | ||
270 | |||
271 | $.camelCase = camelize | ||
272 | $.trim = function(str) { return str.trim() } | ||
273 | |||
274 | // plugin compatibility | ||
275 | $.uuid = 0 | ||
276 | $.support = { } | ||
277 | $.expr = { } | ||
278 | |||
279 | $.map = function(elements, callback){ | ||
280 | var value, values = [], i, key | ||
281 | if (likeArray(elements)) | ||
282 | for (i = 0; i < elements.length; i++) { | ||
283 | value = callback(elements[i], i) | ||
284 | if (value != null) values.push(value) | ||
285 | } | ||
286 | else | ||
287 | for (key in elements) { | ||
288 | value = callback(elements[key], key) | ||
289 | if (value != null) values.push(value) | ||
290 | } | ||
291 | return flatten(values) | ||
292 | } | ||
293 | |||
294 | $.each = function(elements, callback){ | ||
295 | var i, key | ||
296 | if (likeArray(elements)) { | ||
297 | for (i = 0; i < elements.length; i++) | ||
298 | if (callback.call(elements[i], i, elements[i]) === false) return elements | ||
299 | } else { | ||
300 | for (key in elements) | ||
301 | if (callback.call(elements[key], key, elements[key]) === false) return elements | ||
302 | } | ||
303 | |||
304 | return elements | ||
305 | } | ||
306 | |||
307 | $.grep = function(elements, callback){ | ||
308 | return filter.call(elements, callback) | ||
309 | } | ||
310 | |||
311 | if (window.JSON) $.parseJSON = JSON.parse | ||
312 | |||
313 | // Define methods that will be available on all | ||
314 | // Zepto collections | ||
315 | $.fn = { | ||
316 | // Because a collection acts like an array | ||
317 | // copy over these useful array functions. | ||
318 | forEach: emptyArray.forEach, | ||
319 | reduce: emptyArray.reduce, | ||
320 | push: emptyArray.push, | ||
321 | sort: emptyArray.sort, | ||
322 | indexOf: emptyArray.indexOf, | ||
323 | concat: emptyArray.concat, | ||
324 | |||
325 | // `map` and `slice` in the jQuery API work differently | ||
326 | // from their array counterparts | ||
327 | map: function(fn){ | ||
328 | return $($.map(this, function(el, i){ return fn.call(el, i, el) })) | ||
329 | }, | ||
330 | slice: function(){ | ||
331 | return $(slice.apply(this, arguments)) | ||
332 | }, | ||
333 | |||
334 | ready: function(callback){ | ||
335 | if (readyRE.test(document.readyState)) callback($) | ||
336 | else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false) | ||
337 | return this | ||
338 | }, | ||
339 | get: function(idx){ | ||
340 | return idx === undefined ? slice.call(this) : this[idx] | ||
341 | }, | ||
342 | toArray: function(){ return this.get() }, | ||
343 | size: function(){ | ||
344 | return this.length | ||
345 | }, | ||
346 | remove: function(){ | ||
347 | return this.each(function(){ | ||
348 | if (this.parentNode != null) | ||
349 | this.parentNode.removeChild(this) | ||
350 | }) | ||
351 | }, | ||
352 | each: function(callback){ | ||
353 | emptyArray.every.call(this, function(el, idx){ | ||
354 | return callback.call(el, idx, el) !== false | ||
355 | }) | ||
356 | return this | ||
357 | }, | ||
358 | filter: function(selector){ | ||
359 | if (isFunction(selector)) return this.not(this.not(selector)) | ||
360 | return $(filter.call(this, function(element){ | ||
361 | return zepto.matches(element, selector) | ||
362 | })) | ||
363 | }, | ||
364 | add: function(selector,context){ | ||
365 | return $(uniq(this.concat($(selector,context)))) | ||
366 | }, | ||
367 | is: function(selector){ | ||
368 | return this.length > 0 && zepto.matches(this[0], selector) | ||
369 | }, | ||
370 | not: function(selector){ | ||
371 | var nodes=[] | ||
372 | if (isFunction(selector) && selector.call !== undefined) | ||
373 | this.each(function(idx){ | ||
374 | if (!selector.call(this,idx)) nodes.push(this) | ||
375 | }) | ||
376 | else { | ||
377 | var excludes = typeof selector == 'string' ? this.filter(selector) : | ||
378 | (likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector) | ||
379 | this.forEach(function(el){ | ||
380 | if (excludes.indexOf(el) < 0) nodes.push(el) | ||
381 | }) | ||
382 | } | ||
383 | return $(nodes) | ||
384 | }, | ||
385 | has: function(selector){ | ||
386 | return this.filter(function(){ | ||
387 | return isObject(selector) ? | ||
388 | $.contains(this, selector) : | ||
389 | $(this).find(selector).size() | ||
390 | }) | ||
391 | }, | ||
392 | eq: function(idx){ | ||
393 | return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1) | ||
394 | }, | ||
395 | first: function(){ | ||
396 | var el = this[0] | ||
397 | return el && !isObject(el) ? el : $(el) | ||
398 | }, | ||
399 | last: function(){ | ||
400 | var el = this[this.length - 1] | ||
401 | return el && !isObject(el) ? el : $(el) | ||
402 | }, | ||
403 | find: function(selector){ | ||
404 | var result | ||
405 | if (this.length == 1) result = $(zepto.qsa(this[0], selector)) | ||
406 | else result = this.map(function(){ return zepto.qsa(this, selector) }) | ||
407 | return result | ||
408 | }, | ||
409 | closest: function(selector, context){ | ||
410 | var node = this[0] | ||
411 | while (node && !zepto.matches(node, selector)) | ||
412 | node = node !== context && node !== document && node.parentNode | ||
413 | return $(node) | ||
414 | }, | ||
415 | parents: function(selector){ | ||
416 | var ancestors = [], nodes = this | ||
417 | while (nodes.length > 0) | ||
418 | nodes = $.map(nodes, function(node){ | ||
419 | if ((node = node.parentNode) && node !== document && ancestors.indexOf(node) < 0) { | ||
420 | ancestors.push(node) | ||
421 | return node | ||
422 | } | ||
423 | }) | ||
424 | return filtered(ancestors, selector) | ||
425 | }, | ||
426 | parent: function(selector){ | ||
427 | return filtered(uniq(this.pluck('parentNode')), selector) | ||
428 | }, | ||
429 | children: function(selector){ | ||
430 | return filtered(this.map(function(){ return children(this) }), selector) | ||
431 | }, | ||
432 | contents: function() { | ||
433 | return this.map(function() { return slice.call(this.childNodes) }) | ||
434 | }, | ||
435 | siblings: function(selector){ | ||
436 | return filtered(this.map(function(i, el){ | ||
437 | return filter.call(children(el.parentNode), function(child){ return child!==el }) | ||
438 | }), selector) | ||
439 | }, | ||
440 | empty: function(){ | ||
441 | return this.each(function(){ this.innerHTML = '' }) | ||
442 | }, | ||
443 | // `pluck` is borrowed from Prototype.js | ||
444 | pluck: function(property){ | ||
445 | return $.map(this, function(el){ return el[property] }) | ||
446 | }, | ||
447 | show: function(){ | ||
448 | return this.each(function(){ | ||
449 | this.style.display == "none" && (this.style.display = null) | ||
450 | if (getComputedStyle(this, '').getPropertyValue("display") == "none") | ||
451 | this.style.display = defaultDisplay(this.nodeName) | ||
452 | }) | ||
453 | }, | ||
454 | replaceWith: function(newContent){ | ||
455 | return this.before(newContent).remove() | ||
456 | }, | ||
457 | wrap: function(structure){ | ||
458 | var func = isFunction(structure) | ||
459 | if (this[0] && !func) | ||
460 | var dom = $(structure).get(0), | ||
461 | clone = dom.parentNode || this.length > 1 | ||
462 | |||
463 | return this.each(function(index){ | ||
464 | $(this).wrapAll( | ||
465 | func ? structure.call(this, index) : | ||
466 | clone ? dom.cloneNode(true) : dom | ||
467 | ) | ||
468 | }) | ||
469 | }, | ||
470 | wrapAll: function(structure){ | ||
471 | if (this[0]) { | ||
472 | $(this[0]).before(structure = $(structure)) | ||
473 | var children | ||
474 | // drill down to the inmost element | ||
475 | while ((children = structure.children()).length) structure = children.first() | ||
476 | $(structure).append(this) | ||
477 | } | ||
478 | return this | ||
479 | }, | ||
480 | wrapInner: function(structure){ | ||
481 | var func = isFunction(structure) | ||
482 | return this.each(function(index){ | ||
483 | var self = $(this), contents = self.contents(), | ||
484 | dom = func ? structure.call(this, index) : structure | ||
485 | contents.length ? contents.wrapAll(dom) : self.append(dom) | ||
486 | }) | ||
487 | }, | ||
488 | unwrap: function(){ | ||
489 | this.parent().each(function(){ | ||
490 | $(this).replaceWith($(this).children()) | ||
491 | }) | ||
492 | return this | ||
493 | }, | ||
494 | clone: function(){ | ||
495 | return this.map(function(){ return this.cloneNode(true) }) | ||
496 | }, | ||
497 | hide: function(){ | ||
498 | return this.css("display", "none") | ||
499 | }, | ||
500 | toggle: function(setting){ | ||
501 | return this.each(function(){ | ||
502 | var el = $(this) | ||
503 | ;(setting === undefined ? el.css("display") == "none" : setting) ? el.show() : el.hide() | ||
504 | }) | ||
505 | }, | ||
506 | prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') }, | ||
507 | next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') }, | ||
508 | html: function(html){ | ||
509 | return html === undefined ? | ||
510 | (this.length > 0 ? this[0].innerHTML : null) : | ||
511 | this.each(function(idx){ | ||
512 | var originHtml = this.innerHTML | ||
513 | $(this).empty().append( funcArg(this, html, idx, originHtml) ) | ||
514 | }) | ||
515 | }, | ||
516 | text: function(text){ | ||
517 | return text === undefined ? | ||
518 | (this.length > 0 ? this[0].textContent : null) : | ||
519 | this.each(function(){ this.textContent = text }) | ||
520 | }, | ||
521 | attr: function(name, value){ | ||
522 | var result | ||
523 | return (typeof name == 'string' && value === undefined) ? | ||
524 | (this.length == 0 || this[0].nodeType !== 1 ? undefined : | ||
525 | (name == 'value' && this[0].nodeName == 'INPUT') ? this.val() : | ||
526 | (!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result | ||
527 | ) : | ||
528 | this.each(function(idx){ | ||
529 | if (this.nodeType !== 1) return | ||
530 | if (isObject(name)) for (key in name) setAttribute(this, key, name[key]) | ||
531 | else setAttribute(this, name, funcArg(this, value, idx, this.getAttribute(name))) | ||
532 | }) | ||
533 | }, | ||
534 | removeAttr: function(name){ | ||
535 | return this.each(function(){ this.nodeType === 1 && setAttribute(this, name) }) | ||
536 | }, | ||
537 | prop: function(name, value){ | ||
538 | return (value === undefined) ? | ||
539 | (this[0] && this[0][name]) : | ||
540 | this.each(function(idx){ | ||
541 | this[name] = funcArg(this, value, idx, this[name]) | ||
542 | }) | ||
543 | }, | ||
544 | data: function(name, value){ | ||
545 | var data = this.attr('data-' + dasherize(name), value) | ||
546 | return data !== null ? deserializeValue(data) : undefined | ||
547 | }, | ||
548 | val: function(value){ | ||
549 | return (value === undefined) ? | ||
550 | (this[0] && (this[0].multiple ? | ||
551 | $(this[0]).find('option').filter(function(o){ return this.selected }).pluck('value') : | ||
552 | this[0].value) | ||
553 | ) : | ||
554 | this.each(function(idx){ | ||
555 | this.value = funcArg(this, value, idx, this.value) | ||
556 | }) | ||
557 | }, | ||
558 | offset: function(coordinates){ | ||
559 | if (coordinates) return this.each(function(index){ | ||
560 | var $this = $(this), | ||
561 | coords = funcArg(this, coordinates, index, $this.offset()), | ||
562 | parentOffset = $this.offsetParent().offset(), | ||
563 | props = { | ||
564 | top: coords.top - parentOffset.top, | ||
565 | left: coords.left - parentOffset.left | ||
566 | } | ||
567 | |||
568 | if ($this.css('position') == 'static') props['position'] = 'relative' | ||
569 | $this.css(props) | ||
570 | }) | ||
571 | if (this.length==0) return null | ||
572 | var obj = this[0].getBoundingClientRect() | ||
573 | return { | ||
574 | left: obj.left + window.pageXOffset, | ||
575 | top: obj.top + window.pageYOffset, | ||
576 | width: obj.width, | ||
577 | height: obj.height | ||
578 | } | ||
579 | }, | ||
580 | css: function(property, value){ | ||
581 | if (arguments.length < 2 && typeof property == 'string') | ||
582 | return this[0] && (this[0].style[camelize(property)] || getComputedStyle(this[0], '').getPropertyValue(property)) | ||
583 | |||
584 | var css = '' | ||
585 | for (key in property) | ||
586 | if (!property[key] && property[key] !== 0) | ||
587 | this.each(function(){ this.style.removeProperty(dasherize(key)) }) | ||
588 | else | ||
589 | css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';' | ||
590 | |||
591 | if (typeof property == 'string') | ||
592 | if (!value && value !== 0) | ||
593 | this.each(function(){ this.style.removeProperty(dasherize(property)) }) | ||
594 | else | ||
595 | css = dasherize(property) + ":" + maybeAddPx(property, value) | ||
596 | |||
597 | return this.each(function(){ this.style.cssText += ';' + css }) | ||
598 | }, | ||
599 | index: function(element){ | ||
600 | return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0]) | ||
601 | }, | ||
602 | hasClass: function(name){ | ||
603 | return emptyArray.some.call(this, function(el){ | ||
604 | return this.test(className(el)) | ||
605 | }, classRE(name)) | ||
606 | }, | ||
607 | addClass: function(name){ | ||
608 | return this.each(function(idx){ | ||
609 | classList = [] | ||
610 | var cls = className(this), newName = funcArg(this, name, idx, cls) | ||
611 | newName.split(/\s+/g).forEach(function(klass){ | ||
612 | if (!$(this).hasClass(klass)) classList.push(klass) | ||
613 | }, this) | ||
614 | classList.length && className(this, cls + (cls ? " " : "") + classList.join(" ")) | ||
615 | }) | ||
616 | }, | ||
617 | removeClass: function(name){ | ||
618 | return this.each(function(idx){ | ||
619 | if (name === undefined) return className(this, '') | ||
620 | classList = className(this) | ||
621 | funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass){ | ||
622 | classList = classList.replace(classRE(klass), " ") | ||
623 | }) | ||
624 | className(this, classList.trim()) | ||
625 | }) | ||
626 | }, | ||
627 | toggleClass: function(name, when){ | ||
628 | return this.each(function(idx){ | ||
629 | var newName = funcArg(this, name, idx, className(this)) | ||
630 | ;(when === undefined ? !$(this).hasClass(newName) : when) ? | ||
631 | $(this).addClass(newName) : $(this).removeClass(newName) | ||
632 | }) | ||
633 | }, | ||
634 | scrollTop: function(){ | ||
635 | if (!this.length) return | ||
636 | return ('scrollTop' in this[0]) ? this[0].scrollTop : this[0].scrollY | ||
637 | }, | ||
638 | position: function() { | ||
639 | if (!this.length) return | ||
640 | |||
641 | var elem = this[0], | ||
642 | // Get *real* offsetParent | ||
643 | offsetParent = this.offsetParent(), | ||
644 | // Get correct offsets | ||
645 | offset = this.offset(), | ||
646 | parentOffset = rootNodeRE.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset() | ||
647 | |||
648 | // Subtract element margins | ||
649 | // note: when an element has margin: auto the offsetLeft and marginLeft | ||
650 | // are the same in Safari causing offset.left to incorrectly be 0 | ||
651 | offset.top -= parseFloat( $(elem).css('margin-top') ) || 0 | ||
652 | offset.left -= parseFloat( $(elem).css('margin-left') ) || 0 | ||
653 | |||
654 | // Add offsetParent borders | ||
655 | parentOffset.top += parseFloat( $(offsetParent[0]).css('border-top-width') ) || 0 | ||
656 | parentOffset.left += parseFloat( $(offsetParent[0]).css('border-left-width') ) || 0 | ||
657 | |||
658 | // Subtract the two offsets | ||
659 | return { | ||
660 | top: offset.top - parentOffset.top, | ||
661 | left: offset.left - parentOffset.left | ||
662 | } | ||
663 | }, | ||
664 | offsetParent: function() { | ||
665 | return this.map(function(){ | ||
666 | var parent = this.offsetParent || document.body | ||
667 | while (parent && !rootNodeRE.test(parent.nodeName) && $(parent).css("position") == "static") | ||
668 | parent = parent.offsetParent | ||
669 | return parent | ||
670 | }) | ||
671 | } | ||
672 | } | ||
673 | |||
674 | // for now | ||
675 | $.fn.detach = $.fn.remove | ||
676 | |||
677 | // Generate the `width` and `height` functions | ||
678 | ;['width', 'height'].forEach(function(dimension){ | ||
679 | $.fn[dimension] = function(value){ | ||
680 | var offset, Dimension = dimension.replace(/./, function(m){ return m[0].toUpperCase() }) | ||
681 | if (value === undefined) return this[0] == window ? window['inner' + Dimension] : | ||
682 | this[0] == document ? document.documentElement['offset' + Dimension] : | ||
683 | (offset = this.offset()) && offset[dimension] | ||
684 | else return this.each(function(idx){ | ||
685 | var el = $(this) | ||
686 | el.css(dimension, funcArg(this, value, idx, el[dimension]())) | ||
687 | }) | ||
688 | } | ||
689 | }) | ||
690 | |||
691 | function traverseNode(node, fun) { | ||
692 | fun(node) | ||
693 | for (var key in node.childNodes) traverseNode(node.childNodes[key], fun) | ||
694 | } | ||
695 | |||
696 | // Generate the `after`, `prepend`, `before`, `append`, | ||
697 | // `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods. | ||
698 | adjacencyOperators.forEach(function(operator, operatorIndex) { | ||
699 | var inside = operatorIndex % 2 //=> prepend, append | ||
700 | |||
701 | $.fn[operator] = function(){ | ||
702 | // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings | ||
703 | var nodes = $.map(arguments, function(n){ return isObject(n) ? n : zepto.fragment(n) }), | ||
704 | parent, copyByClone = this.length > 1 | ||
705 | if (nodes.length < 1) return this | ||
706 | |||
707 | return this.each(function(_, target){ | ||
708 | parent = inside ? target : target.parentNode | ||
709 | |||
710 | // convert all methods to a "before" operation | ||
711 | target = operatorIndex == 0 ? target.nextSibling : | ||
712 | operatorIndex == 1 ? target.firstChild : | ||
713 | operatorIndex == 2 ? target : | ||
714 | null | ||
715 | |||
716 | nodes.forEach(function(node){ | ||
717 | if (copyByClone) node = node.cloneNode(true) | ||
718 | else if (!parent) return $(node).remove() | ||
719 | |||
720 | traverseNode(parent.insertBefore(node, target), function(el){ | ||
721 | if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' && | ||
722 | (!el.type || el.type === 'text/javascript') && !el.src) | ||
723 | window['eval'].call(window, el.innerHTML) | ||
724 | }) | ||
725 | }) | ||
726 | }) | ||
727 | } | ||
728 | |||
729 | // after => insertAfter | ||
730 | // prepend => prependTo | ||
731 | // before => insertBefore | ||
732 | // append => appendTo | ||
733 | $.fn[inside ? operator+'To' : 'insert'+(operatorIndex ? 'Before' : 'After')] = function(html){ | ||
734 | $(html)[operator](this) | ||
735 | return this | ||
736 | } | ||
737 | }) | ||
738 | |||
739 | zepto.Z.prototype = $.fn | ||
740 | |||
741 | // Export internal API functions in the `$.zepto` namespace | ||
742 | zepto.uniq = uniq | ||
743 | zepto.deserializeValue = deserializeValue | ||
744 | $.zepto = zepto | ||
745 | |||
746 | return $ | ||
747 | })() | ||
748 | |||
749 | // If `$` is not yet defined, point it to `Zepto` | ||
750 | window.Zepto = Zepto | ||
751 | '$' in window || (window.$ = Zepto) | ||