From 39be872353cf522da509bb2cd028287549abe0f2 Mon Sep 17 00:00:00 2001 From: Benjamin Southall Date: Thu, 1 Jun 2017 07:36:30 +0900 Subject: [PATCH] Make compact-boardlist user toggleable from Options side menu --- js/compact-boardlist.js | 126 +++++++++++++++++++++++++++++++++++++++- js/thread-watcher.js | 2 +- 2 files changed, 124 insertions(+), 4 deletions(-) diff --git a/js/compact-boardlist.js b/js/compact-boardlist.js index 89687977..4903da10 100644 --- a/js/compact-boardlist.js +++ b/js/compact-boardlist.js @@ -21,9 +21,66 @@ * //$config['additional_javascript'][] = 'js/watch.js'; * */ +$(document).on("ready", function() { +if (window.Options && Options.get_tab('general')) { + Options.extend_tab("general", + "
Compact Board List " + + ("") + + ("") + + ("") + + ("") + + "
"); +} + +$('.compact-boardlist').on('change', function(){ + var setting = $(this).attr('id'); + + localStorage[setting] = $(this).children('input').is(':checked'); + location.reload(); +}); +$('.compact-boardlisttinyalias').on('change', function(){ + var setting = $(this).attr('id'); -if (device_type == 'desktop') { - compact_boardlist = true; + localStorage[setting] = $(this).children('input').is(':checked'); + location.reload(); +}); +$('.compact-boardlistshortalias').on('change', function(){ + var setting = $(this).attr('id'); + + localStorage[setting] = $(this).children('input').is(':checked'); + location.reload(); +}); +$('.compact-boardlistunicodealias').on('change', function(){ + var setting = $(this).attr('id'); + + localStorage[setting] = $(this).children('input').is(':checked'); + location.reload(); +}); + +if (!localStorage.compactboardlist) { + localStorage.compactboardlist = 'false'; +} +if (!localStorage.compactboardlisttinyalias) { + localStorage.compactboardlistshortalias = 'false'; +} +if (!localStorage.compactboardlistshortalias) { + localStorage.compactboardlistshortalias = 'false'; +} +if (!localStorage.compactboardlistunicodealias) { + localStorage.compactboardlistunicodealias = 'false'; +} + +function getSetting(key) { + return (localStorage[key] == 'true'); +} + +if (getSetting('compactboardlist')) $('#compactboardlist>input').prop('checked', 'checked'); +if (getSetting('compactboardlisttinyalias')) $('#compactboardlisttinyalias>input').prop('checked', 'checked'); +if (getSetting('compactboardlistshortalias')) $('#compactboardlistshortalias>input').prop('checked', 'checked'); +if (getSetting('compactboardlistunicodealias')) $('#compactboardlistunicodealias>input').prop('checked', 'checked'); + +function initCompactBoardList() { //Pashe, influenced by tux, et al, WTFPL + if (!getSetting("compactboardlist")) {return;} do_boardlist = function() { var categories = []; @@ -60,7 +117,23 @@ if (device_type == 'desktop') { .appendTo(topbl) } else { - $(""+item.name+"") + var menuitemname = item.name; + var tinyalias = {"Notices" : "/n/", "STEM" : "/s/" , "People" : "/p/" , "Overboards 1" : "/ob1/" , "Overboards 2" : "/ob2/", "Elsewhere" : "/e/", "Services" : "/s/", "Misc" : '/m/', "Affiliates" : "/af/" }; + var shortalias = {"Notices" : "/not/", "STEM" : "/stem/" , "People" : "/people/" , "Overboards 1" : "/ob1/" , "Overboards 2" : "/ob2/", "Elsewhere" : "/else/", "Services" : "/serv/", "Misc" : "/misc/", "Affiliates" : "/uboa and sushi/" }; + var unicodealias = {"Notices" : "ℹ️", "STEM" : "👨‍💻 " , "People" : "👥" , "Overboards 1" : "💬" , "Overboards 2" : "💭", "Elsewhere" : "🔍", "Services" : "🈂", "Misc" : "⁉", "Affiliates" : "🍣" }; + + if (getSetting("compactboardlisttinyalias")) { + menuitemname = tinyalias[item.name]; + } + else if (getSetting("compactboardlistshortalias")){ + menuitemname = shortalias[item.name]; + + } + else if (getSetting("compactboardlistunicodealias")){ + menuitemname = unicodealias[item.name]; + } + + $(""+ menuitemname+"") .appendTo(topbl) .mouseenter(function() { var list = $("
") @@ -90,4 +163,51 @@ if (device_type == 'desktop') { } do_boardlist = undefined; }; +do_boardlist(); +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); + options_button = $("
["+_("Options")+"]"); + + if ($(".boardlist.compact-boardlist").length) { + options_button.addClass("cb-item cb-fa").html(""); + } + + if ($(".boardlist:first").length) { + options_button.css('float', 'right').appendTo($(".boardlist:first")); + } + else { + var optsdiv = $('
'); + options_button.appendTo(optsdiv); + optsdiv.prependTo($(document.body)); + } + + options_button.on("click", Options.show); + + options_handler.appendTo($(document.body)); + if (typeof watchlist.render !== 'undefined') { + $('.boardlist.compact-boardlist').append(' ['+_('watchlist')+']'); + watchlist.render(); + } + if (typeof twemoji.parse !== 'undefined') { + if (!getSetting("emojiimagefallback")) {return;} + var twemoji_opts = { + callback: function(icon, options, variant) { + switch ( icon ) { + case 'a9': // copyright + case 'ae': // (R) + case '2122': // TM + case '25b6': // post filter + return false; + } + return ''.concat(options.base, options.size, '/', icon, options.ext); + } + } + twemoji.parse(document.body, twemoji_opts); + } } +initCompactBoardList(); +}); diff --git a/js/thread-watcher.js b/js/thread-watcher.js index 0796193b..2318ded7 100644 --- a/js/thread-watcher.js +++ b/js/thread-watcher.js @@ -149,7 +149,7 @@ $(document).ready(function(){ } //Append the watchlist toggle button. - $('.boardlist').append('[ '+_('watchlist')+' ]'); + $('.boardlist .compact-boardlist').append('[ '+_('watchlist')+' ]'); //Append a watch thread button after every OP. $('.op>.intro').append('['+_('Watch Thread')+']');