/* * 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)); }); }();