/* * 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;at:dt},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/vh?(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=ah?(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&&1h&&(d-=h,k=0==k?1:0):d-a<0-(h- n)&&(d+=h,k=0==k?1:0);var g=setInterval(function(){1a.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=0n?(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