ncase.me-trust/js/core/SlideSelect.js

54 lines
1 KiB
JavaScript
Raw Normal View History

2017-06-20 11:10:41 +00:00
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
2017-07-12 13:42:17 +00:00
for(var i=0; i<self.slides.length; i++){
var slide = self.slides[i];
if(slide.id){
self.addDot(slide);
}
}
2017-06-20 11:10:41 +00:00
}
function SlideSelectDot(slide){
var self = this;
self.slide = slide;
// DOM
self.dom = document.createElement("div");
self.dom.className = "dot";
2017-07-12 18:59:22 +00:00
self.dom.setAttribute("data-balloon", Words.get("chapter_"+slide.id));
self.dom.setAttribute("data-balloon-pos", "up");
2017-06-20 11:10:41 +00:00
// On Click
self.dom.onclick = function(){
2017-07-12 13:42:17 +00:00
publish("slideshow/scratch", [slide.id]);
2017-06-20 11:10:41 +00:00
};
// Listen to when the slide changes
subscribe("slideshow/slideChange", function(id){
2017-07-12 21:24:26 +00:00
if(!id) return; // nah
2017-06-20 11:10:41 +00:00
if(id==slide.id){
self.dom.setAttribute("selected","yes");
}else{
self.dom.removeAttribute("selected");
}
});
}