PageRenderTime 53ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/files/zepto/1.0/zepto.js

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