/* Swipe 2.0, (c) Brad Birdsall 2013, (c) Leo Feyer 2013-2014, MIT license */ function Swipe(t, n) { "use strict"; function e() { b = k.children; for (var e = 0; e < b.length; e++) 8 == b[e].nodeType && (k.removeChild(b[e]), --e); (y = b.length), b.length < 2 && (n.continuous = !1), w.transitions && n.continuous && b.length < 3 && (k.appendChild(b[0].cloneNode(!0)), k.appendChild(k.children[1].cloneNode(!0)), (b = k.children), (M = !0)), (T = new Array(b.length)), (L = t.getBoundingClientRect().width || t.offsetWidth), (k.style.width = b.length * L + "px"); for (var i = b.length; i--; ) { var o = b[i]; (o.style.width = L + "px"), o.setAttribute("data-index", i.toString()), w.transitions && ((o.style.left = i * -L + "px"), f(i, D > i ? -L : i > D ? L : 0, 0)); } n.continuous && w.transitions && (f(l(D - 1), -L, 0), f(l(D + 1), L, 0)), w.transitions || (k.style.left = D * -L + "px"), (t.style.visibility = "visible"); } function i(t, n, e) { w.addEventListener ? t.addEventListener(n, e, !1) : window.attachEvent && t.attachEvent("on" + n, e); } function o(t) { (t.returnValue = !1), t.preventDefault && t.preventDefault(); } function a(t, n, e) { w.addEventListener ? t.removeEventListener(n, e, !1) : window.detachEvent && t.detachEvent("on" + n, e); } function r() { for (var t = n.menu.childNodes, e = 0; e < t.length; e++) if (t[e].className && -1 != t[e].className.indexOf("slider-prev")) (O.prev = function (t) { o(t), E(), d(); }), (I.prev = t[e]), i(I.prev, "click", O.prev); else if (t[e].className && -1 != t[e].className.indexOf("slider-next")) (O.next = function (t) { o(t), E(), u(); }), (I.next = t[e]), i(I.next, "click", O.next); else if (t[e].className && -1 != t[e].className.indexOf("slider-menu")) { for (var a = 0; y > a; a++) { var r = document.createElement("b"); (r.innerHTML = "•"), r.setAttribute("data-index", a.toString()), a == N && (r.className = "active"), i( r, "click", (function (t) { return function (n) { o(n), E(), v( parseInt( this.getAttribute ? this.getAttribute("data-index") : t.attributes["data-index"].nodeValue ) ); }; })(r) ), t[e].appendChild(r); } I.dots = t[e]; } } function s() { for (var t = 0; y > t; t++) { var n = I.dots.children[t]; n.className = parseInt(n.getAttribute ? n.getAttribute("data-index") : n.attributes["data-index"].nodeValue) == N ? "active" : ""; } } function c() { for (var t = I.dots.childNodes; t.length > 0; ) I.dots.removeChild(t[0]); a(I.prev, "click", O.prev), a(I.next, "click", O.next); } function d() { n.continuous ? v(D - 1) : D && v(D - 1); } function u() { n.continuous ? v(D + 1) : D < b.length - 1 && v(D + 1); } function l(t) { return (b.length + (t % b.length)) % b.length; } function v(t, e) { if (D != t) { if (w.transitions) { var i = Math.abs(D - t) / (D - t); if (n.continuous) { var o = i; (i = -T[l(t)] / L), i !== o && (t = -i * b.length + t); } for (var a = Math.abs(D - t) - 1; a--; ) f(l((t > D ? t : D) - a - 1), L * i, 0); (t = l(t)), f(D, L * i, e || z), f(t, 0, e || z), n.continuous && f(l(t - i), -(L * i), 0); } else (t = l(t)), m(D * -L, t * -L, e || z); (D = t), (N = M ? D % 2 : D), n.menu && s(), g(n.callback && n.callback(N, b[D])); } } function f(t, n, e) { h(t, n, e), (T[t] = n); } function h(t, n, e) { var i = b[t], o = i && i.style; o && ((o.webkitTransitionDuration = o.MozTransitionDuration = o.msTransitionDuration = o.OTransitionDuration = o.transitionDuration = e + "ms"), (o.webkitTransform = "translate(" + n + "px,0)translateZ(0)"), (o.msTransform = o.MozTransform = o.OTransform = "translateX(" + n + "px)")); } function m(t, e, i) { if (!i) return void (k.style.left = e + "px"); var o = +new Date(), a = setInterval(function () { var r = +new Date() - o; return r > i ? ((k.style.left = e + "px"), S && p(), n.transitionEnd && n.transitionEnd.call(event, N, b[D]), void clearInterval(a)) : void (k.style.left = (e - t) * (Math.floor((r / i) * 100) / 100) + t + "px"); }, 4); } function p() { A = setTimeout(u, S); } function E() { (S = 0), clearTimeout(A); } var x = function () {}, g = function (t) { setTimeout(t || x, 0); }, w = { addEventListener: !!window.addEventListener, touch: "ontouchstart" in window || (window.DocumentTouch && document instanceof DocumentTouch), transitions: (function (t) { var n = ["transitionProperty", "WebkitTransition", "MozTransition", "OTransition", "msTransition"]; for (var e in n) if (void 0 !== t.style[n[e]]) return !0; return !1; })(document.createElement("swipe")), }; if (t) { var b, T, L, y, k = t.children[0]; n = n || {}; var D = parseInt(n.startSlide, 10) || 0, N = D, M = !1, z = n.speed || 300; n.continuous = void 0 !== n.continuous ? n.continuous : !0; var A, C, I = {}, O = {}, S = n.auto || 0, P = {}, V = {}, X = { handleEvent: function (t) { switch (t.type) { case "touchstart": this.start(t); break; case "touchmove": this.move(t); break; case "touchend": g(this.end(t)); break; case "webkitTransitionEnd": case "msTransitionEnd": case "oTransitionEnd": case "otransitionend": case "transitionend": g(this.transitionEnd(t)); break; case "resize": g(e); } n.stopPropagation && t.stopPropagation(); }, start: function (t) { var n = t.touches[0]; (P = { x: n.pageX, y: n.pageY, time: +new Date() }), (C = void 0), (V = {}), k.addEventListener("touchmove", this, !1), k.addEventListener("touchend", this, !1); }, move: function (t) { if (!(t.touches.length > 1 || (t.scale && 1 !== t.scale))) { n.disableScroll && t.preventDefault(); var e = t.touches[0]; (V = { x: e.pageX - P.x, y: e.pageY - P.y }), "undefined" == typeof C && (C = !!(C || Math.abs(V.x) < Math.abs(V.y))), C || (t.preventDefault(), E(), n.continuous ? (h(l(D - 1), V.x + T[l(D - 1)], 0), h(D, V.x + T[D], 0), h(l(D + 1), V.x + T[l(D + 1)], 0)) : ((V.x = V.x / ((!D && V.x > 0) || (D == b.length - 1 && V.x < 0) ? Math.abs(V.x) / L + 1 : 1)), h(D - 1, V.x + T[D - 1], 0), h(D, V.x + T[D], 0), h(D + 1, V.x + T[D + 1], 0))); } }, end: function () { var t = +new Date() - P.time, e = (Number(t) < 250 && Math.abs(V.x) > 20) || Math.abs(V.x) > L / 2, i = (!D && V.x > 0) || (D == b.length - 1 && V.x < 0); n.continuous && (i = !1); var o = V.x < 0; C || (e && !i ? (o ? (n.continuous ? (f(l(D - 1), -L, 0), f(l(D + 2), L, 0)) : f(D - 1, -L, 0), f(D, T[D] - L, z), f(l(D + 1), T[l(D + 1)] - L, z), (D = l(D + 1))) : (n.continuous ? (f(l(D + 1), L, 0), f(l(D - 2), -L, 0)) : f(D + 1, L, 0), f(D, T[D] + L, z), f(l(D - 1), T[l(D - 1)] + L, z), (D = l(D - 1))), (N = M ? D % 2 : D), n.menu && s(), n.callback && n.callback(N, b[D])) : n.continuous ? (f(l(D - 1), -L, z), f(D, 0, z), f(l(D + 1), L, z)) : (f(D - 1, -L, z), f(D, 0, z), f(D + 1, L, z))), k.removeEventListener("touchmove", X, !1), k.removeEventListener("touchend", X, !1); }, transitionEnd: function (t) { parseInt(t.target.getAttribute("data-index"), 10) == D && (S && p(), n.transitionEnd && n.transitionEnd.call(t, N, b[D])); }, }; return ( e(), n.menu && r(), S && p(), w.addEventListener ? (w.touch && k.addEventListener("touchstart", X, !1), w.transitions && (k.addEventListener("webkitTransitionEnd", X, !1), k.addEventListener("msTransitionEnd", X, !1), k.addEventListener("oTransitionEnd", X, !1), k.addEventListener("otransitionend", X, !1), k.addEventListener("transitionend", X, !1)), window.addEventListener("resize", X, !1)) : (window.onresize = function () { e(); }), { setup: function () { e(); }, slide: function (t, n) { E(), v(t, n); }, prev: function () { E(), d(); }, next: function () { E(), u(); }, stop: function () { E(); }, getPos: function () { return N; }, getNumSlides: function () { return y; }, kill: function () { E(), (k.style.width = ""), (k.style.left = ""); for (var t = b.length; t--; ) { var n = b[t]; (n.style.width = ""), (n.style.left = ""), w.transitions && h(t, 0, 0); } w.addEventListener ? (k.removeEventListener("touchstart", X, !1), k.removeEventListener("webkitTransitionEnd", X, !1), k.removeEventListener("msTransitionEnd", X, !1), k.removeEventListener("oTransitionEnd", X, !1), k.removeEventListener("otransitionend", X, !1), k.removeEventListener("transitionend", X, !1), window.removeEventListener("resize", X, !1)) : (window.onresize = null), c(); }, } ); } }