-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmateCarousel.min.js
1 lines (1 loc) · 2.34 KB
/
mateCarousel.min.js
1
var mateCarousel=function(t,e){void 0===e&&(e={});var l,u,n={bulletContainerId:e.bulletContainerId||"menuContainer",bulletMenuClass:e.bulletMenuClass,bulletContent:e.bulletContent||"•",autoplay:e.autoplay||!1,autoplaySpeed:e.autoplaySpeed,buttonBeforeContent:e.buttonBeforeContent||"←",buttonAfterContent:e.buttonAfterContent||"→",buttonBeforeId:e.buttonBeforeId,buttonAfterId:e.buttonAfterId,initialPosition:e.initialPosition||0},o=document.getElementsByClassName(n.bulletMenuClass),a=document.getElementsByClassName(t),r=function(t,e,n,o){var l=document.createTextNode(t),r=document.createElement("button");r.appendChild(l),r.setAttribute("id",n),r.onclick=function(){c(u-1)};var i=document.createTextNode(e),d=document.createElement("button");d.appendChild(i),d.setAttribute("id",o),d.onclick=function(){c(u+1)},a[0].parentNode.appendChild(r),a[0].parentNode.appendChild(d)},i=function(){for(var t=0;t<o.length;t++)t===u?o[t].classList.add("active"):o[t].classList.remove("active")},d=function(){if(document.getElementById(n.bulletContainerId)){var t=document.getElementById(n.bulletContainerId);a[0].parentNode.removeChild(t)}var e=document.createElement("ul");e.setAttribute("id",n.bulletContainerId),a[0].parentNode.appendChild(e);for(var o=0;o<a.length;o++){var l=document.createElement("li"),u=document.createTextNode(n.bulletContent||"");l.appendChild(u),l.classList.add(n.bulletMenuClass),l.dataset.index=o,l.onclick=function(){c(parseInt(this.dataset.index))},e.appendChild(l)}},c=function(t){t==a.length?t=0:-1==t&&(t=a.length-1);for(var e=0;e<a.length;e++)a[e].style.transform="translateX("+100*(e-t)+"%)","translateX(0%)"==a[e].style.transform&&(u=e);u=t,i()},f=function(t){l=setInterval(function(){c(u+1)},t)},s=function(){var t=document.getElementById(n.bulletContainerId);a[0].parentNode.removeChild(t)},C=function(t,e,o){n.bulletContainerId=e||"menuContainer",n.bulletMenuClass=t,n.bulletContent=o||"•",d()};return n.bulletMenuClass&&d(),c(n.initialPosition),n.autoplay&&f(n.autoplaySpeed),n.buttonBeforeId&&n.buttonAfterId&&r(n.buttonBeforeContent,n.buttonAfterContent,n.buttonBeforeId,n.buttonAfterId),{goToPosition:function(t){c(t)},next:function(){c(u+1)},before:function(){c(u-1)},play:function(t){f(t)},pause:function(){clearInterval(l)},getIndex:function(){return u},config:function(){return n},removeMenu:function(){s()},lateCreateMenu:function(t,e,n){C(t,e,n)}}};