/* * floatingcarousel 4.0 * copyright (c) 2017 adam lafene * * licensed under the terms of the mit and gpl licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html */ (function(q, z) { "function" === typeof define && define.amd ? define([], z(q)) : "object" === typeof exports ? module.exports = z(q) : q.floatingcarousel = z(q) } )("undefined" !== typeof global ? global : this.window || this.global, function(q) { var z = !!document.queryselector && !!q.addeventlistener, h = window.jquery, u, w = { autoscroll: !1, autoscrolldirection: "left", autoscrollspeed: 1e4, initclass: "floatingcarouselcontainer", intervalrate: 16, looped: !0, scrolleralignment: "horizontal", scrolleroffset: 0, scrollspeed: "medium", beforecreatefunction: null, aftercreatefunction: null, enabletouchevents: !0, touchoverflowhidden: !0, reverseontouch: !0 }, r = function(c, l, f) { if ("[object object]" === object.prototype.tostring.call(c)) for (var a in c) object.prototype.hasownproperty.call(c, a) && l.call(f, c[a], a, c); else { a = 0; for (var x = c.length; a < x; a++) l.call(f, c[a], a, c) } }, y = function(c, l) { var f = {}; r(c, function(a, l) { f[l] = c[l] }); r(l, function(a, c) { f[c] = l[c] }); return f }, a = function(c, l) { if (c.length) r(c, function(a) { for (var c in l) a.style[c] = l[c] }); else for (var f in l) c.style[f] = l[f]; return c }, m = function(c, l) { var f = element.prototype; return (f.matches || f.webkitmatchesselector || f.mozmatchesselector || f.msmatchesselector || function(a) { return -1 !== [].indexof.call(document.queryselectorall(a), this) } ).call(c, l) }, d = function(c, l) { return array.prototype.filter.call(c.children, function(c) { return m(c, l) }) }, n = function(c) { c = c.getboundingclientrect(); var l = window.pageyoffset || document.documentelement.scrolltop , f = window.pagexoffset || document.documentelement.scrollleft; return { top: parseint(c.top) + l, left: parseint(c.left) + f } }, i = function(c, l) { var f = {} , a = c || []; "string" == typeof a && (a = document.queryselectorall(a)); if (1 < a.length) { var q = []; r(a, function(b) { 1 === b.nodetype && q.push(i(b, l)) }); return q } a = a[0] || a; var k = 0, y = !1, h = 0, j = 0, e = 0, v, g, p, f, b, n, e, d, w, c, x, m, t, b, g = function(a, d) { return "left" == a ? y && b.reverseontouch ? d > t : d < t : y && b.reverseontouch ? d < t : d > t }, k = function() { 0 != b.looped && (p && (clearinterval(p), p = 0), d = d ? d : "vertical" != b.scrolleralignment.tolowercase() ? parseint(e[0].style.left) : parseint(e[0].style.top), b.autoscrollspeed = 1e3 > b.autoscrollspeed ? 1e3 : b.autoscrollspeed, b.autoscrollspeed / v < n ? m = math.round(n / (b.autoscrollspeed / v)) : (m = 1, v = math.round(b.autoscrollspeed / n)), p = setinterval(function() { switch (b.autoscrolldirection.tolowercase()) { case "right": case "down": d + m > h ? (d = 0, k = 0 == k ? 1 : 0) : d += m; break; default: d - m < 0 - (h - n) ? (d = n, k = 0 == k ? 1 : 0) : d -= m } "vertical" != b.scrolleralignment.tolowercase() ? (e[k].style.left = d + "px", e[0 == k ? 1 : 0].style.left = d - h + "px") : (e[k].style.top = d + "px", e[0 == k ? 1 : 0].style.top = d - h + "px") }, v)) }, o = function() { p && (clearinterval(p), p = 0); t = "vertical" != b.scrolleralignment.tolowercase() ? math.round(n(g).left + g.offsetwidth / 2) : math.round(n(g).top + g.offsetheight / 2); d = d ? d : "vertical" != b.scrolleralignment.tolowercase() ? parseint(e[0].style.left) : parseint(e[0].style.top); u = setinterval(function() { try { var a = "vertical" != b.scrolleralignment.tolowercase() ? b.x : b.y } catch (z) { return } var c = n / 2; var f = a < t ? t - a : a - t; m = f < math.ceil(c / 100 * 30) ? 1 : f < math.ceil(c / 100 * 50) ? 2 * w : f < math.ceil(c / 100 * 70) ? 3 * w : f < math.ceil(c / 100 * 90) ? 4 * w : 6 * w; g("left", a) ? 0 < d + m && 0 == b.looped ? d = 0 : d + m > h ? (d = 0, k = 0 == k ? 1 : 0) : d += m : g("right", a) && (d - m < 0 - (h - n) ? 0 == b.looped ? d = 0 - (h - n) : (d = n, k = 0 == k ? 1 : 0) : d -= m); "vertical" != b.scrolleralignment.tolowercase() ? (e[k].style.left = d + "px", e[0 == k ? 1 : 0].style.left = d - h + "px") : (e[k].style.top = d + "px", e[0 == k ? 1 : 0].style.top = d - h + "px") }, v) }, l = function(a) { if (u && (clearinterval(u), u = 0, a && 0 != b.looped && 1 != b.autoscroll && 1 < m)) { a = 0; for (var c = m; 1 < c; c--) a += c; var f = "vertical" != b.scrolleralignment.tolowercase() ? b.x : b.y; g("left", f) ? d + a > h && (d -= h, k = 0 == k ? 1 : 0) : d - a < 0 - (h - n) && (d += h, k = 0 == k ? 1 : 0); var g = setinterval(function() { 1 < m ? (d = g("left", f) ? d + m : d - m, "vertical" != b.scrolleralignment.tolowercase() ? (e[k].style.left = d + "px", e[0 == k ? 1 : 0].style.left = d - h + "px") : (e[k].style.top = d + "px", e[0 == k ? 1 : 0].style.top = d - h + "px"), m--) : clearinterval(g) }, v) } }, p = function(a) { var b = { x: 0, y: 0 }; if (a.changedtouches) a = a.changedtouches[0], b.x = a.pagex, b.y = a.pagey; else if (a.pagex || a.pagey) b.x = a.pagex, b.y = a.pagey; else { var c = document.documentelement , d = document.body; b.x = a.clientx + ((c.scrollleft || d.scrollleft) - (c.clientleft || 0)); b.y = a.clienty + ((c.scrolltop || d.scrolltop) - (c.clienttop || 0)) } b = b }, q = function() { y = !0; b.touchoverflowhidden && (document.body.style.overflow = "hidden"); o() }, r = function() { b.touchoverflowhidden && (document.body.style.overflow = ""); l(!0); 1 == b.autoscroll && k() }, s = function(a) { p(a) }, t = function() { y || o() }, u = function() { y || (l(!0), 1 == b.autoscroll && k()) }, v = function(a) { y || p(a) }; f.destroy = function() { b && (f.pause(), 1 < a.children.length && e[1].parentnode.removechild(e[1]), r(e[0].children, function(a) { a.removeattribute("style") }), m(e[0], "div") ? a.innerhtml = e[0].innerhtml : e[0].removeattribute("style"), a.removeattribute("style"), a.classlist.remove(b.initclass), d = b = null, h = 0) } ; f.update = function(a) { f.destroy(); f.init(a) } ; f.play = function() { f || (b.enabletouchevents && (a.addeventlistener("touchstart", q), a.addeventlistener("touchend", r), a.addeventlistener("touchmove", s)), a.addeventlistener("mouseenter", t), a.addeventlistener("mouseleave", u), a.addeventlistener("mousemove", v), !0 === b.autoscroll && k(), f = !0) } ; f.pause = function() { f && (l(), p && (clearinterval(p), p = 0), u && (clearinterval(u), u = 0), b.enabletouchevents && (a.removeeventlistener("touchstart", q), a.removeeventlistener("touchend", r), a.removeeventlistener("touchmove", s)), a.removeeventlistener("mouseenter", t), a.removeeventlistener("mouseleave", u), a.removeeventlistener("mousemove", v), f = !1) } ; f.init = function(c) { if (1 > a.length) return !1; g = a; if (z) { b = y(w, c || {}); null != b.beforecreatefunction && "function" === typeof b.beforecreatefunction && b.beforecreatefunction.call(a); a.classlist.add(b.initclass); v = b.intervalrate; g.style.paddingleft = "0"; g.style.paddingright = "0"; n = g.offsetwidth; switch (a.children[0].nodename.tolowercase()) { case "div": g.innerhtml = "
" + g.innerhtml + "
"; g.innerhtml += g.innerhtml; e = d(a, "div"); c = d(e[0], "div"); break; case "ul": g.innerhtml += g.innerhtml; e = a.queryselectorall("ul"); c = d(e[0], "li"); break; case "ol": g.innerhtml += g.innerhtml; e = a.queryselectorall("ol"); c = d(e[0], "li"); break; default: return console.log("unable to initialise scroller - please ensure contents are either in a ul, an ol or in divs"), !1 } a(c, { "float": "left" }); switch (b.scrollspeed.tolowercase()) { case "slow": w = 1; break; case "fast": w = 4; break; default: w = 2 } r(c, function(a) { var c = parseint(window.getcomputedstyle(a).getpropertyvalue("margin-top")) , d = parseint(window.getcomputedstyle(a).getpropertyvalue("margin-bottom")) , e = parseint(window.getcomputedstyle(a).getpropertyvalue("margin-left")) , f = parseint(window.getcomputedstyle(a).getpropertyvalue("margin-right")); c = a.offsetheight + c + d; e = a.offsetwidth + e + f; "vertical" != b.scrolleralignment.tolowercase() ? (h += e, a.offsetheight > j && (j = c)) : (h += c, a.offsetwidth > e && (e = e)) }); "vertical" != b.scrolleralignment.tolowercase() ? g.style.height = j + "px" : (g.style.width = e + "px", g.style.height = 0 < g.offsetheight ? g.offsetheight + "px" : g.parentnode.offsetheight + "px", n = g.offsetheight); h > n ? (x = math.round(h / 100 * b.scrolleroffset) - math.round(n / 2), x > h - n && (x = h - n), g.style.overflow = "hidden", g.style.position = "relative", r(e, function(a) { a.style.position = "absolute"; "vertical" != b.scrolleralignment.tolowercase() ? a(a, { top: 0, width: h + "px" }) : a(a, { left: 0, height: h + "px", width: e + "px" }); r(a.children, function(a) { a.style["float"] = "left"; a.style.position = "static" }) }), "vertical" != b.scrolleralignment.tolowercase() ? (e[0].style.left = 0 < x ? "-" + x + "px" : "0", 1 == b.looped ? e[1].style.left = e[0].offsetleft - h + "px" : a(e[1], { display: "none", top: "-1000px" })) : (e[0].style.top = 0 < x ? "-" + x + "px" : "0", 1 == b.looped ? e[1].style.top = e[0].offsettop - h + "px" : a(e[1], { display: "none", top: "-1000px" })), f.play(), null != b.aftercreatefunction && "function" === typeof b.aftercreatefunction && b.aftercreatefunction.call(a)) : (e[1].parentnode.removechild(e[1]), null != b.aftercreatefunction && h.isfunction(b.aftercreatefunction) && b.aftercreatefunction.call(a)) } } ; f.init(l); return f }; h && (h.fn.floatingcarousel = function(c) { return new i(this,c) } ); return i });