f0a23607d169e2253b1485673e5d3c3f2fffefd0.svn-base 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483
  1. /* Zepto 1.1.6 - zepto event ajax form fx data deferred callbacks selector touch - zeptojs.com/license */ ;
  2. (function(root, factory) {
  3. //amd
  4. if (typeof define === 'function' && define.amd) {
  5. define([], factory);
  6. } else if (typeof exports === 'object') { //umd
  7. module.exports = factory();
  8. } else {
  9. root.MobilePhotoPreview = factory();
  10. }
  11. })(this, function() {
  12. var Zepto = (function() {
  13. var undefined, key, $, classList, emptyArray = [],
  14. concat = emptyArray.concat,
  15. filter = emptyArray.filter,
  16. slice = emptyArray.slice,
  17. document = window.document,
  18. elementDisplay = {},
  19. classCache = {},
  20. cssNumber = {
  21. 'column-count': 1,
  22. 'columns': 1,
  23. 'font-weight': 1,
  24. 'line-height': 1,
  25. 'opacity': 1,
  26. 'z-index': 1,
  27. 'zoom': 1
  28. },
  29. fragmentRE = /^\s*<(\w+|!)[^>]*>/,
  30. singleTagRE = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,
  31. tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,
  32. rootNodeRE = /^(?:body|html)$/i,
  33. capitalRE = /([A-Z])/g,
  34. // special attributes that should be get/set via method calls
  35. methodAttributes = ['val', 'css', 'html', 'text', 'data', 'width', 'height', 'offset'],
  36. adjacencyOperators = ['after', 'prepend', 'before', 'append'],
  37. table = document.createElement('table'),
  38. tableRow = document.createElement('tr'),
  39. containers = {
  40. 'tr': document.createElement('tbody'),
  41. 'tbody': table,
  42. 'thead': table,
  43. 'tfoot': table,
  44. 'td': tableRow,
  45. 'th': tableRow,
  46. '*': document.createElement('div')
  47. },
  48. readyRE = /complete|loaded|interactive/,
  49. simpleSelectorRE = /^[\w-]*$/,
  50. class2type = {},
  51. toString = class2type.toString,
  52. zepto = {},
  53. camelize, uniq,
  54. tempParent = document.createElement('div'),
  55. propMap = {
  56. 'tabindex': 'tabIndex',
  57. 'readonly': 'readOnly',
  58. 'for': 'htmlFor',
  59. 'class': 'className',
  60. 'maxlength': 'maxLength',
  61. 'cellspacing': 'cellSpacing',
  62. 'cellpadding': 'cellPadding',
  63. 'rowspan': 'rowSpan',
  64. 'colspan': 'colSpan',
  65. 'usemap': 'useMap',
  66. 'frameborder': 'frameBorder',
  67. 'contenteditable': 'contentEditable'
  68. },
  69. isArray = Array.isArray ||
  70. function(object) {
  71. return object instanceof Array
  72. }
  73. zepto.matches = function(element, selector) {
  74. if (!selector || !element || element.nodeType !== 1) return false
  75. var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector ||
  76. element.oMatchesSelector || element.matchesSelector
  77. if (matchesSelector) return matchesSelector.call(element, selector)
  78. // fall back to performing a selector:
  79. var match, parent = element.parentNode,
  80. temp = !parent
  81. if (temp)(parent = tempParent).appendChild(element)
  82. match = ~zepto.qsa(parent, selector).indexOf(element)
  83. temp && tempParent.removeChild(element)
  84. return match
  85. }
  86. function type(obj) {
  87. return obj == null ? String(obj) :
  88. class2type[toString.call(obj)] || "object"
  89. }
  90. function isFunction(value) {
  91. return type(value) == "function"
  92. }
  93. function isWindow(obj) {
  94. return obj != null && obj == obj.window
  95. }
  96. function isDocument(obj) {
  97. return obj != null && obj.nodeType == obj.DOCUMENT_NODE
  98. }
  99. function isObject(obj) {
  100. return type(obj) == "object"
  101. }
  102. function isPlainObject(obj) {
  103. return isObject(obj) && !isWindow(obj) && Object.getPrototypeOf(obj) == Object.prototype
  104. }
  105. function likeArray(obj) {
  106. return typeof obj.length == 'number'
  107. }
  108. function compact(array) {
  109. return filter.call(array, function(item) {
  110. return item != null
  111. })
  112. }
  113. function flatten(array) {
  114. return array.length > 0 ? $.fn.concat.apply([], array) : array
  115. }
  116. camelize = function(str) {
  117. return str.replace(/-+(.)?/g, function(match, chr) {
  118. return chr ? chr.toUpperCase() : ''
  119. })
  120. }
  121. function dasherize(str) {
  122. return str.replace(/::/g, '/')
  123. .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
  124. .replace(/([a-z\d])([A-Z])/g, '$1_$2')
  125. .replace(/_/g, '-')
  126. .toLowerCase()
  127. }
  128. uniq = function(array) {
  129. return filter.call(array, function(item, idx) {
  130. return array.indexOf(item) == idx
  131. })
  132. }
  133. function classRE(name) {
  134. return name in classCache ?
  135. classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)'))
  136. }
  137. function maybeAddPx(name, value) {
  138. return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value
  139. }
  140. function defaultDisplay(nodeName) {
  141. var element, display
  142. if (!elementDisplay[nodeName]) {
  143. element = document.createElement(nodeName)
  144. document.body.appendChild(element)
  145. display = getComputedStyle(element, '').getPropertyValue("display")
  146. element.parentNode.removeChild(element)
  147. display == "none" && (display = "block")
  148. elementDisplay[nodeName] = display
  149. }
  150. return elementDisplay[nodeName]
  151. }
  152. function children(element) {
  153. return 'children' in element ?
  154. slice.call(element.children) :
  155. $.map(element.childNodes, function(node) {
  156. if (node.nodeType == 1) return node
  157. })
  158. }
  159. function Z(dom, selector) {
  160. var i, len = dom ? dom.length : 0
  161. for (i = 0; i < len; i++) this[i] = dom[i]
  162. this.length = len
  163. this.selector = selector || ''
  164. }
  165. // `$.zepto.fragment` takes a html string and an optional tag name
  166. // to generate DOM nodes nodes from the given html string.
  167. // The generated DOM nodes are returned as an array.
  168. // This function can be overriden in plugins for example to make
  169. // it compatible with browsers that don't support the DOM fully.
  170. zepto.fragment = function(html, name, properties) {
  171. var dom, nodes, container
  172. // A special case optimization for a single tag
  173. if (singleTagRE.test(html)) dom = $(document.createElement(RegExp.$1))
  174. if (!dom) {
  175. if (html.replace) html = html.replace(tagExpanderRE, "<$1></$2>")
  176. if (name === undefined) name = fragmentRE.test(html) && RegExp.$1
  177. if (!(name in containers)) name = '*'
  178. container = containers[name]
  179. container.innerHTML = '' + html
  180. dom = $.each(slice.call(container.childNodes), function() {
  181. container.removeChild(this)
  182. })
  183. }
  184. if (isPlainObject(properties)) {
  185. nodes = $(dom)
  186. $.each(properties, function(key, value) {
  187. if (methodAttributes.indexOf(key) > -1) nodes[key](value)
  188. else nodes.attr(key, value)
  189. })
  190. }
  191. return dom
  192. }
  193. // `$.zepto.Z` swaps out the prototype of the given `dom` array
  194. // of nodes with `$.fn` and thus supplying all the Zepto functions
  195. // to the array. This method can be overriden in plugins.
  196. zepto.Z = function(dom, selector) {
  197. return new Z(dom, selector)
  198. }
  199. // `$.zepto.isZ` should return `true` if the given object is a Zepto
  200. // collection. This method can be overriden in plugins.
  201. zepto.isZ = function(object) {
  202. return object instanceof zepto.Z
  203. }
  204. // `$.zepto.init` is Zepto's counterpart to jQuery's `$.fn.init` and
  205. // takes a CSS selector and an optional context (and handles various
  206. // special cases).
  207. // This method can be overriden in plugins.
  208. zepto.init = function(selector, context) {
  209. var dom
  210. // If nothing given, return an empty Zepto collection
  211. if (!selector) return zepto.Z()
  212. // Optimize for string selectors
  213. else if (typeof selector == 'string') {
  214. selector = selector.trim()
  215. // If it's a html fragment, create nodes from it
  216. // Note: In both Chrome 21 and Firefox 15, DOM error 12
  217. // is thrown if the fragment doesn't begin with <
  218. if (selector[0] == '<' && fragmentRE.test(selector))
  219. dom = zepto.fragment(selector, RegExp.$1, context), selector = null
  220. // If there's a context, create a collection on that context first, and select
  221. // nodes from there
  222. else if (context !== undefined) return $(context).find(selector)
  223. // If it's a CSS selector, use it to select nodes.
  224. else dom = zepto.qsa(document, selector)
  225. }
  226. // If a function is given, call it when the DOM is ready
  227. else if (isFunction(selector)) return $(document).ready(selector)
  228. // If a Zepto collection is given, just return it
  229. else if (zepto.isZ(selector)) return selector
  230. else {
  231. // normalize array if an array of nodes is given
  232. if (isArray(selector)) dom = compact(selector)
  233. // Wrap DOM nodes.
  234. else if (isObject(selector))
  235. dom = [selector], selector = null
  236. // If it's a html fragment, create nodes from it
  237. else if (fragmentRE.test(selector))
  238. dom = zepto.fragment(selector.trim(), RegExp.$1, context), selector = null
  239. // If there's a context, create a collection on that context first, and select
  240. // nodes from there
  241. else if (context !== undefined) return $(context).find(selector)
  242. // And last but no least, if it's a CSS selector, use it to select nodes.
  243. else dom = zepto.qsa(document, selector)
  244. }
  245. // create a new Zepto collection from the nodes found
  246. return zepto.Z(dom, selector)
  247. }
  248. // `$` will be the base `Zepto` object. When calling this
  249. // function just call `$.zepto.init, which makes the implementation
  250. // details of selecting nodes and creating Zepto collections
  251. // patchable in plugins.
  252. $ = function(selector, context) {
  253. return zepto.init(selector, context)
  254. }
  255. function extend(target, source, deep) {
  256. for (key in source)
  257. if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
  258. if (isPlainObject(source[key]) && !isPlainObject(target[key]))
  259. target[key] = {}
  260. if (isArray(source[key]) && !isArray(target[key]))
  261. target[key] = []
  262. extend(target[key], source[key], deep)
  263. } else if (source[key] !== undefined) target[key] = source[key]
  264. }
  265. // Copy all but undefined properties from one or more
  266. // objects to the `target` object.
  267. $.extend = function(target) {
  268. var deep, args = slice.call(arguments, 1)
  269. if (typeof target == 'boolean') {
  270. deep = target
  271. target = args.shift()
  272. }
  273. args.forEach(function(arg) {
  274. extend(target, arg, deep)
  275. })
  276. return target
  277. }
  278. // `$.zepto.qsa` is Zepto's CSS selector implementation which
  279. // uses `document.querySelectorAll` and optimizes for some special cases, like `#id`.
  280. // This method can be overriden in plugins.
  281. zepto.qsa = function(element, selector) {
  282. var found,
  283. maybeID = selector[0] == '#',
  284. maybeClass = !maybeID && selector[0] == '.',
  285. nameOnly = maybeID || maybeClass ? selector.slice(1) : selector, // Ensure that a 1 char tag name still gets checked
  286. isSimple = simpleSelectorRE.test(nameOnly)
  287. return (element.getElementById && isSimple && maybeID) ? // Safari DocumentFragment doesn't have getElementById
  288. ((found = element.getElementById(nameOnly)) ? [found] : []) :
  289. (element.nodeType !== 1 && element.nodeType !== 9 && element.nodeType !== 11) ? [] :
  290. slice.call(
  291. isSimple && !maybeID && element.getElementsByClassName ? // DocumentFragment doesn't have getElementsByClassName/TagName
  292. maybeClass ? element.getElementsByClassName(nameOnly) : // If it's simple, it could be a class
  293. element.getElementsByTagName(selector) : // Or a tag
  294. element.querySelectorAll(selector) // Or it's not simple, and we need to query all
  295. )
  296. }
  297. function filtered(nodes, selector) {
  298. return selector == null ? $(nodes) : $(nodes).filter(selector)
  299. }
  300. $.contains = document.documentElement.contains ?
  301. function(parent, node) {
  302. return parent !== node && parent.contains(node)
  303. } :
  304. function(parent, node) {
  305. while (node && (node = node.parentNode))
  306. if (node === parent) return true
  307. return false
  308. }
  309. function funcArg(context, arg, idx, payload) {
  310. return isFunction(arg) ? arg.call(context, idx, payload) : arg
  311. }
  312. function setAttribute(node, name, value) {
  313. value == null ? node.removeAttribute(name) : node.setAttribute(name, value)
  314. }
  315. // access className property while respecting SVGAnimatedString
  316. function className(node, value) {
  317. var klass = node.className || '',
  318. svg = klass && klass.baseVal !== undefined
  319. if (value === undefined) return svg ? klass.baseVal : klass
  320. svg ? (klass.baseVal = value) : (node.className = value)
  321. }
  322. // "true" => true
  323. // "false" => false
  324. // "null" => null
  325. // "42" => 42
  326. // "42.5" => 42.5
  327. // "08" => "08"
  328. // JSON => parse if valid
  329. // String => self
  330. function deserializeValue(value) {
  331. try {
  332. return value ?
  333. value == "true" ||
  334. (value == "false" ? false :
  335. value == "null" ? null :
  336. +value + "" == value ? +value :
  337. /^[\[\{]/.test(value) ? $.parseJSON(value) :
  338. value) : value
  339. } catch (e) {
  340. return value
  341. }
  342. }
  343. $.type = type
  344. $.isFunction = isFunction
  345. $.isWindow = isWindow
  346. $.isArray = isArray
  347. $.isPlainObject = isPlainObject
  348. $.isEmptyObject = function(obj) {
  349. var name
  350. for (name in obj) return false
  351. return true
  352. }
  353. $.inArray = function(elem, array, i) {
  354. return emptyArray.indexOf.call(array, elem, i)
  355. }
  356. $.camelCase = camelize
  357. $.trim = function(str) {
  358. return str == null ? "" : String.prototype.trim.call(str)
  359. }
  360. // plugin compatibility
  361. $.uuid = 0
  362. $.support = {}
  363. $.expr = {}
  364. $.noop = function() {}
  365. $.map = function(elements, callback) {
  366. var value, values = [],
  367. i, key
  368. if (likeArray(elements))
  369. for (i = 0; i < elements.length; i++) {
  370. value = callback(elements[i], i)
  371. if (value != null) values.push(value)
  372. } else
  373. for (key in elements) {
  374. value = callback(elements[key], key)
  375. if (value != null) values.push(value)
  376. }
  377. return flatten(values)
  378. }
  379. $.each = function(elements, callback) {
  380. var i, key
  381. if (likeArray(elements)) {
  382. for (i = 0; i < elements.length; i++)
  383. if (callback.call(elements[i], i, elements[i]) === false) return elements
  384. } else {
  385. for (key in elements)
  386. if (callback.call(elements[key], key, elements[key]) === false) return elements
  387. }
  388. return elements
  389. }
  390. $.grep = function(elements, callback) {
  391. return filter.call(elements, callback)
  392. }
  393. if (window.JSON) $.parseJSON = JSON.parse
  394. // Populate the class2type map
  395. $.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
  396. class2type["[object " + name + "]"] = name.toLowerCase()
  397. })
  398. // Define methods that will be available on all
  399. // Zepto collections
  400. $.fn = {
  401. constructor: zepto.Z,
  402. length: 0,
  403. // Because a collection acts like an array
  404. // copy over these useful array functions.
  405. forEach: emptyArray.forEach,
  406. reduce: emptyArray.reduce,
  407. push: emptyArray.push,
  408. sort: emptyArray.sort,
  409. splice: emptyArray.splice,
  410. indexOf: emptyArray.indexOf,
  411. concat: function() {
  412. var i, value, args = []
  413. for (i = 0; i < arguments.length; i++) {
  414. value = arguments[i]
  415. args[i] = zepto.isZ(value) ? value.toArray() : value
  416. }
  417. return concat.apply(zepto.isZ(this) ? this.toArray() : this, args)
  418. },
  419. // `map` and `slice` in the jQuery API work differently
  420. // from their array counterparts
  421. map: function(fn) {
  422. return $($.map(this, function(el, i) {
  423. return fn.call(el, i, el)
  424. }))
  425. },
  426. slice: function() {
  427. return $(slice.apply(this, arguments))
  428. },
  429. ready: function(callback) {
  430. // need to check if document.body exists for IE as that browser reports
  431. // document ready when it hasn't yet created the body element
  432. if (readyRE.test(document.readyState) && document.body) callback($)
  433. else document.addEventListener('DOMContentLoaded', function() {
  434. callback($)
  435. }, false)
  436. return this
  437. },
  438. get: function(idx) {
  439. return idx === undefined ? slice.call(this) : this[idx >= 0 ? idx : idx + this.length]
  440. },
  441. toArray: function() {
  442. return this.get()
  443. },
  444. size: function() {
  445. return this.length
  446. },
  447. remove: function() {
  448. return this.each(function() {
  449. if (this.parentNode != null)
  450. this.parentNode.removeChild(this)
  451. })
  452. },
  453. each: function(callback) {
  454. emptyArray.every.call(this, function(el, idx) {
  455. return callback.call(el, idx, el) !== false
  456. })
  457. return this
  458. },
  459. filter: function(selector) {
  460. if (isFunction(selector)) return this.not(this.not(selector))
  461. return $(filter.call(this, function(element) {
  462. return zepto.matches(element, selector)
  463. }))
  464. },
  465. add: function(selector, context) {
  466. return $(uniq(this.concat($(selector, context))))
  467. },
  468. is: function(selector) {
  469. return this.length > 0 && zepto.matches(this[0], selector)
  470. },
  471. not: function(selector) {
  472. var nodes = []
  473. if (isFunction(selector) && selector.call !== undefined)
  474. this.each(function(idx) {
  475. if (!selector.call(this, idx)) nodes.push(this)
  476. })
  477. else {
  478. var excludes = typeof selector == 'string' ? this.filter(selector) :
  479. (likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector)
  480. this.forEach(function(el) {
  481. if (excludes.indexOf(el) < 0) nodes.push(el)
  482. })
  483. }
  484. return $(nodes)
  485. },
  486. has: function(selector) {
  487. return this.filter(function() {
  488. return isObject(selector) ?
  489. $.contains(this, selector) :
  490. $(this).find(selector).size()
  491. })
  492. },
  493. eq: function(idx) {
  494. return idx === -1 ? this.slice(idx) : this.slice(idx, +idx + 1)
  495. },
  496. first: function() {
  497. var el = this[0]
  498. return el && !isObject(el) ? el : $(el)
  499. },
  500. last: function() {
  501. var el = this[this.length - 1]
  502. return el && !isObject(el) ? el : $(el)
  503. },
  504. find: function(selector) {
  505. var result, $this = this
  506. if (!selector) result = $()
  507. else if (typeof selector == 'object')
  508. result = $(selector).filter(function() {
  509. var node = this
  510. return emptyArray.some.call($this, function(parent) {
  511. return $.contains(parent, node)
  512. })
  513. })
  514. else if (this.length == 1) result = $(zepto.qsa(this[0], selector))
  515. else result = this.map(function() {
  516. return zepto.qsa(this, selector)
  517. })
  518. return result
  519. },
  520. closest: function(selector, context) {
  521. var node = this[0],
  522. collection = false
  523. if (typeof selector == 'object') collection = $(selector)
  524. while (node && !(collection ? collection.indexOf(node) >= 0 : zepto.matches(node, selector)))
  525. node = node !== context && !isDocument(node) && node.parentNode
  526. return $(node)
  527. },
  528. parents: function(selector) {
  529. var ancestors = [],
  530. nodes = this
  531. while (nodes.length > 0)
  532. nodes = $.map(nodes, function(node) {
  533. if ((node = node.parentNode) && !isDocument(node) && ancestors.indexOf(node) < 0) {
  534. ancestors.push(node)
  535. return node
  536. }
  537. })
  538. return filtered(ancestors, selector)
  539. },
  540. parent: function(selector) {
  541. return filtered(uniq(this.pluck('parentNode')), selector)
  542. },
  543. children: function(selector) {
  544. return filtered(this.map(function() {
  545. return children(this)
  546. }), selector)
  547. },
  548. contents: function() {
  549. return this.map(function() {
  550. return this.contentDocument || slice.call(this.childNodes)
  551. })
  552. },
  553. siblings: function(selector) {
  554. return filtered(this.map(function(i, el) {
  555. return filter.call(children(el.parentNode), function(child) {
  556. return child !== el
  557. })
  558. }), selector)
  559. },
  560. empty: function() {
  561. return this.each(function() {
  562. this.innerHTML = ''
  563. })
  564. },
  565. // `pluck` is borrowed from Prototype.js
  566. pluck: function(property) {
  567. return $.map(this, function(el) {
  568. return el[property]
  569. })
  570. },
  571. show: function() {
  572. return this.each(function() {
  573. this.style.display == "none" && (this.style.display = '')
  574. if (getComputedStyle(this, '').getPropertyValue("display") == "none")
  575. this.style.display = defaultDisplay(this.nodeName)
  576. })
  577. },
  578. replaceWith: function(newContent) {
  579. return this.before(newContent).remove()
  580. },
  581. wrap: function(structure) {
  582. var func = isFunction(structure)
  583. if (this[0] && !func)
  584. var dom = $(structure).get(0),
  585. clone = dom.parentNode || this.length > 1
  586. return this.each(function(index) {
  587. $(this).wrapAll(
  588. func ? structure.call(this, index) :
  589. clone ? dom.cloneNode(true) : dom
  590. )
  591. })
  592. },
  593. wrapAll: function(structure) {
  594. if (this[0]) {
  595. $(this[0]).before(structure = $(structure))
  596. var children
  597. // drill down to the inmost element
  598. while ((children = structure.children()).length) structure = children.first()
  599. $(structure).append(this)
  600. }
  601. return this
  602. },
  603. wrapInner: function(structure) {
  604. var func = isFunction(structure)
  605. return this.each(function(index) {
  606. var self = $(this),
  607. contents = self.contents(),
  608. dom = func ? structure.call(this, index) : structure
  609. contents.length ? contents.wrapAll(dom) : self.append(dom)
  610. })
  611. },
  612. unwrap: function() {
  613. this.parent().each(function() {
  614. $(this).replaceWith($(this).children())
  615. })
  616. return this
  617. },
  618. clone: function() {
  619. return this.map(function() {
  620. return this.cloneNode(true)
  621. })
  622. },
  623. hide: function() {
  624. return this.css("display", "none")
  625. },
  626. toggle: function(setting) {
  627. return this.each(function() {
  628. var el = $(this);
  629. (setting === undefined ? el.css("display") == "none" : setting) ? el.show() : el.hide()
  630. })
  631. },
  632. prev: function(selector) {
  633. return $(this.pluck('previousElementSibling')).filter(selector || '*')
  634. },
  635. next: function(selector) {
  636. return $(this.pluck('nextElementSibling')).filter(selector || '*')
  637. },
  638. html: function(html) {
  639. return 0 in arguments ?
  640. this.each(function(idx) {
  641. var originHtml = this.innerHTML
  642. $(this).empty().append(funcArg(this, html, idx, originHtml))
  643. }) :
  644. (0 in this ? this[0].innerHTML : null)
  645. },
  646. text: function(text) {
  647. return 0 in arguments ?
  648. this.each(function(idx) {
  649. var newText = funcArg(this, text, idx, this.textContent)
  650. this.textContent = newText == null ? '' : '' + newText
  651. }) :
  652. (0 in this ? this[0].textContent : null)
  653. },
  654. attr: function(name, value) {
  655. var result
  656. return (typeof name == 'string' && !(1 in arguments)) ?
  657. (!this.length || this[0].nodeType !== 1 ? undefined :
  658. (!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result
  659. ) :
  660. this.each(function(idx) {
  661. if (this.nodeType !== 1) return
  662. if (isObject(name))
  663. for (key in name) setAttribute(this, key, name[key])
  664. else setAttribute(this, name, funcArg(this, value, idx, this.getAttribute(name)))
  665. })
  666. },
  667. removeAttr: function(name) {
  668. return this.each(function() {
  669. this.nodeType === 1 && name.split(' ').forEach(function(attribute) {
  670. setAttribute(this, attribute)
  671. }, this)
  672. })
  673. },
  674. prop: function(name, value) {
  675. name = propMap[name] || name
  676. return (1 in arguments) ?
  677. this.each(function(idx) {
  678. this[name] = funcArg(this, value, idx, this[name])
  679. }) :
  680. (this[0] && this[0][name])
  681. },
  682. data: function(name, value) {
  683. var attrName = 'data-' + name.replace(capitalRE, '-$1').toLowerCase()
  684. var data = (1 in arguments) ?
  685. this.attr(attrName, value) :
  686. this.attr(attrName)
  687. return data !== null ? deserializeValue(data) : undefined
  688. },
  689. val: function(value) {
  690. return 0 in arguments ?
  691. this.each(function(idx) {
  692. this.value = funcArg(this, value, idx, this.value)
  693. }) :
  694. (this[0] && (this[0].multiple ?
  695. $(this[0]).find('option').filter(function() {
  696. return this.selected
  697. }).pluck('value') :
  698. this[0].value))
  699. },
  700. offset: function(coordinates) {
  701. if (coordinates) return this.each(function(index) {
  702. var $this = $(this),
  703. coords = funcArg(this, coordinates, index, $this.offset()),
  704. parentOffset = $this.offsetParent().offset(),
  705. props = {
  706. top: coords.top - parentOffset.top,
  707. left: coords.left - parentOffset.left
  708. }
  709. if ($this.css('position') == 'static') props['position'] = 'relative'
  710. $this.css(props)
  711. })
  712. if (!this.length) return null
  713. if (!$.contains(document.documentElement, this[0]))
  714. return {
  715. top: 0,
  716. left: 0
  717. }
  718. var obj = this[0].getBoundingClientRect()
  719. return {
  720. left: obj.left + window.pageXOffset,
  721. top: obj.top + window.pageYOffset,
  722. width: Math.round(obj.width),
  723. height: Math.round(obj.height)
  724. }
  725. },
  726. css: function(property, value) {
  727. if (arguments.length < 2) {
  728. var computedStyle, element = this[0]
  729. if (!element) return
  730. computedStyle = getComputedStyle(element, '')
  731. if (typeof property == 'string')
  732. return element.style[camelize(property)] || computedStyle.getPropertyValue(property)
  733. else if (isArray(property)) {
  734. var props = {}
  735. $.each(property, function(_, prop) {
  736. props[prop] = (element.style[camelize(prop)] || computedStyle.getPropertyValue(prop))
  737. })
  738. return props
  739. }
  740. }
  741. var css = ''
  742. if (type(property) == 'string') {
  743. if (!value && value !== 0)
  744. this.each(function() {
  745. this.style.removeProperty(dasherize(property))
  746. })
  747. else
  748. css = dasherize(property) + ":" + maybeAddPx(property, value)
  749. } else {
  750. for (key in property)
  751. if (!property[key] && property[key] !== 0)
  752. this.each(function() {
  753. this.style.removeProperty(dasherize(key))
  754. })
  755. else
  756. css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';'
  757. }
  758. return this.each(function() {
  759. this.style.cssText += ';' + css
  760. })
  761. },
  762. index: function(element) {
  763. return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0])
  764. },
  765. hasClass: function(name) {
  766. if (!name) return false
  767. return emptyArray.some.call(this, function(el) {
  768. return this.test(className(el))
  769. }, classRE(name))
  770. },
  771. addClass: function(name) {
  772. if (!name) return this
  773. return this.each(function(idx) {
  774. if (!('className' in this)) return
  775. classList = []
  776. var cls = className(this),
  777. newName = funcArg(this, name, idx, cls)
  778. newName.split(/\s+/g).forEach(function(klass) {
  779. if (!$(this).hasClass(klass)) classList.push(klass)
  780. }, this)
  781. classList.length && className(this, cls + (cls ? " " : "") + classList.join(" "))
  782. })
  783. },
  784. removeClass: function(name) {
  785. return this.each(function(idx) {
  786. if (!('className' in this)) return
  787. if (name === undefined) return className(this, '')
  788. classList = className(this)
  789. funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass) {
  790. classList = classList.replace(classRE(klass), " ")
  791. })
  792. className(this, classList.trim())
  793. })
  794. },
  795. toggleClass: function(name, when) {
  796. if (!name) return this
  797. return this.each(function(idx) {
  798. var $this = $(this),
  799. names = funcArg(this, name, idx, className(this))
  800. names.split(/\s+/g).forEach(function(klass) {
  801. (when === undefined ? !$this.hasClass(klass) : when) ?
  802. $this.addClass(klass) : $this.removeClass(klass)
  803. })
  804. })
  805. },
  806. scrollTop: function(value) {
  807. if (!this.length) return
  808. var hasScrollTop = 'scrollTop' in this[0]
  809. if (value === undefined) return hasScrollTop ? this[0].scrollTop : this[0].pageYOffset
  810. return this.each(hasScrollTop ?
  811. function() {
  812. this.scrollTop = value
  813. } :
  814. function() {
  815. this.scrollTo(this.scrollX, value)
  816. })
  817. },
  818. scrollLeft: function(value) {
  819. if (!this.length) return
  820. var hasScrollLeft = 'scrollLeft' in this[0]
  821. if (value === undefined) return hasScrollLeft ? this[0].scrollLeft : this[0].pageXOffset
  822. return this.each(hasScrollLeft ?
  823. function() {
  824. this.scrollLeft = value
  825. } :
  826. function() {
  827. this.scrollTo(value, this.scrollY)
  828. })
  829. },
  830. position: function() {
  831. if (!this.length) return
  832. var elem = this[0],
  833. // Get *real* offsetParent
  834. offsetParent = this.offsetParent(),
  835. // Get correct offsets
  836. offset = this.offset(),
  837. parentOffset = rootNodeRE.test(offsetParent[0].nodeName) ? {
  838. top: 0,
  839. left: 0
  840. } : offsetParent.offset()
  841. // Subtract element margins
  842. // note: when an element has margin: auto the offsetLeft and marginLeft
  843. // are the same in Safari causing offset.left to incorrectly be 0
  844. offset.top -= parseFloat($(elem).css('margin-top')) || 0
  845. offset.left -= parseFloat($(elem).css('margin-left')) || 0
  846. // Add offsetParent borders
  847. parentOffset.top += parseFloat($(offsetParent[0]).css('border-top-width')) || 0
  848. parentOffset.left += parseFloat($(offsetParent[0]).css('border-left-width')) || 0
  849. // Subtract the two offsets
  850. return {
  851. top: offset.top - parentOffset.top,
  852. left: offset.left - parentOffset.left
  853. }
  854. },
  855. offsetParent: function() {
  856. return this.map(function() {
  857. var parent = this.offsetParent || document.body
  858. while (parent && !rootNodeRE.test(parent.nodeName) && $(parent).css("position") == "static")
  859. parent = parent.offsetParent
  860. return parent
  861. })
  862. }
  863. }
  864. // for now
  865. $.fn.detach = $.fn.remove
  866. // Generate the `width` and `height` functions
  867. ;
  868. ['width', 'height'].forEach(function(dimension) {
  869. var dimensionProperty =
  870. dimension.replace(/./, function(m) {
  871. return m[0].toUpperCase()
  872. })
  873. $.fn[dimension] = function(value) {
  874. var offset, el = this[0]
  875. if (value === undefined) return isWindow(el) ? el['inner' + dimensionProperty] :
  876. isDocument(el) ? el.documentElement['scroll' + dimensionProperty] :
  877. (offset = this.offset()) && offset[dimension]
  878. else return this.each(function(idx) {
  879. el = $(this)
  880. el.css(dimension, funcArg(this, value, idx, el[dimension]()))
  881. })
  882. }
  883. })
  884. function traverseNode(node, fun) {
  885. fun(node)
  886. for (var i = 0, len = node.childNodes.length; i < len; i++)
  887. traverseNode(node.childNodes[i], fun)
  888. }
  889. // Generate the `after`, `prepend`, `before`, `append`,
  890. // `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods.
  891. adjacencyOperators.forEach(function(operator, operatorIndex) {
  892. var inside = operatorIndex % 2 //=> prepend, append
  893. $.fn[operator] = function() {
  894. // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings
  895. var argType, nodes = $.map(arguments, function(arg) {
  896. argType = type(arg)
  897. return argType == "object" || argType == "array" || arg == null ?
  898. arg : zepto.fragment(arg)
  899. }),
  900. parent, copyByClone = this.length > 1
  901. if (nodes.length < 1) return this
  902. return this.each(function(_, target) {
  903. parent = inside ? target : target.parentNode
  904. // convert all methods to a "before" operation
  905. target = operatorIndex == 0 ? target.nextSibling :
  906. operatorIndex == 1 ? target.firstChild :
  907. operatorIndex == 2 ? target :
  908. null
  909. var parentInDocument = $.contains(document.documentElement, parent)
  910. nodes.forEach(function(node) {
  911. if (copyByClone) node = node.cloneNode(true)
  912. else if (!parent) return $(node).remove()
  913. parent.insertBefore(node, target)
  914. if (parentInDocument) traverseNode(node, function(el) {
  915. if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' &&
  916. (!el.type || el.type === 'text/javascript') && !el.src)
  917. window['eval'].call(window, el.innerHTML)
  918. })
  919. })
  920. })
  921. }
  922. // after => insertAfter
  923. // prepend => prependTo
  924. // before => insertBefore
  925. // append => appendTo
  926. $.fn[inside ? operator + 'To' : 'insert' + (operatorIndex ? 'Before' : 'After')] = function(html) {
  927. $(html)[operator](this)
  928. return this
  929. }
  930. })
  931. zepto.Z.prototype = Z.prototype = $.fn
  932. // Export internal API functions in the `$.zepto` namespace
  933. zepto.uniq = uniq
  934. zepto.deserializeValue = deserializeValue
  935. $.zepto = zepto
  936. return $
  937. })()
  938. window.Zepto = Zepto
  939. window.$ === undefined && (window.$ = Zepto)
  940. ;
  941. (function($) {
  942. var _zid = 1,
  943. undefined,
  944. slice = Array.prototype.slice,
  945. isFunction = $.isFunction,
  946. isString = function(obj) {
  947. return typeof obj == 'string'
  948. },
  949. handlers = {},
  950. specialEvents = {},
  951. focusinSupported = 'onfocusin' in window,
  952. focus = {
  953. focus: 'focusin',
  954. blur: 'focusout'
  955. },
  956. hover = {
  957. mouseenter: 'mouseover',
  958. mouseleave: 'mouseout'
  959. }
  960. specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents'
  961. function zid(element) {
  962. return element._zid || (element._zid = _zid++)
  963. }
  964. function findHandlers(element, event, fn, selector) {
  965. event = parse(event)
  966. if (event.ns) var matcher = matcherFor(event.ns)
  967. return (handlers[zid(element)] || []).filter(function(handler) {
  968. return handler && (!event.e || handler.e == event.e) && (!event.ns || matcher.test(handler.ns)) && (!fn || zid(handler.fn) === zid(fn)) && (!selector || handler.sel == selector)
  969. })
  970. }
  971. function parse(event) {
  972. var parts = ('' + event).split('.')
  973. return {
  974. e: parts[0],
  975. ns: parts.slice(1).sort().join(' ')
  976. }
  977. }
  978. function matcherFor(ns) {
  979. return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)')
  980. }
  981. function eventCapture(handler, captureSetting) {
  982. return handler.del &&
  983. (!focusinSupported && (handler.e in focus)) ||
  984. !!captureSetting
  985. }
  986. function realEvent(type) {
  987. return hover[type] || (focusinSupported && focus[type]) || type
  988. }
  989. function add(element, events, fn, data, selector, delegator, capture) {
  990. var id = zid(element),
  991. set = (handlers[id] || (handlers[id] = []))
  992. events.split(/\s/).forEach(function(event) {
  993. if (event == 'ready') return $(document).ready(fn)
  994. var handler = parse(event)
  995. handler.fn = fn
  996. handler.sel = selector
  997. // emulate mouseenter, mouseleave
  998. if (handler.e in hover) fn = function(e) {
  999. var related = e.relatedTarget
  1000. if (!related || (related !== this && !$.contains(this, related)))
  1001. return handler.fn.apply(this, arguments)
  1002. }
  1003. handler.del = delegator
  1004. var callback = delegator || fn
  1005. handler.proxy = function(e) {
  1006. e = compatible(e)
  1007. if (e.isImmediatePropagationStopped()) return
  1008. e.data = data
  1009. var result = callback.apply(element, e._args == undefined ? [e] : [e].concat(e._args))
  1010. if (result === false) e.preventDefault(), e.stopPropagation()
  1011. return result
  1012. }
  1013. handler.i = set.length
  1014. set.push(handler)
  1015. if ('addEventListener' in element)
  1016. element.addEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture))
  1017. })
  1018. }
  1019. function remove(element, events, fn, selector, capture) {
  1020. var id = zid(element);
  1021. (events || '').split(/\s/).forEach(function(event) {
  1022. findHandlers(element, event, fn, selector).forEach(function(handler) {
  1023. delete handlers[id][handler.i]
  1024. if ('removeEventListener' in element)
  1025. element.removeEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture))
  1026. })
  1027. })
  1028. }
  1029. $.event = {
  1030. add: add,
  1031. remove: remove
  1032. }
  1033. $.proxy = function(fn, context) {
  1034. var args = (2 in arguments) && slice.call(arguments, 2)
  1035. if (isFunction(fn)) {
  1036. var proxyFn = function() {
  1037. return fn.apply(context, args ? args.concat(slice.call(arguments)) : arguments)
  1038. }
  1039. proxyFn._zid = zid(fn)
  1040. return proxyFn
  1041. } else if (isString(context)) {
  1042. if (args) {
  1043. args.unshift(fn[context], fn)
  1044. return $.proxy.apply(null, args)
  1045. } else {
  1046. return $.proxy(fn[context], fn)
  1047. }
  1048. } else {
  1049. throw new TypeError("expected function")
  1050. }
  1051. }
  1052. $.fn.bind = function(event, data, callback) {
  1053. return this.on(event, data, callback)
  1054. }
  1055. $.fn.unbind = function(event, callback) {
  1056. return this.off(event, callback)
  1057. }
  1058. $.fn.one = function(event, selector, data, callback) {
  1059. return this.on(event, selector, data, callback, 1)
  1060. }
  1061. var returnTrue = function() {
  1062. return true
  1063. },
  1064. returnFalse = function() {
  1065. return false
  1066. },
  1067. ignoreProperties = /^([A-Z]|returnValue$|layer[XY]$)/,
  1068. eventMethods = {
  1069. preventDefault: 'isDefaultPrevented',
  1070. stopImmediatePropagation: 'isImmediatePropagationStopped',
  1071. stopPropagation: 'isPropagationStopped'
  1072. }
  1073. function compatible(event, source) {
  1074. if (source || !event.isDefaultPrevented) {
  1075. source || (source = event)
  1076. $.each(eventMethods, function(name, predicate) {
  1077. var sourceMethod = source[name]
  1078. event[name] = function() {
  1079. this[predicate] = returnTrue
  1080. return sourceMethod && sourceMethod.apply(source, arguments)
  1081. }
  1082. event[predicate] = returnFalse
  1083. })
  1084. if (source.defaultPrevented !== undefined ? source.defaultPrevented :
  1085. 'returnValue' in source ? source.returnValue === false :
  1086. source.getPreventDefault && source.getPreventDefault())
  1087. event.isDefaultPrevented = returnTrue
  1088. }
  1089. return event
  1090. }
  1091. function createProxy(event) {
  1092. var key, proxy = {
  1093. originalEvent: event
  1094. }
  1095. for (key in event)
  1096. if (!ignoreProperties.test(key) && event[key] !== undefined) proxy[key] = event[key]
  1097. return compatible(proxy, event)
  1098. }
  1099. $.fn.delegate = function(selector, event, callback) {
  1100. return this.on(event, selector, callback)
  1101. }
  1102. $.fn.undelegate = function(selector, event, callback) {
  1103. return this.off(event, selector, callback)
  1104. }
  1105. $.fn.live = function(event, callback) {
  1106. $(document.body).delegate(this.selector, event, callback)
  1107. return this
  1108. }
  1109. $.fn.die = function(event, callback) {
  1110. $(document.body).undelegate(this.selector, event, callback)
  1111. return this
  1112. }
  1113. $.fn.on = function(event, selector, data, callback, one) {
  1114. var autoRemove, delegator, $this = this
  1115. if (event && !isString(event)) {
  1116. $.each(event, function(type, fn) {
  1117. $this.on(type, selector, data, fn, one)
  1118. })
  1119. return $this
  1120. }
  1121. if (!isString(selector) && !isFunction(callback) && callback !== false)
  1122. callback = data, data = selector, selector = undefined
  1123. if (callback === undefined || data === false)
  1124. callback = data, data = undefined
  1125. if (callback === false) callback = returnFalse
  1126. return $this.each(function(_, element) {
  1127. if (one) autoRemove = function(e) {
  1128. remove(element, e.type, callback)
  1129. return callback.apply(this, arguments)
  1130. }
  1131. if (selector) delegator = function(e) {
  1132. var evt, match = $(e.target).closest(selector, element).get(0)
  1133. if (match && match !== element) {
  1134. evt = $.extend(createProxy(e), {
  1135. currentTarget: match,
  1136. liveFired: element
  1137. })
  1138. return (autoRemove || callback).apply(match, [evt].concat(slice.call(arguments, 1)))
  1139. }
  1140. }
  1141. add(element, event, callback, data, selector, delegator || autoRemove)
  1142. })
  1143. }
  1144. $.fn.off = function(event, selector, callback) {
  1145. var $this = this
  1146. if (event && !isString(event)) {
  1147. $.each(event, function(type, fn) {
  1148. $this.off(type, selector, fn)
  1149. })
  1150. return $this
  1151. }
  1152. if (!isString(selector) && !isFunction(callback) && callback !== false)
  1153. callback = selector, selector = undefined
  1154. if (callback === false) callback = returnFalse
  1155. return $this.each(function() {
  1156. remove(this, event, callback, selector)
  1157. })
  1158. }
  1159. $.fn.trigger = function(event, args) {
  1160. event = (isString(event) || $.isPlainObject(event)) ? $.Event(event) : compatible(event)
  1161. event._args = args
  1162. return this.each(function() {
  1163. // handle focus(), blur() by calling them directly
  1164. if (event.type in focus && typeof this[event.type] == "function") this[event.type]()
  1165. // items in the collection might not be DOM elements
  1166. else if ('dispatchEvent' in this) this.dispatchEvent(event)
  1167. else $(this).triggerHandler(event, args)
  1168. })
  1169. }
  1170. // triggers event handlers on current element just as if an event occurred,
  1171. // doesn't trigger an actual event, doesn't bubble
  1172. $.fn.triggerHandler = function(event, args) {
  1173. var e, result
  1174. this.each(function(i, element) {
  1175. e = createProxy(isString(event) ? $.Event(event) : event)
  1176. e._args = args
  1177. e.target = element
  1178. $.each(findHandlers(element, event.type || event), function(i, handler) {
  1179. result = handler.proxy(e)
  1180. if (e.isImmediatePropagationStopped()) return false
  1181. })
  1182. })
  1183. return result
  1184. }
  1185. // shortcut methods for `.bind(event, fn)` for each event type
  1186. ;
  1187. ('focusin focusout focus blur load resize scroll unload click dblclick ' +
  1188. 'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave ' +
  1189. 'change select keydown keypress keyup error').split(' ').forEach(function(event) {
  1190. $.fn[event] = function(callback) {
  1191. return (0 in arguments) ?
  1192. this.bind(event, callback) :
  1193. this.trigger(event)
  1194. }
  1195. })
  1196. $.Event = function(type, props) {
  1197. if (!isString(type)) props = type, type = props.type
  1198. var event = document.createEvent(specialEvents[type] || 'Events'),
  1199. bubbles = true
  1200. if (props)
  1201. for (var name in props)(name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name])
  1202. event.initEvent(type, bubbles, true)
  1203. return compatible(event)
  1204. }
  1205. })(Zepto)
  1206. ;
  1207. (function($) {
  1208. var jsonpID = 0,
  1209. document = window.document,
  1210. key,
  1211. name,
  1212. rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
  1213. scriptTypeRE = /^(?:text|application)\/javascript/i,
  1214. xmlTypeRE = /^(?:text|application)\/xml/i,
  1215. jsonType = 'application/json',
  1216. htmlType = 'text/html',
  1217. blankRE = /^\s*$/,
  1218. originAnchor = document.createElement('a')
  1219. originAnchor.href = window.location.href
  1220. // trigger a custom event and return false if it was cancelled
  1221. function triggerAndReturn(context, eventName, data) {
  1222. var event = $.Event(eventName)
  1223. $(context).trigger(event, data)
  1224. return !event.isDefaultPrevented()
  1225. }
  1226. // trigger an Ajax "global" event
  1227. function triggerGlobal(settings, context, eventName, data) {
  1228. if (settings.global) return triggerAndReturn(context || document, eventName, data)
  1229. }
  1230. // Number of active Ajax requests
  1231. $.active = 0
  1232. function ajaxStart(settings) {
  1233. if (settings.global && $.active++ === 0) triggerGlobal(settings, null, 'ajaxStart')
  1234. }
  1235. function ajaxStop(settings) {
  1236. if (settings.global && !(--$.active)) triggerGlobal(settings, null, 'ajaxStop')
  1237. }
  1238. // triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable
  1239. function ajaxBeforeSend(xhr, settings) {
  1240. var context = settings.context
  1241. if (settings.beforeSend.call(context, xhr, settings) === false ||
  1242. triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false)
  1243. return false
  1244. triggerGlobal(settings, context, 'ajaxSend', [xhr, settings])
  1245. }
  1246. function ajaxSuccess(data, xhr, settings, deferred) {
  1247. var context = settings.context,
  1248. status = 'success'
  1249. settings.success.call(context, data, status, xhr)
  1250. if (deferred) deferred.resolveWith(context, [data, status, xhr])
  1251. triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data])
  1252. ajaxComplete(status, xhr, settings)
  1253. }
  1254. // type: "timeout", "error", "abort", "parsererror"
  1255. function ajaxError(error, type, xhr, settings, deferred) {
  1256. var context = settings.context
  1257. settings.error.call(context, xhr, type, error)
  1258. if (deferred) deferred.rejectWith(context, [xhr, type, error])
  1259. triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error || type])
  1260. ajaxComplete(type, xhr, settings)
  1261. }
  1262. // status: "success", "notmodified", "error", "timeout", "abort", "parsererror"
  1263. function ajaxComplete(status, xhr, settings) {
  1264. var context = settings.context
  1265. settings.complete.call(context, xhr, status)
  1266. triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings])
  1267. ajaxStop(settings)
  1268. }
  1269. // Empty function, used as default callback
  1270. function empty() {}
  1271. $.ajaxJSONP = function(options, deferred) {
  1272. if (!('type' in options)) return $.ajax(options)
  1273. var _callbackName = options.jsonpCallback,
  1274. callbackName = ($.isFunction(_callbackName) ?
  1275. _callbackName() : _callbackName) || ('jsonp' + (++jsonpID)),
  1276. script = document.createElement('script'),
  1277. originalCallback = window[callbackName],
  1278. responseData,
  1279. abort = function(errorType) {
  1280. $(script).triggerHandler('error', errorType || 'abort')
  1281. },
  1282. xhr = {
  1283. abort: abort
  1284. },
  1285. abortTimeout
  1286. if (deferred) deferred.promise(xhr)
  1287. $(script).on('load error', function(e, errorType) {
  1288. clearTimeout(abortTimeout)
  1289. $(script).off().remove()
  1290. if (e.type == 'error' || !responseData) {
  1291. ajaxError(null, errorType || 'error', xhr, options, deferred)
  1292. } else {
  1293. ajaxSuccess(responseData[0], xhr, options, deferred)
  1294. }
  1295. window[callbackName] = originalCallback
  1296. if (responseData && $.isFunction(originalCallback))
  1297. originalCallback(responseData[0])
  1298. originalCallback = responseData = undefined
  1299. })
  1300. if (ajaxBeforeSend(xhr, options) === false) {
  1301. abort('abort')
  1302. return xhr
  1303. }
  1304. window[callbackName] = function() {
  1305. responseData = arguments
  1306. }
  1307. script.src = options.url.replace(/\?(.+)=\?/, '?$1=' + callbackName)
  1308. document.head.appendChild(script)
  1309. if (options.timeout > 0) abortTimeout = setTimeout(function() {
  1310. abort('timeout')
  1311. }, options.timeout)
  1312. return xhr
  1313. }
  1314. $.ajaxSettings = {
  1315. // Default type of request
  1316. type: 'GET',
  1317. // Callback that is executed before request
  1318. beforeSend: empty,
  1319. // Callback that is executed if the request succeeds
  1320. success: empty,
  1321. // Callback that is executed the the server drops error
  1322. error: empty,
  1323. // Callback that is executed on request complete (both: error and success)
  1324. complete: empty,
  1325. // The context for the callbacks
  1326. context: null,
  1327. // Whether to trigger "global" Ajax events
  1328. global: true,
  1329. // Transport
  1330. xhr: function() {
  1331. return new window.XMLHttpRequest()
  1332. },
  1333. // MIME types mapping
  1334. // IIS returns Javascript as "application/x-javascript"
  1335. accepts: {
  1336. script: 'text/javascript, application/javascript, application/x-javascript',
  1337. json: jsonType,
  1338. xml: 'application/xml, text/xml',
  1339. html: htmlType,
  1340. text: 'text/plain'
  1341. },
  1342. // Whether the request is to another domain
  1343. crossDomain: false,
  1344. // Default timeout
  1345. timeout: 0,
  1346. // Whether data should be serialized to string
  1347. processData: true,
  1348. // Whether the browser should be allowed to cache GET responses
  1349. cache: true
  1350. }
  1351. function mimeToDataType(mime) {
  1352. if (mime) mime = mime.split(';', 2)[0]
  1353. return mime && (mime == htmlType ? 'html' :
  1354. mime == jsonType ? 'json' :
  1355. scriptTypeRE.test(mime) ? 'script' :
  1356. xmlTypeRE.test(mime) && 'xml') || 'text'
  1357. }
  1358. function appendQuery(url, query) {
  1359. if (query == '') return url
  1360. return (url + '&' + query).replace(/[&?]{1,2}/, '?')
  1361. }
  1362. // serialize payload and append it to the URL for GET requests
  1363. function serializeData(options) {
  1364. if (options.processData && options.data && $.type(options.data) != "string")
  1365. options.data = $.param(options.data, options.traditional)
  1366. if (options.data && (!options.type || options.type.toUpperCase() == 'GET'))
  1367. options.url = appendQuery(options.url, options.data), options.data = undefined
  1368. }
  1369. $.ajax = function(options) {
  1370. var settings = $.extend({}, options || {}),
  1371. deferred = $.Deferred && $.Deferred(),
  1372. urlAnchor, hashIndex
  1373. for (key in $.ajaxSettings)
  1374. if (settings[key] === undefined) settings[key] = $.ajaxSettings[key]
  1375. ajaxStart(settings)
  1376. if (!settings.crossDomain) {
  1377. urlAnchor = document.createElement('a')
  1378. urlAnchor.href = settings.url
  1379. // cleans up URL for .href (IE only), see https://github.com/madrobby/zepto/pull/1049
  1380. urlAnchor.href = urlAnchor.href
  1381. settings.crossDomain = (originAnchor.protocol + '//' + originAnchor.host) !== (urlAnchor.protocol + '//' + urlAnchor.host)
  1382. }
  1383. if (!settings.url) settings.url = window.location.toString()
  1384. if ((hashIndex = settings.url.indexOf('#')) > -1) settings.url = settings.url.slice(0, hashIndex)
  1385. serializeData(settings)
  1386. var dataType = settings.dataType,
  1387. hasPlaceholder = /\?.+=\?/.test(settings.url)
  1388. if (hasPlaceholder) dataType = 'jsonp'
  1389. if (settings.cache === false || (
  1390. (!options || options.cache !== true) &&
  1391. ('script' == dataType || 'jsonp' == dataType)
  1392. ))
  1393. settings.url = appendQuery(settings.url, '_=' + Date.now())
  1394. if ('jsonp' == dataType) {
  1395. if (!hasPlaceholder)
  1396. settings.url = appendQuery(settings.url,
  1397. settings.jsonp ? (settings.jsonp + '=?') : settings.jsonp === false ? '' : 'callback=?')
  1398. return $.ajaxJSONP(settings, deferred)
  1399. }
  1400. var mime = settings.accepts[dataType],
  1401. headers = {},
  1402. setHeader = function(name, value) {
  1403. headers[name.toLowerCase()] = [name, value]
  1404. },
  1405. protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol,
  1406. xhr = settings.xhr(),
  1407. nativeSetHeader = xhr.setRequestHeader,
  1408. abortTimeout
  1409. if (deferred) deferred.promise(xhr)
  1410. if (!settings.crossDomain) setHeader('X-Requested-With', 'XMLHttpRequest')
  1411. setHeader('Accept', mime || '*/*')
  1412. if (mime = settings.mimeType || mime) {
  1413. if (mime.indexOf(',') > -1) mime = mime.split(',', 2)[0]
  1414. xhr.overrideMimeType && xhr.overrideMimeType(mime)
  1415. }
  1416. if (settings.contentType || (settings.contentType !== false && settings.data && settings.type.toUpperCase() != 'GET'))
  1417. setHeader('Content-Type', settings.contentType || 'application/x-www-form-urlencoded')
  1418. if (settings.headers)
  1419. for (name in settings.headers) setHeader(name, settings.headers[name])
  1420. xhr.setRequestHeader = setHeader
  1421. xhr.onreadystatechange = function() {
  1422. if (xhr.readyState == 4) {
  1423. xhr.onreadystatechange = empty
  1424. clearTimeout(abortTimeout)
  1425. var result, error = false
  1426. if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) {
  1427. dataType = dataType || mimeToDataType(settings.mimeType || xhr.getResponseHeader('content-type'))
  1428. result = xhr.responseText
  1429. try {
  1430. // http://perfectionkills.com/global-eval-what-are-the-options/
  1431. if (dataType == 'script')(1, eval)(result)
  1432. else if (dataType == 'xml') result = xhr.responseXML
  1433. else if (dataType == 'json') result = blankRE.test(result) ? null : $.parseJSON(result)
  1434. } catch (e) {
  1435. error = e
  1436. }
  1437. if (error) ajaxError(error, 'parsererror', xhr, settings, deferred)
  1438. else ajaxSuccess(result, xhr, settings, deferred)
  1439. } else {
  1440. ajaxError(xhr.statusText || null, xhr.status ? 'error' : 'abort', xhr, settings, deferred)
  1441. }
  1442. }
  1443. }
  1444. if (ajaxBeforeSend(xhr, settings) === false) {
  1445. xhr.abort()
  1446. ajaxError(null, 'abort', xhr, settings, deferred)
  1447. return xhr
  1448. }
  1449. if (settings.xhrFields)
  1450. for (name in settings.xhrFields) xhr[name] = settings.xhrFields[name]
  1451. var async = 'async' in settings ? settings.async : true
  1452. xhr.open(settings.type, settings.url, async, settings.username, settings.password)
  1453. for (name in headers) nativeSetHeader.apply(xhr, headers[name])
  1454. if (settings.timeout > 0) abortTimeout = setTimeout(function() {
  1455. xhr.onreadystatechange = empty
  1456. xhr.abort()
  1457. ajaxError(null, 'timeout', xhr, settings, deferred)
  1458. }, settings.timeout)
  1459. // avoid sending empty string (#319)
  1460. xhr.send(settings.data ? settings.data : null)
  1461. return xhr
  1462. }
  1463. // handle optional data/success arguments
  1464. function parseArguments(url, data, success, dataType) {
  1465. if ($.isFunction(data)) dataType = success, success = data, data = undefined
  1466. if (!$.isFunction(success)) dataType = success, success = undefined
  1467. return {
  1468. url: url,
  1469. data: data,
  1470. success: success,
  1471. dataType: dataType
  1472. }
  1473. }
  1474. $.get = function( /* url, data, success, dataType */ ) {
  1475. return $.ajax(parseArguments.apply(null, arguments))
  1476. }
  1477. $.post = function( /* url, data, success, dataType */ ) {
  1478. var options = parseArguments.apply(null, arguments)
  1479. options.type = 'POST'
  1480. return $.ajax(options)
  1481. }
  1482. $.getJSON = function( /* url, data, success */ ) {
  1483. var options = parseArguments.apply(null, arguments)
  1484. options.dataType = 'json'
  1485. return $.ajax(options)
  1486. }
  1487. $.fn.load = function(url, data, success) {
  1488. if (!this.length) return this
  1489. var self = this,
  1490. parts = url.split(/\s/),
  1491. selector,
  1492. options = parseArguments(url, data, success),
  1493. callback = options.success
  1494. if (parts.length > 1) options.url = parts[0], selector = parts[1]
  1495. options.success = function(response) {
  1496. self.html(selector ?
  1497. $('<div>').html(response.replace(rscript, "")).find(selector) : response)
  1498. callback && callback.apply(self, arguments)
  1499. }
  1500. $.ajax(options)
  1501. return this
  1502. }
  1503. var escape = encodeURIComponent
  1504. function serialize(params, obj, traditional, scope) {
  1505. var type, array = $.isArray(obj),
  1506. hash = $.isPlainObject(obj)
  1507. $.each(obj, function(key, value) {
  1508. type = $.type(value)
  1509. if (scope) key = traditional ? scope :
  1510. scope + '[' + (hash || type == 'object' || type == 'array' ? key : '') + ']'
  1511. // handle data in serializeArray() format
  1512. if (!scope && array) params.add(value.name, value.value)
  1513. // recurse into nested objects
  1514. else if (type == "array" || (!traditional && type == "object"))
  1515. serialize(params, value, traditional, key)
  1516. else params.add(key, value)
  1517. })
  1518. }
  1519. $.param = function(obj, traditional) {
  1520. var params = []
  1521. params.add = function(key, value) {
  1522. if ($.isFunction(value)) value = value()
  1523. if (value == null) value = ""
  1524. this.push(escape(key) + '=' + escape(value))
  1525. }
  1526. serialize(params, obj, traditional)
  1527. return params.join('&').replace(/%20/g, '+')
  1528. }
  1529. })(Zepto)
  1530. ;
  1531. (function($) {
  1532. $.fn.serializeArray = function() {
  1533. var name, type, result = [],
  1534. add = function(value) {
  1535. if (value.forEach) return value.forEach(add)
  1536. result.push({
  1537. name: name,
  1538. value: value
  1539. })
  1540. }
  1541. if (this[0]) $.each(this[0].elements, function(_, field) {
  1542. type = field.type, name = field.name
  1543. if (name && field.nodeName.toLowerCase() != 'fieldset' &&
  1544. !field.disabled && type != 'submit' && type != 'reset' && type != 'button' && type != 'file' &&
  1545. ((type != 'radio' && type != 'checkbox') || field.checked))
  1546. add($(field).val())
  1547. })
  1548. return result
  1549. }
  1550. $.fn.serialize = function() {
  1551. var result = []
  1552. this.serializeArray().forEach(function(elm) {
  1553. result.push(encodeURIComponent(elm.name) + '=' + encodeURIComponent(elm.value))
  1554. })
  1555. return result.join('&')
  1556. }
  1557. $.fn.submit = function(callback) {
  1558. if (0 in arguments) this.bind('submit', callback)
  1559. else if (this.length) {
  1560. var event = $.Event('submit')
  1561. this.eq(0).trigger(event)
  1562. if (!event.isDefaultPrevented()) this.get(0).submit()
  1563. }
  1564. return this
  1565. }
  1566. })(Zepto)
  1567. ;
  1568. (function($, undefined) {
  1569. var prefix = '',
  1570. eventPrefix,
  1571. vendors = {
  1572. Webkit: 'webkit',
  1573. Moz: '',
  1574. O: 'o'
  1575. },
  1576. testEl = document.createElement('div'),
  1577. supportedTransforms = /^((translate|rotate|scale)(X|Y|Z|3d)?|matrix(3d)?|perspective|skew(X|Y)?)$/i,
  1578. transform,
  1579. transitionProperty, transitionDuration, transitionTiming, transitionDelay,
  1580. animationName, animationDuration, animationTiming, animationDelay,
  1581. cssReset = {}
  1582. function dasherize(str) {
  1583. return str.replace(/([a-z])([A-Z])/, '$1-$2').toLowerCase()
  1584. }
  1585. function normalizeEvent(name) {
  1586. return eventPrefix ? eventPrefix + name : name.toLowerCase()
  1587. }
  1588. $.each(vendors, function(vendor, event) {
  1589. if (testEl.style[vendor + 'TransitionProperty'] !== undefined) {
  1590. prefix = '-' + vendor.toLowerCase() + '-'
  1591. eventPrefix = event
  1592. return false
  1593. }
  1594. })
  1595. transform = prefix + 'transform'
  1596. cssReset[transitionProperty = prefix + 'transition-property'] =
  1597. cssReset[transitionDuration = prefix + 'transition-duration'] =
  1598. cssReset[transitionDelay = prefix + 'transition-delay'] =
  1599. cssReset[transitionTiming = prefix + 'transition-timing-function'] =
  1600. cssReset[animationName = prefix + 'animation-name'] =
  1601. cssReset[animationDuration = prefix + 'animation-duration'] =
  1602. cssReset[animationDelay = prefix + 'animation-delay'] =
  1603. cssReset[animationTiming = prefix + 'animation-timing-function'] = ''
  1604. $.fx = {
  1605. off: (eventPrefix === undefined && testEl.style.transitionProperty === undefined),
  1606. speeds: {
  1607. _default: 400,
  1608. fast: 200,
  1609. slow: 600
  1610. },
  1611. cssPrefix: prefix,
  1612. transitionEnd: normalizeEvent('TransitionEnd'),
  1613. animationEnd: normalizeEvent('AnimationEnd')
  1614. }
  1615. $.fn.animate = function(properties, duration, ease, callback, delay) {
  1616. if ($.isFunction(duration))
  1617. callback = duration, ease = undefined, duration = undefined
  1618. if ($.isFunction(ease))
  1619. callback = ease, ease = undefined
  1620. if ($.isPlainObject(duration))
  1621. ease = duration.easing, callback = duration.complete, delay = duration.delay, duration = duration.duration
  1622. if (duration) duration = (typeof duration == 'number' ? duration :
  1623. ($.fx.speeds[duration] || $.fx.speeds._default)) / 1000
  1624. if (delay) delay = parseFloat(delay) / 1000
  1625. return this.anim(properties, duration, ease, callback, delay)
  1626. }
  1627. $.fn.anim = function(properties, duration, ease, callback, delay) {
  1628. var key, cssValues = {},
  1629. cssProperties, transforms = '',
  1630. that = this,
  1631. wrappedCallback, endEvent = $.fx.transitionEnd,
  1632. fired = false
  1633. if (duration === undefined) duration = $.fx.speeds._default / 1000
  1634. if (delay === undefined) delay = 0
  1635. if ($.fx.off) duration = 0
  1636. if (typeof properties == 'string') {
  1637. // keyframe animation
  1638. cssValues[animationName] = properties
  1639. cssValues[animationDuration] = duration + 's'
  1640. cssValues[animationDelay] = delay + 's'
  1641. cssValues[animationTiming] = (ease || 'linear')
  1642. endEvent = $.fx.animationEnd
  1643. } else {
  1644. cssProperties = []
  1645. // CSS transitions
  1646. for (key in properties)
  1647. if (supportedTransforms.test(key)) transforms += key + '(' + properties[key] + ') '
  1648. else cssValues[key] = properties[key], cssProperties.push(dasherize(key))
  1649. if (transforms) cssValues[transform] = transforms, cssProperties.push(transform)
  1650. if (duration > 0 && typeof properties === 'object') {
  1651. cssValues[transitionProperty] = cssProperties.join(', ')
  1652. cssValues[transitionDuration] = duration + 's'
  1653. cssValues[transitionDelay] = delay + 's'
  1654. cssValues[transitionTiming] = (ease || 'linear')
  1655. }
  1656. }
  1657. wrappedCallback = function(event) {
  1658. if (typeof event !== 'undefined') {
  1659. if (event.target !== event.currentTarget) return // makes sure the event didn't bubble from "below"
  1660. $(event.target).unbind(endEvent, wrappedCallback)
  1661. } else
  1662. $(this).unbind(endEvent, wrappedCallback) // triggered by setTimeout
  1663. fired = true
  1664. $(this).css(cssReset)
  1665. callback && callback.call(this)
  1666. }
  1667. if (duration > 0) {
  1668. this.bind(endEvent, wrappedCallback)
  1669. // transitionEnd is not always firing on older Android phones
  1670. // so make sure it gets fired
  1671. setTimeout(function() {
  1672. if (fired) return
  1673. wrappedCallback.call(that)
  1674. }, ((duration + delay) * 1000) + 25)
  1675. }
  1676. // trigger page reflow so new elements can animate
  1677. this.size() && this.get(0).clientLeft
  1678. this.css(cssValues)
  1679. if (duration <= 0) setTimeout(function() {
  1680. that.each(function() {
  1681. wrappedCallback.call(this)
  1682. })
  1683. }, 0)
  1684. return this
  1685. }
  1686. testEl = null
  1687. })(Zepto)
  1688. ;
  1689. (function($) {
  1690. var data = {},
  1691. dataAttr = $.fn.data,
  1692. camelize = $.camelCase,
  1693. exp = $.expando = 'Zepto' + (+new Date()),
  1694. emptyArray = []
  1695. // Get value from node:
  1696. // 1. first try key as given,
  1697. // 2. then try camelized key,
  1698. // 3. fall back to reading "data-*" attribute.
  1699. function getData(node, name) {
  1700. var id = node[exp],
  1701. store = id && data[id]
  1702. if (name === undefined) return store || setData(node)
  1703. else {
  1704. if (store) {
  1705. if (name in store) return store[name]
  1706. var camelName = camelize(name)
  1707. if (camelName in store) return store[camelName]
  1708. }
  1709. return dataAttr.call($(node), name)
  1710. }
  1711. }
  1712. // Store value under camelized key on node
  1713. function setData(node, name, value) {
  1714. var id = node[exp] || (node[exp] = ++$.uuid),
  1715. store = data[id] || (data[id] = attributeData(node))
  1716. if (name !== undefined) store[camelize(name)] = value
  1717. return store
  1718. }
  1719. // Read all "data-*" attributes from a node
  1720. function attributeData(node) {
  1721. var store = {}
  1722. $.each(node.attributes || emptyArray, function(i, attr) {
  1723. if (attr.name.indexOf('data-') == 0)
  1724. store[camelize(attr.name.replace('data-', ''))] =
  1725. $.zepto.deserializeValue(attr.value)
  1726. })
  1727. return store
  1728. }
  1729. $.fn.data = function(name, value) {
  1730. return value === undefined ?
  1731. // set multiple values via object
  1732. $.isPlainObject(name) ?
  1733. this.each(function(i, node) {
  1734. $.each(name, function(key, value) {
  1735. setData(node, key, value)
  1736. })
  1737. }) :
  1738. // get value from first element
  1739. (0 in this ? getData(this[0], name) : undefined) :
  1740. // set value on all elements
  1741. this.each(function() {
  1742. setData(this, name, value)
  1743. })
  1744. }
  1745. $.fn.removeData = function(names) {
  1746. if (typeof names == 'string') names = names.split(/\s+/)
  1747. return this.each(function() {
  1748. var id = this[exp],
  1749. store = id && data[id]
  1750. if (store) $.each(names || store, function(key) {
  1751. delete store[names ? camelize(this) : key]
  1752. })
  1753. })
  1754. }
  1755. // Generate extended `remove` and `empty` functions
  1756. ;
  1757. ['remove', 'empty'].forEach(function(methodName) {
  1758. var origFn = $.fn[methodName]
  1759. $.fn[methodName] = function() {
  1760. var elements = this.find('*')
  1761. if (methodName === 'remove') elements = elements.add(this)
  1762. elements.removeData()
  1763. return origFn.call(this)
  1764. }
  1765. })
  1766. })(Zepto)
  1767. ;
  1768. (function($) {
  1769. var slice = Array.prototype.slice
  1770. function Deferred(func) {
  1771. var tuples = [
  1772. // action, add listener, listener list, final state
  1773. ["resolve", "done", $.Callbacks({
  1774. once: 1,
  1775. memory: 1
  1776. }), "resolved"],
  1777. ["reject", "fail", $.Callbacks({
  1778. once: 1,
  1779. memory: 1
  1780. }), "rejected"],
  1781. ["notify", "progress", $.Callbacks({
  1782. memory: 1
  1783. })]
  1784. ],
  1785. state = "pending",
  1786. promise = {
  1787. state: function() {
  1788. return state
  1789. },
  1790. always: function() {
  1791. deferred.done(arguments).fail(arguments)
  1792. return this
  1793. },
  1794. then: function( /* fnDone [, fnFailed [, fnProgress]] */ ) {
  1795. var fns = arguments
  1796. return Deferred(function(defer) {
  1797. $.each(tuples, function(i, tuple) {
  1798. var fn = $.isFunction(fns[i]) && fns[i]
  1799. deferred[tuple[1]](function() {
  1800. var returned = fn && fn.apply(this, arguments)
  1801. if (returned && $.isFunction(returned.promise)) {
  1802. returned.promise()
  1803. .done(defer.resolve)
  1804. .fail(defer.reject)
  1805. .progress(defer.notify)
  1806. } else {
  1807. var context = this === promise ? defer.promise() : this,
  1808. values = fn ? [returned] : arguments
  1809. defer[tuple[0] + "With"](context, values)
  1810. }
  1811. })
  1812. })
  1813. fns = null
  1814. }).promise()
  1815. },
  1816. promise: function(obj) {
  1817. return obj != null ? $.extend(obj, promise) : promise
  1818. }
  1819. },
  1820. deferred = {}
  1821. $.each(tuples, function(i, tuple) {
  1822. var list = tuple[2],
  1823. stateString = tuple[3]
  1824. promise[tuple[1]] = list.add
  1825. if (stateString) {
  1826. list.add(function() {
  1827. state = stateString
  1828. }, tuples[i ^ 1][2].disable, tuples[2][2].lock)
  1829. }
  1830. deferred[tuple[0]] = function() {
  1831. deferred[tuple[0] + "With"](this === deferred ? promise : this, arguments)
  1832. return this
  1833. }
  1834. deferred[tuple[0] + "With"] = list.fireWith
  1835. })
  1836. promise.promise(deferred)
  1837. if (func) func.call(deferred, deferred)
  1838. return deferred
  1839. }
  1840. $.when = function(sub) {
  1841. var resolveValues = slice.call(arguments),
  1842. len = resolveValues.length,
  1843. i = 0,
  1844. remain = len !== 1 || (sub && $.isFunction(sub.promise)) ? len : 0,
  1845. deferred = remain === 1 ? sub : Deferred(),
  1846. progressValues, progressContexts, resolveContexts,
  1847. updateFn = function(i, ctx, val) {
  1848. return function(value) {
  1849. ctx[i] = this
  1850. val[i] = arguments.length > 1 ? slice.call(arguments) : value
  1851. if (val === progressValues) {
  1852. deferred.notifyWith(ctx, val)
  1853. } else if (!(--remain)) {
  1854. deferred.resolveWith(ctx, val)
  1855. }
  1856. }
  1857. }
  1858. if (len > 1) {
  1859. progressValues = new Array(len)
  1860. progressContexts = new Array(len)
  1861. resolveContexts = new Array(len)
  1862. for (; i < len; ++i) {
  1863. if (resolveValues[i] && $.isFunction(resolveValues[i].promise)) {
  1864. resolveValues[i].promise()
  1865. .done(updateFn(i, resolveContexts, resolveValues))
  1866. .fail(deferred.reject)
  1867. .progress(updateFn(i, progressContexts, progressValues))
  1868. } else {
  1869. --remain
  1870. }
  1871. }
  1872. }
  1873. if (!remain) deferred.resolveWith(resolveContexts, resolveValues)
  1874. return deferred.promise()
  1875. }
  1876. $.Deferred = Deferred
  1877. })(Zepto)
  1878. ;
  1879. (function($) {
  1880. // Create a collection of callbacks to be fired in a sequence, with configurable behaviour
  1881. // Option flags:
  1882. // - once: Callbacks fired at most one time.
  1883. // - memory: Remember the most recent context and arguments
  1884. // - stopOnFalse: Cease iterating over callback list
  1885. // - unique: Permit adding at most one instance of the same callback
  1886. $.Callbacks = function(options) {
  1887. options = $.extend({}, options)
  1888. var memory, // Last fire value (for non-forgettable lists)
  1889. fired, // Flag to know if list was already fired
  1890. firing, // Flag to know if list is currently firing
  1891. firingStart, // First callback to fire (used internally by add and fireWith)
  1892. firingLength, // End of the loop when firing
  1893. firingIndex, // Index of currently firing callback (modified by remove if needed)
  1894. list = [], // Actual callback list
  1895. stack = !options.once && [], // Stack of fire calls for repeatable lists
  1896. fire = function(data) {
  1897. memory = options.memory && data
  1898. fired = true
  1899. firingIndex = firingStart || 0
  1900. firingStart = 0
  1901. firingLength = list.length
  1902. firing = true
  1903. for (; list && firingIndex < firingLength; ++firingIndex) {
  1904. if (list[firingIndex].apply(data[0], data[1]) === false && options.stopOnFalse) {
  1905. memory = false
  1906. break
  1907. }
  1908. }
  1909. firing = false
  1910. if (list) {
  1911. if (stack) stack.length && fire(stack.shift())
  1912. else if (memory) list.length = 0
  1913. else Callbacks.disable()
  1914. }
  1915. },
  1916. Callbacks = {
  1917. add: function() {
  1918. if (list) {
  1919. var start = list.length,
  1920. add = function(args) {
  1921. $.each(args, function(_, arg) {
  1922. if (typeof arg === "function") {
  1923. if (!options.unique || !Callbacks.has(arg)) list.push(arg)
  1924. } else if (arg && arg.length && typeof arg !== 'string') add(arg)
  1925. })
  1926. }
  1927. add(arguments)
  1928. if (firing) firingLength = list.length
  1929. else if (memory) {
  1930. firingStart = start
  1931. fire(memory)
  1932. }
  1933. }
  1934. return this
  1935. },
  1936. remove: function() {
  1937. if (list) {
  1938. $.each(arguments, function(_, arg) {
  1939. var index
  1940. while ((index = $.inArray(arg, list, index)) > -1) {
  1941. list.splice(index, 1)
  1942. // Handle firing indexes
  1943. if (firing) {
  1944. if (index <= firingLength)--firingLength
  1945. if (index <= firingIndex)--firingIndex
  1946. }
  1947. }
  1948. })
  1949. }
  1950. return this
  1951. },
  1952. has: function(fn) {
  1953. return !!(list && (fn ? $.inArray(fn, list) > -1 : list.length))
  1954. },
  1955. empty: function() {
  1956. firingLength = list.length = 0
  1957. return this
  1958. },
  1959. disable: function() {
  1960. list = stack = memory = undefined
  1961. return this
  1962. },
  1963. disabled: function() {
  1964. return !list
  1965. },
  1966. lock: function() {
  1967. stack = undefined;
  1968. if (!memory) Callbacks.disable()
  1969. return this
  1970. },
  1971. locked: function() {
  1972. return !stack
  1973. },
  1974. fireWith: function(context, args) {
  1975. if (list && (!fired || stack)) {
  1976. args = args || []
  1977. args = [context, args.slice ? args.slice() : args]
  1978. if (firing) stack.push(args)
  1979. else fire(args)
  1980. }
  1981. return this
  1982. },
  1983. fire: function() {
  1984. return Callbacks.fireWith(this, arguments)
  1985. },
  1986. fired: function() {
  1987. return !!fired
  1988. }
  1989. }
  1990. return Callbacks
  1991. }
  1992. })(Zepto)
  1993. ;
  1994. (function($) {
  1995. var zepto = $.zepto,
  1996. oldQsa = zepto.qsa,
  1997. oldMatches = zepto.matches
  1998. function visible(elem) {
  1999. elem = $(elem)
  2000. return !!(elem.width() || elem.height()) && elem.css("display") !== "none"
  2001. }
  2002. // Implements a subset from:
  2003. // http://api.jquery.com/category/selectors/jquery-selector-extensions/
  2004. //
  2005. // Each filter function receives the current index, all nodes in the
  2006. // considered set, and a value if there were parentheses. The value
  2007. // of `this` is the node currently being considered. The function returns the
  2008. // resulting node(s), null, or undefined.
  2009. //
  2010. // Complex selectors are not supported:
  2011. // li:has(label:contains("foo")) + li:has(label:contains("bar"))
  2012. // ul.inner:first > li
  2013. var filters = $.expr[':'] = {
  2014. visible: function() {
  2015. if (visible(this)) return this
  2016. },
  2017. hidden: function() {
  2018. if (!visible(this)) return this
  2019. },
  2020. selected: function() {
  2021. if (this.selected) return this
  2022. },
  2023. checked: function() {
  2024. if (this.checked) return this
  2025. },
  2026. parent: function() {
  2027. return this.parentNode
  2028. },
  2029. first: function(idx) {
  2030. if (idx === 0) return this
  2031. },
  2032. last: function(idx, nodes) {
  2033. if (idx === nodes.length - 1) return this
  2034. },
  2035. eq: function(idx, _, value) {
  2036. if (idx === value) return this
  2037. },
  2038. contains: function(idx, _, text) {
  2039. if ($(this).text().indexOf(text) > -1) return this
  2040. },
  2041. has: function(idx, _, sel) {
  2042. if (zepto.qsa(this, sel).length) return this
  2043. }
  2044. }
  2045. var filterRe = new RegExp('(.*):(\\w+)(?:\\(([^)]+)\\))?$\\s*'),
  2046. childRe = /^\s*>/,
  2047. classTag = 'Zepto' + (+new Date())
  2048. function process(sel, fn) {
  2049. // quote the hash in `a[href^=#]` expression
  2050. sel = sel.replace(/=#\]/g, '="#"]')
  2051. var filter, arg, match = filterRe.exec(sel)
  2052. if (match && match[2] in filters) {
  2053. filter = filters[match[2]], arg = match[3]
  2054. sel = match[1]
  2055. if (arg) {
  2056. var num = Number(arg)
  2057. if (isNaN(num)) arg = arg.replace(/^["']|["']$/g, '')
  2058. else arg = num
  2059. }
  2060. }
  2061. return fn(sel, filter, arg)
  2062. }
  2063. zepto.qsa = function(node, selector) {
  2064. return process(selector, function(sel, filter, arg) {
  2065. try {
  2066. var taggedParent
  2067. if (!sel && filter) sel = '*'
  2068. else if (childRe.test(sel))
  2069. // support "> *" child queries by tagging the parent node with a
  2070. // unique class and prepending that classname onto the selector
  2071. taggedParent = $(node).addClass(classTag), sel = '.' + classTag + ' ' + sel
  2072. var nodes = oldQsa(node, sel)
  2073. } catch (e) {
  2074. console.error('error performing selector: %o', selector)
  2075. throw e
  2076. } finally {
  2077. if (taggedParent) taggedParent.removeClass(classTag)
  2078. }
  2079. return !filter ? nodes :
  2080. zepto.uniq($.map(nodes, function(n, i) {
  2081. return filter.call(n, i, nodes, arg)
  2082. }))
  2083. })
  2084. }
  2085. zepto.matches = function(node, selector) {
  2086. return process(selector, function(sel, filter, arg) {
  2087. return (!sel || oldMatches(node, sel)) &&
  2088. (!filter || filter.call(node, null, arg) === node)
  2089. })
  2090. }
  2091. })(Zepto)
  2092. ;
  2093. (function($) {
  2094. var touch = {},
  2095. touchTimeout, tapTimeout, swipeTimeout, longTapTimeout,
  2096. longTapDelay = 750,
  2097. gesture
  2098. function swipeDirection(x1, x2, y1, y2) {
  2099. return Math.abs(x1 - x2) >=
  2100. Math.abs(y1 - y2) ? (x1 - x2 > 0 ? 'Left' : 'Right') : (y1 - y2 > 0 ? 'Up' : 'Down')
  2101. }
  2102. function longTap() {
  2103. longTapTimeout = null
  2104. if (touch.last) {
  2105. touch.el.trigger('longTap')
  2106. touch = {}
  2107. }
  2108. }
  2109. function cancelLongTap() {
  2110. if (longTapTimeout) clearTimeout(longTapTimeout)
  2111. longTapTimeout = null
  2112. }
  2113. function cancelAll() {
  2114. if (touchTimeout) clearTimeout(touchTimeout)
  2115. if (tapTimeout) clearTimeout(tapTimeout)
  2116. if (swipeTimeout) clearTimeout(swipeTimeout)
  2117. if (longTapTimeout) clearTimeout(longTapTimeout)
  2118. touchTimeout = tapTimeout = swipeTimeout = longTapTimeout = null
  2119. touch = {}
  2120. }
  2121. function isPrimaryTouch(event) {
  2122. return (event.pointerType == 'touch' ||
  2123. event.pointerType == event.MSPOINTER_TYPE_TOUCH) && event.isPrimary
  2124. }
  2125. function isPointerEventType(e, type) {
  2126. return (e.type == 'pointer' + type ||
  2127. e.type.toLowerCase() == 'mspointer' + type)
  2128. }
  2129. $(document).ready(function() {
  2130. var now, delta, deltaX = 0,
  2131. deltaY = 0,
  2132. firstTouch, _isPointerType
  2133. if ('MSGesture' in window) {
  2134. gesture = new MSGesture()
  2135. gesture.target = document.body
  2136. }
  2137. $(document)
  2138. .bind('MSGestureEnd', function(e) {
  2139. var swipeDirectionFromVelocity =
  2140. e.velocityX > 1 ? 'Right' : e.velocityX < -1 ? 'Left' : e.velocityY > 1 ? 'Down' : e.velocityY < -1 ? 'Up' : null;
  2141. if (swipeDirectionFromVelocity) {
  2142. touch.el.trigger('swipe')
  2143. touch.el.trigger('swipe' + swipeDirectionFromVelocity)
  2144. }
  2145. })
  2146. .on('touchstart MSPointerDown pointerdown', function(e) {
  2147. if ((_isPointerType = isPointerEventType(e, 'down')) &&
  2148. !isPrimaryTouch(e)) return
  2149. firstTouch = _isPointerType ? e : e.touches[0]
  2150. if (e.touches && e.touches.length === 1 && touch.x2) {
  2151. // Clear out touch movement data if we have it sticking around
  2152. // This can occur if touchcancel doesn't fire due to preventDefault, etc.
  2153. touch.x2 = undefined
  2154. touch.y2 = undefined
  2155. }
  2156. now = Date.now()
  2157. delta = now - (touch.last || now)
  2158. touch.el = $('tagName' in firstTouch.target ?
  2159. firstTouch.target : firstTouch.target.parentNode)
  2160. touchTimeout && clearTimeout(touchTimeout)
  2161. touch.x1 = firstTouch.pageX
  2162. touch.y1 = firstTouch.pageY
  2163. if (delta > 0 && delta <= 250) touch.isDoubleTap = true
  2164. touch.last = now
  2165. longTapTimeout = setTimeout(longTap, longTapDelay)
  2166. // adds the current touch contact for IE gesture recognition
  2167. if (gesture && _isPointerType) gesture.addPointer(e.pointerId);
  2168. })
  2169. .on('touchmove MSPointerMove pointermove', function(e) {
  2170. if ((_isPointerType = isPointerEventType(e, 'move')) &&
  2171. !isPrimaryTouch(e)) return
  2172. firstTouch = _isPointerType ? e : e.touches[0]
  2173. cancelLongTap()
  2174. touch.x2 = firstTouch.pageX
  2175. touch.y2 = firstTouch.pageY
  2176. deltaX += Math.abs(touch.x1 - touch.x2)
  2177. deltaY += Math.abs(touch.y1 - touch.y2)
  2178. })
  2179. .on('touchend MSPointerUp pointerup', function(e) {
  2180. if ((_isPointerType = isPointerEventType(e, 'up')) &&
  2181. !isPrimaryTouch(e)) return
  2182. cancelLongTap()
  2183. // swipe
  2184. if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) ||
  2185. (touch.y2 && Math.abs(touch.y1 - touch.y2) > 30))
  2186. swipeTimeout = setTimeout(function() {
  2187. touch.el.trigger('swipe')
  2188. touch.el.trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2)))
  2189. touch = {}
  2190. }, 0)
  2191. // normal tap
  2192. else if ('last' in touch)
  2193. // don't fire tap when delta position changed by more than 30 pixels,
  2194. // for instance when moving to a point and back to origin
  2195. if (deltaX < 30 && deltaY < 30) {
  2196. // delay by one tick so we can cancel the 'tap' event if 'scroll' fires
  2197. // ('tap' fires before 'scroll')
  2198. tapTimeout = setTimeout(function() {
  2199. // trigger universal 'tap' with the option to cancelTouch()
  2200. // (cancelTouch cancels processing of single vs double taps for faster 'tap' response)
  2201. var event = $.Event('tap')
  2202. event.cancelTouch = cancelAll
  2203. touch.el.trigger(event)
  2204. // trigger double tap immediately
  2205. if (touch.isDoubleTap) {
  2206. if (touch.el) touch.el.trigger('doubleTap')
  2207. touch = {}
  2208. }
  2209. // trigger single tap after 250ms of inactivity
  2210. else {
  2211. touchTimeout = setTimeout(function() {
  2212. touchTimeout = null
  2213. if (touch.el) touch.el.trigger('singleTap')
  2214. touch = {}
  2215. }, 250)
  2216. }
  2217. }, 0)
  2218. } else {
  2219. touch = {}
  2220. }
  2221. deltaX = deltaY = 0
  2222. })
  2223. // when the browser window loses focus,
  2224. // for example when a modal dialog is shown,
  2225. // cancel all ongoing events
  2226. .on('touchcancel MSPointerCancel pointercancel', cancelAll)
  2227. // scrolling the window indicates intention of the user
  2228. // to scroll, not tap or swipe, so cancel all ongoing events
  2229. $(window).on('scroll', cancelAll)
  2230. })
  2231. ;
  2232. ['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown',
  2233. 'doubleTap', 'tap', 'singleTap', 'longTap'
  2234. ].forEach(function(eventName) {
  2235. $.fn[eventName] = function(callback) {
  2236. return this.on(eventName, callback)
  2237. }
  2238. })
  2239. })(Zepto)
  2240. return Zepto;
  2241. });