/* This file is dedicated to the public domain; you may do as you wish with it. */ if (typeof _ == 'undefined') { var _ = function(a) { return a; }; } // Default settings var defaultSettings = { "videoexpand": true, "videohover": false, "videovolume": 1.0 }; // Non-persistent settings for when localStorage is absent/disabled var tempSettings = {}; // Scripts obtain settings by calling this function function setting(name) { if (localStorage) { if (localStorage[name] === undefined) return defaultSettings[name]; return JSON.parse(localStorage[name]); } else { if (tempSettings[name] === undefined) return defaultSettings[name]; return tempSettings[name]; } } // Settings should be changed with this function function changeSetting(name, value) { if (localStorage) { localStorage[name] = JSON.stringify(value); } else { tempSettings[name] = value; } } // Create settings menu var settingsMenu = document.createElement("div"); settingsMenu.style.textAlign = "right"; settingsMenu.style.background = "inherit"; settingsMenu.innerHTML = ''+_('WebM Settings')+'' + '
'; function refreshSettings() { var settingsItems = settingsMenu.getElementsByTagName("input"); for (var i = 0; i < settingsItems.length; i++) { var control = settingsItems[i]; if (control.type == "checkbox") { control.checked = setting(control.name); } else if (control.type == "range") { control.value = setting(control.name); } } } function setupControl(control) { if (control.addEventListener) control.addEventListener("change", function(e) { if (control.type == "checkbox") { changeSetting(control.name, control.checked); } else if (control.type == "range") { changeSetting(control.name, control.value); } }, false); } refreshSettings(); var settingsItems = settingsMenu.getElementsByTagName("input"); for (var i = 0; i < settingsItems.length; i++) { setupControl(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); }