You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1773 lines
61 KiB

7 years ago
  1. // Zepto.js
  2. // (c) 2010-2015 Thomas Fuchs
  3. // Zepto.js may be freely distributed under the MIT license.
  4. var Zepto = (function() {
  5. var undefined, key, $, classList, emptyArray = [], concat = emptyArray.concat, filter = emptyArray.filter, slice = emptyArray.slice,
  6. document = window.document,
  7. elementDisplay = {}, classCache = {},
  8. cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 },
  9. fragmentRE = /^\s*<(\w+|!)[^>]*>/,
  10. singleTagRE = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,
  11. tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,
  12. rootNodeRE = /^(?:body|html)$/i,
  13. capitalRE = /([A-Z])/g,
  14. // special attributes that should be get/set via method calls
  15. methodAttributes = ['val', 'css', 'html', 'text', 'data', 'width', 'height', 'offset'],
  16. adjacencyOperators = [ 'after', 'prepend', 'before', 'append' ],
  17. table = document.createElement('table'),
  18. tableRow = document.createElement('tr'),
  19. containers = {
  20. 'tr': document.createElement('tbody'),
  21. 'tbody': table, 'thead': table, 'tfoot': table,
  22. 'td': tableRow, 'th': tableRow,
  23. '*': document.createElement('div')
  24. },
  25. readyRE = /complete|loaded|interactive/,
  26. simpleSelectorRE = /^[\w-]*$/,
  27. class2type = {},
  28. toString = class2type.toString,
  29. zepto = {},
  30. camelize, uniq,
  31. tempParent = document.createElement('div'),
  32. propMap = {
  33. 'tabindex': 'tabIndex',
  34. 'readonly': 'readOnly',
  35. 'for': 'htmlFor',
  36. 'class': 'className',
  37. 'maxlength': 'maxLength',
  38. 'cellspacing': 'cellSpacing',
  39. 'cellpadding': 'cellPadding',
  40. 'rowspan': 'rowSpan',
  41. 'colspan': 'colSpan',
  42. 'usemap': 'useMap',
  43. 'frameborder': 'frameBorder',
  44. 'contenteditable': 'contentEditable'
  45. },
  46. isArray = Array.isArray ||
  47. function(object){ return object instanceof Array }
  48. zepto.matches = function(element, selector) {
  49. if (!selector || !element || element.nodeType !== 1) return false
  50. var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector ||
  51. element.oMatchesSelector || element.matchesSelector
  52. if (matchesSelector) return matchesSelector.call(element, selector)
  53. // fall back to performing a selector:
  54. var match, parent = element.parentNode, temp = !parent
  55. if (temp) (parent = tempParent).appendChild(element)
  56. match = ~zepto.qsa(parent, selector).indexOf(element)
  57. temp && tempParent.removeChild(element)
  58. return match
  59. }
  60. function type(obj) {
  61. return obj == null ? String(obj) :
  62. class2type[toString.call(obj)] || "object"
  63. }
  64. function isFunction(value) { return type(value) == "function" }
  65. function isWindow(obj) { return obj != null && obj == obj.window }
  66. function isDocument(obj) { return obj != null && obj.nodeType == obj.DOCUMENT_NODE }
  67. function isObject(obj) { return type(obj) == "object" }
  68. function isPlainObject(obj) {
  69. return isObject(obj) && !isWindow(obj) && Object.getPrototypeOf(obj) == Object.prototype
  70. }
  71. function likeArray(obj) { return typeof obj.length == 'number' }
  72. function compact(array) { return filter.call(array, function(item){ return item != null }) }
  73. function flatten(array) { return array.length > 0 ? $.fn.concat.apply([], array) : array }
  74. camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) }
  75. function dasherize(str) {
  76. return str.replace(/::/g, '/')
  77. .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
  78. .replace(/([a-z\d])([A-Z])/g, '$1_$2')
  79. .replace(/_/g, '-')
  80. .toLowerCase()
  81. }
  82. uniq = function(array){ return filter.call(array, function(item, idx){ return array.indexOf(item) == idx }) }
  83. function classRE(name) {
  84. return name in classCache ?
  85. classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)'))
  86. }
  87. function maybeAddPx(name, value) {
  88. return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value
  89. }
  90. function defaultDisplay(nodeName) {
  91. var element, display
  92. if (!elementDisplay[nodeName]) {
  93. element = document.createElement(nodeName)
  94. document.body.appendChild(element)
  95. display = getComputedStyle(element, '').getPropertyValue("display")
  96. element.parentNode.removeChild(element)
  97. display == "none" && (display = "block")
  98. elementDisplay[nodeName] = display
  99. }
  100. return elementDisplay[nodeName]
  101. }
  102. function children(element) {
  103. return 'children' in element ?
  104. slice.call(element.children) :
  105. $.map(element.childNodes, function(node){ if (node.nodeType == 1) return node })
  106. }
  107. function Z(dom, selector) {
  108. var i, len = dom ? dom.length : 0
  109. for (i = 0; i < len; i++) this[i] = dom[i]
  110. this.length = len
  111. this.selector = selector || ''
  112. }
  113. // `$.zepto.fragment` takes a html string and an optional tag name
  114. // to generate DOM nodes nodes from the given html string.
  115. // The generated DOM nodes are returned as an array.
  116. // This function can be overriden in plugins for example to make
  117. // it compatible with browsers that don't support the DOM fully.
  118. zepto.fragment = function(html, name, properties) {
  119. var dom, nodes, container
  120. // A special case optimization for a single tag
  121. if (singleTagRE.test(html)) dom = $(document.createElement(RegExp.$1))
  122. if (!dom) {
  123. if (html.replace) html = html.replace(tagExpanderRE, "<$1></$2>")
  124. if (name === undefined) name = fragmentRE.test(html) && RegExp.$1
  125. if (!(name in containers)) name = '*'
  126. container = containers[name]
  127. container.innerHTML = '' + html
  128. dom = $.each(slice.call(container.childNodes), function(){
  129. container.removeChild(this)
  130. })
  131. }
  132. if (isPlainObject(properties)) {
  133. nodes = $(dom)
  134. $.each(properties, function(key, value) {
  135. if (methodAttributes.indexOf(key) > -1) nodes[key](value)
  136. else nodes.attr(key, value)
  137. })
  138. }
  139. return dom
  140. }
  141. // `$.zepto.Z` swaps out the prototype of the given `dom` array
  142. // of nodes with `$.fn` and thus supplying all the Zepto functions
  143. // to the array. This method can be overriden in plugins.
  144. zepto.Z = function(dom, selector) {
  145. return new Z(dom, selector)
  146. }
  147. // `$.zepto.isZ` should return `true` if the given object is a Zepto
  148. // collection. This method can be overriden in plugins.
  149. zepto.isZ = function(object) {
  150. return object instanceof zepto.Z
  151. }
  152. // `$.zepto.init` is Zepto's counterpart to jQuery's `$.fn.init` and
  153. // takes a CSS selector and an optional context (and handles various
  154. // special cases).
  155. // This method can be overriden in plugins.
  156. zepto.init = function(selector, context) {
  157. var dom
  158. // If nothing given, return an empty Zepto collection
  159. if (!selector) return zepto.Z()
  160. // Optimize for string selectors
  161. else if (typeof selector == 'string') {
  162. selector = selector.trim()
  163. // If it's a html fragment, create nodes from it
  164. // Note: In both Chrome 21 and Firefox 15, DOM error 12
  165. // is thrown if the fragment doesn't begin with <
  166. if (selector[0] == '<' && fragmentRE.test(selector))
  167. dom = zepto.fragment(selector, RegExp.$1, context), selector = null
  168. // If there's a context, create a collection on that context first, and select
  169. // nodes from there
  170. else if (context !== undefined) return $(context).find(selector)
  171. // If it's a CSS selector, use it to select nodes.
  172. else dom = zepto.qsa(document, selector)
  173. }
  174. // If a function is given, call it when the DOM is ready
  175. else if (isFunction(selector)) return $(document).ready(selector)
  176. // If a Zepto collection is given, just return it
  177. else if (zepto.isZ(selector)) return selector
  178. else {
  179. // normalize array if an array of nodes is given
  180. if (isArray(selector)) dom = compact(selector)
  181. // Wrap DOM nodes.
  182. else if (isObject(selector))
  183. dom = [selector], selector = null
  184. // If it's a html fragment, create nodes from it
  185. else if (fragmentRE.test(selector))
  186. dom = zepto.fragment(selector.trim(), 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. // And last but no least, if it's a CSS selector, use it to select nodes.
  191. else dom = zepto.qsa(document, selector)
  192. }
  193. // create a new Zepto collection from the nodes found
  194. return zepto.Z(dom, selector)
  195. }
  196. // `$` will be the base `Zepto` object. When calling this
  197. // function just call `$.zepto.init, which makes the implementation
  198. // details of selecting nodes and creating Zepto collections
  199. // patchable in plugins.
  200. $ = function(selector, context){
  201. return zepto.init(selector, context)
  202. }
  203. function extend(target, source, deep) {
  204. for (key in source)
  205. if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
  206. if (isPlainObject(source[key]) && !isPlainObject(target[key]))
  207. target[key] = {}
  208. if (isArray(source[key]) && !isArray(target[key]))
  209. target[key] = []
  210. extend(target[key], source[key], deep)
  211. }
  212. else if (source[key] !== undefined) target[key] = source[key]
  213. }
  214. // Copy all but undefined properties from one or more
  215. // objects to the `target` object.
  216. $.extend = function(target){
  217. var deep, args = slice.call(arguments, 1)
  218. if (typeof target == 'boolean') {
  219. deep = target
  220. target = args.shift()
  221. }
  222. args.forEach(function(arg){ extend(target, arg, deep) })
  223. return target
  224. }
  225. // `$.zepto.qsa` is Zepto's CSS selector implementation which
  226. // uses `document.querySelectorAll` and optimizes for some special cases, like `#id`.
  227. // This method can be overriden in plugins.
  228. zepto.qsa = function(element, selector){
  229. var found,
  230. maybeID = selector[0] == '#',
  231. maybeClass = !maybeID && selector[0] == '.',
  232. nameOnly = maybeID || maybeClass ? selector.slice(1) : selector, // Ensure that a 1 char tag name still gets checked
  233. isSimple = simpleSelectorRE.test(nameOnly)
  234. return (element.getElementById && isSimple && maybeID) ? // Safari DocumentFragment doesn't have getElementById
  235. ( (found = element.getElementById(nameOnly)) ? [found] : [] ) :
  236. (element.nodeType !== 1 && element.nodeType !== 9 && element.nodeType !== 11) ? [] :
  237. slice.call(
  238. isSimple && !maybeID && element.getElementsByClassName ? // DocumentFragment doesn't have getElementsByClassName/TagName
  239. maybeClass ? element.getElementsByClassName(nameOnly) : // If it's simple, it could be a class
  240. element.getElementsByTagName(selector) : // Or a tag
  241. element.querySelectorAll(selector) // Or it's not simple, and we need to query all
  242. )
  243. }
  244. function filtered(nodes, selector) {
  245. return selector == null ? $(nodes) : $(nodes).filter(selector)
  246. }
  247. $.contains = document.documentElement.contains ?
  248. function(parent, node) {
  249. return parent !== node && parent.contains(node)
  250. } :
  251. function(parent, node) {
  252. while (node && (node = node.parentNode))
  253. if (node === parent) return true
  254. return false
  255. }
  256. function funcArg(context, arg, idx, payload) {
  257. return isFunction(arg) ? arg.call(context, idx, payload) : arg
  258. }
  259. function setAttribute(node, name, value) {
  260. value == null ? node.removeAttribute(name) : node.setAttribute(name, value)
  261. }
  262. // access className property while respecting SVGAnimatedString
  263. function className(node, value){
  264. var klass = node.className || '',
  265. svg = klass && klass.baseVal !== undefined
  266. if (value === undefined) return svg ? klass.baseVal : klass
  267. svg ? (klass.baseVal = value) : (node.className = value)
  268. }
  269. // "true" => true
  270. // "false" => false
  271. // "null" => null
  272. // "42" => 42
  273. // "42.5" => 42.5
  274. // "08" => "08"
  275. // JSON => parse if valid
  276. // String => self
  277. function deserializeValue(value) {
  278. try {
  279. return value ?
  280. value == "true" ||
  281. ( value == "false" ? false :
  282. value == "null" ? null :
  283. +value + "" == value ? +value :
  284. /^[\[\{]/.test(value) ? $.parseJSON(value) :
  285. value )
  286. : value
  287. } catch(e) {
  288. return value
  289. }
  290. }
  291. $.type = type
  292. $.isFunction = isFunction
  293. $.isWindow = isWindow
  294. $.isArray = isArray
  295. $.isPlainObject = isPlainObject
  296. $.isEmptyObject = function(obj) {
  297. var name
  298. for (name in obj) return false
  299. return true
  300. }
  301. $.inArray = function(elem, array, i){
  302. return emptyArray.indexOf.call(array, elem, i)
  303. }
  304. $.camelCase = camelize
  305. $.trim = function(str) {
  306. return str == null ? "" : String.prototype.trim.call(str)
  307. }
  308. // plugin compatibility
  309. $.uuid = 0
  310. $.support = { }
  311. $.expr = { }
  312. $.noop = function() {}
  313. $.map = function(elements, callback){
  314. var value, values = [], i, key
  315. if (likeArray(elements))
  316. for (i = 0; i < elements.length; i++) {
  317. value = callback(elements[i], i)
  318. if (value != null) values.push(value)
  319. }
  320. else
  321. for (key in elements) {
  322. value = callback(elements[key], key)
  323. if (value != null) values.push(value)
  324. }
  325. return flatten(values)
  326. }
  327. $.each = function(elements, callback){
  328. var i, key
  329. if (likeArray(elements)) {
  330. for (i = 0; i < elements.length; i++)
  331. if (callback.call(elements[i], i, elements[i]) === false) return elements
  332. } else {
  333. for (key in elements)
  334. if (callback.call(elements[key], key, elements[key]) === false) return elements
  335. }
  336. return elements
  337. }
  338. $.grep = function(elements, callback){
  339. return filter.call(elements, callback)
  340. }
  341. if (window.JSON) $.parseJSON = JSON.parse
  342. // Populate the class2type map
  343. $.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
  344. class2type[ "[object " + name + "]" ] = name.toLowerCase()
  345. })
  346. // Define methods that will be available on all
  347. // Zepto collections
  348. $.fn = {
  349. constructor: zepto.Z,
  350. length: 0,
  351. // Because a collection acts like an array
  352. // copy over these useful array functions.
  353. forEach: emptyArray.forEach,
  354. reduce: emptyArray.reduce,
  355. push: emptyArray.push,
  356. sort: emptyArray.sort,
  357. splice: emptyArray.splice,
  358. indexOf: emptyArray.indexOf,
  359. concat: function(){
  360. var i, value, args = []
  361. for (i = 0; i < arguments.length; i++) {
  362. value = arguments[i]
  363. args[i] = zepto.isZ(value) ? value.toArray() : value
  364. }
  365. return concat.apply(zepto.isZ(this) ? this.toArray() : this, args)
  366. },
  367. // `map` and `slice` in the jQuery API work differently
  368. // from their array counterparts
  369. map: function(fn){
  370. return $($.map(this, function(el, i){ return fn.call(el, i, el) }))
  371. },
  372. slice: function(){
  373. return $(slice.apply(this, arguments))
  374. },
  375. ready: function(callback){
  376. // need to check if document.body exists for IE as that browser reports
  377. // document ready when it hasn't yet created the body element
  378. if (readyRE.test(document.readyState) && document.body) callback($)
  379. else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false)
  380. return this
  381. },
  382. get: function(idx){
  383. return idx === undefined ? slice.call(this) : this[idx >= 0 ? idx : idx + this.length]
  384. },
  385. toArray: function(){ return this.get() },
  386. size: function(){
  387. return this.length
  388. },
  389. remove: function(){
  390. return this.each(function(){
  391. if (this.parentNode != null)
  392. this.parentNode.removeChild(this)
  393. })
  394. },
  395. each: function(callback){
  396. emptyArray.every.call(this, function(el, idx){
  397. return callback.call(el, idx, el) !== false
  398. })
  399. return this
  400. },
  401. filter: function(selector){
  402. if (isFunction(selector)) return this.not(this.not(selector))
  403. return $(filter.call(this, function(element){
  404. return zepto.matches(element, selector)
  405. }))
  406. },
  407. add: function(selector,context){
  408. return $(uniq(this.concat($(selector,context))))
  409. },
  410. is: function(selector){
  411. return this.length > 0 && zepto.matches(this[0], selector)
  412. },
  413. not: function(selector){
  414. var nodes=[]
  415. if (isFunction(selector) && selector.call !== undefined)
  416. this.each(function(idx){
  417. if (!selector.call(this,idx)) nodes.push(this)
  418. })
  419. else {
  420. var excludes = typeof selector == 'string' ? this.filter(selector) :
  421. (likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector)
  422. this.forEach(function(el){
  423. if (excludes.indexOf(el) < 0) nodes.push(el)
  424. })
  425. }
  426. return $(nodes)
  427. },
  428. has: function(selector){
  429. return this.filter(function(){
  430. return isObject(selector) ?
  431. $.contains(this, selector) :
  432. $(this).find(selector).size()
  433. })
  434. },
  435. eq: function(idx){
  436. return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1)
  437. },
  438. first: function(){
  439. var el = this[0]
  440. return el && !isObject(el) ? el : $(el)
  441. },
  442. last: function(){
  443. var el = this[this.length - 1]
  444. return el && !isObject(el) ? el : $(el)
  445. },
  446. find: function(selector){
  447. var result, $this = this
  448. if (!selector) result = $()
  449. else if (typeof selector == 'object')
  450. result = $(selector).filter(function(){
  451. var node = this
  452. return emptyArray.some.call($this, function(parent){
  453. return $.contains(parent, node)
  454. })
  455. })
  456. else if (this.length == 1) result = $(zepto.qsa(this[0], selector))
  457. else result = this.map(function(){ return zepto.qsa(this, selector) })
  458. return result
  459. },
  460. closest: function(selector, context){
  461. var node = this[0], collection = false
  462. if (typeof selector == 'object') collection = $(selector)
  463. while (node && !(collection ? collection.indexOf(node) >= 0 : zepto.matches(node, selector)))
  464. node = node !== context && !isDocument(node) && node.parentNode
  465. return $(node)
  466. },
  467. parents: function(selector){
  468. var ancestors = [], nodes = this
  469. while (nodes.length > 0)
  470. nodes = $.map(nodes, function(node){
  471. if ((node = node.parentNode) && !isDocument(node) && ancestors.indexOf(node) < 0) {
  472. ancestors.push(node)
  473. return node
  474. }
  475. })
  476. return filtered(ancestors, selector)
  477. },
  478. parent: function(selector){
  479. return filtered(uniq(this.pluck('parentNode')), selector)
  480. },
  481. children: function(selector){
  482. return filtered(this.map(function(){ return children(this) }), selector)
  483. },
  484. contents: function() {
  485. return this.map(function() { return this.contentDocument || slice.call(this.childNodes) })
  486. },
  487. siblings: function(selector){
  488. return filtered(this.map(function(i, el){
  489. return filter.call(children(el.parentNode), function(child){ return child!==el })
  490. }), selector)
  491. },
  492. empty: function(){
  493. return this.each(function(){ this.innerHTML = '' })
  494. },
  495. // `pluck` is borrowed from Prototype.js
  496. pluck: function(property){
  497. return $.map(this, function(el){ return el[property] })
  498. },
  499. show: function(){
  500. return this.each(function(){
  501. this.style.display == "none" && (this.style.display = '')
  502. if (getComputedStyle(this, '').getPropertyValue("display") == "none")
  503. this.style.display = defaultDisplay(this.nodeName)
  504. })
  505. },
  506. replaceWith: function(newContent){
  507. return this.before(newContent).remove()
  508. },
  509. wrap: function(structure){
  510. var func = isFunction(structure)
  511. if (this[0] && !func)
  512. var dom = $(structure).get(0),
  513. clone = dom.parentNode || this.length > 1
  514. return this.each(function(index){
  515. $(this).wrapAll(
  516. func ? structure.call(this, index) :
  517. clone ? dom.cloneNode(true) : dom
  518. )
  519. })
  520. },
  521. wrapAll: function(structure){
  522. if (this[0]) {
  523. $(this[0]).before(structure = $(structure))
  524. var children
  525. // drill down to the inmost element
  526. while ((children = structure.children()).length) structure = children.first()
  527. $(structure).append(this)
  528. }
  529. return this
  530. },
  531. wrapInner: function(structure){
  532. var func = isFunction(structure)
  533. return this.each(function(index){
  534. var self = $(this), contents = self.contents(),
  535. dom = func ? structure.call(this, index) : structure
  536. contents.length ? contents.wrapAll(dom) : self.append(dom)
  537. })
  538. },
  539. unwrap: function(){
  540. this.parent().each(function(){
  541. $(this).replaceWith($(this).children())
  542. })
  543. return this
  544. },
  545. clone: function(){
  546. return this.map(function(){ return this.cloneNode(true) })
  547. },
  548. hide: function(){
  549. return this.css("display", "none")
  550. },
  551. toggle: function(setting){
  552. return this.each(function(){
  553. var el = $(this)
  554. ;(setting === undefined ? el.css("display") == "none" : setting) ? el.show() : el.hide()
  555. })
  556. },
  557. prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') },
  558. next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') },
  559. html: function(html){
  560. return 0 in arguments ?
  561. this.each(function(idx){
  562. var originHtml = this.innerHTML
  563. $(this).empty().append( funcArg(this, html, idx, originHtml) )
  564. }) :
  565. (0 in this ? this[0].innerHTML : null)
  566. },
  567. text: function(text){
  568. return 0 in arguments ?
  569. this.each(function(idx){
  570. var newText = funcArg(this, text, idx, this.textContent)
  571. this.textContent = newText == null ? '' : ''+newText
  572. }) :
  573. (0 in this ? this[0].textContent : null)
  574. },
  575. attr: function(name, value){
  576. var result
  577. return (typeof name == 'string' && !(1 in arguments)) ?
  578. (!this.length || this[0].nodeType !== 1 ? undefined :
  579. (!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result
  580. ) :
  581. this.each(function(idx){
  582. if (this.nodeType !== 1) return
  583. if (isObject(name)) for (key in name) setAttribute(this, key, name[key])
  584. else setAttribute(this, name, funcArg(this, value, idx, this.getAttribute(name)))
  585. })
  586. },
  587. removeAttr: function(name){
  588. return this.each(function(){ this.nodeType === 1 && name.split(' ').forEach(function(attribute){
  589. setAttribute(this, attribute)
  590. }, this)})
  591. },
  592. prop: function(name, value){
  593. name = propMap[name] || name
  594. return (1 in arguments) ?
  595. this.each(function(idx){
  596. this[name] = funcArg(this, value, idx, this[name])
  597. }) :
  598. (this[0] && this[0][name])
  599. },
  600. data: function(name, value){
  601. var attrName = 'data-' + name.replace(capitalRE, '-$1').toLowerCase()
  602. var data = (1 in arguments) ?
  603. this.attr(attrName, value) :
  604. this.attr(attrName)
  605. return data !== null ? deserializeValue(data) : undefined
  606. },
  607. val: function(value){
  608. return 0 in arguments ?
  609. this.each(function(idx){
  610. this.value = funcArg(this, value, idx, this.value)
  611. }) :
  612. (this[0] && (this[0].multiple ?
  613. $(this[0]).find('option').filter(function(){ return this.selected }).pluck('value') :
  614. this[0].value)
  615. )
  616. },
  617. offset: function(coordinates){
  618. if (coordinates) return this.each(function(index){
  619. var $this = $(this),
  620. coords = funcArg(this, coordinates, index, $this.offset()),
  621. parentOffset = $this.offsetParent().offset(),
  622. props = {
  623. top: coords.top - parentOffset.top,
  624. left: coords.left - parentOffset.left
  625. }
  626. if ($this.css('position') == 'static') props['position'] = 'relative'
  627. $this.css(props)
  628. })
  629. if (!this.length) return null
  630. if (!$.contains(document.documentElement, this[0]))
  631. return {top: 0, left: 0}
  632. var obj = this[0].getBoundingClientRect()
  633. return {
  634. left: obj.left + window.pageXOffset,
  635. top: obj.top + window.pageYOffset,
  636. width: Math.round(obj.width),
  637. height: Math.round(obj.height)
  638. }
  639. },
  640. css: function(property, value){
  641. if (arguments.length < 2) {
  642. var computedStyle, element = this[0]
  643. if(!element) return
  644. computedStyle = getComputedStyle(element, '')
  645. if (typeof property == 'string')
  646. return element.style[camelize(property)] || computedStyle.getPropertyValue(property)
  647. else if (isArray(property)) {
  648. var props = {}
  649. $.each(property, function(_, prop){
  650. props[prop] = (element.style[camelize(prop)] || computedStyle.getPropertyValue(prop))
  651. })
  652. return props
  653. }
  654. }
  655. var css = ''
  656. if (type(property) == 'string') {
  657. if (!value && value !== 0)
  658. this.each(function(){ this.style.removeProperty(dasherize(property)) })
  659. else
  660. css = dasherize(property) + ":" + maybeAddPx(property, value)
  661. } else {
  662. for (key in property)
  663. if (!property[key] && property[key] !== 0)
  664. this.each(function(){ this.style.removeProperty(dasherize(key)) })
  665. else
  666. css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';'
  667. }
  668. return this.each(function(){ this.style.cssText += ';' + css })
  669. },
  670. index: function(element){
  671. return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0])
  672. },
  673. hasClass: function(name){
  674. if (!name) return false
  675. return emptyArray.some.call(this, function(el){
  676. return this.test(className(el))
  677. }, classRE(name))
  678. },
  679. addClass: function(name){
  680. if (!name) return this
  681. return this.each(function(idx){
  682. if (!('className' in this)) return
  683. classList = []
  684. var cls = className(this), newName = funcArg(this, name, idx, cls)
  685. newName.split(/\s+/g).forEach(function(klass){
  686. if (!$(this).hasClass(klass)) classList.push(klass)
  687. }, this)
  688. classList.length && className(this, cls + (cls ? " " : "") + classList.join(" "))
  689. })
  690. },
  691. removeClass: function(name){
  692. return this.each(function(idx){
  693. if (!('className' in this)) return
  694. if (name === undefined) return className(this, '')
  695. classList = className(this)
  696. funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass){
  697. classList = classList.replace(classRE(klass), " ")
  698. })
  699. className(this, classList.trim())
  700. })
  701. },
  702. toggleClass: function(name, when){
  703. if (!name) return this
  704. return this.each(function(idx){
  705. var $this = $(this), names = funcArg(this, name, idx, className(this))
  706. names.split(/\s+/g).forEach(function(klass){
  707. (when === undefined ? !$this.hasClass(klass) : when) ?
  708. $this.addClass(klass) : $this.removeClass(klass)
  709. })
  710. })
  711. },
  712. scrollTop: function(value){
  713. if (!this.length) return
  714. var hasScrollTop = 'scrollTop' in this[0]
  715. if (value === undefined) return hasScrollTop ? this[0].scrollTop : this[0].pageYOffset
  716. return this.each(hasScrollTop ?
  717. function(){ this.scrollTop = value } :
  718. function(){ this.scrollTo(this.scrollX, value) })
  719. },
  720. scrollLeft: function(value){
  721. if (!this.length) return
  722. var hasScrollLeft = 'scrollLeft' in this[0]
  723. if (value === undefined) return hasScrollLeft ? this[0].scrollLeft : this[0].pageXOffset
  724. return this.each(hasScrollLeft ?
  725. function(){ this.scrollLeft = value } :
  726. function(){ this.scrollTo(value, this.scrollY) })
  727. },
  728. position: function() {
  729. if (!this.length) return
  730. var elem = this[0],
  731. // Get *real* offsetParent
  732. offsetParent = this.offsetParent(),
  733. // Get correct offsets
  734. offset = this.offset(),
  735. parentOffset = rootNodeRE.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset()
  736. // Subtract element margins
  737. // note: when an element has margin: auto the offsetLeft and marginLeft
  738. // are the same in Safari causing offset.left to incorrectly be 0
  739. offset.top -= parseFloat( $(elem).css('margin-top') ) || 0
  740. offset.left -= parseFloat( $(elem).css('margin-left') ) || 0
  741. // Add offsetParent borders
  742. parentOffset.top += parseFloat( $(offsetParent[0]).css('border-top-width') ) || 0
  743. parentOffset.left += parseFloat( $(offsetParent[0]).css('border-left-width') ) || 0
  744. // Subtract the two offsets
  745. return {
  746. top: offset.top - parentOffset.top,
  747. left: offset.left - parentOffset.left
  748. }
  749. },
  750. offsetParent: function() {
  751. return this.map(function(){
  752. var parent = this.offsetParent || document.body
  753. while (parent && !rootNodeRE.test(parent.nodeName) && $(parent).css("position") == "static")
  754. parent = parent.offsetParent
  755. return parent
  756. })
  757. }
  758. }
  759. // for now
  760. $.fn.detach = $.fn.remove
  761. // Generate the `width` and `height` functions
  762. ;['width', 'height'].forEach(function(dimension){
  763. var dimensionProperty =
  764. dimension.replace(/./, function(m){ return m[0].toUpperCase() })
  765. $.fn[dimension] = function(value){
  766. var offset, el = this[0]
  767. if (value === undefined) return isWindow(el) ? el['inner' + dimensionProperty] :
  768. isDocument(el) ? el.documentElement['scroll' + dimensionProperty] :
  769. (offset = this.offset()) && offset[dimension]
  770. else return this.each(function(idx){
  771. el = $(this)
  772. el.css(dimension, funcArg(this, value, idx, el[dimension]()))
  773. })
  774. }
  775. })
  776. function traverseNode(node, fun) {
  777. fun(node)
  778. for (var i = 0, len = node.childNodes.length; i < len; i++)
  779. traverseNode(node.childNodes[i], fun)
  780. }
  781. // Generate the `after`, `prepend`, `before`, `append`,
  782. // `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods.
  783. adjacencyOperators.forEach(function(operator, operatorIndex) {
  784. var inside = operatorIndex % 2 //=> prepend, append
  785. $.fn[operator] = function(){
  786. // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings
  787. var argType, nodes = $.map(arguments, function(arg) {
  788. argType = type(arg)
  789. return argType == "object" || argType == "array" || arg == null ?
  790. arg : zepto.fragment(arg)
  791. }),
  792. parent, copyByClone = this.length > 1
  793. if (nodes.length < 1) return this
  794. return this.each(function(_, target){
  795. parent = inside ? target : target.parentNode
  796. // convert all methods to a "before" operation
  797. target = operatorIndex == 0 ? target.nextSibling :
  798. operatorIndex == 1 ? target.firstChild :
  799. operatorIndex == 2 ? target :
  800. null
  801. var parentInDocument = $.contains(document.documentElement, parent)
  802. nodes.forEach(function(node){
  803. if (copyByClone) node = node.cloneNode(true)
  804. else if (!parent) return $(node).remove()
  805. parent.insertBefore(node, target)
  806. if (parentInDocument) traverseNode(node, function(el){
  807. if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' &&
  808. (!el.type || el.type === 'text/javascript') && !el.src)
  809. window['eval'].call(window, el.innerHTML)
  810. })
  811. })
  812. })
  813. }
  814. // after => insertAfter
  815. // prepend => prependTo
  816. // before => insertBefore
  817. // append => appendTo
  818. $.fn[inside ? operator+'To' : 'insert'+(operatorIndex ? 'Before' : 'After')] = function(html){
  819. $(html)[operator](this)
  820. return this
  821. }
  822. })
  823. zepto.Z.prototype = Z.prototype = $.fn
  824. // Export internal API functions in the `$.zepto` namespace
  825. zepto.uniq = uniq
  826. zepto.deserializeValue = deserializeValue
  827. $.zepto = zepto
  828. return $
  829. })()
  830. // If `$` is not yet defined, point it to `Zepto`
  831. window.Zepto = Zepto
  832. window.$ === undefined && (window.$ = Zepto)
  833. // Zepto.js
  834. // (c) 2010-2015 Thomas Fuchs
  835. // Zepto.js may be freely distributed under the MIT license.
  836. ;(function($){
  837. var _zid = 1, undefined,
  838. slice = Array.prototype.slice,
  839. isFunction = $.isFunction,
  840. isString = function(obj){ return typeof obj == 'string' },
  841. handlers = {},
  842. specialEvents={},
  843. focusinSupported = 'onfocusin' in window,
  844. focus = { focus: 'focusin', blur: 'focusout' },
  845. hover = { mouseenter: 'mouseover', mouseleave: 'mouseout' }
  846. specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents'
  847. function zid(element) {
  848. return element._zid || (element._zid = _zid++)
  849. }
  850. function findHandlers(element, event, fn, selector) {
  851. event = parse(event)
  852. if (event.ns) var matcher = matcherFor(event.ns)
  853. return (handlers[zid(element)] || []).filter(function(handler) {
  854. return handler
  855. && (!event.e || handler.e == event.e)
  856. && (!event.ns || matcher.test(handler.ns))
  857. && (!fn || zid(handler.fn) === zid(fn))
  858. && (!selector || handler.sel == selector)
  859. })
  860. }
  861. function parse(event) {
  862. var parts = ('' + event).split('.')
  863. return {e: parts[0], ns: parts.slice(1).sort().join(' ')}
  864. }
  865. function matcherFor(ns) {
  866. return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)')
  867. }
  868. function eventCapture(handler, captureSetting) {
  869. return handler.del &&
  870. (!focusinSupported && (handler.e in focus)) ||
  871. !!captureSetting
  872. }
  873. function realEvent(type) {
  874. return hover[type] || (focusinSupported && focus[type]) || type
  875. }
  876. function add(element, events, fn, data, selector, delegator, capture){
  877. var id = zid(element), set = (handlers[id] || (handlers[id] = []))
  878. events.split(/\s/).forEach(function(event){
  879. if (event == 'ready') return $(document).ready(fn)
  880. var handler = parse(event)
  881. handler.fn = fn
  882. handler.sel = selector
  883. // emulate mouseenter, mouseleave
  884. if (handler.e in hover) fn = function(e){
  885. var related = e.relatedTarget
  886. if (!related || (related !== this && !$.contains(this, related)))
  887. return handler.fn.apply(this, arguments)
  888. }
  889. handler.del = delegator
  890. var callback = delegator || fn
  891. handler.proxy = function(e){
  892. e = compatible(e)
  893. if (e.isImmediatePropagationStopped()) return
  894. e.data = data
  895. var result = callback.apply(element, e._args == undefined ? [e] : [e].concat(e._args))
  896. if (result === false) e.preventDefault(), e.stopPropagation()
  897. return result
  898. }
  899. handler.i = set.length
  900. set.push(handler)
  901. if ('addEventListener' in element)
  902. element.addEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture))
  903. })
  904. }
  905. function remove(element, events, fn, selector, capture){
  906. var id = zid(element)
  907. ;(events || '').split(/\s/).forEach(function(event){
  908. findHandlers(element, event, fn, selector).forEach(function(handler){
  909. delete handlers[id][handler.i]
  910. if ('removeEventListener' in element)
  911. element.removeEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture))
  912. })
  913. })
  914. }
  915. $.event = { add: add, remove: remove }
  916. $.proxy = function(fn, context) {
  917. var args = (2 in arguments) && slice.call(arguments, 2)
  918. if (isFunction(fn)) {
  919. var proxyFn = function(){ return fn.apply(context, args ? args.concat(slice.call(arguments)) : arguments) }
  920. proxyFn._zid = zid(fn)
  921. return proxyFn
  922. } else if (isString(context)) {
  923. if (args) {
  924. args.unshift(fn[context], fn)
  925. return $.proxy.apply(null, args)
  926. } else {
  927. return $.proxy(fn[context], fn)
  928. }
  929. } else {
  930. throw new TypeError("expected function")
  931. }
  932. }
  933. $.fn.bind = function(event, data, callback){
  934. return this.on(event, data, callback)
  935. }
  936. $.fn.unbind = function(event, callback){
  937. return this.off(event, callback)
  938. }
  939. $.fn.one = function(event, selector, data, callback){
  940. return this.on(event, selector, data, callback, 1)
  941. }
  942. var returnTrue = function(){return true},
  943. returnFalse = function(){return false},
  944. ignoreProperties = /^([A-Z]|returnValue$|layer[XY]$)/,
  945. eventMethods = {
  946. preventDefault: 'isDefaultPrevented',
  947. stopImmediatePropagation: 'isImmediatePropagationStopped',
  948. stopPropagation: 'isPropagationStopped'
  949. }
  950. function compatible(event, source) {
  951. if (source || !event.isDefaultPrevented) {
  952. source || (source = event)
  953. $.each(eventMethods, function(name, predicate) {
  954. var sourceMethod = source[name]
  955. event[name] = function(){
  956. this[predicate] = returnTrue
  957. return sourceMethod && sourceMethod.apply(source, arguments)
  958. }
  959. event[predicate] = returnFalse
  960. })
  961. if (source.defaultPrevented !== undefined ? source.defaultPrevented :
  962. 'returnValue' in source ? source.returnValue === false :
  963. source.getPreventDefault && source.getPreventDefault())
  964. event.isDefaultPrevented = returnTrue
  965. }
  966. return event
  967. }
  968. function createProxy(event) {
  969. var key, proxy = { originalEvent: event }
  970. for (key in event)
  971. if (!ignoreProperties.test(key) && event[key] !== undefined) proxy[key] = event[key]
  972. return compatible(proxy, event)
  973. }
  974. $.fn.delegate = function(selector, event, callback){
  975. return this.on(event, selector, callback)
  976. }
  977. $.fn.undelegate = function(selector, event, callback){
  978. return this.off(event, selector, callback)
  979. }
  980. $.fn.live = function(event, callback){
  981. $(document.body).delegate(this.selector, event, callback)
  982. return this
  983. }
  984. $.fn.die = function(event, callback){
  985. $(document.body).undelegate(this.selector, event, callback)
  986. return this
  987. }
  988. $.fn.on = function(event, selector, data, callback, one){
  989. var autoRemove, delegator, $this = this
  990. if (event && !isString(event)) {
  991. $.each(event, function(type, fn){
  992. $this.on(type, selector, data, fn, one)
  993. })
  994. return $this
  995. }
  996. if (!isString(selector) && !isFunction(callback) && callback !== false)
  997. callback = data, data = selector, selector = undefined
  998. if (callback === undefined || data === false)
  999. callback = data, data = undefined
  1000. if (callback === false) callback = returnFalse
  1001. return $this.each(function(_, element){
  1002. if (one) autoRemove = function(e){
  1003. remove(element, e.type, callback)
  1004. return callback.apply(this, arguments)
  1005. }
  1006. if (selector) delegator = function(e){
  1007. var evt, match = $(e.target).closest(selector, element).get(0)
  1008. if (match && match !== element) {
  1009. evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element})
  1010. return (autoRemove || callback).apply(match, [evt].concat(slice.call(arguments, 1)))
  1011. }
  1012. }
  1013. add(element, event, callback, data, selector, delegator || autoRemove)
  1014. })
  1015. }
  1016. $.fn.off = function(event, selector, callback){
  1017. var $this = this
  1018. if (event && !isString(event)) {
  1019. $.each(event, function(type, fn){
  1020. $this.off(type, selector, fn)
  1021. })
  1022. return $this
  1023. }
  1024. if (!isString(selector) && !isFunction(callback) && callback !== false)
  1025. callback = selector, selector = undefined
  1026. if (callback === false) callback = returnFalse
  1027. return $this.each(function(){
  1028. remove(this, event, callback, selector)
  1029. })
  1030. }
  1031. $.fn.trigger = function(event, args){
  1032. event = (isString(event) || $.isPlainObject(event)) ? $.Event(event) : compatible(event)
  1033. event._args = args
  1034. return this.each(function(){
  1035. // handle focus(), blur() by calling them directly
  1036. if (event.type in focus && typeof this[event.type] == "function") this[event.type]()
  1037. // items in the collection might not be DOM elements
  1038. else if ('dispatchEvent' in this) this.dispatchEvent(event)
  1039. else $(this).triggerHandler(event, args)
  1040. })
  1041. }
  1042. // triggers event handlers on current element just as if an event occurred,
  1043. // doesn't trigger an actual event, doesn't bubble
  1044. $.fn.triggerHandler = function(event, args){
  1045. var e, result
  1046. this.each(function(i, element){
  1047. e = createProxy(isString(event) ? $.Event(event) : event)
  1048. e._args = args
  1049. e.target = element
  1050. $.each(findHandlers(element, event.type || event), function(i, handler){
  1051. result = handler.proxy(e)
  1052. if (e.isImmediatePropagationStopped()) return false
  1053. })
  1054. })
  1055. return result
  1056. }
  1057. // shortcut methods for `.bind(event, fn)` for each event type
  1058. ;('focusin focusout focus blur load resize scroll unload click dblclick '+
  1059. 'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave '+
  1060. 'change select keydown keypress keyup error').split(' ').forEach(function(event) {
  1061. $.fn[event] = function(callback) {
  1062. return (0 in arguments) ?
  1063. this.bind(event, callback) :
  1064. this.trigger(event)
  1065. }
  1066. })
  1067. $.Event = function(type, props) {
  1068. if (!isString(type)) props = type, type = props.type
  1069. var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true
  1070. if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name])
  1071. event.initEvent(type, bubbles, true)
  1072. return compatible(event)
  1073. }
  1074. })(Zepto)
  1075. // Zepto.js
  1076. // (c) 2010-2015 Thomas Fuchs
  1077. // Zepto.js may be freely distributed under the MIT license.
  1078. ;(function($){
  1079. var touch = {},
  1080. touchTimeout, tapTimeout, swipeTimeout, longTapTimeout,
  1081. longTapDelay = 750,
  1082. gesture
  1083. function swipeDirection(x1, x2, y1, y2) {
  1084. return Math.abs(x1 - x2) >=
  1085. Math.abs(y1 - y2) ? (x1 - x2 > 0 ? 'Left' : 'Right') : (y1 - y2 > 0 ? 'Up' : 'Down')
  1086. }
  1087. function longTap() {
  1088. longTapTimeout = null
  1089. if (touch.last) {
  1090. touch.el.trigger('longTap')
  1091. touch = {}
  1092. }
  1093. }
  1094. function cancelLongTap() {
  1095. if (longTapTimeout) clearTimeout(longTapTimeout)
  1096. longTapTimeout = null
  1097. }
  1098. function cancelAll() {
  1099. if (touchTimeout) clearTimeout(touchTimeout)
  1100. if (tapTimeout) clearTimeout(tapTimeout)
  1101. if (swipeTimeout) clearTimeout(swipeTimeout)
  1102. if (longTapTimeout) clearTimeout(longTapTimeout)
  1103. touchTimeout = tapTimeout = swipeTimeout = longTapTimeout = null
  1104. touch = {}
  1105. }
  1106. function isPrimaryTouch(event){
  1107. return (event.pointerType == 'touch' ||
  1108. event.pointerType == event.MSPOINTER_TYPE_TOUCH)
  1109. && event.isPrimary
  1110. }
  1111. function isPointerEventType(e, type){
  1112. return (e.type == 'pointer'+type ||
  1113. e.type.toLowerCase() == 'mspointer'+type)
  1114. }
  1115. $(document).ready(function(){
  1116. var now, delta, deltaX = 0, deltaY = 0, firstTouch, _isPointerType
  1117. if ('MSGesture' in window) {
  1118. gesture = new MSGesture()
  1119. gesture.target = document.body
  1120. }
  1121. $(document)
  1122. .bind('MSGestureEnd', function(e){
  1123. var swipeDirectionFromVelocity =
  1124. e.velocityX > 1 ? 'Right' : e.velocityX < -1 ? 'Left' : e.velocityY > 1 ? 'Down' : e.velocityY < -1 ? 'Up' : null;
  1125. if (swipeDirectionFromVelocity) {
  1126. touch.el.trigger('swipe')
  1127. touch.el.trigger('swipe'+ swipeDirectionFromVelocity)
  1128. }
  1129. })
  1130. .on('touchstart MSPointerDown pointerdown', function(e){
  1131. if((_isPointerType = isPointerEventType(e, 'down')) &&
  1132. !isPrimaryTouch(e)) return
  1133. firstTouch = _isPointerType ? e : e.touches[0]
  1134. if (e.touches && e.touches.length === 1 && touch.x2) {
  1135. // Clear out touch movement data if we have it sticking around
  1136. // This can occur if touchcancel doesn't fire due to preventDefault, etc.
  1137. touch.x2 = undefined
  1138. touch.y2 = undefined
  1139. }
  1140. now = Date.now()
  1141. delta = now - (touch.last || now)
  1142. touch.el = $('tagName' in firstTouch.target ?
  1143. firstTouch.target : firstTouch.target.parentNode)
  1144. touchTimeout && clearTimeout(touchTimeout)
  1145. touch.x1 = firstTouch.pageX
  1146. touch.y1 = firstTouch.pageY
  1147. if (delta > 0 && delta <= 250) touch.isDoubleTap = true
  1148. touch.last = now
  1149. longTapTimeout = setTimeout(longTap, longTapDelay)
  1150. // adds the current touch contact for IE gesture recognition
  1151. if (gesture && _isPointerType) gesture.addPointer(e.pointerId);
  1152. })
  1153. .on('touchmove MSPointerMove pointermove', function(e){
  1154. if((_isPointerType = isPointerEventType(e, 'move')) &&
  1155. !isPrimaryTouch(e)) return
  1156. firstTouch = _isPointerType ? e : e.touches[0]
  1157. cancelLongTap()
  1158. touch.x2 = firstTouch.pageX
  1159. touch.y2 = firstTouch.pageY
  1160. deltaX += Math.abs(touch.x1 - touch.x2)
  1161. deltaY += Math.abs(touch.y1 - touch.y2)
  1162. })
  1163. .on('touchend MSPointerUp pointerup', function(e){
  1164. if((_isPointerType = isPointerEventType(e, 'up')) &&
  1165. !isPrimaryTouch(e)) return
  1166. cancelLongTap()
  1167. // swipe
  1168. if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) ||
  1169. (touch.y2 && Math.abs(touch.y1 - touch.y2) > 30))
  1170. swipeTimeout = setTimeout(function() {
  1171. touch.el.trigger('swipe')
  1172. touch.el.trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2)))
  1173. touch = {}
  1174. }, 0)
  1175. // normal tap
  1176. else if ('last' in touch)
  1177. // don't fire tap when delta position changed by more than 30 pixels,
  1178. // for instance when moving to a point and back to origin
  1179. if (deltaX < 30 && deltaY < 30) {
  1180. // delay by one tick so we can cancel the 'tap' event if 'scroll' fires
  1181. // ('tap' fires before 'scroll')
  1182. tapTimeout = setTimeout(function() {
  1183. // trigger universal 'tap' with the option to cancelTouch()
  1184. // (cancelTouch cancels processing of single vs double taps for faster 'tap' response)
  1185. var event = $.Event('tap')
  1186. event.cancelTouch = cancelAll
  1187. touch.el.trigger(event)
  1188. // trigger double tap immediately
  1189. if (touch.isDoubleTap) {
  1190. if (touch.el) touch.el.trigger('doubleTap')
  1191. touch = {}
  1192. }
  1193. // trigger single tap after 250ms of inactivity
  1194. else {
  1195. touchTimeout = setTimeout(function(){
  1196. touchTimeout = null
  1197. if (touch.el) touch.el.trigger('singleTap')
  1198. touch = {}
  1199. }, 250)
  1200. }
  1201. }, 0)
  1202. } else {
  1203. touch = {}
  1204. }
  1205. deltaX = deltaY = 0
  1206. })
  1207. // when the browser window loses focus,
  1208. // for example when a modal dialog is shown,
  1209. // cancel all ongoing events
  1210. .on('touchcancel MSPointerCancel pointercancel', cancelAll)
  1211. // scrolling the window indicates intention of the user
  1212. // to scroll, not tap or swipe, so cancel all ongoing events
  1213. $(window).on('scroll', cancelAll)
  1214. })
  1215. ;['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown',
  1216. 'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(eventName){
  1217. $.fn[eventName] = function(callback){ return this.on(eventName, callback) }
  1218. })
  1219. })(Zepto)
  1220. // Zepto.js
  1221. // (c) 2010-2015 Thomas Fuchs
  1222. // Zepto.js may be freely distributed under the MIT license.
  1223. ;(function($){
  1224. var jsonpID = 0,
  1225. document = window.document,
  1226. key,
  1227. name,
  1228. rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
  1229. scriptTypeRE = /^(?:text|application)\/javascript/i,
  1230. xmlTypeRE = /^(?:text|application)\/xml/i,
  1231. jsonType = 'application/json',
  1232. htmlType = 'text/html',
  1233. blankRE = /^\s*$/,
  1234. originAnchor = document.createElement('a')
  1235. originAnchor.href = window.location.href
  1236. // trigger a custom event and return false if it was cancelled
  1237. function triggerAndReturn(context, eventName, data) {
  1238. var event = $.Event(eventName)
  1239. $(context).trigger(event, data)
  1240. return !event.isDefaultPrevented()
  1241. }
  1242. // trigger an Ajax "global" event
  1243. function triggerGlobal(settings, context, eventName, data) {
  1244. if (settings.global) return triggerAndReturn(context || document, eventName, data)
  1245. }
  1246. // Number of active Ajax requests
  1247. $.active = 0
  1248. function ajaxStart(settings) {
  1249. if (settings.global && $.active++ === 0) triggerGlobal(settings, null, 'ajaxStart')
  1250. }
  1251. function ajaxStop(settings) {
  1252. if (settings.global && !(--$.active)) triggerGlobal(settings, null, 'ajaxStop')
  1253. }
  1254. // triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable
  1255. function ajaxBeforeSend(xhr, settings) {
  1256. var context = settings.context
  1257. if (settings.beforeSend.call(context, xhr, settings) === false ||
  1258. triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false)
  1259. return false
  1260. triggerGlobal(settings, context, 'ajaxSend', [xhr, settings])
  1261. }
  1262. function ajaxSuccess(data, xhr, settings, deferred) {
  1263. var context = settings.context, status = 'success'
  1264. settings.success.call(context, data, status, xhr)
  1265. if (deferred) deferred.resolveWith(context, [data, status, xhr])
  1266. triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data])
  1267. ajaxComplete(status, xhr, settings)
  1268. }
  1269. // type: "timeout", "error", "abort", "parsererror"
  1270. function ajaxError(error, type, xhr, settings, deferred) {
  1271. var context = settings.context
  1272. settings.error.call(context, xhr, type, error)
  1273. if (deferred) deferred.rejectWith(context, [xhr, type, error])
  1274. triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error || type])
  1275. ajaxComplete(type, xhr, settings)
  1276. }
  1277. // status: "success", "notmodified", "error", "timeout", "abort", "parsererror"
  1278. function ajaxComplete(status, xhr, settings) {
  1279. var context = settings.context
  1280. settings.complete.call(context, xhr, status)
  1281. triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings])
  1282. ajaxStop(settings)
  1283. }
  1284. // Empty function, used as default callback
  1285. function empty() {}
  1286. $.ajaxJSONP = function(options, deferred){
  1287. if (!('type' in options)) return $.ajax(options)
  1288. var _callbackName = options.jsonpCallback,
  1289. callbackName = ($.isFunction(_callbackName) ?
  1290. _callbackName() : _callbackName) || ('jsonp' + (++jsonpID)),
  1291. script = document.createElement('script'),
  1292. originalCallback = window[callbackName],
  1293. responseData,
  1294. abort = function(errorType) {
  1295. $(script).triggerHandler('error', errorType || 'abort')
  1296. },
  1297. xhr = { abort: abort }, abortTimeout
  1298. if (deferred) deferred.promise(xhr)
  1299. $(script).on('load error', function(e, errorType){
  1300. clearTimeout(abortTimeout)
  1301. $(script).off().remove()
  1302. if (e.type == 'error' || !responseData) {
  1303. ajaxError(null, errorType || 'error', xhr, options, deferred)
  1304. } else {
  1305. ajaxSuccess(responseData[0], xhr, options, deferred)
  1306. }
  1307. window[callbackName] = originalCallback
  1308. if (responseData && $.isFunction(originalCallback))
  1309. originalCallback(responseData[0])
  1310. originalCallback = responseData = undefined
  1311. })
  1312. if (ajaxBeforeSend(xhr, options) === false) {
  1313. abort('abort')
  1314. return xhr
  1315. }
  1316. window[callbackName] = function(){
  1317. responseData = arguments
  1318. }
  1319. script.src = options.url.replace(/\?(.+)=\?/, '?$1=' + callbackName)
  1320. document.head.appendChild(script)
  1321. if (options.timeout > 0) abortTimeout = setTimeout(function(){
  1322. abort('timeout')
  1323. }, options.timeout)
  1324. return xhr
  1325. }
  1326. $.ajaxSettings = {
  1327. // Default type of request
  1328. type: 'GET',
  1329. // Callback that is executed before request
  1330. beforeSend: empty,
  1331. // Callback that is executed if the request succeeds
  1332. success: empty,
  1333. // Callback that is executed the the server drops error
  1334. error: empty,
  1335. // Callback that is executed on request complete (both: error and success)
  1336. complete: empty,
  1337. // The context for the callbacks
  1338. context: null,
  1339. // Whether to trigger "global" Ajax events
  1340. global: true,
  1341. // Transport
  1342. xhr: function () {
  1343. return new window.XMLHttpRequest()
  1344. },
  1345. // MIME types mapping
  1346. // IIS returns Javascript as "application/x-javascript"
  1347. accepts: {
  1348. script: 'text/javascript, application/javascript, application/x-javascript',
  1349. json: jsonType,
  1350. xml: 'application/xml, text/xml',
  1351. html: htmlType,
  1352. text: 'text/plain'
  1353. },
  1354. // Whether the request is to another domain
  1355. crossDomain: false,
  1356. // Default timeout
  1357. timeout: 0,
  1358. // Whether data should be serialized to string
  1359. processData: true,
  1360. // Whether the browser should be allowed to cache GET responses
  1361. cache: true
  1362. }
  1363. function mimeToDataType(mime) {
  1364. if (mime) mime = mime.split(';', 2)[0]
  1365. return mime && ( mime == htmlType ? 'html' :
  1366. mime == jsonType ? 'json' :
  1367. scriptTypeRE.test(mime) ? 'script' :
  1368. xmlTypeRE.test(mime) && 'xml' ) || 'text'
  1369. }
  1370. function appendQuery(url, query) {
  1371. if (query == '') return url
  1372. return (url + '&' + query).replace(/[&?]{1,2}/, '?')
  1373. }
  1374. // serialize payload and append it to the URL for GET requests
  1375. function serializeData(options) {
  1376. if (options.processData && options.data && $.type(options.data) != "string")
  1377. options.data = $.param(options.data, options.traditional)
  1378. if (options.data && (!options.type || options.type.toUpperCase() == 'GET'))
  1379. options.url = appendQuery(options.url, options.data), options.data = undefined
  1380. }
  1381. $.ajax = function(options){
  1382. var settings = $.extend({}, options || {}),
  1383. deferred = $.Deferred && $.Deferred(),
  1384. urlAnchor, hashIndex
  1385. for (key in $.ajaxSettings) if (settings[key] === undefined) settings[key] = $.ajaxSettings[key]
  1386. ajaxStart(settings)
  1387. if (!settings.crossDomain) {
  1388. urlAnchor = document.createElement('a')
  1389. urlAnchor.href = settings.url
  1390. // cleans up URL for .href (IE only), see https://github.com/madrobby/zepto/pull/1049
  1391. urlAnchor.href = urlAnchor.href
  1392. settings.crossDomain = (originAnchor.protocol + '//' + originAnchor.host) !== (urlAnchor.protocol + '//' + urlAnchor.host)
  1393. }
  1394. if (!settings.url) settings.url = window.location.toString()
  1395. if ((hashIndex = settings.url.indexOf('#')) > -1) settings.url = settings.url.slice(0, hashIndex)
  1396. serializeData(settings)
  1397. var dataType = settings.dataType, hasPlaceholder = /\?.+=\?/.test(settings.url)
  1398. if (hasPlaceholder) dataType = 'jsonp'
  1399. if (settings.cache === false || (
  1400. (!options || options.cache !== true) &&
  1401. ('script' == dataType || 'jsonp' == dataType)
  1402. ))
  1403. settings.url = appendQuery(settings.url, '_=' + Date.now())
  1404. if ('jsonp' == dataType) {
  1405. if (!hasPlaceholder)
  1406. settings.url = appendQuery(settings.url,
  1407. settings.jsonp ? (settings.jsonp + '=?') : settings.jsonp === false ? '' : 'callback=?')
  1408. return $.ajaxJSONP(settings, deferred)
  1409. }
  1410. var mime = settings.accepts[dataType],
  1411. headers = { },
  1412. setHeader = function(name, value) { headers[name.toLowerCase()] = [name, value] },
  1413. protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol,
  1414. xhr = settings.xhr(),
  1415. nativeSetHeader = xhr.setRequestHeader,
  1416. abortTimeout
  1417. if (deferred) deferred.promise(xhr)
  1418. if (!settings.crossDomain) setHeader('X-Requested-With', 'XMLHttpRequest')
  1419. setHeader('Accept', mime || '*/*')
  1420. if (mime = settings.mimeType || mime) {
  1421. if (mime.indexOf(',') > -1) mime = mime.split(',', 2)[0]
  1422. xhr.overrideMimeType && xhr.overrideMimeType(mime)
  1423. }
  1424. if (settings.contentType || (settings.contentType !== false && settings.data && settings.type.toUpperCase() != 'GET'))
  1425. setHeader('Content-Type', settings.contentType || 'application/x-www-form-urlencoded')
  1426. if (settings.headers) for (name in settings.headers) setHeader(name, settings.headers[name])
  1427. xhr.setRequestHeader = setHeader
  1428. xhr.onreadystatechange = function(){
  1429. if (xhr.readyState == 4) {
  1430. xhr.onreadystatechange = empty
  1431. clearTimeout(abortTimeout)
  1432. var result, error = false
  1433. if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) {
  1434. dataType = dataType || mimeToDataType(settings.mimeType || xhr.getResponseHeader('content-type'))
  1435. result = xhr.responseText
  1436. try {
  1437. // http://perfectionkills.com/global-eval-what-are-the-options/
  1438. if (dataType == 'script') (1,eval)(result)
  1439. else if (dataType == 'xml') result = xhr.responseXML
  1440. else if (dataType == 'json') result = blankRE.test(result) ? null : $.parseJSON(result)
  1441. } catch (e) { error = e }
  1442. if (error) ajaxError(error, 'parsererror', xhr, settings, deferred)
  1443. else ajaxSuccess(result, xhr, settings, deferred)
  1444. } else {
  1445. ajaxError(xhr.statusText || null, xhr.status ? 'error' : 'abort', xhr, settings, deferred)
  1446. }
  1447. }
  1448. }
  1449. if (ajaxBeforeSend(xhr, settings) === false) {
  1450. xhr.abort()
  1451. ajaxError(null, 'abort', xhr, settings, deferred)
  1452. return xhr
  1453. }
  1454. if (settings.xhrFields) for (name in settings.xhrFields) xhr[name] = settings.xhrFields[name]
  1455. var async = 'async' in settings ? settings.async : true
  1456. xhr.open(settings.type, settings.url, async, settings.username, settings.password)
  1457. for (name in headers) nativeSetHeader.apply(xhr, headers[name])
  1458. if (settings.timeout > 0) abortTimeout = setTimeout(function(){
  1459. xhr.onreadystatechange = empty
  1460. xhr.abort()
  1461. ajaxError(null, 'timeout', xhr, settings, deferred)
  1462. }, settings.timeout)
  1463. // avoid sending empty string (#319)
  1464. xhr.send(settings.data ? settings.data : null)
  1465. return xhr
  1466. }
  1467. // handle optional data/success arguments
  1468. function parseArguments(url, data, success, dataType) {
  1469. if ($.isFunction(data)) dataType = success, success = data, data = undefined
  1470. if (!$.isFunction(success)) dataType = success, success = undefined
  1471. return {
  1472. url: url
  1473. , data: data
  1474. , success: success
  1475. , dataType: dataType
  1476. }
  1477. }
  1478. $.get = function(/* url, data, success, dataType */){
  1479. return $.ajax(parseArguments.apply(null, arguments))
  1480. }
  1481. $.post = function(/* url, data, success, dataType */){
  1482. var options = parseArguments.apply(null, arguments)
  1483. options.type = 'POST'
  1484. return $.ajax(options)
  1485. }
  1486. $.getJSON = function(/* url, data, success */){
  1487. var options = parseArguments.apply(null, arguments)
  1488. options.dataType = 'json'
  1489. return $.ajax(options)
  1490. }
  1491. $.fn.load = function(url, data, success){
  1492. if (!this.length) return this
  1493. var self = this, parts = url.split(/\s/), selector,
  1494. options = parseArguments(url, data, success),
  1495. callback = options.success
  1496. if (parts.length > 1) options.url = parts[0], selector = parts[1]
  1497. options.success = function(response){
  1498. self.html(selector ?
  1499. $('<div>').html(response.replace(rscript, "")).find(selector)
  1500. : response)
  1501. callback && callback.apply(self, arguments)
  1502. }
  1503. $.ajax(options)
  1504. return this
  1505. }
  1506. var escape = encodeURIComponent
  1507. function serialize(params, obj, traditional, scope){
  1508. var type, array = $.isArray(obj), hash = $.isPlainObject(obj)
  1509. $.each(obj, function(key, value) {
  1510. type = $.type(value)
  1511. if (scope) key = traditional ? scope :
  1512. scope + '[' + (hash || type == 'object' || type == 'array' ? key : '') + ']'
  1513. // handle data in serializeArray() format
  1514. if (!scope && array) params.add(value.name, value.value)
  1515. // recurse into nested objects
  1516. else if (type == "array" || (!traditional && type == "object"))
  1517. serialize(params, value, traditional, key)
  1518. else params.add(key, value)
  1519. })
  1520. }
  1521. $.param = function(obj, traditional){
  1522. var params = []
  1523. params.add = function(key, value) {
  1524. if ($.isFunction(value)) value = value()
  1525. if (value == null) value = ""
  1526. this.push(escape(key) + '=' + escape(value))
  1527. }
  1528. serialize(params, obj, traditional)
  1529. return params.join('&').replace(/%20/g, '+')
  1530. }
  1531. })(Zepto)
  1532. // Zepto.js
  1533. // (c) 2010-2015 Thomas Fuchs
  1534. // Zepto.js may be freely distributed under the MIT license.
  1535. ;(function(){
  1536. // getComputedStyle shouldn't freak out when called
  1537. // without a valid element as argument
  1538. try {
  1539. getComputedStyle(undefined)
  1540. } catch(e) {
  1541. var nativeGetComputedStyle = getComputedStyle;
  1542. window.getComputedStyle = function(element){
  1543. try {
  1544. return nativeGetComputedStyle(element)
  1545. } catch(e) {
  1546. return null
  1547. }
  1548. }
  1549. }
  1550. })()
  1551. // Zepto.js
  1552. // (c) 2010-2015 Thomas Fuchs
  1553. // Zepto.js may be freely distributed under the MIT license.
  1554. ;(function($){
  1555. $.fn.serializeArray = function() {
  1556. var name, type, result = [],
  1557. add = function(value) {
  1558. if (value.forEach) return value.forEach(add)
  1559. result.push({ name: name, value: value })
  1560. }
  1561. if (this[0]) $.each(this[0].elements, function(_, field){
  1562. type = field.type, name = field.name
  1563. if (name && field.nodeName.toLowerCase() != 'fieldset' &&
  1564. !field.disabled && type != 'submit' && type != 'reset' && type != 'button' && type != 'file' &&
  1565. ((type != 'radio' && type != 'checkbox') || field.checked))
  1566. add($(field).val())
  1567. })
  1568. return result
  1569. }
  1570. $.fn.serialize = function(){
  1571. var result = []
  1572. this.serializeArray().forEach(function(elm){
  1573. result.push(encodeURIComponent(elm.name) + '=' + encodeURIComponent(elm.value))
  1574. })
  1575. return result.join('&')
  1576. }
  1577. $.fn.submit = function(callback) {
  1578. if (0 in arguments) this.bind('submit', callback)
  1579. else if (this.length) {
  1580. var event = $.Event('submit')
  1581. this.eq(0).trigger(event)
  1582. if (!event.isDefaultPrevented()) this.get(0).submit()
  1583. }
  1584. return this
  1585. }
  1586. })(Zepto)