zepto_1.1.3.js 53 KB

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