Merge from Appchan X: src/General/Header.coffee

This commit is contained in:
ccd0 2015-02-03 00:17:09 -08:00
parent e1b63d4a99
commit 8c17090b3d

View File

@ -6,14 +6,16 @@ Header =
className: 'menu-button' className: 'menu-button'
$.extend menuButton, <%= html('<i></i>') %> $.extend menuButton, <%= html('<i></i>') %>
barFixedToggler = UI.checkbox 'Fixed Header', 'Fixed Header' box = UI.checkbox
headerToggler = UI.checkbox 'Header auto-hide', 'Auto-hide header'
scrollHeaderToggler = UI.checkbox 'Header auto-hide on scroll', 'Auto-hide header on scroll' barFixedToggler = box 'Fixed Header', 'Fixed Header'
barPositionToggler = UI.checkbox 'Bottom Header', 'Bottom header' headerToggler = box 'Header auto-hide', 'Auto-hide header'
linkJustifyToggler = UI.checkbox 'Centered links', 'Centered links' scrollHeaderToggler = box 'Header auto-hide on scroll', 'Auto-hide header on scroll'
customNavToggler = UI.checkbox 'Custom Board Navigation', 'Custom board navigation' barPositionToggler = box 'Bottom Header', 'Bottom header'
footerToggler = UI.checkbox 'Bottom Board List', 'Hide bottom board list' linkJustifyToggler = box 'Centered links', 'Centered links'
shortcutToggler = UI.checkbox 'Shortcut Icons', 'Shortcut Icons' customNavToggler = box 'Custom Board Navigation', 'Custom board navigation'
footerToggler = box 'Bottom Board List', 'Hide bottom board list'
shortcutToggler = box 'Shortcut Icons', 'Shortcut Icons'
editCustomNav = $.el 'a', editCustomNav = $.el 'a',
textContent: 'Edit custom board navigation' textContent: 'Edit custom board navigation'
href: 'javascript:;' href: 'javascript:;'
@ -33,7 +35,6 @@ Header =
$.on @barPositionToggler, 'change', @toggleBarPosition $.on @barPositionToggler, 'change', @toggleBarPosition
$.on @scrollHeaderToggler, 'change', @toggleHideBarOnScroll $.on @scrollHeaderToggler, 'change', @toggleHideBarOnScroll
$.on @linkJustifyToggler, 'change', @toggleLinkJustify $.on @linkJustifyToggler, 'change', @toggleLinkJustify
$.on @headerToggler, 'change', @toggleBarVisibility
$.on @footerToggler, 'change', @toggleFooterVisibility $.on @footerToggler, 'change', @toggleFooterVisibility
$.on @shortcutToggler, 'change', @toggleShortcutIcons $.on @shortcutToggler, 'change', @toggleShortcutIcons
$.on @customNavToggler, 'change', @toggleCustomNav $.on @customNavToggler, 'change', @toggleCustomNav
@ -185,7 +186,13 @@ Header =
return unless boardnav return unless boardnav
boardnav = boardnav.replace /(\r\n|\n|\r)/g, ' ' boardnav = boardnav.replace /(\r\n|\n|\r)/g, ' '
as = $$ '#full-board-list a[title]', Header.boardList as = $$ '#full-board-list a[title]', Header.boardList
nodes = boardnav.match(/[\w@]+(-(all|title|replace|full|index|catalog|archive|expired|text:"[^"]+"(,"[^"]+")?))*|[^\w@]+/g).map (t) -> re = /[\w@]+(-(all|title|replace|full|index|catalog|archive|expired|text:"[^"]+"(,"[^"]+")?))*|[^\w@]+/g
nodes = (Header.mapCustomNavigation t, as for t in boardnav.match re)
$.add list, nodes
$.ready CatalogLinks.initBoardList
mapCustomNavigation: (t, as) ->
if /^[^\w@]/.test t if /^[^\w@]/.test t
return $.tn t return $.tn t
@ -210,10 +217,8 @@ Header =
className: 'external' className: 'external'
return a return a
boardID = if /^current/.test t boardID = t.split('-')[0]
g.BOARD.ID boardID = g.BOARD.ID if boardID is 'current'
else
t.match(/^[^-]+/)[0]
for aOrig in as for aOrig in as
if aOrig.textContent is boardID if aOrig.textContent is boardID
@ -226,14 +231,12 @@ Header =
else else
return $.tn t return $.tn t
a.textContent = if /-title/.test(t) or /-replace/.test(t) and $.hasClass a, 'current' a.textContent = if /-title/.test(t) or /-replace/.test(t) and boardID is g.BOARD.ID
a.title or a.textContent a.title or a.textContent
else if /-full/.test t else if /-full/.test t
"/#{boardID}/" + (if a.title then " - #{a.title}" else '') "/#{boardID}/" + (if a.title then " - #{a.title}" else '')
else if text
text
else else
a.textContent text or boardID
if m = t.match /-(index|catalog)/ if m = t.match /-(index|catalog)/
a.dataset.only = m[1] a.dataset.only = m[1]
@ -244,19 +247,16 @@ Header =
if href = Redirect.to 'board', {boardID} if href = Redirect.to 'board', {boardID}
a.href = href a.href = href
else else
return $.tn a.textContent return a.firstChild # Its text node.
if /-expired/.test t if /-expired/.test t
if boardID not in ['b', 'f'] if boardID not in ['b', 'f']
a.href = "/#{boardID}/archive" a.href = "/#{boardID}/archive"
else else
return $.tn a.textContent return a.firstChild # Its text node.
$.addClass a, 'navSmall' if boardID is '@' $.addClass a, 'navSmall' if boardID is '@'
return a a
$.add list, nodes
$.ready CatalogLinks.initBoardList
toggleBoardList: -> toggleBoardList: ->
{bar} = Header {bar} = Header
@ -323,10 +323,9 @@ Header =
@checked @checked
else else
!$.hasClass Header.bar, 'autohide' !$.hasClass Header.bar, 'autohide'
# set checked status if called from keybind
@checked = hide
$.set 'Header auto-hide', Conf['Header auto-hide'] = hide Conf['Header auto-hide'] = hide
$.set 'Header auto-hide', hide
Header.setBarVisibility hide Header.setBarVisibility hide
message = "The header bar will #{if hide message = "The header bar will #{if hide
'automatically hide itself.' 'automatically hide itself.'
@ -412,7 +411,7 @@ Header =
editCustomNav: -> editCustomNav: ->
Settings.open 'Advanced' Settings.open 'Advanced'
settings = $.id 'fourchanx-settings' settings = $.id 'fourchanx-settings'
$('textarea[name=boardnav]', settings).focus() $('[name=boardnav]', settings).focus()
hashScroll: -> hashScroll: ->
hash = @location.hash[1..] hash = @location.hash[1..]