diff --git a/js/expand-video.js b/js/expand-video.js index 76a2018e..79872510 100644 --- a/js/expand-video.js +++ b/js/expand-video.js @@ -218,7 +218,8 @@ function setupVideosIn(element) { onready(function(){ // Insert menu from settings.js - if (typeof settingsMenu != "undefined") document.body.insertBefore(settingsMenu, document.getElementsByTagName("hr")[0]); + if (typeof settingsMenu != "undefined" && typeof Options == "undefined") + document.body.insertBefore(settingsMenu, document.getElementsByTagName("hr")[0]); // Setup Javascript events for videos in document now setupVideosIn(document); diff --git a/js/options.js b/js/options.js new file mode 100644 index 00000000..4a7f3ce9 --- /dev/null +++ b/js/options.js @@ -0,0 +1,126 @@ +/* + * options.js - allow users choose board options as they wish + * + * Copyright (c) 2014 Marcin Łabanowski + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/options.js'; + */ + ++function(){ + +var options_button, options_handler, options_background, options_div + , options_close, options_tablist, options_tabs, options_current_tab; + +var Options = {}; +window.Options = Options; + +var first_tab = function() { + for (var i in options_tabs) { + return i; + } + return false; +}; + +Options.show = function() { + if (!options_current_tab) { + Options.select_tab(first_tab(), true); + } + options_handler.fadeIn(); +}; +Options.hide = function() { + options_handler.fadeOut(); +}; + +options_tabs = {}; + +Options.add_tab = function(id, icon, name, content) { + var tab = {}; + + if (typeof content == "string") { + content = $("
"+content+"
"); + } + + tab.id = id; + tab.name = name; + tab.icon = $("
"+name+"
"); + tab.content = $("
").css("display", "none"); + + tab.content.appendTo(options_div); + + tab.icon.on("click", function() { + Options.select_tab(id); + }).appendTo(options_tablist); + + $("

"+name+"

").appendTo(tab.content); + + if (content) { + content.appendTo(tab.content); + } + + options_tabs[id] = tab; + + return tab; +}; + +Options.get_tab = function(id) { + return options_tabs[id]; +}; + +Options.extend_tab = function(id, content) { + if (typeof content == "string") { + content = $("
"+content+"
"); + } + + content.appendTo(options_tabs[id].content); + + return options_tabs[id]; +}; + +Options.select_tab = function(id, quick) { + if (options_current_tab) { + if (options_current_tab.id == id) { + return false; + } + options_current_tab.content.fadeOut(); + options_current_tab.icon.removeClass("active"); + } + var tab = options_tabs[id]; + options_current_tab = tab; + options_current_tab.icon.addClass("active"); + tab.content[quick? "show" : "fadeIn"](); + + return tab; +}; + +options_handler = $("
").css("display", "none"); +options_background = $("
").on("click", Options.hide).appendTo(options_handler); +options_div = $("
").appendTo(options_handler); +options_close = $("") + .on("click", Options.hide).appendTo(options_div); +options_tablist = $("
").appendTo(options_div); + + +$(function(){ + options_button = $("
["+_("Options")+"]").css("float", "right"); + + if ($(".boardlist.compact-boardlist").length) { + options_button.addClass("cb-item cb-fa").html(""); + } + + if ($(".boardlist:first").length) { + options_button.appendTo($(".boardlist:first")); + } + else { + options_button.prependTo($(document.body)); + } + + options_button.on("click", Options.show); + + options_handler.appendTo($(document.body)); +}); + + + +}(); diff --git a/js/options/general.js b/js/options/general.js new file mode 100644 index 00000000..f95ba04f --- /dev/null +++ b/js/options/general.js @@ -0,0 +1,44 @@ +/* + * options/general.js - general settings tab for options panel + * + * Copyright (c) 2014 Marcin Łabanowski + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/options.js'; + * $config['additional_javascript'][] = 'js/style-select.js'; + * $config['additional_javascript'][] = 'js/options/general.js'; + */ + ++function(){ + +var tab = Options.add_tab("general", "home", _("General")); + +$(function(){ + var stor = $("
"+_("Storage: ")+"
"); + stor.appendTo(tab.content); + + $("").appendTo(stor).on("click", function() { + var str = JSON.stringify(localStorage); + + $(".output").remove(); + $("").appendTo(stor).val(str); + }); + $("").appendTo(stor).on("click", function() { + var str = prompt(_("Paste your storage data")); + if (!str) return false; + var obj = JSON.parse(str); + if (!obj) return false; + + localStorage.clear(); + for (var i in obj) { + localStorage[i] = obj[i]; + } + + document.location.reload(); + }); + + $("#style-select").detach().css({float:"none","margin-bottom":0}).appendTo(tab.content); +}); + +}(); diff --git a/js/webm-settings.js b/js/webm-settings.js index 3e792741..bd3c6f0f 100644 --- a/js/webm-settings.js +++ b/js/webm-settings.js @@ -36,15 +36,25 @@ function changeSetting(name, value) { // Create settings menu var settingsMenu = document.createElement("div"); -settingsMenu.style.textAlign = "right"; -settingsMenu.style.background = "inherit"; +var prefix = "", suffix = "", style = ""; +if (window.Options) { + var tab = Options.add_tab("webm", "video-camera", _("WebM")); + $(settingsMenu).appendTo(tab.content); +} +else { + prefix = ''+_('WebM Settings')+''; + settingsMenu.style.textAlign = "right"; + settingsMenu.style.background = "inherit"; + suffix = ''; + style = 'display: none; text-align: left; position: absolute; right: 1em; margin-left: -999em; margin-top: -1px; padding-top: 1px; background: inherit;'; +} -settingsMenu.innerHTML = ''+_('WebM Settings')+'' - + '
' +settingsMenu.innerHTML = prefix + + '
' + '
' + '
' + '
' - + '
'; + + suffix; function refreshSettings() { var settingsItems = settingsMenu.getElementsByTagName("input"); @@ -74,7 +84,7 @@ for (var i = 0; i < settingsItems.length; i++) { setupControl(settingsItems[i]); } -if (settingsMenu.addEventListener) { +if (settingsMenu.addEventListener && !window.Options) { settingsMenu.addEventListener("mouseover", function(e) { refreshSettings(); settingsMenu.getElementsByTagName("a")[0].style.fontWeight = "bold"; diff --git a/stylesheets/style.css b/stylesheets/style.css index 3688b939..66f6cb91 100644 --- a/stylesheets/style.css +++ b/stylesheets/style.css @@ -636,3 +636,76 @@ form.ban-appeal textarea { .new-threads { text-align: center; } + +/* options.js */ +#options_handler { + position: fixed; + top: 0px; left: 0px; right: 0px; bottom: 0px; + width: 100%; height: 100%; + text-align: center; + z-index: 9900; +} +#options_background { + background: black; + opacity: 0.5; + position: absolute; + top: 0px; left: 0px; right: 0px; bottom: 0px; + width: 100%; height: 100%; + z-index: -1; +} +#options_div { + background-color: #d6daf0; + border: 1px solid black; + display: inline-block; + position: relative; + margin-top: 20px; + width: 600px; + height: 300px; +} +#options_close { + top: 0px; right: 0px; + position: absolute; + margin-right: 3px; + font-size: 20px; z-index: 100; +} +#options_tablist { + padding: 0px 5px; + left: 0px; + width: 70px; + top: 0px; + bottom: 0px; + height: 100%; + border-right: 1px solid black; +} +.options_tab_icon { + padding: 5px; + color: black; +} +.options_tab_icon.active { + color: red; +} +.options_tab_icon i { + font-size: 20px; +} +.options_tab_icon div { + font-size: 11px; +} +.options_tab { + padding: 10px; + position: absolute; + top: 0px; bottom: 0px; + left: 81px; right: 0px; + text-align: left; + font-size: 12px; +} +.options_tab h2 { + text-align: center; + margin-bottom: 5px; +} + +.mobile-style #options_div { + display: block; + width: 100%; + height: 100%; + margin-top: 0px; +}