1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-28 09:20:58 +01:00
vichan/settings.js

57 lines
2.0 KiB
JavaScript
Raw Normal View History

// Scripts obtain settings by calling this function
function setting(name) {
return JSON.parse(localStorage[name]);
}
// Default settings
function setDefault(name, value) {
if (!(name in localStorage)) {
localStorage[name] = JSON.stringify(value);
}
}
setDefault("videoexpand", true);
setDefault("videohover", false);
setDefault("videomuted", false);
// Create settings menu
var settingsMenu = document.createElement("span");
settingsMenu.className = "settings";
settingsMenu.innerHTML = '<span>[Settings]</span>'
2013-11-14 07:41:35 +01:00
+ '<div style="display: none; text-align: left; position: absolute; right: 0px; margin-left: -999em; margin-top: -1px; padding-top: 1px;">'
+ '<label><input type="checkbox" name="videoexpand">Expand videos inline</label><br>'
2013-11-09 23:28:49 +01:00
+ '<label><input type="checkbox" name="videohover">Play videos on hover</label><br>'
+ '<label><input type="checkbox" name="videomuted">Open videos muted</label><br>'
2013-11-09 10:11:22 +01:00
+ '</div>';
function refreshSettings() {
var settingsItems = settingsMenu.getElementsByTagName("input");
2013-11-09 10:11:22 +01:00
for (var i = 0; i < settingsItems.length; i++) {
var box = settingsItems[i];
box.checked = setting(box.name);
2013-11-09 10:11:22 +01:00
}
}
function setupCheckbox(box) {
if (box.addEventListener) box.addEventListener("change", function(e) {
2013-11-09 10:11:22 +01:00
localStorage[box.name] = JSON.stringify(box.checked);
}, false);
2013-11-09 10:11:22 +01:00
}
refreshSettings();
var settingsItems = settingsMenu.getElementsByTagName("input");
2013-11-09 10:11:22 +01:00
for (var i = 0; i < settingsItems.length; i++) {
setupCheckbox(settingsItems[i]);
}
if (settingsMenu.addEventListener) {
settingsMenu.addEventListener("mouseover", function(e) {
refreshSettings();
settingsMenu.getElementsByTagName("span")[0].style.fontWeight = "bold";
settingsMenu.getElementsByTagName("div")[0].style.display = "block";
}, false);
settingsMenu.addEventListener("mouseout", function(e) {
settingsMenu.getElementsByTagName("span")[0].style.fontWeight = "normal";
settingsMenu.getElementsByTagName("div")[0].style.display = "none";
}, false);
}