jquery.mobile.custom.js
8.43 KB
!function(a, b, c){"function" == typeof define && define.amd?define(["jquery"], function(d){return c(d, a, b), d.mobile}):c(a.jQuery, a, b)}(this, document, function(a, b, c, d){!function(a, b, c, d){function y(a){for (; a && "undefined" != typeof a.originalEvent; )a = a.originalEvent; return a}function z(b, c){var f, g, i, k, l, m, n, o, p, e = b.type; if (b = a.Event(b), b.type = c, f = b.originalEvent, g = a.event.props, e.search(/^(mouse|click)/) > - 1 && (g = j), f)for (n = g.length, k; n; )k = g[--n], b[k] = f[k]; if (e.search(/mouse(down|up)|click/) > - 1 && !b.which && (b.which = 1), e.search(/^touch/) !== - 1 && (i = y(f), e = i.touches, l = i.changedTouches, m = e && e.length?e[0]:l && l.length?l[0]:d))for (o = 0, p = h.length; o < p; o++)k = h[o], b[k] = m[k]; return b}function A(b){for (var d, f, c = {}; b; ){d = a.data(b, e); for (f in d)d[f] && (c[f] = c.hasVirtualBinding = !0); b = b.parentNode}return c}function B(b, c){for (var d; b; ){if (d = a.data(b, e), d && (!c || d[c]))return b; b = b.parentNode}return null}function C(){r = !1}function D(){r = !0}function E(){v = 0, p.length = 0, q = !1, D()}function F(){C()}function G(){H(), l = setTimeout(function(){l = 0, E()}, a.vmouse.resetTimerDuration)}function H(){l && (clearTimeout(l), l = 0)}function I(b, c, d){var e; return(d && d[b] || !d && B(c.target, b)) && (e = z(c, b), a(c.target).trigger(e)), e}function J(b){var d, c = a.data(b.target, f); q || v && v === c || (d = I("v" + b.type, b), d && (d.isDefaultPrevented() && b.preventDefault(), d.isPropagationStopped() && b.stopPropagation(), d.isImmediatePropagationStopped() && b.stopImmediatePropagation()))}function K(b){var d, e, g, c = y(b).touches; c && 1 === c.length && (d = b.target, e = A(d), e.hasVirtualBinding && (v = u++, a.data(d, f, v), H(), F(), o = !1, g = y(b).touches[0], m = g.pageX, n = g.pageY, I("vmouseover", b, e), I("vmousedown", b, e)))}function L(a){r || (o || I("vmousecancel", a, A(a.target)), o = !0, G())}function M(b){if (!r){var c = y(b).touches[0], d = o, e = a.vmouse.moveDistanceThreshold, f = A(b.target); o = o || Math.abs(c.pageX - m) > e || Math.abs(c.pageY - n) > e, o && !d && I("vmousecancel", b, f), I("vmousemove", b, f), G()}}function N(a){if (!r){D(); var c, d, b = A(a.target); I("vmouseup", a, b), o || (c = I("vclick", a, b), c && c.isDefaultPrevented() && (d = y(a).changedTouches[0], p.push({touchID:v, x:d.clientX, y:d.clientY}), q = !0)), I("vmouseout", a, b), o = !1, G()}}function O(b){var d, c = a.data(b, e); if (c)for (d in c)if (c[d])return!0; return!1}function P(){}function Q(b){var c = b.substr(1); return{setup:function(){O(this) || a.data(this, e, {}); var d = a.data(this, e); d[b] = !0, k[b] = (k[b] || 0) + 1, 1 === k[b] && t.bind(c, J), a(this).bind(c, P), s && (k.touchstart = (k.touchstart || 0) + 1, 1 === k.touchstart && t.bind("touchstart", K).bind("touchend", N).bind("touchmove", M).bind("scroll", L))}, teardown:function(){--k[b], k[b] || t.unbind(c, J), s && (--k.touchstart, k.touchstart || t.unbind("touchstart", K).unbind("touchmove", M).unbind("touchend", N).unbind("scroll", L)); var d = a(this), f = a.data(this, e); f && (f[b] = !1), d.unbind(c, P), O(this) || d.removeData(e)}}}var w, x, e = "virtualMouseBindings", f = "virtualTouchID", g = "vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel".split(" "), h = "clientX clientY pageX pageY screenX screenY".split(" "), i = a.event.mouseHooks?a.event.mouseHooks.props:[], j = a.event.props.concat(i), k = {}, l = 0, m = 0, n = 0, o = !1, p = [], q = !1, r = !1, s = "addEventListener"in c, t = a(c), u = 1, v = 0; for (a.vmouse = {moveDistanceThreshold:10, clickDistanceThreshold:10, resetTimerDuration:1500}, x = 0; x < g.length; x++)a.event.special[g[x]] = Q(g[x]); s && c.addEventListener("click", function(b){var e, g, h, i, j, k, c = p.length, d = b.target; if (c)for (e = b.clientX, g = b.clientY, w = a.vmouse.clickDistanceThreshold, h = d; h; ){for (i = 0; i < c; i++)if (j = p[i], k = 0, h === d && Math.abs(j.x - e) < w && Math.abs(j.y - g) < w || a.data(h, f) === j.touchID)return b.preventDefault(), void b.stopPropagation(); h = h.parentNode}}, !0)}(a, b, c), function(a){a.mobile = {}}(a), function(a, b){var d = {touch:"ontouchend"in c}; a.mobile.support = a.mobile.support || {}, a.extend(a.support, d), a.extend(a.mobile.support, d)}(a), function(a, b, d){function k(b, c, e, f){var g = e.type; e.type = c, f?a.event.trigger(e, d, b):a.event.dispatch.call(b, e), e.type = g}var e = a(c), f = a.mobile.support.touch, g = "touchmove scroll", h = f?"touchstart":"mousedown", i = f?"touchend":"mouseup", j = f?"touchmove":"mousemove"; a.each("touchstart touchmove touchend tap taphold swipe swipeleft swiperight scrollstart scrollstop".split(" "), function(b, c){a.fn[c] = function(a){return a?this.bind(c, a):this.trigger(c)}, a.attrFn && (a.attrFn[c] = !0)}), a.event.special.scrollstart = {enabled:!0, setup:function(){function f(a, c){d = c, k(b, d?"scrollstart":"scrollstop", a)}var d, e, b = this, c = a(b); c.bind(g, function(b){a.event.special.scrollstart.enabled && (d || f(b, !0), clearTimeout(e), e = setTimeout(function(){f(b, !1)}, 50))})}, teardown:function(){a(this).unbind(g)}}, a.event.special.tap = {tapholdThreshold:750, emitTapOnTaphold:!0, setup:function(){var b = this, c = a(b), d = !1; c.bind("vmousedown", function(f){function i(){clearTimeout(h)}function j(){i(), c.unbind("vclick", l).unbind("vmouseup", i), e.unbind("vmousecancel", j)}function l(a){j(), d || g !== a.target?d && a.preventDefault():k(b, "tap", a)}if (d = !1, f.which && 1 !== f.which)return!1; var h, g = f.target; c.bind("vmouseup", i).bind("vclick", l), e.bind("vmousecancel", j), h = setTimeout(function(){a.event.special.tap.emitTapOnTaphold || (d = !0), k(b, "taphold", a.Event("taphold", {target:g}))}, a.event.special.tap.tapholdThreshold)})}, teardown:function(){a(this).unbind("vmousedown").unbind("vclick").unbind("vmouseup"), e.unbind("vmousecancel")}}, a.event.special.swipe = {scrollSupressionThreshold:30, durationThreshold:1e3, horizontalDistanceThreshold:30, verticalDistanceThreshold:30, getLocation:function(a){var c = b.pageXOffset, d = b.pageYOffset, e = a.clientX, f = a.clientY; return 0 === a.pageY && Math.floor(f) > Math.floor(a.pageY) || 0 === a.pageX && Math.floor(e) > Math.floor(a.pageX)?(e -= c, f -= d):(f < a.pageY - d || e < a.pageX - c) && (e = a.pageX - c, f = a.pageY - d), {x:e, y:f}}, start:function(b){var c = b.originalEvent.touches?b.originalEvent.touches[0]:b, d = a.event.special.swipe.getLocation(c); return{time:(new Date).getTime(), coords:[d.x, d.y], origin:a(b.target)}}, stop:function(b){var c = b.originalEvent.touches?b.originalEvent.touches[0]:b, d = a.event.special.swipe.getLocation(c); return{time:(new Date).getTime(), coords:[d.x, d.y]}}, handleSwipe:function(b, c, d, e){if (c.time - b.time < a.event.special.swipe.durationThreshold && Math.abs(b.coords[0] - c.coords[0]) > a.event.special.swipe.horizontalDistanceThreshold && Math.abs(b.coords[1] - c.coords[1]) < a.event.special.swipe.verticalDistanceThreshold){var f = b.coords[0] > c.coords[0]?"swipeleft":"swiperight"; return k(d, "swipe", a.Event("swipe", {target:e, swipestart:b, swipestop:c}), !0), k(d, f, a.Event(f, {target:e, swipestart:b, swipestop:c}), !0), !0}return!1}, eventInProgress:!1, setup:function(){var b, c = this, d = a(c), f = {}; b = a.data(this, "mobile-events"), b || (b = {length:0}, a.data(this, "mobile-events", b)), b.length++, b.swipe = f, f.start = function(b){if (!a.event.special.swipe.eventInProgress){a.event.special.swipe.eventInProgress = !0; var d, g = a.event.special.swipe.start(b), h = b.target, k = !1; f.move = function(b){g && !b.isDefaultPrevented() && (d = a.event.special.swipe.stop(b), k || (k = a.event.special.swipe.handleSwipe(g, d, c, h), k && (a.event.special.swipe.eventInProgress = !1)), Math.abs(g.coords[0] - d.coords[0]) > a.event.special.swipe.scrollSupressionThreshold && b.preventDefault())}, f.stop = function(){k = !0, a.event.special.swipe.eventInProgress = !1, e.off(j, f.move), f.move = null}, e.on(j, f.move).one(i, f.stop)}}, d.on(h, f.start)}, teardown:function(){var b, c; b = a.data(this, "mobile-events"), b && (c = b.swipe, delete b.swipe, b.length--, 0 === b.length && a.removeData(this, "mobile-events")), c && (c.start && a(this).off(h, c.start), c.move && e.off(j, c.move), c.stop && e.off(i, c.stop))}}, a.each({scrollstop:"scrollstart", taphold:"tap", swipeleft:"swipe.left", swiperight:"swipe.right"}, function(b, c){a.event.special[b] = {setup:function(){a(this).bind(c, a.noop)}, teardown:function(){a(this).unbind(c)}}})}(a, this)});