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;
case 39:
if ((submenu = $('.submenu', entry))) {
next = submenu.firstElementChild;
if ((submenu = $('.submenu', entry)) && (next = submenu.firstElementChild)) {
while (nextPrev = this.findNextEntry(next, -1)) {
next = nextPrev;
}
@ -918,7 +917,7 @@
Header = {
init: function() {
var boardList, boardListButton, boardTitle, headerBar, menuButton, toggleBar;
var boardList, boardListButton, boardTitle, catalogToggler, headerBar, menuButton, toggleBar;
this.menu = new UI.Menu('header');
this.headerEl = $.el('div', {
id: 'header',
@ -955,6 +954,15 @@
});
$.on(toggleBar, 'click', this.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() {
return d.body;
}), function() {
@ -988,6 +996,17 @@
$('.board-name', 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() {
var isAutohiding, message;
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', {
type: 'header',
el: link,
order: 100
order: 110
});
link = $.el('a', {
className: 'fourchan-settings-link',
@ -1063,7 +1082,7 @@
$.event('AddMenuEntry', {
type: 'header',
el: link,
order: 101,
order: 111,
open: function() {
return !Conf['Disable 4chan\'s extension'];
}

View File

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

View File

@ -37,6 +37,14 @@ Header =
$.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), ->
$.prepend d.body, Header.headerEl
$.asap (-> $.id 'boardNavDesktop'), @setBoardList
@ -61,6 +69,15 @@ Header =
$('.board-name', 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: ->
message = if isAutohiding = $.id('header-bar').classList.toggle 'autohide'
'The header bar will automatically hide itself.'
@ -108,7 +125,7 @@ Settings =
$.event 'AddMenuEntry',
type: 'header'
el: link
order: 100
order: 110
# 4chan settings link
link = $.el 'a',
@ -119,7 +136,7 @@ Settings =
$.event 'AddMenuEntry',
type: 'header'
el: link
order: 101
order: 111
open: -> !Conf['Disable 4chan\'s extension']
return unless Conf['Disable 4chan\'s extension']