2014-01-19 07:36:23 -05:00
/ *
2014-01-19 07:59:31 -05:00
* compact - boardlist . js - a compact boardlist implementation making it
* act more like a menubar
2014-01-19 07:36:23 -05:00
* https : //github.com/vichan-devel/Tinyboard/blob/master/js/compact-boardlist.js
*
* Released under the MIT license
* Copyright ( c ) 2014 Marcin Łabanowski < marcin @ 6 irc . net >
*
* Usage :
* $config [ 'boards' ] = array (
* "icon_vichan" => array ( '*' ) , # would refer to / static / icons / vichan . png
* "Regular" => array ( 'b' , 'cp' , 'r+oc' , 'id' , 'waifu' ) ,
* "Topical" => array ( 'sci' , "Offsite board name" => '//int.vichan.net/s/' ) ,
* "fa_search" => array ( "search" => "/search.php" ) # would refer to a search
* # font - awesome icon
* )
*
* $config [ 'additional_javascript' ] [ ] = 'js/jquery.min.js' ;
2014-01-19 07:40:29 -05:00
* $config [ 'additional_javascript' ] [ ] = 'js/mobile-style.js' ;
2014-01-19 07:36:23 -05:00
* $config [ 'additional_javascript' ] [ ] = 'js/compact-boardlist.js' ;
2014-01-19 07:40:29 -05:00
* //$config['additional_javascript'][] = 'js/watch.js';
2014-01-19 07:36:23 -05:00
*
* /
2017-05-31 18:36:30 -04:00
$ ( document ) . on ( "ready" , function ( ) {
if ( window . Options && Options . get _tab ( 'general' ) ) {
Options . extend _tab ( "general" ,
"<fieldset><legend> Compact Board List </legend>"
+ ( "<label class='compact-boardlist' id='compactboardlist' style='padding:0px;'><input type='checkbox' /> Enable Compact Board List </label>" )
+ ( "<label class='compact-boardlisttinyalias' id='compactboardlisttinyalias'><input type='checkbox' /> Tiny Alias for Compact Board List </label>" )
+ ( "<label class='compact-boardlistshortalias' id='compactboardlistshortalias'><input type='checkbox' /> Short Alias for Compact Board List </label>" )
+ ( "<label class='compact-boardlistunicodealias' id='compactboardlistunicodealias'><input type='checkbox' /> Unicode Alias for Compact Board List </label>" )
+ "</fieldset>" ) ;
}
$ ( '.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' ) ;
2014-01-19 07:36:23 -05:00
2017-05-31 18:36:30 -04:00
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 ; }
2013-12-27 18:53:42 -05:00
do _boardlist = function ( ) {
var categories = [ ] ;
var topbl = $ ( '.boardlist:first' ) ;
topbl . find ( '>.sub' ) . each ( function ( ) {
var cat = { name : $ ( this ) . data ( 'description' ) , boards : [ ] } ;
$ ( this ) . find ( 'a' ) . each ( function ( ) {
var board = { name : $ ( this ) . prop ( 'title' ) , uri : $ ( this ) . html ( ) , href : $ ( this ) . prop ( 'href' ) }
cat . boards . push ( board ) ;
} ) ;
categories . push ( cat ) ;
} ) ;
topbl . addClass ( "compact-boardlist" )
. html ( "" ) ;
for ( var i in categories ) {
var item = categories [ i ] ;
if ( item . name . match ( /^icon_/ ) ) {
var icon = item . name . replace ( /^icon_/ , '' )
$ ( "<a class='cb-item cb-icon' href='" + categories [ i ] . boards [ 0 ] . href + "'><img src='/static/icons/" + icon + ".png'></a>" )
. appendTo ( topbl )
}
else if ( item . name . match ( /^fa_/ ) ) {
var icon = item . name . replace ( /^fa_/ , '' )
2014-01-16 18:36:59 -05:00
$ ( '<a class="cb-item cb-fa" href="' + categories [ i ] . boards [ 0 ] . href + '"><i class="fa-' + icon + ' fa"></i></a>' )
2013-12-27 18:53:42 -05:00
. appendTo ( topbl )
}
2014-04-20 19:19:34 -04:00
else if ( item . name . match ( /^d_/ ) ) {
var icon = item . name . replace ( /^d_/ , '' )
$ ( '<a class="cb-item cb-cat" href="' + categories [ i ] . boards [ 0 ] . href + '">' + icon + '</a>' )
. appendTo ( topbl )
}
2013-12-27 18:53:42 -05:00
else {
2017-05-31 18:36:30 -04:00
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 ] ;
}
$ ( "<a class='cb-item cb-cat' href='javascript:void(0)'>" + menuitemname + "</a>" )
2013-12-27 18:53:42 -05:00
. appendTo ( topbl )
. mouseenter ( function ( ) {
var list = $ ( "<div class='boardlist top cb-menu'></div>" )
. css ( "top" , $ ( this ) . position ( ) . top + 13 + $ ( this ) . height ( ) )
. css ( "left" , $ ( this ) . position ( ) . left )
. css ( "right" , "auto" )
. appendTo ( this ) ;
for ( var j in this . item . boards ) {
var board = this . item . boards [ j ] ;
var tag ;
if ( board . name ) {
tag = $ ( "<a href='" + board . href + "'><span>" + board . name + "</span><span class='cb-uri'>/" + board . uri + "/</span></a>" )
}
else {
2014-01-16 18:36:59 -05:00
tag = $ ( "<a href='" + board . href + "'><span>" + board . uri + "</span><span class='cb-uri'><i class='fa fa-globe'></i></span></a>" )
2013-12-27 18:53:42 -05:00
}
tag
. addClass ( "cb-menuitem" )
. appendTo ( list )
}
} )
. mouseleave ( function ( ) {
topbl . find ( ".cb-menu" ) . remove ( ) ;
} ) [ 0 ] . item = item ;
}
}
do _boardlist = undefined ;
} ;
2017-05-31 18:36:30 -04:00
do _boardlist ( ) ;
options _handler = $ ( "<div id='options_handler'></div>" ) . css ( "display" , "none" ) ;
options _background = $ ( "<div id='options_background'></div>" ) . on ( "click" , Options . hide ) . appendTo ( options _handler ) ;
options _div = $ ( "<div id='options_div'></div>" ) . appendTo ( options _handler ) ;
options _close = $ ( "<a id='options_close' href='javascript:void(0)'><i class='fa fa-times'></i></div>" )
. on ( "click" , Options . hide ) . appendTo ( options _div ) ;
options _tablist = $ ( "<div id='options_tablist'></div>" ) . appendTo ( options _div ) ;
options _button = $ ( "<a href='javascript:void(0)' title='" + _ ( "Options" ) + "'>[" + _ ( "Options" ) + "]</a>" ) ;
if ( $ ( ".boardlist.compact-boardlist" ) . length ) {
options _button . addClass ( "cb-item cb-fa" ) . html ( "<i class='fa fa-gear'></i>" ) ;
}
if ( $ ( ".boardlist:first" ) . length ) {
options _button . css ( 'float' , 'right' ) . appendTo ( $ ( ".boardlist:first" ) ) ;
}
else {
var optsdiv = $ ( '<div style="text-align: right"></div>' ) ;
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 ( ' <a class="watchlist-toggle cb-item cb-cat" href="#"><span>[' + _ ( 'watchlist' ) + ']</span></a>' ) ;
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 ) ;
}
2013-12-27 18:53:42 -05:00
}
2017-05-31 18:36:30 -04:00
initCompactBoardList ( ) ;
} ) ;