ncase.me-trust/js/core/SlideSelect.js
2017-06-26 15:52:49 -04:00

46 lines
No EOL
837 B
JavaScript

function SlideSelect(config){
var self = this;
self.config = config;
// DOM
self.dom = config.dom;
// Slides
self.slides = config.slides;
// Create a dot, and onclick
self.addDot = function(slide){
var dot = new SlideSelectDot(slide);
self.dom.appendChild(dot.dom);
};
// Populate dots
for(var i=0; i<self.slides.length; i++) self.addDot(self.slides[i]);
}
function SlideSelectDot(slide){
var self = this;
self.slide = slide;
// DOM
self.dom = document.createElement("div");
self.dom.className = "dot";
// On Click
self.dom.onclick = function(){
publish("slideshow/goto", [slide.id]);
};
// Listen to when the slide changes
subscribe("slideshow/slideChange", function(id){
if(id==slide.id){
self.dom.setAttribute("selected","yes");
}else{
self.dom.removeAttribute("selected");
}
});
}