crowds/slides/js/slideshow/Slideshow.js

111 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-03-27 17:39:08 +00:00
/******************************************
THE SLIDESHOW
- background: fullscreen iframe (so can draw everywhere)
- foreground: words & pictures
******************************************/
2018-03-26 15:52:43 +00:00
var SLIDES = [];
function Slideshow(){
var self = this;
// The DOM & properties...
self.dom = $("#slideshow");
self.slideIndex = 0;
2018-03-28 17:12:05 +00:00
self.currentSlide = null;
self.currentState = null;
// My stuff...
self.boxes = new Boxes();
self.simulations = new Simulations();
2018-03-26 15:52:43 +00:00
// GOTO and NEXT
self.goto = function(index){
self.slideIndex = index;
2018-03-28 17:12:05 +00:00
self.currentSlide = SLIDES[self.slideIndex];
var slide = self.currentSlide;
2018-03-26 15:52:43 +00:00
2018-03-28 17:12:05 +00:00
// Clear?
if(slide.clear) self.clear();
2018-03-27 17:39:08 +00:00
2018-04-01 16:34:52 +00:00
// Remove stuff
slide.remove = slide.remove || [];
slide.remove.forEach(function(childConfig){
switch(childConfig.type){
case "box":
self.boxes.removeChildByID(childConfig.id);
break;
case "sim":
//self.simulations.removeChildByID(childConfig);
break;
}
});
// Move stuff
slide.move = slide.move || [];
slide.move.forEach(function(childConfig){
switch(childConfig.type){
case "box":
//self.boxes.add(childConfig);
break;
case "sim":
var sim = self.simulations.getChildByID(childConfig.id);
sim.config.x = (childConfig.x===undefined) ? sim.config.x : childConfig.x;
sim.config.y = (childConfig.y===undefined) ? sim.config.y : childConfig.y;
break;
}
});
2018-03-28 17:12:05 +00:00
// Add stuff
2018-04-01 16:34:52 +00:00
slide.add = slide.add || [];
2018-03-28 17:12:05 +00:00
slide.add.forEach(function(childConfig){
switch(childConfig.type){
case "box":
self.boxes.add(childConfig);
break;
case "sim":
self.simulations.add(childConfig);
break;
}
2018-03-26 15:52:43 +00:00
});
2018-03-28 17:12:05 +00:00
// On start (if any)
self.currentState = {};
if(slide.onstart) slide.onstart(self, self.currentState);
2018-03-26 15:52:43 +00:00
};
self.gotoChapter = function(chapterID){
var index = SLIDES.findIndex(function(slide){
return slide.chapter == chapterID;
});
self.goto(index);
};
self.next = function(){
self.goto(self.slideIndex+1);
};
// Clear out the DOM
self.clear = function(){
2018-03-28 17:12:05 +00:00
self.boxes.clear();
self.simulations.clear();
2018-03-26 15:52:43 +00:00
self.dom.innerHTML = "";
};
// Update
self.update = function(){
2018-03-28 17:12:05 +00:00
var slide = self.currentSlide;
self.simulations.update();
if(slide.onupdate) slide.onupdate(self, self.currentState);
};
2018-03-28 17:12:05 +00:00
// Draw
self.draw = function(){
self.simulations.draw();
}
2018-03-26 15:52:43 +00:00
}