Add the catalog links toggler.

This commit is contained in:
Nicolas Stepien 2013-02-13 23:09:40 +01:00
parent faee3e0d9e
commit 2b8f808b6b
3 changed files with 44 additions and 9 deletions

View File

@ -349,8 +349,7 @@
} }
break; break;
case 39: case 39:
if ((submenu = $('.submenu', entry))) { if ((submenu = $('.submenu', entry)) && (next = submenu.firstElementChild)) {
next = submenu.firstElementChild;
while (nextPrev = this.findNextEntry(next, -1)) { while (nextPrev = this.findNextEntry(next, -1)) {
next = nextPrev; next = nextPrev;
} }
@ -918,7 +917,7 @@
Header = { Header = {
init: function() { init: function() {
var boardList, boardListButton, boardTitle, headerBar, menuButton, toggleBar; var boardList, boardListButton, boardTitle, catalogToggler, headerBar, menuButton, toggleBar;
this.menu = new UI.Menu('header'); this.menu = new UI.Menu('header');
this.headerEl = $.el('div', { this.headerEl = $.el('div', {
id: 'header', id: 'header',
@ -955,6 +954,15 @@
}); });
$.on(toggleBar, 'click', this.toggleBar); $.on(toggleBar, 'click', this.toggleBar);
$.prepend(headerBar, [menuButton, boardListButton, $.tn(' '), boardTitle, boardList, toggleBar]); $.prepend(headerBar, [menuButton, boardListButton, $.tn(' '), boardTitle, boardList, toggleBar]);
catalogToggler = $.el('label', {
innerHTML: "<input type=checkbox" + (g.VIEW === 'catalog' ? ' checked' : '') + "> Use catalog links"
});
$.on(catalogToggler.firstElementChild, 'change', this.toggleCatalogLinks);
$.event('AddMenuEntry', {
type: 'header',
el: catalogToggler,
order: 105
});
$.asap((function() { $.asap((function() {
return d.body; return d.body;
}), function() { }), function() {
@ -988,6 +996,17 @@
$('.board-name', headerEl).hidden = showBoardList; $('.board-name', headerEl).hidden = showBoardList;
return $('.board-list', headerEl).hidden = !showBoardList; return $('.board-list', headerEl).hidden = !showBoardList;
}, },
toggleCatalogLinks: function() {
var a, as, root, useCatalog, _i, _len;
useCatalog = this.checked;
root = $('.board-list', Header.headerEl);
as = $$('a[href*="boards.4chan.org"]', root);
as.push($('.board-name', Header.headerEl));
for (_i = 0, _len = as.length; _i < _len; _i++) {
a = as[_i];
a.pathname = "/" + (a.pathname.split('/')[1]) + "/" + (useCatalog ? 'catalog' : '');
}
},
toggleBar: function() { toggleBar: function() {
var isAutohiding, message; var isAutohiding, message;
message = (isAutohiding = $.id('header-bar').classList.toggle('autohide')) ? 'The header bar will automatically hide itself.' : 'The header bar will remain visible.'; message = (isAutohiding = $.id('header-bar').classList.toggle('autohide')) ? 'The header bar will automatically hide itself.' : 'The header bar will remain visible.';
@ -1050,7 +1069,7 @@
$.event('AddMenuEntry', { $.event('AddMenuEntry', {
type: 'header', type: 'header',
el: link, el: link,
order: 100 order: 110
}); });
link = $.el('a', { link = $.el('a', {
className: 'fourchan-settings-link', className: 'fourchan-settings-link',
@ -1063,7 +1082,7 @@
$.event('AddMenuEntry', { $.event('AddMenuEntry', {
type: 'header', type: 'header',
el: link, el: link,
order: 101, order: 111,
open: function() { open: function() {
return !Conf['Disable 4chan\'s extension']; return !Conf['Disable 4chan\'s extension'];
} }

View File

@ -130,8 +130,7 @@ UI = (->
if next = @findNextEntry entry, +1 if next = @findNextEntry entry, +1
@focus next @focus next
when 39 # Right when 39 # Right
if (submenu = $ '.submenu', entry) if (submenu = $ '.submenu', entry) and next = submenu.firstElementChild
next = submenu.firstElementChild
while nextPrev = @findNextEntry next, -1 while nextPrev = @findNextEntry next, -1
next = nextPrev next = nextPrev
@focus next @focus next

View File

@ -37,6 +37,14 @@ Header =
$.prepend headerBar, [menuButton, boardListButton, $.tn(' '), boardTitle, boardList, toggleBar] $.prepend headerBar, [menuButton, boardListButton, $.tn(' '), boardTitle, boardList, toggleBar]
catalogToggler = $.el 'label',
innerHTML: "<input type=checkbox#{if g.VIEW is 'catalog' then ' checked' else ''}> Use catalog links"
$.on catalogToggler.firstElementChild, 'change', @toggleCatalogLinks
$.event 'AddMenuEntry',
type: 'header'
el: catalogToggler
order: 105
$.asap (-> d.body), -> $.asap (-> d.body), ->
$.prepend d.body, Header.headerEl $.prepend d.body, Header.headerEl
$.asap (-> $.id 'boardNavDesktop'), @setBoardList $.asap (-> $.id 'boardNavDesktop'), @setBoardList
@ -61,6 +69,15 @@ Header =
$('.board-name', headerEl).hidden = showBoardList $('.board-name', headerEl).hidden = showBoardList
$('.board-list', headerEl).hidden = !showBoardList $('.board-list', headerEl).hidden = !showBoardList
toggleCatalogLinks: ->
useCatalog = @checked
root = $ '.board-list', Header.headerEl
as = $$ 'a[href*="boards.4chan.org"]', root
as.push $ '.board-name', Header.headerEl
for a in as
a.pathname = "/#{a.pathname.split('/')[1]}/#{if useCatalog then 'catalog' else ''}"
return
toggleBar: -> toggleBar: ->
message = if isAutohiding = $.id('header-bar').classList.toggle 'autohide' message = if isAutohiding = $.id('header-bar').classList.toggle 'autohide'
'The header bar will automatically hide itself.' 'The header bar will automatically hide itself.'
@ -108,7 +125,7 @@ Settings =
$.event 'AddMenuEntry', $.event 'AddMenuEntry',
type: 'header' type: 'header'
el: link el: link
order: 100 order: 110
# 4chan settings link # 4chan settings link
link = $.el 'a', link = $.el 'a',
@ -119,7 +136,7 @@ Settings =
$.event 'AddMenuEntry', $.event 'AddMenuEntry',
type: 'header' type: 'header'
el: link el: link
order: 101 order: 111
open: -> !Conf['Disable 4chan\'s extension'] open: -> !Conf['Disable 4chan\'s extension']
return unless Conf['Disable 4chan\'s extension'] return unless Conf['Disable 4chan\'s extension']