So first I have a script that checks for the class .current and adds prevent default for all the links without that class, and then a callback that should re-check and restore click behavior for the link with the new .current class while applying prevent default to the other links.
- Initial script that sets prevent default
var links = document.querySelectorAll('.link-slider');
var slidesv = document.querySelectorAll('.carousel-3d-slide');
for (var i = 0; i < slidesv.length; i++) {
var slidev = slidesv[i];
var link = links[i];
if (slidev.classList.contains('current')) {
// Class exists!
/*console.log("works");
link.addEventListener("click", function(e){ return true; });*/
} else {
// Class not found
console.log("nonworks");
link.addEventListener("click", function(e) {
e.preventDefault(); }, false);
}
}
- callback
onAfterSlideChange() {
var linkscallback = document.querySelectorAll('.link-slider');
var slidescallback = document.querySelectorAll('.carousel-3d-slide');
for (var i = 0; i < slidescallback.length; i++) {
var slidecallback = slidescallback[i];
var linkcallback = linkscallback[i];
linkcallback.addEventListener("click", function(e){ return true; });
console.log("true");
if (slidecallback.classList.contains('current')) {
// Class exists!
} else {
linkcallback.addEventListener("click", function(e) {
e.preventDefault(); }, false);
}
}
},