|
(function(){ |
|
var index = 0; |
|
var slides = document.getElementsByClassName("slide"); |
|
var max = document.getElementById("total-slides").innerHTML; |
|
var progressbar = document.getElementsByClassName("j-slides-loaded-bar progress-bar")[0]; |
|
var bufferedbar = document.getElementsByClassName("buffered-bar")[0]; |
|
|
|
document.getElementById("btnNext").addEventListener("click",function(){ |
|
|
|
if(index != max-1){ |
|
moveTo(index+1) |
|
} |
|
}) |
|
|
|
document.getElementById("btnPrevious").addEventListener("click",function(){ |
|
|
|
if(index != 0){ |
|
moveTo(index-1) |
|
} |
|
}) |
|
|
|
function moveTo(new_index){ |
|
var width = slides[index].offsetWidth; |
|
var height = slides[index].offsetHeight; |
|
slides[index].setAttribute("class", "slide"); |
|
slides[index].removeAttribute("itemprop"); |
|
|
|
index = new_index; |
|
slides[new_index].setAttribute("class", "slide show"); |
|
slides[new_index].setAttribute("itemprop", "image"); |
|
var image = slides[new_index].getElementsByClassName("slide_image")[0]; |
|
var spinner = slides[new_index].getElementsByClassName("fa fa-spinner fa-spin")[0]; |
|
if(spinner){ |
|
image.addEventListener("load", function(){ |
|
slides[new_index].removeChild(spinner); |
|
image.removeAttribute("style"); |
|
}) |
|
image.style.height = height + "px"; |
|
} |
|
image.setAttribute("src",image.getAttribute("data-normal")) |
|
document.getElementById("current-slide").innerHTML = new_index + 1; |
|
if(new_index == 0){ |
|
document.getElementById("btnPrevious").children[0].setAttribute("class", "j-prev-btn arrow-left disabled"); |
|
document.getElementById("btnNext").children[0].setAttribute("class", "j-next-btn arrow-right"); |
|
} else if(new_index == max-1) { |
|
document.getElementById("btnNext").children[0].setAttribute("class", "j-next-btn arrow-right disabled"); |
|
document.getElementById("btnPrevious").children[0].setAttribute("class", "j-prev-btn arrow-left"); |
|
} else { |
|
document.getElementById("btnPrevious").children[0].setAttribute("class", "j-prev-btn arrow-left"); |
|
document.getElementById("btnNext").children[0].setAttribute("class", "j-next-btn arrow-right"); |
|
} |
|
progressbar.style.width = new_index/(max-1)*100+"%"; |
|
} |
|
|
|
progressbar.addEventListener("click", function(e){ |
|
moveTo(parseInt(e.offsetX/bufferedbar.offsetWidth*(max-1))); |
|
}) |
|
|
|
bufferedbar.addEventListener("click", function(e){ |
|
moveTo(parseInt(e.offsetX/bufferedbar.offsetWidth*(max-1))); |
|
}) |
|
|
|
})() |