PageRenderTime 86ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 1ms

/ajax/libs/thorax/2.0.0rc1/thorax-mobile.js

https://bitbucket.org/kolbyjAFK/cdnjs
JavaScript | 8982 lines | 8307 code | 340 blank | 335 comment | 747 complexity | 3b8926b17122699de88f5bfafb06b4ba MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. /* Zepto v1.0rc1 - polyfill zepto event detect fx ajax form touch - zeptojs.com/license */
  2. ;(function(undefined){
  3. if (String.prototype.trim === undefined) // fix for iOS 3.2
  4. String.prototype.trim = function(){ return this.replace(/^\s+/, '').replace(/\s+$/, '') }
  5. // For iOS 3.x
  6. // from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduce
  7. if (Array.prototype.reduce === undefined)
  8. Array.prototype.reduce = function(fun){
  9. if(this === void 0 || this === null) throw new TypeError()
  10. var t = Object(this), len = t.length >>> 0, k = 0, accumulator
  11. if(typeof fun != 'function') throw new TypeError()
  12. if(len == 0 && arguments.length == 1) throw new TypeError()
  13. if(arguments.length >= 2)
  14. accumulator = arguments[1]
  15. else
  16. do{
  17. if(k in t){
  18. accumulator = t[k++]
  19. break
  20. }
  21. if(++k >= len) throw new TypeError()
  22. } while (true)
  23. while (k < len){
  24. if(k in t) accumulator = fun.call(undefined, accumulator, t[k], k, t)
  25. k++
  26. }
  27. return accumulator
  28. }
  29. })()
  30. var Zepto = (function() {
  31. var undefined, key, $, classList, emptyArray = [], slice = emptyArray.slice,
  32. document = window.document,
  33. elementDisplay = {}, classCache = {},
  34. getComputedStyle = document.defaultView.getComputedStyle,
  35. cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 },
  36. fragmentRE = /^\s*<(\w+|!)[^>]*>/,
  37. // Used by `$.zepto.init` to wrap elements, text/comment nodes, document,
  38. // and document fragment node types.
  39. elementTypes = [1, 3, 8, 9, 11],
  40. adjacencyOperators = [ 'after', 'prepend', 'before', 'append' ],
  41. table = document.createElement('table'),
  42. tableRow = document.createElement('tr'),
  43. containers = {
  44. 'tr': document.createElement('tbody'),
  45. 'tbody': table, 'thead': table, 'tfoot': table,
  46. 'td': tableRow, 'th': tableRow,
  47. '*': document.createElement('div')
  48. },
  49. readyRE = /complete|loaded|interactive/,
  50. classSelectorRE = /^\.([\w-]+)$/,
  51. idSelectorRE = /^#([\w-]+)$/,
  52. tagSelectorRE = /^[\w-]+$/,
  53. toString = ({}).toString,
  54. zepto = {},
  55. camelize, uniq,
  56. tempParent = document.createElement('div')
  57. zepto.matches = function(element, selector) {
  58. if (!element || element.nodeType !== 1) return false
  59. var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector ||
  60. element.oMatchesSelector || element.matchesSelector
  61. if (matchesSelector) return matchesSelector.call(element, selector)
  62. // fall back to performing a selector:
  63. var match, parent = element.parentNode, temp = !parent
  64. if (temp) (parent = tempParent).appendChild(element)
  65. match = ~zepto.qsa(parent, selector).indexOf(element)
  66. temp && tempParent.removeChild(element)
  67. return match
  68. }
  69. function isFunction(value) { return toString.call(value) == "[object Function]" }
  70. function isObject(value) { return value instanceof Object }
  71. function isPlainObject(value) {
  72. var key, ctor
  73. if (toString.call(value) !== "[object Object]") return false
  74. ctor = (isFunction(value.constructor) && value.constructor.prototype)
  75. if (!ctor || !hasOwnProperty.call(ctor, 'isPrototypeOf')) return false
  76. for (key in value);
  77. return key === undefined || hasOwnProperty.call(value, key)
  78. }
  79. function isArray(value) { return value instanceof Array }
  80. function likeArray(obj) { return typeof obj.length == 'number' }
  81. function compact(array) { return array.filter(function(item){ return item !== undefined && item !== null }) }
  82. function flatten(array) { return array.length > 0 ? [].concat.apply([], array) : array }
  83. camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) }
  84. function dasherize(str) {
  85. return str.replace(/::/g, '/')
  86. .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
  87. .replace(/([a-z\d])([A-Z])/g, '$1_$2')
  88. .replace(/_/g, '-')
  89. .toLowerCase()
  90. }
  91. uniq = function(array){ return array.filter(function(item, idx){ return array.indexOf(item) == idx }) }
  92. function classRE(name) {
  93. return name in classCache ?
  94. classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)'))
  95. }
  96. function maybeAddPx(name, value) {
  97. return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value
  98. }
  99. function defaultDisplay(nodeName) {
  100. var element, display
  101. if (!elementDisplay[nodeName]) {
  102. element = document.createElement(nodeName)
  103. document.body.appendChild(element)
  104. display = getComputedStyle(element, '').getPropertyValue("display")
  105. element.parentNode.removeChild(element)
  106. display == "none" && (display = "block")
  107. elementDisplay[nodeName] = display
  108. }
  109. return elementDisplay[nodeName]
  110. }
  111. // `$.zepto.fragment` takes a html string and an optional tag name
  112. // to generate DOM nodes nodes from the given html string.
  113. // The generated DOM nodes are returned as an array.
  114. // This function can be overriden in plugins for example to make
  115. // it compatible with browsers that don't support the DOM fully.
  116. zepto.fragment = function(html, name) {
  117. if (name === undefined) name = fragmentRE.test(html) && RegExp.$1
  118. if (!(name in containers)) name = '*'
  119. var container = containers[name]
  120. container.innerHTML = '' + html
  121. return $.each(slice.call(container.childNodes), function(){
  122. container.removeChild(this)
  123. })
  124. }
  125. // `$.zepto.Z` swaps out the prototype of the given `dom` array
  126. // of nodes with `$.fn` and thus supplying all the Zepto functions
  127. // to the array. Note that `__proto__` is not supported on Internet
  128. // Explorer. This method can be overriden in plugins.
  129. zepto.Z = function(dom, selector) {
  130. dom = dom || []
  131. dom.__proto__ = arguments.callee.prototype
  132. dom.selector = selector || ''
  133. return dom
  134. }
  135. // `$.zepto.isZ` should return `true` if the given object is a Zepto
  136. // collection. This method can be overriden in plugins.
  137. zepto.isZ = function(object) {
  138. return object instanceof zepto.Z
  139. }
  140. // `$.zepto.init` is Zepto's counterpart to jQuery's `$.fn.init` and
  141. // takes a CSS selector and an optional context (and handles various
  142. // special cases).
  143. // This method can be overriden in plugins.
  144. zepto.init = function(selector, context) {
  145. // If nothing given, return an empty Zepto collection
  146. if (!selector) return zepto.Z()
  147. // If a function is given, call it when the DOM is ready
  148. else if (isFunction(selector)) return $(document).ready(selector)
  149. // If a Zepto collection is given, juts return it
  150. else if (zepto.isZ(selector)) return selector
  151. else {
  152. var dom
  153. // normalize array if an array of nodes is given
  154. if (isArray(selector)) dom = compact(selector)
  155. // if a JavaScript object is given, return a copy of it
  156. // this is a somewhat peculiar option, but supported by
  157. // jQuery so we'll do it, too
  158. else if (isPlainObject(selector))
  159. dom = [$.extend({}, selector)], selector = null
  160. // wrap stuff like `document` or `window`
  161. else if (elementTypes.indexOf(selector.nodeType) >= 0 || selector === window)
  162. dom = [selector], selector = null
  163. // If it's a html fragment, create nodes from it
  164. else if (fragmentRE.test(selector))
  165. dom = zepto.fragment(selector.trim(), RegExp.$1), selector = null
  166. // If there's a context, create a collection on that context first, and select
  167. // nodes from there
  168. else if (context !== undefined) return $(context).find(selector)
  169. // And last but no least, if it's a CSS selector, use it to select nodes.
  170. else dom = zepto.qsa(document, selector)
  171. // create a new Zepto collection from the nodes found
  172. return zepto.Z(dom, selector)
  173. }
  174. }
  175. // `$` will be the base `Zepto` object. When calling this
  176. // function just call `$.zepto.init, whichs makes the implementation
  177. // details of selecting nodes and creating Zepto collections
  178. // patchable in plugins.
  179. $ = function(selector, context){
  180. return zepto.init(selector, context)
  181. }
  182. // Copy all but undefined properties from one or more
  183. // objects to the `target` object.
  184. $.extend = function(target){
  185. slice.call(arguments, 1).forEach(function(source) {
  186. for (key in source)
  187. if (source[key] !== undefined)
  188. target[key] = source[key]
  189. })
  190. return target
  191. }
  192. // `$.zepto.qsa` is Zepto's CSS selector implementation which
  193. // uses `document.querySelectorAll` and optimizes for some special cases, like `#id`.
  194. // This method can be overriden in plugins.
  195. zepto.qsa = function(element, selector){
  196. var found
  197. return (element === document && idSelectorRE.test(selector)) ?
  198. ( (found = element.getElementById(RegExp.$1)) ? [found] : emptyArray ) :
  199. (element.nodeType !== 1 && element.nodeType !== 9) ? emptyArray :
  200. slice.call(
  201. classSelectorRE.test(selector) ? element.getElementsByClassName(RegExp.$1) :
  202. tagSelectorRE.test(selector) ? element.getElementsByTagName(selector) :
  203. element.querySelectorAll(selector)
  204. )
  205. }
  206. function filtered(nodes, selector) {
  207. return selector === undefined ? $(nodes) : $(nodes).filter(selector)
  208. }
  209. function funcArg(context, arg, idx, payload) {
  210. return isFunction(arg) ? arg.call(context, idx, payload) : arg
  211. }
  212. $.isFunction = isFunction
  213. $.isObject = isObject
  214. $.isArray = isArray
  215. $.isPlainObject = isPlainObject
  216. $.inArray = function(elem, array, i){
  217. return emptyArray.indexOf.call(array, elem, i)
  218. }
  219. $.trim = function(str) { return str.trim() }
  220. // plugin compatibility
  221. $.uuid = 0
  222. $.map = function(elements, callback){
  223. var value, values = [], i, key
  224. if (likeArray(elements))
  225. for (i = 0; i < elements.length; i++) {
  226. value = callback(elements[i], i)
  227. if (value != null) values.push(value)
  228. }
  229. else
  230. for (key in elements) {
  231. value = callback(elements[key], key)
  232. if (value != null) values.push(value)
  233. }
  234. return flatten(values)
  235. }
  236. $.each = function(elements, callback){
  237. var i, key
  238. if (likeArray(elements)) {
  239. for (i = 0; i < elements.length; i++)
  240. if (callback.call(elements[i], i, elements[i]) === false) return elements
  241. } else {
  242. for (key in elements)
  243. if (callback.call(elements[key], key, elements[key]) === false) return elements
  244. }
  245. return elements
  246. }
  247. // Define methods that will be available on all
  248. // Zepto collections
  249. $.fn = {
  250. // Because a collection acts like an array
  251. // copy over these useful array functions.
  252. forEach: emptyArray.forEach,
  253. reduce: emptyArray.reduce,
  254. push: emptyArray.push,
  255. indexOf: emptyArray.indexOf,
  256. concat: emptyArray.concat,
  257. // `map` and `slice` in the jQuery API work differently
  258. // from their array counterparts
  259. map: function(fn){
  260. return $.map(this, function(el, i){ return fn.call(el, i, el) })
  261. },
  262. slice: function(){
  263. return $(slice.apply(this, arguments))
  264. },
  265. ready: function(callback){
  266. if (readyRE.test(document.readyState)) callback($)
  267. else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false)
  268. return this
  269. },
  270. get: function(idx){
  271. return idx === undefined ? slice.call(this) : this[idx]
  272. },
  273. toArray: function(){ return this.get() },
  274. size: function(){
  275. return this.length
  276. },
  277. remove: function(){
  278. return this.each(function(){
  279. if (this.parentNode != null)
  280. this.parentNode.removeChild(this)
  281. })
  282. },
  283. each: function(callback){
  284. this.forEach(function(el, idx){ callback.call(el, idx, el) })
  285. return this
  286. },
  287. filter: function(selector){
  288. return $([].filter.call(this, function(element){
  289. return zepto.matches(element, selector)
  290. }))
  291. },
  292. add: function(selector,context){
  293. return $(uniq(this.concat($(selector,context))))
  294. },
  295. is: function(selector){
  296. return this.length > 0 && zepto.matches(this[0], selector)
  297. },
  298. not: function(selector){
  299. var nodes=[]
  300. if (isFunction(selector) && selector.call !== undefined)
  301. this.each(function(idx){
  302. if (!selector.call(this,idx)) nodes.push(this)
  303. })
  304. else {
  305. var excludes = typeof selector == 'string' ? this.filter(selector) :
  306. (likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector)
  307. this.forEach(function(el){
  308. if (excludes.indexOf(el) < 0) nodes.push(el)
  309. })
  310. }
  311. return $(nodes)
  312. },
  313. eq: function(idx){
  314. return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1)
  315. },
  316. first: function(){
  317. var el = this[0]
  318. return el && !isObject(el) ? el : $(el)
  319. },
  320. last: function(){
  321. var el = this[this.length - 1]
  322. return el && !isObject(el) ? el : $(el)
  323. },
  324. find: function(selector){
  325. var result
  326. if (this.length == 1) result = zepto.qsa(this[0], selector)
  327. else result = this.map(function(){ return zepto.qsa(this, selector) })
  328. return $(result)
  329. },
  330. closest: function(selector, context){
  331. var node = this[0]
  332. while (node && !zepto.matches(node, selector))
  333. node = node !== context && node !== document && node.parentNode
  334. return $(node)
  335. },
  336. parents: function(selector){
  337. var ancestors = [], nodes = this
  338. while (nodes.length > 0)
  339. nodes = $.map(nodes, function(node){
  340. if ((node = node.parentNode) && node !== document && ancestors.indexOf(node) < 0) {
  341. ancestors.push(node)
  342. return node
  343. }
  344. })
  345. return filtered(ancestors, selector)
  346. },
  347. parent: function(selector){
  348. return filtered(uniq(this.pluck('parentNode')), selector)
  349. },
  350. children: function(selector){
  351. return filtered(this.map(function(){ return slice.call(this.children) }), selector)
  352. },
  353. siblings: function(selector){
  354. return filtered(this.map(function(i, el){
  355. return slice.call(el.parentNode.children).filter(function(child){ return child!==el })
  356. }), selector)
  357. },
  358. empty: function(){
  359. return this.each(function(){ this.innerHTML = '' })
  360. },
  361. // `pluck` is borrowed from Prototype.js
  362. pluck: function(property){
  363. return this.map(function(){ return this[property] })
  364. },
  365. show: function(){
  366. return this.each(function(){
  367. this.style.display == "none" && (this.style.display = null)
  368. if (getComputedStyle(this, '').getPropertyValue("display") == "none")
  369. this.style.display = defaultDisplay(this.nodeName)
  370. })
  371. },
  372. replaceWith: function(newContent){
  373. return this.before(newContent).remove()
  374. },
  375. wrap: function(newContent){
  376. return this.each(function(){
  377. $(this).wrapAll($(newContent)[0].cloneNode(false))
  378. })
  379. },
  380. wrapAll: function(newContent){
  381. if (this[0]) {
  382. $(this[0]).before(newContent = $(newContent))
  383. newContent.append(this)
  384. }
  385. return this
  386. },
  387. unwrap: function(){
  388. this.parent().each(function(){
  389. $(this).replaceWith($(this).children())
  390. })
  391. return this
  392. },
  393. clone: function(){
  394. return $(this.map(function(){ return this.cloneNode(true) }))
  395. },
  396. hide: function(){
  397. return this.css("display", "none")
  398. },
  399. toggle: function(setting){
  400. return (setting === undefined ? this.css("display") == "none" : setting) ? this.show() : this.hide()
  401. },
  402. prev: function(){ return $(this.pluck('previousElementSibling')) },
  403. next: function(){ return $(this.pluck('nextElementSibling')) },
  404. html: function(html){
  405. return html === undefined ?
  406. (this.length > 0 ? this[0].innerHTML : null) :
  407. this.each(function(idx){
  408. var originHtml = this.innerHTML
  409. $(this).empty().append( funcArg(this, html, idx, originHtml) )
  410. })
  411. },
  412. text: function(text){
  413. return text === undefined ?
  414. (this.length > 0 ? this[0].textContent : null) :
  415. this.each(function(){ this.textContent = text })
  416. },
  417. attr: function(name, value){
  418. var result
  419. return (typeof name == 'string' && value === undefined) ?
  420. (this.length == 0 || this[0].nodeType !== 1 ? undefined :
  421. (name == 'value' && this[0].nodeName == 'INPUT') ? this.val() :
  422. (!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result
  423. ) :
  424. this.each(function(idx){
  425. if (this.nodeType !== 1) return
  426. if (isObject(name)) for (key in name) this.setAttribute(key, name[key])
  427. else this.setAttribute(name, funcArg(this, value, idx, this.getAttribute(name)))
  428. })
  429. },
  430. removeAttr: function(name){
  431. return this.each(function(){ if (this.nodeType === 1) this.removeAttribute(name) })
  432. },
  433. prop: function(name, value){
  434. return (value === undefined) ?
  435. (this[0] ? this[0][name] : undefined) :
  436. this.each(function(idx){
  437. this[name] = funcArg(this, value, idx, this[name])
  438. })
  439. },
  440. data: function(name, value){
  441. var data = this.attr('data-' + dasherize(name), value)
  442. return data !== null ? data : undefined
  443. },
  444. val: function(value){
  445. return (value === undefined) ?
  446. (this.length > 0 ? this[0].value : undefined) :
  447. this.each(function(idx){
  448. this.value = funcArg(this, value, idx, this.value)
  449. })
  450. },
  451. offset: function(){
  452. if (this.length==0) return null
  453. var obj = this[0].getBoundingClientRect()
  454. return {
  455. left: obj.left + window.pageXOffset,
  456. top: obj.top + window.pageYOffset,
  457. width: obj.width,
  458. height: obj.height
  459. }
  460. },
  461. css: function(property, value){
  462. if (value === undefined && typeof property == 'string')
  463. return (
  464. this.length == 0
  465. ? undefined
  466. : this[0].style[camelize(property)] || getComputedStyle(this[0], '').getPropertyValue(property))
  467. var css = ''
  468. for (key in property)
  469. if(typeof property[key] == 'string' && property[key] == '')
  470. this.each(function(){ this.style.removeProperty(dasherize(key)) })
  471. else
  472. css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';'
  473. if (typeof property == 'string')
  474. if (value == '')
  475. this.each(function(){ this.style.removeProperty(dasherize(property)) })
  476. else
  477. css = dasherize(property) + ":" + maybeAddPx(property, value)
  478. return this.each(function(){ this.style.cssText += ';' + css })
  479. },
  480. index: function(element){
  481. return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0])
  482. },
  483. hasClass: function(name){
  484. if (this.length < 1) return false
  485. else return classRE(name).test(this[0].className)
  486. },
  487. addClass: function(name){
  488. return this.each(function(idx){
  489. classList = []
  490. var cls = this.className, newName = funcArg(this, name, idx, cls)
  491. newName.split(/\s+/g).forEach(function(klass){
  492. if (!$(this).hasClass(klass)) classList.push(klass)
  493. }, this)
  494. classList.length && (this.className += (cls ? " " : "") + classList.join(" "))
  495. })
  496. },
  497. removeClass: function(name){
  498. return this.each(function(idx){
  499. if (name === undefined)
  500. return this.className = ''
  501. classList = this.className
  502. funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass){
  503. classList = classList.replace(classRE(klass), " ")
  504. })
  505. this.className = classList.trim()
  506. })
  507. },
  508. toggleClass: function(name, when){
  509. return this.each(function(idx){
  510. var newName = funcArg(this, name, idx, this.className)
  511. ;(when === undefined ? !$(this).hasClass(newName) : when) ?
  512. $(this).addClass(newName) : $(this).removeClass(newName)
  513. })
  514. }
  515. }
  516. // Generate the `width` and `height` functions
  517. ;['width', 'height'].forEach(function(dimension){
  518. $.fn[dimension] = function(value){
  519. var offset, Dimension = dimension.replace(/./, function(m){ return m[0].toUpperCase() })
  520. if (value === undefined) return this[0] == window ? window['inner' + Dimension] :
  521. this[0] == document ? document.documentElement['offset' + Dimension] :
  522. (offset = this.offset()) && offset[dimension]
  523. else return this.each(function(idx){
  524. var el = $(this)
  525. el.css(dimension, funcArg(this, value, idx, el[dimension]()))
  526. })
  527. }
  528. })
  529. function insert(operator, target, node) {
  530. var parent = (operator % 2) ? target : target.parentNode
  531. parent ? parent.insertBefore(node,
  532. !operator ? target.nextSibling : // after
  533. operator == 1 ? parent.firstChild : // prepend
  534. operator == 2 ? target : // before
  535. null) : // append
  536. $(node).remove()
  537. }
  538. function traverseNode(node, fun) {
  539. fun(node)
  540. for (var key in node.childNodes) traverseNode(node.childNodes[key], fun)
  541. }
  542. // Generate the `after`, `prepend`, `before`, `append`,
  543. // `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods.
  544. adjacencyOperators.forEach(function(key, operator) {
  545. $.fn[key] = function(){
  546. // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings
  547. var nodes = $.map(arguments, function(n){ return isObject(n) ? n : zepto.fragment(n) })
  548. if (nodes.length < 1) return this
  549. var size = this.length, copyByClone = size > 1, inReverse = operator < 2
  550. return this.each(function(index, target){
  551. for (var i = 0; i < nodes.length; i++) {
  552. var node = nodes[inReverse ? nodes.length-i-1 : i]
  553. traverseNode(node, function(node){
  554. if (node.nodeName != null && node.nodeName.toUpperCase() === 'SCRIPT' && (!node.type || node.type === 'text/javascript'))
  555. window['eval'].call(window, node.innerHTML)
  556. })
  557. if (copyByClone && index < size - 1) node = node.cloneNode(true)
  558. insert(operator, target, node)
  559. }
  560. })
  561. }
  562. $.fn[(operator % 2) ? key+'To' : 'insert'+(operator ? 'Before' : 'After')] = function(html){
  563. $(html)[key](this)
  564. return this
  565. }
  566. })
  567. zepto.Z.prototype = $.fn
  568. // Export internal API functions in the `$.zepto` namespace
  569. zepto.camelize = camelize
  570. zepto.uniq = uniq
  571. $.zepto = zepto
  572. return $
  573. })()
  574. // If `$` is not yet defined, point it to `Zepto`
  575. window.Zepto = Zepto
  576. '$' in window || (window.$ = Zepto)
  577. ;(function($){
  578. var $$ = $.zepto.qsa, handlers = {}, _zid = 1, specialEvents={}
  579. specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents'
  580. function zid(element) {
  581. return element._zid || (element._zid = _zid++)
  582. }
  583. function findHandlers(element, event, fn, selector) {
  584. event = parse(event)
  585. if (event.ns) var matcher = matcherFor(event.ns)
  586. return (handlers[zid(element)] || []).filter(function(handler) {
  587. return handler
  588. && (!event.e || handler.e == event.e)
  589. && (!event.ns || matcher.test(handler.ns))
  590. && (!fn || zid(handler.fn) === zid(fn))
  591. && (!selector || handler.sel == selector)
  592. })
  593. }
  594. function parse(event) {
  595. var parts = ('' + event).split('.')
  596. return {e: parts[0], ns: parts.slice(1).sort().join(' ')}
  597. }
  598. function matcherFor(ns) {
  599. return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)')
  600. }
  601. function eachEvent(events, fn, iterator){
  602. if ($.isObject(events)) $.each(events, iterator)
  603. else events.split(/\s/).forEach(function(type){ iterator(type, fn) })
  604. }
  605. // WARN fix namespaced focus & blur events delegation. Issues #552 & #597 patched from the upstream changes:
  606. // https://github.com/madrobby/zepto/commit/bbb5ca17d7c1874cff2a9a7c3ea94a8c8d79a791
  607. // https://github.com/madrobby/zepto/commit/74bd6f531c5ba154be48e48ff223929a0f57c2fa
  608. function eventCapture(handler, captureSetting) {
  609. return handler.del &&
  610. (handler.e == 'focus' || handler.e == 'blur') ||
  611. !!captureSetting
  612. }
  613. function add(element, events, fn, selector, getDelegate, capture){
  614. var id = zid(element), set = (handlers[id] || (handlers[id] = []))
  615. eachEvent(events, fn, function(event, fn){
  616. var delegate = getDelegate && getDelegate(fn, event),
  617. callback = delegate || fn
  618. var proxyfn = function (event) {
  619. var result = callback.apply(element, [event].concat(event.data))
  620. if (result === false) event.preventDefault()
  621. return result
  622. }
  623. var handler = $.extend(parse(event), {fn: fn, proxy: proxyfn, sel: selector, del: delegate, i: set.length})
  624. set.push(handler)
  625. element.addEventListener(handler.e, proxyfn, eventCapture(handler, capture))
  626. })
  627. }
  628. function remove(element, events, fn, selector, capture){
  629. var id = zid(element)
  630. eachEvent(events || '', fn, function(event, fn){
  631. findHandlers(element, event, fn, selector).forEach(function(handler){
  632. delete handlers[id][handler.i]
  633. element.removeEventListener(handler.e, handler.proxy, eventCapture(handler, capture))
  634. })
  635. })
  636. }
  637. $.event = { add: add, remove: remove }
  638. $.proxy = function(fn, context) {
  639. if ($.isFunction(fn)) {
  640. var proxyFn = function(){ return fn.apply(context, arguments) }
  641. proxyFn._zid = zid(fn)
  642. return proxyFn
  643. } else if (typeof context == 'string') {
  644. return $.proxy(fn[context], fn)
  645. } else {
  646. throw new TypeError("expected function")
  647. }
  648. }
  649. $.fn.bind = function(event, callback){
  650. return this.each(function(){
  651. add(this, event, callback)
  652. })
  653. }
  654. $.fn.unbind = function(event, callback){
  655. return this.each(function(){
  656. remove(this, event, callback)
  657. })
  658. }
  659. $.fn.one = function(event, callback){
  660. return this.each(function(i, element){
  661. add(this, event, callback, null, function(fn, type){
  662. return function(){
  663. var result = fn.apply(element, arguments)
  664. remove(element, type, fn)
  665. return result
  666. }
  667. })
  668. })
  669. }
  670. var returnTrue = function(){return true},
  671. returnFalse = function(){return false},
  672. eventMethods = {
  673. preventDefault: 'isDefaultPrevented',
  674. stopImmediatePropagation: 'isImmediatePropagationStopped',
  675. stopPropagation: 'isPropagationStopped'
  676. }
  677. function createProxy(event) {
  678. var proxy = $.extend({originalEvent: event}, event)
  679. $.each(eventMethods, function(name, predicate) {
  680. proxy[name] = function(){
  681. this[predicate] = returnTrue
  682. return event[name].apply(event, arguments)
  683. }
  684. proxy[predicate] = returnFalse
  685. })
  686. return proxy
  687. }
  688. // emulates the 'defaultPrevented' property for browsers that have none
  689. function fix(event) {
  690. if (!('defaultPrevented' in event)) {
  691. event.defaultPrevented = false
  692. var prevent = event.preventDefault
  693. event.preventDefault = function() {
  694. this.defaultPrevented = true
  695. prevent.call(this)
  696. }
  697. }
  698. }
  699. $.fn.delegate = function(selector, event, callback){
  700. return this.each(function(i, element){
  701. add(element, event, callback, selector, function(fn){
  702. return function(e){
  703. var evt, match = $(e.target).closest(selector, element).get(0)
  704. if (match) {
  705. evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element})
  706. return fn.apply(match, [evt].concat([].slice.call(arguments, 1)))
  707. }
  708. }
  709. })
  710. })
  711. }
  712. $.fn.undelegate = function(selector, event, callback){
  713. return this.each(function(){
  714. remove(this, event, callback, selector)
  715. })
  716. }
  717. $.fn.live = function(event, callback){
  718. $(document.body).delegate(this.selector, event, callback)
  719. return this
  720. }
  721. $.fn.die = function(event, callback){
  722. $(document.body).undelegate(this.selector, event, callback)
  723. return this
  724. }
  725. $.fn.on = function(event, selector, callback){
  726. return selector == undefined || $.isFunction(selector) ?
  727. this.bind(event, selector) : this.delegate(selector, event, callback)
  728. }
  729. $.fn.off = function(event, selector, callback){
  730. return selector == undefined || $.isFunction(selector) ?
  731. this.unbind(event, selector) : this.undelegate(selector, event, callback)
  732. }
  733. $.fn.trigger = function(event, data){
  734. if (typeof event == 'string') event = $.Event(event)
  735. fix(event)
  736. event.data = data
  737. return this.each(function(){
  738. // items in the collection might not be DOM elements
  739. // (todo: possibly support events on plain old objects)
  740. if('dispatchEvent' in this) this.dispatchEvent(event)
  741. })
  742. }
  743. // triggers event handlers on current element just as if an event occurred,
  744. // doesn't trigger an actual event, doesn't bubble
  745. $.fn.triggerHandler = function(event, data){
  746. var e, result
  747. this.each(function(i, element){
  748. e = createProxy(typeof event == 'string' ? $.Event(event) : event)
  749. e.data = data
  750. e.target = element
  751. $.each(findHandlers(element, event.type || event), function(i, handler){
  752. result = handler.proxy(e)
  753. if (e.isImmediatePropagationStopped()) return false
  754. })
  755. })
  756. return result
  757. }
  758. // shortcut methods for `.bind(event, fn)` for each event type
  759. ;('focusin focusout load resize scroll unload click dblclick '+
  760. 'mousedown mouseup mousemove mouseover mouseout '+
  761. 'change select keydown keypress keyup error').split(' ').forEach(function(event) {
  762. $.fn[event] = function(callback){ return this.bind(event, callback) }
  763. })
  764. ;['focus', 'blur'].forEach(function(name) {
  765. $.fn[name] = function(callback) {
  766. if (callback) this.bind(name, callback)
  767. else if (this.length) try { this.get(0)[name]() } catch(e){}
  768. return this
  769. }
  770. })
  771. $.Event = function(type, props) {
  772. var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true
  773. if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name])
  774. event.initEvent(type, bubbles, true, null, null, null, null, null, null, null, null, null, null, null, null)
  775. return event
  776. }
  777. })(Zepto)
  778. ;(function($){
  779. function detect(ua){
  780. var os = this.os = {}, browser = this.browser = {},
  781. webkit = ua.match(/WebKit\/([\d.]+)/),
  782. android = ua.match(/(Android)\s+([\d.]+)/),
  783. ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
  784. iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
  785. webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/),
  786. touchpad = webos && ua.match(/TouchPad/),
  787. kindle = ua.match(/Kindle\/([\d.]+)/),
  788. silk = ua.match(/Silk\/([\d._]+)/),
  789. blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/)
  790. // todo clean this up with a better OS/browser
  791. // separation. we need to discern between multiple
  792. // browsers on android, and decide if kindle fire in
  793. // silk mode is android or not
  794. if (browser.webkit = !!webkit) browser.version = webkit[1]
  795. if (android) os.android = true, os.version = android[2]
  796. if (iphone) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.')
  797. if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.')
  798. if (webos) os.webos = true, os.version = webos[2]
  799. if (touchpad) os.touchpad = true
  800. if (blackberry) os.blackberry = true, os.version = blackberry[2]
  801. if (kindle) os.kindle = true, os.version = kindle[1]
  802. if (silk) browser.silk = true, browser.version = silk[1]
  803. if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true
  804. }
  805. detect.call($, navigator.userAgent)
  806. // make available to unit tests
  807. $.__detect = detect
  808. })(Zepto)
  809. ;(function($, undefined){
  810. var prefix = '', eventPrefix, endEventName, endAnimationName,
  811. vendors = { Webkit: 'webkit', Moz: '', O: 'o', ms: 'MS' },
  812. document = window.document, testEl = document.createElement('div'),
  813. supportedTransforms = /^((translate|rotate|scale)(X|Y|Z|3d)?|matrix(3d)?|perspective|skew(X|Y)?)$/i,
  814. clearProperties = {}
  815. function downcase(str) { return str.toLowerCase() }
  816. function normalizeEvent(name) { return eventPrefix ? eventPrefix + name : downcase(name) }
  817. $.each(vendors, function(vendor, event){
  818. if (testEl.style[vendor + 'TransitionProperty'] !== undefined) {
  819. prefix = '-' + downcase(vendor) + '-'
  820. eventPrefix = event
  821. return false
  822. }
  823. })
  824. clearProperties[prefix + 'transition-property'] =
  825. clearProperties[prefix + 'transition-duration'] =
  826. clearProperties[prefix + 'transition-timing-function'] =
  827. clearProperties[prefix + 'animation-name'] =
  828. clearProperties[prefix + 'animation-duration'] = ''
  829. $.fx = {
  830. off: (eventPrefix === undefined && testEl.style.transitionProperty === undefined),
  831. cssPrefix: prefix,
  832. transitionEnd: normalizeEvent('TransitionEnd'),
  833. animationEnd: normalizeEvent('AnimationEnd')
  834. }
  835. $.fn.animate = function(properties, duration, ease, callback){
  836. if ($.isObject(duration))
  837. ease = duration.easing, callback = duration.complete, duration = duration.duration
  838. if (duration) duration = duration / 1000
  839. return this.anim(properties, duration, ease, callback)
  840. }
  841. $.fn.anim = function(properties, duration, ease, callback){
  842. var transforms, cssProperties = {}, key, that = this, wrappedCallback, endEvent = $.fx.transitionEnd
  843. if (duration === undefined) duration = 0.4
  844. if ($.fx.off) duration = 0
  845. if (typeof properties == 'string') {
  846. // keyframe animation
  847. cssProperties[prefix + 'animation-name'] = properties
  848. cssProperties[prefix + 'animation-duration'] = duration + 's'
  849. endEvent = $.fx.animationEnd
  850. } else {
  851. // CSS transitions
  852. for (key in properties)
  853. if (supportedTransforms.test(key)) {
  854. transforms || (transforms = [])
  855. transforms.push(key + '(' + properties[key] + ')')
  856. }
  857. else cssProperties[key] = properties[key]
  858. if (transforms) cssProperties[prefix + 'transform'] = transforms.join(' ')
  859. if (!$.fx.off && typeof properties === 'object') {
  860. cssProperties[prefix + 'transition-property'] = Object.keys(properties).join(', ')
  861. cssProperties[prefix + 'transition-duration'] = duration + 's'
  862. cssProperties[prefix + 'transition-timing-function'] = (ease || 'linear')
  863. }
  864. }
  865. wrappedCallback = function(event){
  866. if (typeof event !== 'undefined') {
  867. if (event.target !== event.currentTarget) return // makes sure the event didn't bubble from "below"
  868. $(event.target).unbind(endEvent, arguments.callee)
  869. }
  870. $(this).css(clearProperties)
  871. callback && callback.call(this)
  872. }
  873. if (duration > 0) this.bind(endEvent, wrappedCallback)
  874. setTimeout(function() {
  875. that.css(cssProperties)
  876. if (duration <= 0) setTimeout(function() {
  877. that.each(function(){ wrappedCallback.call(this) })
  878. }, 0)
  879. }, 0)
  880. return this
  881. }
  882. testEl = null
  883. })(Zepto)
  884. ;(function($){
  885. var jsonpID = 0,
  886. isObject = $.isObject,
  887. document = window.document,
  888. key,
  889. name,
  890. rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
  891. scriptTypeRE = /^(?:text|application)\/javascript/i,
  892. xmlTypeRE = /^(?:text|application)\/xml/i,
  893. jsonType = 'application/json',
  894. htmlType = 'text/html',
  895. blankRE = /^\s*$/
  896. // trigger a custom event and return false if it was cancelled
  897. function triggerAndReturn(context, eventName, data) {
  898. var event = $.Event(eventName)
  899. $(context).trigger(event, data)
  900. return !event.defaultPrevented
  901. }
  902. // trigger an Ajax "global" event
  903. function triggerGlobal(settings, context, eventName, data) {
  904. if (settings.global) return triggerAndReturn(context || document, eventName, data)
  905. }
  906. // Number of active Ajax requests
  907. $.active = 0
  908. function ajaxStart(settings) {
  909. if (settings.global && $.active++ === 0) triggerGlobal(settings, null, 'ajaxStart')
  910. }
  911. function ajaxStop(settings) {
  912. if (settings.global && !(--$.active)) triggerGlobal(settings, null, 'ajaxStop')
  913. }
  914. // triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable
  915. function ajaxBeforeSend(xhr, settings) {
  916. var context = settings.context
  917. if (settings.beforeSend.call(context, xhr, settings) === false ||
  918. triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false)
  919. return false
  920. triggerGlobal(settings, context, 'ajaxSend', [xhr, settings])
  921. }
  922. function ajaxSuccess(data, xhr, settings) {
  923. var context = settings.context, status = 'success'
  924. settings.success.call(context, data, status, xhr)
  925. triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data])
  926. ajaxComplete(status, xhr, settings)
  927. }
  928. // type: "timeout", "error", "abort", "parsererror"
  929. function ajaxError(error, type, xhr, settings) {
  930. var context = settings.context
  931. settings.error.call(context, xhr, type, error)
  932. triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error])
  933. ajaxComplete(type, xhr, settings)
  934. }
  935. // status: "success", "notmodified", "error", "timeout", "abort", "parsererror"
  936. function ajaxComplete(status, xhr, settings) {
  937. var context = settings.context
  938. settings.complete.call(context, xhr, status)
  939. triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings])
  940. ajaxStop(settings)
  941. }
  942. // Empty function, used as default callback
  943. function empty() {}
  944. $.ajaxJSONP = function(options){
  945. var callbackName = 'jsonp' + (++jsonpID),
  946. script = document.createElement('script'),
  947. abort = function(){
  948. $(script).remove()
  949. if (callbackName in window) window[callbackName] = empty
  950. ajaxComplete('abort', xhr, options)
  951. },
  952. xhr = { abort: abort }, abortTimeout
  953. if (options.error) script.onerror = function() {
  954. xhr.abort()
  955. options.error()
  956. }
  957. window[callbackName] = function(data){
  958. clearTimeout(abortTimeout)
  959. $(script).remove()
  960. delete window[callbackName]
  961. ajaxSuccess(data, xhr, options)
  962. }
  963. serializeData(options)
  964. script.src = options.url.replace(/=\?/, '=' + callbackName)
  965. $('head').append(script)
  966. if (options.timeout > 0) abortTimeout = setTimeout(function(){
  967. xhr.abort()
  968. ajaxComplete('timeout', xhr, options)
  969. }, options.timeout)
  970. return xhr
  971. }
  972. $.ajaxSettings = {
  973. // Default type of request
  974. type: 'GET',
  975. // Callback that is executed before request
  976. beforeSend: empty,
  977. // Callback that is executed if the request succeeds
  978. success: empty,
  979. // Callback that is executed the the server drops error
  980. error: empty,
  981. // Callback that is executed on request complete (both: error and success)
  982. complete: empty,
  983. // The context for the callbacks
  984. context: null,
  985. // Whether to trigger "global" Ajax events
  986. global: true,
  987. // Transport
  988. xhr: function () {
  989. return new window.XMLHttpRequest()
  990. },
  991. // MIME types mapping
  992. accepts: {
  993. script: 'text/javascript, application/javascript',
  994. json: jsonType,
  995. xml: 'application/xml, text/xml',
  996. html: htmlType,
  997. text: 'text/plain'
  998. },
  999. // Whether the request is to another domain
  1000. crossDomain: false,
  1001. // Default timeout
  1002. timeout: 0
  1003. }
  1004. function mimeToDataType(mime) {
  1005. return mime && ( mime == htmlType ? 'html' :
  1006. mime == jsonType ? 'json' :
  1007. scriptTypeRE.test(mime) ? 'script' :
  1008. xmlTypeRE.test(mime) && 'xml' ) || 'text'
  1009. }
  1010. function appendQuery(url, query) {
  1011. return (url + '&' + query).replace(/[&?]{1,2}/, '?')
  1012. }
  1013. // serialize payload and append it to the URL for GET requests
  1014. function serializeData(options) {
  1015. if (isObject(options.data)) options.data = $.param(options.data)
  1016. if (options.data && (!options.type || options.type.toUpperCase() == 'GET'))
  1017. options.url = appendQuery(options.url, options.data)
  1018. }
  1019. $.ajax = function(options){
  1020. var settings = $.extend({}, options || {})
  1021. for (key in $.ajaxSettings) if (settings[key] === undefined) settings[key] = $.ajaxSettings[key]
  1022. ajaxStart(settings)
  1023. if (!settings.crossDomain) settings.crossDomain = /^([\w-]+:)?\/\/([^\/]+)/.test(settings.url) &&
  1024. RegExp.$2 != window.location.host
  1025. var dataType = settings.dataType, hasPlaceholder = /=\?/.test(settings.url)
  1026. if (dataType == 'jsonp' || hasPlaceholder) {
  1027. if (!hasPlaceholder) settings.url = appendQuery(settings.url, 'callback=?')
  1028. return $.ajaxJSONP(settings)
  1029. }
  1030. if (!settings.url) settings.url = window.location.toString()
  1031. serializeData(settings)
  1032. var mime = settings.accepts[dataType],
  1033. baseHeaders = { },
  1034. protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol,
  1035. xhr = $.ajaxSettings.xhr(), abortTimeout
  1036. if (!settings.crossDomain) baseHeaders['X-Requested-With'] = 'XMLHttpRequest'
  1037. if (mime) {
  1038. baseHeaders['Accept'] = mime
  1039. if (mime.indexOf(',') > -1) mime = mime.split(',', 2)[0]
  1040. xhr.overrideMimeType && xhr.overrideMimeType(mime)
  1041. }
  1042. if (settings.contentType || (settings.data && settings.type.toUpperCase() != 'GET'))
  1043. baseHeaders['Content-Type'] = (settings.contentType || 'application/x-www-form-urlencoded')
  1044. settings.headers = $.extend(baseHeaders, settings.headers || {})
  1045. xhr.onreadystatechange = function(){
  1046. if (xhr.readyState == 4) {
  1047. clearTimeout(abortTimeout)
  1048. var result, error = false
  1049. if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) {
  1050. dataType = dataType || mimeToDataType(xhr.getResponseHeader('content-type'))
  1051. result = xhr.responseText
  1052. try {
  1053. if (dataType == 'script') (1,eval)(result)
  1054. else if (dataType == 'xml') result = xhr.responseXML
  1055. else if (dataType == 'json') result = blankRE.test(result) ? null : JSON.parse(result)
  1056. } catch (e) { error = e }
  1057. if (error) ajaxError(error, 'parsererror', xhr, settings)
  1058. else ajaxSuccess(result, xhr, settings)
  1059. } else {
  1060. ajaxError(null, 'error', xhr, settings)
  1061. }
  1062. }
  1063. }
  1064. var async = 'async' in settings ? settings.async : true
  1065. xhr.open(settings.type, settings.url, async)
  1066. for (name in settings.headers) xhr.setRequestHeader(name, settings.headers[name])
  1067. if (ajaxBeforeSend(xhr, settings) === false) {
  1068. xhr.abort()
  1069. return false
  1070. }
  1071. if (settings.timeout > 0) abortTimeout = setTimeout(function(){
  1072. xhr.onreadystatechange = empty
  1073. xhr.abort()
  1074. ajaxError(null, 'timeout', xhr, settings)
  1075. }, settings.timeout)
  1076. // avoid sending empty string (#319)
  1077. xhr.send(settings.data ? settings.data : null)
  1078. return xhr
  1079. }
  1080. $.get = function(url, success){ return $.ajax({ url: url, success: success }) }
  1081. $.post = function(url, data, success, dataType){
  1082. if ($.isFunction(data)) dataType = dataType || success, success = data, data = null
  1083. return $.ajax({ type: 'POST', url: url, data: data, success: success, dataType: dataType })
  1084. }
  1085. $.getJSON = function(url, success){
  1086. return $.ajax({ url: url, success: success, dataType: 'json' })
  1087. }
  1088. $.fn.load = function(url, success){
  1089. if (!this.length) return this
  1090. var self = this, parts = url.split(/\s/), selector
  1091. if (parts.length > 1) url = parts[0], selector = parts[1]
  1092. $.get(url, function(response){
  1093. self.html(selector ?
  1094. $(document.createElement('div')).html(response.replace(rscript, "")).find(selector).html()
  1095. : response)
  1096. success && success.call(self)
  1097. })
  1098. return this
  1099. }
  1100. var escape = encodeURIComponent
  1101. function serialize(params, obj, traditional, scope){
  1102. var array = $.isArray(obj)
  1103. $.each(obj, function(key, value) {
  1104. if (scope) key = traditional ? scope : scope + '[' + (array ? '' : key) + ']'
  1105. // handle data in serializeArray() format
  1106. if (!scope && array) params.add(value.name, value.value)
  1107. // recurse into nested objects
  1108. else if (traditional ? $.isArray(value) : isObject(value))
  1109. serialize(params, value, traditional, key)
  1110. else params.add(key, value)
  1111. })
  1112. }
  1113. $.param = function(obj, traditional){
  1114. var params = []
  1115. params.add = function(k, v){ this.push(escape(k) + '=' + escape(v)) }
  1116. serialize(params, obj, traditional)
  1117. return params.join('&').replace('%20', '+')
  1118. }
  1119. })(Zepto)
  1120. ;(function ($) {
  1121. $.fn.serializeArray = function () {
  1122. var result = [], el
  1123. $( Array.prototype.slice.call(this.get(0).elements) ).each(function () {
  1124. el = $(this)
  1125. var type = el.attr('type')
  1126. if (this.nodeName.toLowerCase() != 'fieldset' &&
  1127. !this.disabled && type != 'submit' && type != 'reset' && type != 'button' &&
  1128. ((type != 'radio' && type != 'checkbox') || this.checked))
  1129. result.push({
  1130. name: el.attr('name'),
  1131. value: el.val()
  1132. })
  1133. })
  1134. return result
  1135. }
  1136. $.fn.serialize = function () {
  1137. var result = []
  1138. this.serializeArray().forEach(function (elm) {
  1139. result.push( encodeURIComponent(elm.name) + '=' + encodeURIComponent(elm.value) )
  1140. })
  1141. return result.join('&')
  1142. }
  1143. $.fn.submit = function (callback) {
  1144. if (callback) this.bind('submit', callback)
  1145. else if (this.length) {
  1146. var event = $.Event('submit')
  1147. this.eq(0).trigger(event)
  1148. if (!event.defaultPrevented) this.get(0).submit()
  1149. }
  1150. return this
  1151. }
  1152. })(Zepto)
  1153. ;(function($){
  1154. var touch = {}, touchTimeout
  1155. function parentIfText(node){
  1156. return 'tagName' in node ? node : node.parentNode
  1157. }
  1158. function swipeDirection(x1, x2, y1, y2){
  1159. var xDelta = Math.abs(x1 - x2), yDelta = Math.abs(y1 - y2)
  1160. return xDelta >= yDelta ? (x1 - x2 > 0 ? 'Left' : 'Right') : (y1 - y2 > 0 ? 'Up' : 'Down')
  1161. }
  1162. var longTapDelay = 750, longTapTimeout
  1163. function longTap(){
  1164. longTapTimeout = null
  1165. if (touch.last) {
  1166. touch.el.trigger('longTap')
  1167. touch = {}
  1168. }
  1169. }
  1170. function cancelLongTap(){
  1171. if (longTapTimeout) clearTimeout(longTapTimeout)
  1172. longTapTimeout = null
  1173. }
  1174. $(document).ready(function(){
  1175. var now, delta
  1176. $(document.body).bind('touchstart', function(e){
  1177. now = Date.now()
  1178. delta = now - (touch.last || now)
  1179. touch.el = $(parentIfText(e.touches[0].target))
  1180. touchTimeout && clearTimeout(touchTimeout)
  1181. touch.x1 = e.touches[0].pageX
  1182. touch.y1 = e.touches[0].pageY
  1183. if (delta > 0 && delta <= 250) touch.isDoubleTap = true
  1184. touch.last = now
  1185. longTapTimeout = setTimeout(longTap, longTapDelay)
  1186. }).bind('touchmove', function(e){
  1187. cancelLongTap()
  1188. touch.x2 = e.touches[0].pageX
  1189. touch.y2 = e.touches[0].pageY
  1190. }).bind('touchend', function(e){
  1191. cancelLongTap()
  1192. // double tap (tapped twice within 250ms)
  1193. if (touch.isDoubleTap) {
  1194. touch.el.trigger('doubleTap')
  1195. touch = {}
  1196. // swipe
  1197. } else if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) ||
  1198. (touch.y2 && Math.abs(touch.y1 - touch.y2) > 30)) {
  1199. touch.el.trigger('swipe') &&
  1200. touch.el.trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2)))
  1201. touch = {}
  1202. // normal tap
  1203. } else if ('last' in touch) {
  1204. touch.el.trigger('tap')
  1205. touchTimeout = setTimeout(function(){
  1206. touchTimeout = null
  1207. touch.el.trigger('singleTap')
  1208. touch = {}
  1209. }, 250)
  1210. }
  1211. }).bind('touchcancel', function(){
  1212. if (touchTimeout) clearTimeout(touchTimeout)
  1213. if (longTapTimeout) clearTimeout(longTapTimeout)
  1214. longTapTimeout = touchTimeout = null
  1215. touch = {}
  1216. })
  1217. })
  1218. ;['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(m){
  1219. $.fn[m] = function(callback){ return this.bind(m, callback) }
  1220. })
  1221. })(Zepto)
  1222. // lib/handlebars/base.js
  1223. /*jshint eqnull:true*/
  1224. this.Handlebars = {};
  1225. (function(Handlebars) {
  1226. Handlebars.VERSION = "1.0.rc.1";
  1227. Handlebars.helpers = {};
  1228. Handlebars.partials = {};
  1229. Handlebars.registerHelper = function(name, fn, inverse) {
  1230. if(inverse) { fn.not = inverse; }
  1231. this.helpers[name] = fn;
  1232. };
  1233. Handlebars.registerPartial = function(name, str) {
  1234. this.partials[name] = str;
  1235. };
  1236. Handlebars.registerHelper('helperMissing', function(arg) {
  1237. if(arguments.length === 2) {
  1238. return undefined;
  1239. } else {
  1240. throw new Error("Could not find property '" + arg + "'");
  1241. }
  1242. });
  1243. var toString = Object.prototype.toString, functionType = "[object Function]";
  1244. Handlebars.registerHelper('blockHelperMissing', function(context, options) {
  1245. var inverse = options.inverse || function() {}, fn = options.fn;
  1246. var ret = "";
  1247. var type = toString.call(context);
  1248. if(type === functionType) { context = context.call(this); }
  1249. if(context === true) {
  1250. return fn(this);
  1251. } else if(context === false || context == null) {
  1252. return inverse(this);
  1253. } else if(type === "[object Array]") {
  1254. if(context.length > 0) {
  1255. return Handlebars.helpers.each(context, options);
  1256. } else {
  1257. return inverse(this);
  1258. }
  1259. } else {
  1260. return fn(context);
  1261. }
  1262. });
  1263. Handlebars.K = function() {};
  1264. Handlebars.createFrame = Object.create || function(object) {
  1265. Handlebars.K.prototype = object;
  1266. var obj = new Handlebars.K();
  1267. Handlebars.K.prototype = null;
  1268. return obj;
  1269. };
  1270. Handlebars.registerHelper('each', function(context, options) {
  1271. var fn = options.fn, inverse = options.inverse;
  1272. var ret = "", data;
  1273. if (options.data) {
  1274. data = Handlebars.createF

Large files files are truncated, but you can click here to view the full file