var zepto = (function() { var undefined, key, $, classlist, emptyarray = [], slice = emptyarray.slice, filter = emptyarray.filter, document = window.document, elementdisplay = {}, classcache = {}, cssnumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1, 'opacity': 1, 'z-index': 1, 'zoom': 1 }, fragmentre = /^\s*<(\w+|!)[^>]*>/, singletagre = /^<(\w+)\s*\/?>(?:<\/\1>|)$/, tagexpanderre = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig, rootnodere = /^(?:body|html)$/i, capitalre = /([a-z])/g, methodattributes = ['val', 'css', 'html', 'text', 'data', 'width', 'height', 'offset'], adjacencyoperators = ['after', 'prepend', 'before', 'append'], table = document.createelement('table'), tablerow = document.createelement('tr'), containers = { 'tr': document.createelement('tbody'), 'tbody': table, 'thead': table, 'tfoot': table, 'td': tablerow, 'th': tablerow, '*': document.createelement('div') }, readyre = /complete|loaded|interactive/, simpleselectorre = /^[\w-]*$/, class2type = {}, tostring = class2type.tostring, zepto = {}, camelize, uniq, tempparent = document.createelement('div'), propmap = { 'tabindex': 'tabindex', 'readonly': 'readonly', 'for': 'htmlfor', 'class': 'classname', 'maxlength': 'maxlength', 'cellspacing': 'cellspacing', 'cellpadding': 'cellpadding', 'rowspan': 'rowspan', 'colspan': 'colspan', 'usemap': 'usemap', 'frameborder': 'frameborder', 'contenteditable': 'contenteditable' }, isarray = array.isarray || function(object) { return object instanceof array } zepto.matches = function(element, selector) { if (!selector || !element || element.nodetype !== 1) return false var matchesselector = element.webkitmatchesselector || element.mozmatchesselector || element.omatchesselector || element.matchesselector if (matchesselector) return matchesselector.call(element, selector) var match, parent = element.parentnode, temp = !parent if (temp)(parent = tempparent).appendchild(element) match = ~zepto.qsa(parent, selector).indexof(element) temp && tempparent.removechild(element) return match } function type(obj) { return obj == null ? string(obj) : class2type[tostring.call(obj)] || "object" } function isfunction(value) { return type(value) == "function" } function iswindow(obj) { return obj != null && obj == obj.window } function isdocument(obj) { return obj != null && obj.nodetype == obj.document_node } function isobject(obj) { return type(obj) == "object" } function isplainobject(obj) { return isobject(obj) && !iswindow(obj) && object.getprototypeof(obj) == object.prototype } function likearray(obj) { return typeof obj.length == 'number' } function compact(array) { return filter.call(array, function(item) { return item != null }) } function flatten(array) { return array.length > 0 ? $.fn.concat.apply([], array) : array } camelize = function(str) { return str.replace(/-+(.)?/g, function(match, chr) { return chr ? chr.touppercase() : '' }) } function dasherize(str) { return str.replace(/::/g, '/').replace(/([a-z]+)([a-z][a-z])/g, '$1_$2').replace(/([a-z\d])([a-z])/g, '$1_$2').replace(/_/g, '-').tolowercase() } uniq = function(array) { return filter.call(array, function(item, idx) { return array.indexof(item) == idx }) } function classre(name) { return name in classcache ? classcache[name] : (classcache[name] = new regexp('(^|\\s)' + name + '(\\s|$)')) } function maybeaddpx(name, value) { return (typeof value == "number" && !cssnumber[dasherize(name)]) ? value + "px" : value } function defaultdisplay(nodename) { var element, display if (!elementdisplay[nodename]) { element = document.createelement(nodename) document.body.appendchild(element) display = getcomputedstyle(element, '').getpropertyvalue("display") element.parentnode.removechild(element) display == "none" && (display = "block") elementdisplay[nodename] = display } return elementdisplay[nodename] } function children(element) { return 'children' in element ? slice.call(element.children) : $.map(element.childnodes, function(node) { if (node.nodetype == 1) return node }) } zepto.fragment = function(html, name, properties) { var dom, nodes, container if (singletagre.test(html)) dom = $(document.createelement(regexp.$1)) if (!dom) { if (html.replace) html = html.replace(tagexpanderre, "<$1>") if (name === undefined) name = fragmentre.test(html) && regexp.$1 if (!(name in containers)) name = '*' container = containers[name] container.innerhtml = '' + html dom = $.each(slice.call(container.childnodes), function() { container.removechild(this) }) } if (isplainobject(properties)) { nodes = $(dom) $.each(properties, function(key, value) { if (methodattributes.indexof(key) > -1) nodes[key](value) else nodes.attr(key, value) }) } return dom } zepto.z = function(dom, selector) { dom = dom || [] dom.__proto__ = $.fn dom.selector = selector || '' return dom } zepto.isz = function(object) { return object instanceof zepto.z } zepto.init = function(selector, context) { var dom if (!selector) return zepto.z() else if (typeof selector == 'string') { selector = selector.trim() if (selector[0] == '<' && fragmentre.test(selector)) dom = zepto.fragment(selector, regexp.$1, context), selector = null else if (context !== undefined) return $(context).find(selector) else dom = zepto.qsa(document, selector) } else if (isfunction(selector)) return $(document).ready(selector) else if (zepto.isz(selector)) return selector else { if (isarray(selector)) dom = compact(selector) else if (isobject(selector)) dom = [selector], selector = null else if (fragmentre.test(selector)) dom = zepto.fragment(selector.trim(), regexp.$1, context), selector = null else if (context !== undefined) return $(context).find(selector) else dom = zepto.qsa(document, selector) } return zepto.z(dom, selector) } $ = function(selector, context) { return zepto.init(selector, context) } function extend(target, source, deep) { for (key in source) if (deep && (isplainobject(source[key]) || isarray(source[key]))) { if (isplainobject(source[key]) && !isplainobject(target[key])) target[key] = {} if (isarray(source[key]) && !isarray(target[key])) target[key] = [] extend(target[key], source[key], deep) } else if (source[key] !== undefined) target[key] = source[key] } $.extend = function(target) { var deep, args = slice.call(arguments, 1) if (typeof target == 'boolean') { deep = target target = args.shift() } args.foreach(function(arg) { extend(target, arg, deep) }) return target } zepto.qsa = function(element, selector) { var found, maybeid = selector[0] == '#', maybeclass = !maybeid && selector[0] == '.', nameonly = maybeid || maybeclass ? selector.slice(1) : selector, issimple = simpleselectorre.test(nameonly) return (isdocument(element) && issimple && maybeid) ? ((found = element.getelementbyid(nameonly)) ? [found] : []) : (element.nodetype !== 1 && element.nodetype !== 9) ? [] : slice.call(issimple && !maybeid ? maybeclass ? element.getelementsbyclassname(nameonly) : element.getelementsbytagname(selector) : element.queryselectorall(selector)) } function filtered(nodes, selector) { return selector == null ? $(nodes) : $(nodes).filter(selector) } $.contains = function(parent, node) { return parent !== node && parent.contains(node) } function funcarg(context, arg, idx, payload) { return isfunction(arg) ? arg.call(context, idx, payload) : arg } function setattribute(node, name, value) { value == null ? node.removeattribute(name) : node.setattribute(name, value) } function classname(node, value) { var klass = node.classname, svg = klass && klass.baseval !== undefined if (value === undefined) return svg ? klass.baseval : klass svg ? (klass.baseval = value) : (node.classname = value) } function deserializevalue(value) { var num try { return value ? value == "true" || (value == "false" ? false : value == "null" ? null : !/^0/.test(value) && !isnan(num = number(value)) ? num : /^[\[\{]/.test(value) ? $.parsejson(value) : value) : value } catch (e) { return value } } $.type = type $.isfunction = isfunction $.iswindow = iswindow $.isarray = isarray $.isplainobject = isplainobject $.isemptyobject = function(obj) { var name for (name in obj) return false return true } $.inarray = function(elem, array, i) { return emptyarray.indexof.call(array, elem, i) } $.camelcase = camelize $.trim = function(str) { return str == null ? "" : string.prototype.trim.call(str) } $.uuid = 0 $.support = {} $.expr = {} $.map = function(elements, callback) { var value, values = [], i, key if (likearray(elements)) for (i = 0; i < elements.length; i++) { value = callback(elements[i], i) if (value != null) values.push(value) } else for (key in elements) { value = callback(elements[key], key) if (value != null) values.push(value) } return flatten(values) } $.each = function(elements, callback) { var i, key if (likearray(elements)) { for (i = 0; i < elements.length; i++) if (callback.call(elements[i], i, elements[i]) === false) return elements } else { for (key in elements) if (callback.call(elements[key], key, elements[key]) === false) return elements } return elements } $.grep = function(elements, callback) { return filter.call(elements, callback) } if (window.json) $.parsejson = json.parse $.each("boolean number string function array date regexp object error".split(" "), function(i, name) { class2type["[object " + name + "]"] = name.tolowercase() }) $.fn = { foreach: emptyarray.foreach, reduce: emptyarray.reduce, push: emptyarray.push, sort: emptyarray.sort, indexof: emptyarray.indexof, concat: emptyarray.concat, map: function(fn) { return $($.map(this, function(el, i) { return fn.call(el, i, el) })) }, slice: function() { return $(slice.apply(this, arguments)) }, ready: function(callback) { if (readyre.test(document.readystate) && document.body) callback($) else document.addeventlistener('domcontentloaded', function() { callback($) }, false) return this }, get: function(idx) { return idx === undefined ? slice.call(this) : this[idx >= 0 ? idx : idx + this.length] }, toarray: function() { return this.get() }, size: function() { return this.length }, remove: function() { return this.each(function() { if (this.parentnode != null) this.parentnode.removechild(this) }) }, each: function(callback) { emptyarray.every.call(this, function(el, idx) { return callback.call(el, idx, el) !== false }) return this }, filter: function(selector) { if (isfunction(selector)) return this.not(this.not(selector)) return $(filter.call(this, function(element) { return zepto.matches(element, selector) })) }, add: function(selector, context) { return $(uniq(this.concat($(selector, context)))) }, is: function(selector) { return this.length > 0 && zepto.matches(this[0], selector) }, not: function(selector) { var nodes = [] if (isfunction(selector) && selector.call !== undefined) this.each(function(idx) { if (!selector.call(this, idx)) nodes.push(this) }) else { var excludes = typeof selector == 'string' ? this.filter(selector) : (likearray(selector) && isfunction(selector.item)) ? slice.call(selector) : $(selector) this.foreach(function(el) { if (excludes.indexof(el) < 0) nodes.push(el) }) } return $(nodes) }, has: function(selector) { return this.filter(function() { return isobject(selector) ? $.contains(this, selector) : $(this).find(selector).size() }) }, eq: function(idx) { return idx === -1 ? this.slice(idx) : this.slice(idx, +idx + 1) }, first: function() { var el = this[0] return el && !isobject(el) ? el : $(el) }, last: function() { var el = this[this.length - 1] return el && !isobject(el) ? el : $(el) }, find: function(selector) { var result, $this = this if (typeof selector == 'object') result = $(selector).filter(function() { var node = this return emptyarray.some.call($this, function(parent) { return $.contains(parent, node) }) }) else if (this.length == 1) result = $(zepto.qsa(this[0], selector)) else result = this.map(function() { return zepto.qsa(this, selector) }) return result }, closest: function(selector, context) { var node = this[0], collection = false if (typeof selector == 'object') collection = $(selector) while (node && !(collection ? collection.indexof(node) >= 0 : zepto.matches(node, selector))) node = node !== context && !isdocument(node) && node.parentnode return $(node) }, parents: function(selector) { var ancestors = [], nodes = this while (nodes.length > 0) nodes = $.map(nodes, function(node) { if ((node = node.parentnode) && !isdocument(node) && ancestors.indexof(node) < 0) { ancestors.push(node) return node } }) return filtered(ancestors, selector) }, parent: function(selector) { return filtered(uniq(this.pluck('parentnode')), selector) }, children: function(selector) { return filtered(this.map(function() { return children(this) }), selector) }, contents: function() { return this.map(function() { return slice.call(this.childnodes) }) }, siblings: function(selector) { return filtered(this.map(function(i, el) { return filter.call(children(el.parentnode), function(child) { return child !== el }) }), selector) }, empty: function() { return this.each(function() { this.innerhtml = '' }) }, pluck: function(property) { return $.map(this, function(el) { return el[property] }) }, show: function() { return this.each(function() { this.style.display == "none" && (this.style.display = '') if (getcomputedstyle(this, '').getpropertyvalue("display") == "none") this.style.display = defaultdisplay(this.nodename) }) }, replacewith: function(newcontent) { return this.before(newcontent).remove() }, wrap: function(structure) { var func = isfunction(structure) if (this[0] && !func) var dom = $(structure).get(0), clone = dom.parentnode || this.length > 1 return this.each(function(index) { $(this).wrapall(func ? structure.call(this, index) : clone ? dom.clonenode(true) : dom) }) }, wrapall: function(structure) { if (this[0]) { $(this[0]).before(structure = $(structure)) var children while ((children = structure.children()).length) structure = children.first() $(structure).append(this) } return this }, wrapinner: function(structure) { var func = isfunction(structure) return this.each(function(index) { var self = $(this), contents = self.contents(), dom = func ? structure.call(this, index) : structure contents.length ? contents.wrapall(dom) : self.append(dom) }) }, unwrap: function() { this.parent().each(function() { $(this).replacewith($(this).children()) }) return this }, clone: function() { return this.map(function() { return this.clonenode(true) }) }, hide: function() { return this.css("display", "none") }, toggle: function(setting) { return this.each(function() { var el = $(this); (setting === undefined ? el.css("display") == "none" : setting) ? el.show(): el.hide() }) }, prev: function(selector) { return $(this.pluck('previouselementsibling')).filter(selector || '*') }, next: function(selector) { return $(this.pluck('nextelementsibling')).filter(selector || '*') }, html: function(html) { return arguments.length === 0 ? (this.length > 0 ? this[0].innerhtml : null) : this.each(function(idx) { var originhtml = this.innerhtml $(this).empty().append(funcarg(this, html, idx, originhtml)) }) }, text: function(text) { return arguments.length === 0 ? (this.length > 0 ? this[0].textcontent : null) : this.each(function() { this.textcontent = (text === undefined) ? '' : '' + text }) }, attr: function(name, value) { var result return (typeof name == 'string' && value === undefined) ? (this.length == 0 || this[0].nodetype !== 1 ? undefined : (name == 'value' && this[0].nodename == 'input') ? this.val() : (!(result = this[0].getattribute(name)) && name in this[0]) ? this[0][name] : result) : this.each(function(idx) { if (this.nodetype !== 1) return if (isobject(name)) for (key in name) setattribute(this, key, name[key]) else setattribute(this, name, funcarg(this, value, idx, this.getattribute(name))) }) }, removeattr: function(name) { return this.each(function() { this.nodetype === 1 && setattribute(this, name) }) }, prop: function(name, value) { name = propmap[name] || name return (value === undefined) ? (this[0] && this[0][name]) : this.each(function(idx) { this[name] = funcarg(this, value, idx, this[name]) }) }, data: function(name, value) { var data = this.attr('data-' + name.replace(capitalre, '-$1').tolowercase(), value) return data !== null ? deserializevalue(data) : undefined }, val: function(value) { return arguments.length === 0 ? (this[0] && (this[0].multiple ? $(this[0]).find('option').filter(function() { return this.selected }).pluck('value') : this[0].value)) : this.each(function(idx) { this.value = funcarg(this, value, idx, this.value) }) }, offset: function(coordinates) { if (coordinates) return this.each(function(index) { var $this = $(this), coords = funcarg(this, coordinates, index, $this.offset()), parentoffset = $this.offsetparent().offset(), props = { top: coords.top - parentoffset.top, left: coords.left - parentoffset.left } if ($this.css('position') == 'static') props['position'] = 'relative' $this.css(props) }) if (this.length == 0) return null var obj = this[0].getboundingclientrect() return { left: obj.left + window.pagexoffset, top: obj.top + window.pageyoffset, width: math.round(obj.width), height: math.round(obj.height) } }, css: function(property, value) { if (arguments.length < 2) { var element = this[0], computedstyle = getcomputedstyle(element, '') if (!element) return if (typeof property == 'string') return element.style[camelize(property)] || computedstyle.getpropertyvalue(property) else if (isarray(property)) { var props = {} $.each(isarray(property) ? property : [property], function(_, prop) { props[prop] = (element.style[camelize(prop)] || computedstyle.getpropertyvalue(prop)) }) return props } } var css = '' if (type(property) == 'string') { if (!value && value !== 0) this.each(function() { this.style.removeproperty(dasherize(property)) }) else css = dasherize(property) + ":" + maybeaddpx(property, value) } else { for (key in property) if (!property[key] && property[key] !== 0) this.each(function() { this.style.removeproperty(dasherize(key)) }) else css += dasherize(key) + ':' + maybeaddpx(key, property[key]) + ';' } return this.each(function() { this.style.csstext += ';' + css }) }, index: function(element) { return element ? this.indexof($(element)[0]) : this.parent().children().indexof(this[0]) }, hasclass: function(name) { if (!name) return false return emptyarray.some.call(this, function(el) { return this.test(classname(el)) }, classre(name)) }, addclass: function(name) { if (!name) return this return this.each(function(idx) { classlist = [] var cls = classname(this), newname = funcarg(this, name, idx, cls) newname.split(/\s+/g).foreach(function(klass) { if (!$(this).hasclass(klass)) classlist.push(klass) }, this) classlist.length && classname(this, cls + (cls ? " " : "") + classlist.join(" ")) }) }, removeclass: function(name) { return this.each(function(idx) { if (name === undefined) return classname(this, '') classlist = classname(this) funcarg(this, name, idx, classlist).split(/\s+/g).foreach(function(klass) { classlist = classlist.replace(classre(klass), " ") }) classname(this, classlist.trim()) }) }, toggleclass: function(name, when) { if (!name) return this return this.each(function(idx) { var $this = $(this), names = funcarg(this, name, idx, classname(this)) names.split(/\s+/g).foreach(function(klass) { (when === undefined ? !$this.hasclass(klass) : when) ? $this.addclass(klass): $this.removeclass(klass) }) }) }, scrolltop: function(value) { if (!this.length) return var hasscrolltop = 'scrolltop' in this[0] if (value === undefined) return hasscrolltop ? this[0].scrolltop : this[0].pageyoffset return this.each(hasscrolltop ? function() { this.scrolltop = value } : function() { this.scrollto(this.scrollx, value) }) }, scrollleft: function(value) { if (!this.length) return var hasscrollleft = 'scrollleft' in this[0] if (value === undefined) return hasscrollleft ? this[0].scrollleft : this[0].pagexoffset return this.each(hasscrollleft ? function() { this.scrollleft = value } : function() { this.scrollto(value, this.scrolly) }) }, position: function() { if (!this.length) return var elem = this[0], offsetparent = this.offsetparent(), offset = this.offset(), parentoffset = rootnodere.test(offsetparent[0].nodename) ? { top: 0, left: 0 } : offsetparent.offset() offset.top -= parsefloat($(elem).css('margin-top')) || 0 offset.left -= parsefloat($(elem).css('margin-left')) || 0 parentoffset.top += parsefloat($(offsetparent[0]).css('border-top-width')) || 0 parentoffset.left += parsefloat($(offsetparent[0]).css('border-left-width')) || 0 return { top: offset.top - parentoffset.top, left: offset.left - parentoffset.left } }, offsetparent: function() { return this.map(function() { var parent = this.offsetparent || document.body while (parent && !rootnodere.test(parent.nodename) && $(parent).css("position") == "static") parent = parent.offsetparent return parent }) } } $.fn.detach = $.fn.remove; ['width', 'height'].foreach(function(dimension) { var dimensionproperty = dimension.replace(/./, function(m) { return m[0].touppercase() }) $.fn[dimension] = function(value) { var offset, el = this[0] if (value === undefined) return iswindow(el) ? el['inner' + dimensionproperty] : isdocument(el) ? el.documentelement['scroll' + dimensionproperty] : (offset = this.offset()) && offset[dimension] else return this.each(function(idx) { el = $(this) el.css(dimension, funcarg(this, value, idx, el[dimension]())) }) } }) function traversenode(node, fun) { fun(node) for (var key in node.childnodes) traversenode(node.childnodes[key], fun) } adjacencyoperators.foreach(function(operator, operatorindex) { var inside = operatorindex % 2 $.fn[operator] = function() { var argtype, nodes = $.map(arguments, function(arg) { argtype = type(arg) return argtype == "object" || argtype == "array" || arg == null ? arg : zepto.fragment(arg) }), parent, copybyclone = this.length > 1 if (nodes.length < 1) return this return this.each(function(_, target) { parent = inside ? target : target.parentnode target = operatorindex == 0 ? target.nextsibling : operatorindex == 1 ? target.firstchild : operatorindex == 2 ? target : null nodes.foreach(function(node) { if (copybyclone) node = node.clonenode(true) else if (!parent) return $(node).remove() traversenode(parent.insertbefore(node, target), function(el) { if (el.nodename != null && el.nodename.touppercase() === 'script' && (!el.type || el.type === 'text/javascript') && !el.src) window['eval'].call(window, el.innerhtml) }) }) }) } $.fn[inside ? operator + 'to' : 'insert' + (operatorindex ? 'before' : 'after')] = function(html) { $(html)[operator](this) return this } }) zepto.z.prototype = $.fn zepto.uniq = uniq zepto.deserializevalue = deserializevalue $.zepto = zepto return $ })() window.zepto = zepto window.$ === undefined && (window.$ = zepto); (function($) { var _zid = 1, undefined, slice = array.prototype.slice, isfunction = $.isfunction, isstring = function(obj) { return typeof obj == 'string' }, handlers = {}, specialevents = {}, focusinsupported = 'onfocusin' in window, focus = { focus: 'focusin', blur: 'focusout' }, hover = { mouseenter: 'mouseover', mouseleave: 'mouseout' } specialevents.click = specialevents.mousedown = specialevents.mouseup = specialevents.mousemove = 'mouseevents' function zid(element) { return element._zid || (element._zid = _zid++) } function findhandlers(element, event, fn, selector) { event = parse(event) if (event.ns) var matcher = matcherfor(event.ns) return (handlers[zid(element)] || []).filter(function(handler) { return handler && (!event.e || handler.e == event.e) && (!event.ns || matcher.test(handler.ns)) && (!fn || zid(handler.fn) === zid(fn)) && (!selector || handler.sel == selector) }) } function parse(event) { var parts = ('' + event).split('.') return { e: parts[0], ns: parts.slice(1).sort().join(' ') } } function matcherfor(ns) { return new regexp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)') } function eventcapture(handler, capturesetting) { return handler.del && (!focusinsupported && (handler.e in focus)) || !!capturesetting } function realevent(type) { return hover[type] || (focusinsupported && focus[type]) || type } function add(element, events, fn, data, selector, delegator, capture) { var id = zid(element), set = (handlers[id] || (handlers[id] = [])) events.split(/\s/).foreach(function(event) { if (event == 'ready') return $(document).ready(fn) var handler = parse(event) handler.fn = fn handler.sel = selector if (handler.e in hover) fn = function(e) { var related = e.relatedtarget if (!related || (related !== this && !$.contains(this, related))) return handler.fn.apply(this, arguments) } handler.del = delegator var callback = delegator || fn handler.proxy = function(e) { e = compatible(e) if (e.isimmediatepropagationstopped()) return e.data = data var result = callback.apply(element, e._args == undefined ? [e] : [e].concat(e._args)) if (result === false) e.preventdefault(), e.stoppropagation() return result } handler.i = set.length set.push(handler) if ('addeventlistener' in element) element.addeventlistener(realevent(handler.e), handler.proxy, eventcapture(handler, capture)) }) } function remove(element, events, fn, selector, capture) { var id = zid(element); (events || '').split(/\s/).foreach(function(event) { findhandlers(element, event, fn, selector).foreach(function(handler) { delete handlers[id][handler.i] if ('removeeventlistener' in element) element.removeeventlistener(realevent(handler.e), handler.proxy, eventcapture(handler, capture)) }) }) } $.event = { add: add, remove: remove } $.proxy = function(fn, context) { if (isfunction(fn)) { var proxyfn = function() { return fn.apply(context, arguments) } proxyfn._zid = zid(fn) return proxyfn } else if (isstring(context)) { return $.proxy(fn[context], fn) } else { throw new typeerror("expected function") } } $.fn.bind = function(event, data, callback) { return this.on(event, data, callback) } $.fn.unbind = function(event, callback) { return this.off(event, callback) } $.fn.one = function(event, selector, data, callback) { return this.on(event, selector, data, callback, 1) } var returntrue = function() { return true }, returnfalse = function() { return false }, ignoreproperties = /^([a-z]|returnvalue$|layer[xy]$)/, eventmethods = { preventdefault: 'isdefaultprevented', stopimmediatepropagation: 'isimmediatepropagationstopped', stoppropagation: 'ispropagationstopped' } function compatible(event, source) { if (source || !event.isdefaultprevented) { source || (source = event) $.each(eventmethods, function(name, predicate) { var sourcemethod = source[name] event[name] = function() { this[predicate] = returntrue return sourcemethod && sourcemethod.apply(source, arguments) } event[predicate] = returnfalse }) if (source.defaultprevented !== undefined ? source.defaultprevented : 'returnvalue' in source ? source.returnvalue === false : source.getpreventdefault && source.getpreventdefault()) event.isdefaultprevented = returntrue } return event } function createproxy(event) { var key, proxy = { originalevent: event } for (key in event) if (!ignoreproperties.test(key) && event[key] !== undefined) proxy[key] = event[key] return compatible(proxy, event) } $.fn.delegate = function(selector, event, callback) { return this.on(event, selector, callback) } $.fn.undelegate = function(selector, event, callback) { return this.off(event, selector, callback) } $.fn.live = function(event, callback) { $(document.body).delegate(this.selector, event, callback) return this } $.fn.die = function(event, callback) { $(document.body).undelegate(this.selector, event, callback) return this } $.fn.on = function(event, selector, data, callback, one) { var autoremove, delegator, $this = this if (event && !isstring(event)) { $.each(event, function(type, fn) { $this.on(type, selector, data, fn, one) }) return $this } if (!isstring(selector) && !isfunction(callback) && callback !== false) callback = data, data = selector, selector = undefined if (isfunction(data) || data === false) callback = data, data = undefined if (callback === false) callback = returnfalse return $this.each(function(_, element) { if (one) autoremove = function(e) { remove(element, e.type, callback) return callback.apply(this, arguments) } if (selector) delegator = function(e) { var evt, match = $(e.target).closest(selector, element).get(0) if (match && match !== element) { evt = $.extend(createproxy(e), { currenttarget: match, livefired: element }) return (autoremove || callback).apply(match, [evt].concat(slice.call(arguments, 1))) } } add(element, event, callback, data, selector, delegator || autoremove) }) } $.fn.off = function(event, selector, callback) { var $this = this if (event && !isstring(event)) { $.each(event, function(type, fn) { $this.off(type, selector, fn) }) return $this } if (!isstring(selector) && !isfunction(callback) && callback !== false) callback = selector, selector = undefined if (callback === false) callback = returnfalse return $this.each(function() { remove(this, event, callback, selector) }) } $.fn.trigger = function(event, args) { event = (isstring(event) || $.isplainobject(event)) ? $.event(event) : compatible(event) event._args = args return this.each(function() { if ('dispatchevent' in this) this.dispatchevent(event) else $(this).triggerhandler(event, args) }) } $.fn.triggerhandler = function(event, args) { var e, result this.each(function(i, element) { e = createproxy(isstring(event) ? $.event(event) : event) e._args = args e.target = element $.each(findhandlers(element, event.type || event), function(i, handler) { result = handler.proxy(e) if (e.isimmediatepropagationstopped()) return false }) }) return result }; ('focusin focusout load resize scroll unload click dblclick ' + 'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave ' + 'change select keydown keypress keyup error').split(' ').foreach(function(event) { $.fn[event] = function(callback) { return callback ? this.bind(event, callback) : this.trigger(event) } }); ['focus', 'blur'].foreach(function(name) { $.fn[name] = function(callback) { if (callback) this.bind(name, callback) else this.each(function() { try { this[name]() } catch (e) {} }) return this } }) $.event = function(type, props) { if (!isstring(type)) props = type, type = props.type var event = document.createevent(specialevents[type] || 'events'), bubbles = true if (props) for (var name in props)(name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name]) event.initevent(type, bubbles, true) return compatible(event) } })(zepto); (function($) { var jsonpid = 0, document = window.document, key, name, rscript = /)<[^<]*)*<\/script>/gi, scripttypere = /^(?:text|application)\/javascript/i, xmltypere = /^(?:text|application)\/xml/i, jsontype = 'application/json', htmltype = 'text/html', blankre = /^\s*$/ function triggerandreturn(context, eventname, data) { var event = $.event(eventname) $(context).trigger(event, data) return !event.isdefaultprevented() } function triggerglobal(settings, context, eventname, data) { if (settings.global) return triggerandreturn(context || document, eventname, data) } $.active = 0 function ajaxstart(settings) { if (settings.global && $.active++ === 0) triggerglobal(settings, null, 'ajaxstart') } function ajaxstop(settings) { if (settings.global && !(--$.active)) triggerglobal(settings, null, 'ajaxstop') } function ajaxbeforesend(xhr, settings) { var context = settings.context if (settings.beforesend.call(context, xhr, settings) === false || triggerglobal(settings, context, 'ajaxbeforesend', [xhr, settings]) === false) return false triggerglobal(settings, context, 'ajaxsend', [xhr, settings]) } function ajaxsuccess(data, xhr, settings, deferred) { var context = settings.context, status = 'success' settings.success.call(context, data, status, xhr) if (deferred) deferred.resolvewith(context, [data, status, xhr]) triggerglobal(settings, context, 'ajaxsuccess', [xhr, settings, data]) ajaxcomplete(status, xhr, settings) } function ajaxerror(error, type, xhr, settings, deferred) { var context = settings.context settings.error.call(context, xhr, type, error) if (deferred) deferred.rejectwith(context, [xhr, type, error]) triggerglobal(settings, context, 'ajaxerror', [xhr, settings, error || type]) ajaxcomplete(type, xhr, settings) } function ajaxcomplete(status, xhr, settings) { var context = settings.context settings.complete.call(context, xhr, status) triggerglobal(settings, context, 'ajaxcomplete', [xhr, settings]) ajaxstop(settings) } function empty() {} $.ajaxjsonp = function(options, deferred) { if (!('type' in options)) return $.ajax(options) var _callbackname = options.jsonpcallback, callbackname = ($.isfunction(_callbackname) ? _callbackname() : _callbackname) || ('jsonp' + (++jsonpid)), script = document.createelement('script'), originalcallback = window[callbackname], responsedata, abort = function(errortype) { $(script).triggerhandler('error', errortype || 'abort') }, xhr = { abort: abort }, aborttimeout if (deferred) deferred.promise(xhr) $(script).on('load error', function(e, errortype) { cleartimeout(aborttimeout) $(script).off().remove() if (e.type == 'error' || !responsedata) { ajaxerror(null, errortype || 'error', xhr, options, deferred) } else { ajaxsuccess(responsedata[0], xhr, options, deferred) } window[callbackname] = originalcallback if (responsedata && $.isfunction(originalcallback)) originalcallback(responsedata[0]) originalcallback = responsedata = undefined }) if (ajaxbeforesend(xhr, options) === false) { abort('abort') return xhr } window[callbackname] = function() { responsedata = arguments } script.src = options.url.replace(/\?(.+)=\?/, '?$1=' + callbackname) document.head.appendchild(script) if (options.timeout > 0) aborttimeout = settimeout(function() { abort('timeout') }, options.timeout) return xhr } $.ajaxsettings = { type: 'get', beforesend: empty, success: empty, error: empty, complete: empty, context: null, global: true, xhr: function() { return new window.xmlhttprequest() }, accepts: { script: 'text/javascript, application/javascript, application/x-javascript', json: jsontype, xml: 'application/xml, text/xml', html: htmltype, text: 'text/plain' }, crossdomain: false, timeout: 0, processdata: true, cache: true } function mimetodatatype(mime) { if (mime) mime = mime.split(';', 2)[0] return mime && (mime == htmltype ? 'html' : mime == jsontype ? 'json' : scripttypere.test(mime) ? 'script' : xmltypere.test(mime) && 'xml') || 'text' } function appendquery(url, query) { if (query == '') return url return (url + '&' + query).replace(/[&?]{1,2}/, '?') } function serializedata(options) { if (options.processdata && options.data && $.type(options.data) != "string") options.data = $.param(options.data, options.traditional) if (options.data && (!options.type || options.type.touppercase() == 'get')) options.url = appendquery(options.url, options.data), options.data = undefined } $.ajax = function(options) { var settings = $.extend({}, options || {}), deferred = $.deferred && $.deferred() for (key in $.ajaxsettings) if (settings[key] === undefined) settings[key] = $.ajaxsettings[key] ajaxstart(settings) if (!settings.crossdomain) settings.crossdomain = /^([\w-]+:)?\/\/([^\/]+)/.test(settings.url) && regexp.$2 != window.location.host if (!settings.url) settings.url = window.location.tostring() serializedata(settings) if (settings.cache === false) settings.url = appendquery(settings.url, '_=' + date.now()) var datatype = settings.datatype, hasplaceholder = /\?.+=\?/.test(settings.url) if (datatype == 'jsonp' || hasplaceholder) { if (!hasplaceholder) settings.url = appendquery(settings.url, settings.jsonp ? (settings.jsonp + '=?') : settings.jsonp === false ? '' : 'callback=?') return $.ajaxjsonp(settings, deferred) } var mime = settings.accepts[datatype], headers = {}, setheader = function(name, value) { headers[name.tolowercase()] = [name, value] }, protocol = /^([\w-]+:)\/\//.test(settings.url) ? regexp.$1 : window.location.protocol, xhr = settings.xhr(), nativesetheader = xhr.setrequestheader, aborttimeout if (deferred) deferred.promise(xhr) if (!settings.crossdomain) setheader('x-requested-with', 'xmlhttprequest') setheader('accept', mime || '*/*') if (mime = settings.mimetype || mime) { if (mime.indexof(',') > -1) mime = mime.split(',', 2)[0] xhr.overridemimetype && xhr.overridemimetype(mime) } if (settings.contenttype || (settings.contenttype !== false && settings.data && settings.type.touppercase() != 'get')) setheader('content-type', settings.contenttype || 'application/x-www-form-urlencoded') if (settings.headers) for (name in settings.headers) setheader(name, settings.headers[name]) xhr.setrequestheader = setheader xhr.onreadystatechange = function() { if (xhr.readystate == 4) { xhr.onreadystatechange = empty cleartimeout(aborttimeout) var result, error = false if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) { datatype = datatype || mimetodatatype(settings.mimetype || xhr.getresponseheader('content-type')) result = xhr.responsetext try { if (datatype == 'script')(1, eval)(result) else if (datatype == 'xml') result = xhr.responsexml else if (datatype == 'json') result = blankre.test(result) ? null : $.parsejson(result) } catch (e) { error = e } if (error) ajaxerror(error, 'parsererror', xhr, settings, deferred) else ajaxsuccess(result, xhr, settings, deferred) } else { ajaxerror(xhr.statustext || null, xhr.status ? 'error' : 'abort', xhr, settings, deferred) } } } if (ajaxbeforesend(xhr, settings) === false) { xhr.abort() ajaxerror(null, 'abort', xhr, settings, deferred) return xhr } if (settings.xhrfields) for (name in settings.xhrfields) xhr[name] = settings.xhrfields[name] var async = 'async' in settings ? settings.async : true xhr.open(settings.type, settings.url, async, settings.username, settings.password) for (name in headers) nativesetheader.apply(xhr, headers[name]) if (settings.timeout > 0) aborttimeout = settimeout(function() { xhr.onreadystatechange = empty xhr.abort() ajaxerror(null, 'timeout', xhr, settings, deferred) }, settings.timeout) xhr.send(settings.data ? settings.data : null) return xhr } function parsearguments(url, data, success, datatype) { if ($.isfunction(data)) datatype = success, success = data, data = undefined if (!$.isfunction(success)) datatype = success, success = undefined return { url: url, data: data, success: success, datatype: datatype } } $.get = function() { return $.ajax(parsearguments.apply(null, arguments)) } $.post = function() { var options = parsearguments.apply(null, arguments) options.type = 'post' return $.ajax(options) } $.getjson = function() { var options = parsearguments.apply(null, arguments) options.datatype = 'json' return $.ajax(options) } $.fn.load = function(url, data, success) { if (!this.length) return this var self = this, parts = url.split(/\s/), selector, options = parsearguments(url, data, success), callback = options.success if (parts.length > 1) options.url = parts[0], selector = parts[1] options.success = function(response) { self.html(selector ? $('
').html(response.replace(rscript, "")).find(selector) : response) callback && callback.apply(self, arguments) } $.ajax(options) return this } var escape = encodeuricomponent function serialize(params, obj, traditional, scope) { var type, array = $.isarray(obj), hash = $.isplainobject(obj) $.each(obj, function(key, value) { type = $.type(value) if (scope) key = traditional ? scope : scope + '[' + (hash || type == 'object' || type == 'array' ? key : '') + ']' if (!scope && array) params.add(value.name, value.value) else if (type == "array" || (!traditional && type == "object")) serialize(params, value, traditional, key) else params.add(key, value) }) } $.param = function(obj, traditional) { var params = [] params.add = function(k, v) { this.push(escape(k) + '=' + escape(v)) } serialize(params, obj, traditional) return params.join('&').replace(/%20/g, '+') } })(zepto); (function($) { $.fn.serializearray = function() { var result = [], el $([].slice.call(this.get(0).elements)).each(function() { el = $(this) var type = el.attr('type') if (this.nodename.tolowercase() != 'fieldset' && !this.disabled && type != 'submit' && type != 'reset' && type != 'button' && ((type != 'radio' && type != 'checkbox') || this.checked)) result.push({ name: el.attr('name'), value: el.val() }) }) return result } $.fn.serialize = function() { var result = [] this.serializearray().foreach(function(elm) { result.push(encodeuricomponent(elm.name) + '=' + encodeuricomponent(elm.value)) }) return result.join('&') } $.fn.submit = function(callback) { if (callback) this.bind('submit', callback) else if (this.length) { var event = $.event('submit') this.eq(0).trigger(event) if (!event.isdefaultprevented()) this.get(0).submit() } return this } })(zepto); (function($) { if (!('__proto__' in {})) { $.extend($.zepto, { z: function(dom, selector) { dom = dom || [] $.extend(dom, $.fn) dom.selector = selector || '' dom.__z = true return dom }, isz: function(object) { return $.type(object) === 'array' && '__z' in object } }) } try { getcomputedstyle(undefined) } catch (e) { var nativegetcomputedstyle = getcomputedstyle; window.getcomputedstyle = function(element) { try { return nativegetcomputedstyle(element) } catch (e) { return null } } } })(zepto); (function($) { function detect(ua) { var os = this.os = {}, browser = this.browser = {}, webkit = ua.match(/web[kk]it[\/]{0,1}([\d.]+)/), android = ua.match(/(android);?[\s\/]+([\d.]+)?/), osx = !!ua.match(/\(macintosh\; intel /), ipad = ua.match(/(ipad).*os\s([\d_]+)/), ipod = ua.match(/(ipod)(.*os\s([\d_]+))?/), iphone = !ipad && ua.match(/(iphone\sos)\s([\d_]+)/), webos = ua.match(/(webos|hpwos)[\s\/]([\d.]+)/), wp = ua.match(/windows phone ([\d.]+)/), touchpad = webos && ua.match(/touchpad/), kindle = ua.match(/kindle\/([\d.]+)/), silk = ua.match(/silk\/([\d._]+)/), blackberry = ua.match(/(blackberry).*version\/([\d.]+)/), bb10 = ua.match(/(bb10).*version\/([\d.]+)/), rimtabletos = ua.match(/(rim\stablet\sos)\s([\d.]+)/), playbook = ua.match(/playbook/), chrome = ua.match(/chrome\/([\d.]+)/) || ua.match(/crios\/([\d.]+)/), firefox = ua.match(/firefox\/([\d.]+)/), ie = ua.match(/msie\s([\d.]+)/) || ua.match(/trident\/[\d](?=[^\?]+).*rv:([0-9.].)/), webview = !chrome && ua.match(/(iphone|ipod|ipad).*applewebkit(?!.*safari)/), safari = webview || ua.match(/version\/([\d.]+)([^s](safari)|[^m]*(mobile)[^s]*(safari))/) if (browser.webkit = !!webkit) browser.version = webkit[1] if (android) os.android = true, os.version = android[2] if (iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.') if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.') if (ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null if (wp) os.wp = true, os.version = wp[1] if (webos) os.webos = true, os.version = webos[2] if (touchpad) os.touchpad = true if (blackberry) os.blackberry = true, os.version = blackberry[2] if (bb10) os.bb10 = true, os.version = bb10[2] if (rimtabletos) os.rimtabletos = true, os.version = rimtabletos[2] if (playbook) browser.playbook = true if (kindle) os.kindle = true, os.version = kindle[1] if (silk) browser.silk = true, browser.version = silk[1] if (!silk && os.android && ua.match(/kindle fire/)) browser.silk = true if (chrome) browser.chrome = true, browser.version = chrome[1] if (firefox) browser.firefox = true, browser.version = firefox[1] if (ie) browser.ie = true, browser.version = ie[1] if (safari && (osx || os.ios)) { browser.safari = true; if (osx) browser.version = safari[1] } if (webview) browser.webview = true os.tablet = !!(ipad || playbook || (android && !ua.match(/mobile/)) || (firefox && ua.match(/tablet/)) || (ie && !ua.match(/phone/) && ua.match(/touch/))) os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos || blackberry || bb10 || (chrome && ua.match(/android/)) || (chrome && ua.match(/crios\/([\d.]+)/)) || (firefox && ua.match(/mobile/)) || (ie && ua.match(/touch/)))) } detect.call($, navigator.useragent) $.__detect = detect })(zepto); (function($, undefined) { var prefix = '', eventprefix, endeventname, endanimationname, vendors = { webkit: 'webkit', moz: '', o: 'o' }, document = window.document, testel = document.createelement('div'), supportedtransforms = /^((translate|rotate|scale)(x|y|z|3d)?|matrix(3d)?|perspective|skew(x|y)?)$/i, transform, transitionproperty, transitionduration, transitiontiming, transitiondelay, animationname, animationduration, animationtiming, animationdelay, cssreset = {} function dasherize(str) { return str.replace(/([a-z])([a-z])/, '$1-$2').tolowercase() } function normalizeevent(name) { return eventprefix ? eventprefix + name : name.tolowercase() } $.each(vendors, function(vendor, event) { if (testel.style[vendor + 'transitionproperty'] !== undefined) { prefix = '-' + vendor.tolowercase() + '-' eventprefix = event return false } }) transform = prefix + 'transform' cssreset[transitionproperty = prefix + 'transition-property'] = cssreset[transitionduration = prefix + 'transition-duration'] = cssreset[transitiondelay = prefix + 'transition-delay'] = cssreset[transitiontiming = prefix + 'transition-timing-function'] = cssreset[animationname = prefix + 'animation-name'] = cssreset[animationduration = prefix + 'animation-duration'] = cssreset[animationdelay = prefix + 'animation-delay'] = cssreset[animationtiming = prefix + 'animation-timing-function'] = '' $.fx = { off: (eventprefix === undefined && testel.style.transitionproperty === undefined), speeds: { _default: 400, fast: 200, slow: 600 }, cssprefix: prefix, transitionend: normalizeevent('transitionend'), animationend: normalizeevent('animationend') } $.fn.animate = function(properties, duration, ease, callback, delay) { if ($.isfunction(duration)) callback = duration, ease = undefined, duration = undefined if ($.isfunction(ease)) callback = ease, ease = undefined if ($.isplainobject(duration)) ease = duration.easing, callback = duration.complete, delay = duration.delay, duration = duration.duration if (duration) duration = (typeof duration == 'number' ? duration : ($.fx.speeds[duration] || $.fx.speeds._default)) / 1000 if (delay) delay = parsefloat(delay) / 1000 return this.anim(properties, duration, ease, callback, delay) } $.fn.anim = function(properties, duration, ease, callback, delay) { var key, cssvalues = {}, cssproperties, transforms = '', that = this, wrappedcallback, endevent = $.fx.transitionend, fired = false if (duration === undefined) duration = $.fx.speeds._default / 1000 if (delay === undefined) delay = 0 if ($.fx.off) duration = 0 if (typeof properties == 'string') { cssvalues[animationname] = properties cssvalues[animationduration] = duration + 's' cssvalues[animationdelay] = delay + 's' cssvalues[animationtiming] = (ease || 'linear') endevent = $.fx.animationend } else { cssproperties = [] for (key in properties) if (supportedtransforms.test(key)) transforms += key + '(' + properties[key] + ') ' else cssvalues[key] = properties[key], cssproperties.push(dasherize(key)) if (transforms) cssvalues[transform] = transforms, cssproperties.push(transform) if (duration > 0 && typeof properties === 'object') { cssvalues[transitionproperty] = cssproperties.join(', ') cssvalues[transitionduration] = duration + 's' cssvalues[transitiondelay] = delay + 's' cssvalues[transitiontiming] = (ease || 'linear') } } wrappedcallback = function(event) { if (typeof event !== 'undefined') { if (event.target !== event.currenttarget) return $(event.target).unbind(endevent, wrappedcallback) } else $(this).unbind(endevent, wrappedcallback) fired = true $(this).css(cssreset) callback && callback.call(this) } if (duration > 0) { this.bind(endevent, wrappedcallback) settimeout(function() { if (fired) return wrappedcallback.call(that) }, (duration * 1000) + 25) } this.size() && this.get(0).clientleft this.css(cssvalues) if (duration <= 0) settimeout(function() { that.each(function() { wrappedcallback.call(this) }) }, 0) return this } testel = null })(zepto); (function($) { var cache = [], timeout $.fn.remove = function() { return this.each(function() { if (this.parentnode) { if (this.tagname === 'img') { cache.push(this) this.src = 'data:image/gif;base64,r0lgodlhaqabaad/acwaaaaaaqabaaacads=' if (timeout) cleartimeout(timeout) timeout = settimeout(function() { cache = [] }, 60000) } this.parentnode.removechild(this) } }) } })(zepto); (function($) { var data = {}, dataattr = $.fn.data, camelize = $.camelcase, exp = $.expando = 'zepto' + (+new date()), emptyarray = [] function getdata(node, name) { var id = node[exp], store = id && data[id] if (name === undefined) return store || setdata(node) else { if (store) { if (name in store) return store[name] var camelname = camelize(name) if (camelname in store) return store[camelname] } return dataattr.call($(node), name) } } function setdata(node, name, value) { var id = node[exp] || (node[exp] = ++$.uuid), store = data[id] || (data[id] = attributedata(node)) if (name !== undefined) store[camelize(name)] = value return store } function attributedata(node) { var store = {} $.each(node.attributes || emptyarray, function(i, attr) { if (attr.name.indexof('data-') == 0) store[camelize(attr.name.replace('data-', ''))] = $.zepto.deserializevalue(attr.value) }) return store } $.fn.data = function(name, value) { return value === undefined ? $.isplainobject(name) ? this.each(function(i, node) { $.each(name, function(key, value) { setdata(node, key, value) }) }) : this.length == 0 ? undefined : getdata(this[0], name) : this.each(function() { setdata(this, name, value) }) } $.fn.removedata = function(names) { if (typeof names == 'string') names = names.split(/\s+/) return this.each(function() { var id = this[exp], store = id && data[id] if (store) $.each(names || store, function(key) { delete store[names ? camelize(this) : key] }) }) }; ['remove', 'empty'].foreach(function(methodname) { var origfn = $.fn[methodname] $.fn[methodname] = function() { var elements = this.find('*') if (methodname === 'remove') elements = elements.add(this) elements.removedata() return origfn.call(this) } }) })(zepto); (function($) { var slice = array.prototype.slice function deferred(func) { var tuples = [ ["resolve", "done", $.callbacks({ once: 1, memory: 1 }), "resolved"], ["reject", "fail", $.callbacks({ once: 1, memory: 1 }), "rejected"], ["notify", "progress", $.callbacks({ memory: 1 })] ], state = "pending", promise = { state: function() { return state }, always: function() { deferred.done(arguments).fail(arguments) return this }, then: function() { var fns = arguments return deferred(function(defer) { $.each(tuples, function(i, tuple) { var fn = $.isfunction(fns[i]) && fns[i] deferred[tuple[1]](function() { var returned = fn && fn.apply(this, arguments) if (returned && $.isfunction(returned.promise)) { returned.promise().done(defer.resolve).fail(defer.reject).progress(defer.notify) } else { var context = this === promise ? defer.promise() : this, values = fn ? [returned] : arguments defer[tuple[0] + "with"](context, values) } }) }) fns = null }).promise() }, promise: function(obj) { return obj != null ? $.extend(obj, promise) : promise } }, deferred = {} $.each(tuples, function(i, tuple) { var list = tuple[2], statestring = tuple[3] promise[tuple[1]] = list.add if (statestring) { list.add(function() { state = statestring }, tuples[i ^ 1][2].disable, tuples[2][2].lock) } deferred[tuple[0]] = function() { deferred[tuple[0] + "with"](this === deferred ? promise : this, arguments) return this } deferred[tuple[0] + "with"] = list.firewith }) promise.promise(deferred) if (func) func.call(deferred, deferred) return deferred } $.when = function(sub) { var resolvevalues = slice.call(arguments), len = resolvevalues.length, i = 0, remain = len !== 1 || (sub && $.isfunction(sub.promise)) ? len : 0, deferred = remain === 1 ? sub : deferred(), progressvalues, progresscontexts, resolvecontexts, updatefn = function(i, ctx, val) { return function(value) { ctx[i] = this val[i] = arguments.length > 1 ? slice.call(arguments) : value if (val === progressvalues) { deferred.notifywith(ctx, val) } else if (!(--remain)) { deferred.resolvewith(ctx, val) } } } if (len > 1) { progressvalues = new array(len) progresscontexts = new array(len) resolvecontexts = new array(len) for (; i < len; ++i) { if (resolvevalues[i] && $.isfunction(resolvevalues[i].promise)) { resolvevalues[i].promise().done(updatefn(i, resolvecontexts, resolvevalues)).fail(deferred.reject).progress(updatefn(i, progresscontexts, progressvalues)) } else { --remain } } } if (!remain) deferred.resolvewith(resolvecontexts, resolvevalues) return deferred.promise() } $.deferred = deferred })(zepto); (function($) { $.callbacks = function(options) { options = $.extend({}, options) var memory, fired, firing, firingstart, firinglength, firingindex, list = [], stack = !options.once && [], fire = function(data) { memory = options.memory && data fired = true firingindex = firingstart || 0 firingstart = 0 firinglength = list.length firing = true for (; list && firingindex < firinglength; ++firingindex) { if (list[firingindex].apply(data[0], data[1]) === false && options.stoponfalse) { memory = false break } } firing = false if (list) { if (stack) stack.length && fire(stack.shift()) else if (memory) list.length = 0 else callbacks.disable() } }, callbacks = { add: function() { if (list) { var start = list.length, add = function(args) { $.each(args, function(_, arg) { if (typeof arg === "function") { if (!options.unique || !callbacks.has(arg)) list.push(arg) } else if (arg && arg.length && typeof arg !== 'string') add(arg) }) } add(arguments) if (firing) firinglength = list.length else if (memory) { firingstart = start fire(memory) } } return this }, remove: function() { if (list) { $.each(arguments, function(_, arg) { var index while ((index = $.inarray(arg, list, index)) > -1) { list.splice(index, 1) if (firing) { if (index <= firinglength) --firinglength if (index <= firingindex) --firingindex } } }) } return this }, has: function(fn) { return !!(list && (fn ? $.inarray(fn, list) > -1 : list.length)) }, empty: function() { firinglength = list.length = 0 return this }, disable: function() { list = stack = memory = undefined return this }, disabled: function() { return !list }, lock: function() { stack = undefined; if (!memory) callbacks.disable() return this }, locked: function() { return !stack }, firewith: function(context, args) { if (list && (!fired || stack)) { args = args || [] args = [context, args.slice ? args.slice() : args] if (firing) stack.push(args) else fire(args) } return this }, fire: function() { return callbacks.firewith(this, arguments) }, fired: function() { return !!fired } } return callbacks } })(zepto); (function($) { var zepto = $.zepto, oldqsa = zepto.qsa, oldmatches = zepto.matches function visible(elem) { elem = $(elem) return !!(elem.width() || elem.height()) && elem.css("display") !== "none" } var filters = $.expr[':'] = { visible: function() { if (visible(this)) return this }, hidden: function() { if (!visible(this)) return this }, selected: function() { if (this.selected) return this }, checked: function() { if (this.checked) return this }, parent: function() { return this.parentnode }, first: function(idx) { if (idx === 0) return this }, last: function(idx, nodes) { if (idx === nodes.length - 1) return this }, eq: function(idx, _, value) { if (idx === value) return this }, contains: function(idx, _, text) { if ($(this).text().indexof(text) > -1) return this }, has: function(idx, _, sel) { if (zepto.qsa(this, sel).length) return this } } var filterre = new regexp('(.*):(\\w+)(?:\\(([^)]+)\\))?$\\s*'), childre = /^\s*>/, classtag = 'zepto' + (+new date()) function process(sel, fn) { sel = sel.replace(/=#\]/g, '="#"]') var filter, arg, match = filterre.exec(sel) if (match && match[2] in filters) { filter = filters[match[2]], arg = match[3] sel = match[1] if (arg) { var num = number(arg) if (isnan(num)) arg = arg.replace(/^["']|["']$/g, '') else arg = num } } return fn(sel, filter, arg) } zepto.qsa = function(node, selector) { return process(selector, function(sel, filter, arg) { try { var taggedparent if (!sel && filter) sel = '*' else if (childre.test(sel)) taggedparent = $(node).addclass(classtag), sel = '.' + classtag + ' ' + sel var nodes = oldqsa(node, sel) } catch (e) { console.error('error performing selector: %o', selector) throw e } finally { if (taggedparent) taggedparent.removeclass(classtag) } return !filter ? nodes : zepto.uniq($.map(nodes, function(n, i) { return filter.call(n, i, nodes, arg) })) }) } zepto.matches = function(node, selector) { return process(selector, function(sel, filter, arg) { return (!sel || oldmatches(node, sel)) && (!filter || filter.call(node, null, arg) === node) }) } })(zepto); (function($) { var touch = {}, touchtimeout, taptimeout, swipetimeout, longtaptimeout, longtapdelay = 750, gesture function swipedirection(x1, x2, y1, y2) { return math.abs(x1 - x2) >= math.abs(y1 - y2) ? (x1 - x2 > 0 ? 'left' : 'right') : (y1 - y2 > 0 ? 'up' : 'down') } function longtap() { longtaptimeout = null if (touch.last) { touch.el.trigger('longtap') touch = {} } } function cancellongtap() { if (longtaptimeout) cleartimeout(longtaptimeout) longtaptimeout = null } function cancelall() { if (touchtimeout) cleartimeout(touchtimeout) if (taptimeout) cleartimeout(taptimeout) if (swipetimeout) cleartimeout(swipetimeout) if (longtaptimeout) cleartimeout(longtaptimeout) touchtimeout = taptimeout = swipetimeout = longtaptimeout = null touch = {} } function isprimarytouch(event) { return (event.pointertype == 'touch' || event.pointertype == event.mspointer_type_touch) && event.isprimary } function ispointereventtype(e, type) { return (e.type == 'pointer' + type || e.type.tolowercase() == 'mspointer' + type) } $(document).ready(function() { var now, delta, deltax = 0, deltay = 0, firsttouch, _ispointertype if ('msgesture' in window) { gesture = new msgesture() gesture.target = document.body } $(document).bind('msgestureend', function(e) { var swipedirectionfromvelocity = e.velocityx > 1 ? 'right' : e.velocityx < -1 ? 'left' : e.velocityy > 1 ? 'down' : e.velocityy < -1 ? 'up' : null; if (swipedirectionfromvelocity) { touch.el.trigger('swipe') touch.el.trigger('swipe' + swipedirectionfromvelocity) } }).on('touchstart mspointerdown pointerdown', function(e) { if ((_ispointertype = ispointereventtype(e, 'down')) && !isprimarytouch(e)) return firsttouch = _ispointertype ? e : e.touches[0] if (e.touches && e.touches.length === 1 && touch.x2) { touch.x2 = undefined touch.y2 = undefined } now = date.now() delta = now - (touch.last || now) touch.el = $('tagname' in firsttouch.target ? firsttouch.target : firsttouch.target.parentnode) touchtimeout && cleartimeout(touchtimeout) touch.x1 = firsttouch.pagex touch.y1 = firsttouch.pagey if (delta > 0 && delta <= 250) touch.isdoubletap = true touch.last = now longtaptimeout = settimeout(longtap, longtapdelay) if (gesture && _ispointertype) gesture.addpointer(e.pointerid); }).on('touchmove mspointermove pointermove', function(e) { if (touch.last) { if ((_ispointertype = ispointereventtype(e, 'move')) && !isprimarytouch(e)) return firsttouch = _ispointertype ? e : e.touches[0] cancellongtap() touch.x2 = firsttouch.pagex touch.y2 = firsttouch.pagey deltax += math.abs(touch.x1 - touch.x2) deltay += math.abs(touch.y1 - touch.y2) } }).on('touchend mspointerup pointerup', function(e) { if ((_ispointertype = ispointereventtype(e, 'up')) && !isprimarytouch(e)) return cancellongtap() if ((touch.x2 && math.abs(touch.x1 - touch.x2) > 30) || (touch.y2 && math.abs(touch.y1 - touch.y2) > 30)) swipetimeout = settimeout(function() { touch.el.trigger('swipe') touch.el.trigger('swipe' + (swipedirection(touch.x1, touch.x2, touch.y1, touch.y2))) touch = {} }, 0) else if ('last' in touch) if (deltax < 30 && deltay < 30) { taptimeout = settimeout(function() { var event = $.event('tap') event.canceltouch = cancelall touch.el.trigger(event) if (touch.isdoubletap) { if (touch.el) touch.el.trigger('doubletap') touch = {} } else { touchtimeout = settimeout(function() { touchtimeout = null if (touch.el) touch.el.trigger('singletap') touch = {} }, 250) } }, 0) } else { touch = {} } deltax = deltay = 0 }).on('touchcancel mspointercancel pointercancel', cancelall) $(window).on('scroll', cancelall) }); ['swipe', 'swipeleft', 'swiperight', 'swipeup', 'swipedown', 'doubletap', 'tap', 'singletap', 'longtap'].foreach(function(eventname) { $.fn[eventname] = function(callback) { return this.on(eventname, callback) } }) })(zepto); (function($) { if ($.os.ios) { var gesture = {}, gesturetimeout function parentiftext(node) { return 'tagname' in node ? node : node.parentnode } $(document).bind('gesturestart', function(e) { var now = date.now(), delta = now - (gesture.last || now) gesture.target = parentiftext(e.target) gesturetimeout && cleartimeout(gesturetimeout) gesture.e1 = e.scale gesture.last = now }).bind('gesturechange', function(e) { gesture.e2 = e.scale }).bind('gestureend', function(e) { if (gesture.e2 > 0) { math.abs(gesture.e1 - gesture.e2) != 0 && $(gesture.target).trigger('pinch') && $(gesture.target).trigger('pinch' + (gesture.e1 - gesture.e2 > 0 ? 'in' : 'out')) gesture.e1 = gesture.e2 = gesture.last = 0 } else if ('last' in gesture) { gesture = {} } }); ['pinch', 'pinchin', 'pinchout'].foreach(function(m) { $.fn[m] = function(callback) { return this.bind(m, callback) } }) } })(zepto); (function($) { $.fn.end = function() { return this.prevobject || $() } $.fn.andself = function() { return this.add(this.prevobject || $()) } 'filter,add,not,eq,first,last,find,closest,parents,parent,children,siblings'.split(',').foreach(function(property) { var fn = $.fn[property] $.fn[property] = function() { var ret = fn.apply(this, arguments) ret.prevobject = this return ret } }) })(zepto)