zepto.js 70 KB

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