2018-03-28 17:12:05 +00:00
|
|
|
/******************************
|
|
|
|
|
|
|
|
Boxes of HTML. With words and pictures!
|
|
|
|
|
|
|
|
******************************/
|
|
|
|
|
|
|
|
function Boxes(){
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
self.dom = $("#slideshow");
|
|
|
|
|
|
|
|
self.boxes = [];
|
|
|
|
|
|
|
|
// Clear
|
|
|
|
self.clear = function(){
|
|
|
|
self.boxes.forEach(function(box){
|
|
|
|
self.dom.removeChild(box);
|
2018-04-18 15:25:41 +00:00
|
|
|
if(box.kill) box.kill();
|
2018-03-28 17:12:05 +00:00
|
|
|
});
|
|
|
|
self.boxes = [];
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add Box
|
2018-04-02 17:43:20 +00:00
|
|
|
self.add = function(config, withFade){
|
2018-03-28 17:12:05 +00:00
|
|
|
|
|
|
|
// Add to DOM
|
|
|
|
var box = document.createElement("div");
|
|
|
|
box.className = "box";
|
2018-04-02 17:43:20 +00:00
|
|
|
if(!withFade){
|
|
|
|
self.dom.appendChild(box);
|
|
|
|
}else{
|
|
|
|
fadeIn(self.dom, box);
|
|
|
|
}
|
2018-03-28 17:12:05 +00:00
|
|
|
|
|
|
|
// Standard box properties...
|
|
|
|
if(config.id) box.id = config.id;
|
2018-04-25 18:46:26 +00:00
|
|
|
if(config.x) box.style.left = config.x + "px";
|
|
|
|
if(config.y) box.style.top = config.y + "px";
|
|
|
|
if(config.w) box.style.width = config.w + "px";
|
|
|
|
if(config.h) box.style.height = config.h + "px";
|
2018-03-28 17:12:05 +00:00
|
|
|
if(config.hidden) box.style.display = "none";
|
|
|
|
|
2018-04-04 15:57:35 +00:00
|
|
|
// background
|
|
|
|
if(config.background){
|
|
|
|
box.style.left = "-1000px";
|
|
|
|
box.style.top = "-1000px";
|
2018-04-25 18:46:26 +00:00
|
|
|
box.style.width = 10000 + "px";
|
|
|
|
box.style.height = 10000 + "px";
|
2018-04-04 15:57:35 +00:00
|
|
|
box.style.background = config.background;
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:12:05 +00:00
|
|
|
// words:
|
|
|
|
if(config.text){
|
|
|
|
box.innerHTML = getWords(config.text);
|
|
|
|
if(config.align) box.style.textAlign = config.align;
|
|
|
|
if(config.color) box.style.color = config.color;
|
2018-04-12 17:12:45 +00:00
|
|
|
if(config.fontSize) box.style.fontSize = config.fontSize;
|
|
|
|
if(config.lineHeight) box.style.lineHeight = config.lineHeight;
|
2018-03-28 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// pics:
|
|
|
|
if(config.img){
|
|
|
|
box.classList.add("image");
|
|
|
|
box.style.backgroundImage = "url("+config.img+")"
|
|
|
|
}
|
|
|
|
|
2018-04-06 16:06:55 +00:00
|
|
|
// Sim UI
|
|
|
|
if(config.sim_ui){
|
|
|
|
var simUI = new SimUI(box, config.sim_ui);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sandbox UI
|
|
|
|
if(config.sandbox){
|
|
|
|
var sandboxUI = new SandboxUI(box);
|
2018-04-03 15:25:13 +00:00
|
|
|
}
|
|
|
|
|
2018-04-01 16:34:52 +00:00
|
|
|
// Replace "next" buttons!
|
|
|
|
var next;
|
|
|
|
if(next = box.querySelector("next")){
|
|
|
|
|
|
|
|
// Create next button
|
|
|
|
var nextButton = document.createElement("div");
|
|
|
|
nextButton.className = "next_button";
|
|
|
|
nextButton.innerHTML = next.innerHTML;
|
|
|
|
nextButton.onclick = function(){
|
2018-04-20 18:47:58 +00:00
|
|
|
publish("sound/button");
|
2018-04-01 16:34:52 +00:00
|
|
|
slideshow.next();
|
|
|
|
};
|
|
|
|
|
2018-04-18 18:02:27 +00:00
|
|
|
// to prevent sim from resetting...
|
2018-04-24 18:12:38 +00:00
|
|
|
_stopPropButton(nextButton);
|
2018-04-18 18:02:27 +00:00
|
|
|
|
2018-04-01 16:34:52 +00:00
|
|
|
// Replace it in parent!
|
|
|
|
next.parentNode.replaceChild(nextButton, next);
|
|
|
|
|
2018-03-28 17:12:05 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 19:14:08 +00:00
|
|
|
// Add onclicks to "ref"s!
|
|
|
|
box.querySelectorAll("ref").forEach(function(ref){
|
|
|
|
ref.onclick = function(){
|
|
|
|
var id = ref.id;
|
|
|
|
publish("reference/show",[id]);
|
|
|
|
};
|
2018-04-24 18:12:38 +00:00
|
|
|
_stopPropButton(ref);
|
2018-04-16 19:14:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Bonus boxes...
|
|
|
|
box.querySelectorAll("bon").forEach(function(bon){
|
|
|
|
var title = $("bonus#"+bon.id+" > h3").innerHTML.trim();
|
2018-04-27 12:24:33 +00:00
|
|
|
bon.innerHTML = title;
|
2018-04-16 19:14:08 +00:00
|
|
|
bon.onclick = function(){
|
|
|
|
publish("bonus/show", [bon.id]);
|
|
|
|
};
|
2018-04-24 18:12:38 +00:00
|
|
|
_stopPropButton(bon);
|
2018-04-16 19:14:08 +00:00
|
|
|
});
|
2018-04-02 17:43:20 +00:00
|
|
|
|
2018-04-16 19:49:56 +00:00
|
|
|
// Replace icons
|
|
|
|
box.querySelectorAll("icon").forEach(function(icon){
|
|
|
|
|
|
|
|
// Create next button
|
2018-04-27 12:24:33 +00:00
|
|
|
var name = icon.getAttribute("name");
|
2018-04-16 19:49:56 +00:00
|
|
|
var src = "sprites/icons/"+name+".png";
|
|
|
|
var img = new Image();
|
|
|
|
img.src = src;
|
|
|
|
img.className = "peep_icon";
|
|
|
|
|
|
|
|
// Replace it in parent!
|
|
|
|
icon.parentNode.replaceChild(img, icon);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-03-28 17:12:05 +00:00
|
|
|
// Add to array
|
|
|
|
self.boxes.push(box);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Update & Draw... nothing
|
|
|
|
self.update = function(){};
|
|
|
|
self.draw = function(){};
|
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
// HELPERS AND STUFF //
|
|
|
|
///////////////////////
|
|
|
|
|
|
|
|
self.getChildByID = function(id){
|
|
|
|
return self.boxes.find(function(box){
|
|
|
|
return box.id==id;
|
|
|
|
});
|
|
|
|
};
|
2018-04-03 17:32:26 +00:00
|
|
|
self.showChildByID = function(id, withFade){
|
2018-03-28 17:12:05 +00:00
|
|
|
var toShow = self.getChildByID(id);
|
2018-04-03 17:32:26 +00:00
|
|
|
if(!withFade){
|
|
|
|
toShow.style.display = "block";
|
|
|
|
}else{
|
|
|
|
fadeIn(self.dom, toShow);
|
|
|
|
}
|
2018-03-28 17:12:05 +00:00
|
|
|
};
|
2018-04-16 19:49:56 +00:00
|
|
|
|
2018-04-02 17:43:20 +00:00
|
|
|
self.removeChildByID = function(id, withFade){
|
|
|
|
|
2018-04-01 16:34:52 +00:00
|
|
|
var removeBox = self.getChildByID(id);
|
2018-04-02 17:43:20 +00:00
|
|
|
if(!withFade){
|
|
|
|
self.dom.removeChild(removeBox);
|
|
|
|
}else{
|
|
|
|
fadeOut(self.dom, removeBox);
|
|
|
|
}
|
2018-04-01 16:34:52 +00:00
|
|
|
removeFromArray(self.boxes, removeBox);
|
2018-04-18 15:25:41 +00:00
|
|
|
if(removeBox.kill) removeBox.kill();
|
2018-04-02 17:43:20 +00:00
|
|
|
|
2018-04-01 16:34:52 +00:00
|
|
|
};
|
2018-03-28 17:12:05 +00:00
|
|
|
|
2018-04-20 18:47:58 +00:00
|
|
|
}
|