zepto.js 55 KB

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