Always remember catalog index mode, redesign catalog/index links. #150

This commit is contained in:
ccd0 2014-10-18 00:34:51 -07:00
parent 5bf0c9ede3
commit a10c0e564a
5 changed files with 38 additions and 59 deletions

View File

@ -5,6 +5,10 @@ Config =
true true
'Replace the board index with a dynamically generated one supporting searching, sorting, and infinite scrolling.' 'Replace the board index with a dynamically generated one supporting searching, sorting, and infinite scrolling.'
] ]
'External Catalog': [
false
'Link to external catalog instead of the internal one.'
]
'Use 4chan X Catalog': [ 'Use 4chan X Catalog': [
false false
'Link to 4chan X\'s catalog instead of the native 4chan one.' 'Link to 4chan X\'s catalog instead of the native 4chan one.'
@ -13,10 +17,6 @@ Config =
true true
'Add toggle link in header menu to turn Navigation links into links to each board\'s catalog.' 'Add toggle link in header menu to turn Navigation links into links to each board\'s catalog.'
] ]
'External Catalog': [
false
'Link to external catalog instead of the internal one.'
]
'QR Shortcut': [ 'QR Shortcut': [
false, false,
'Adds a small [QR] link in the header.' 'Adds a small [QR] link in the header.'

View File

@ -194,13 +194,8 @@ Header =
if m = t.match /-(index|catalog)/ if m = t.match /-(index|catalog)/
a.dataset.only = m[1] a.dataset.only = m[1]
a.href = "//boards.4chan.org/#{board}/" a.href = CatalogLinks[m[1]] board
if m[1] is 'catalog' $.addClass a, 'catalog' if m[1] is 'catalog'
if Conf['External Catalog']
a.href = CatalogLinks.external board
else
a.href += if Conf['JSON Navigation'] and Conf['Use 4chan X Catalog'] then '#catalog' else 'catalog'
$.addClass a, 'catalog'
$.addClass a, 'navSmall' if board is '@' $.addClass a, 'navSmall' if board is '@'
return a return a

View File

@ -1,12 +1,7 @@
Index = Index =
showHiddenThreads: false showHiddenThreads: false
init: -> init: ->
return if g.BOARD.ID is 'f' or !Conf['JSON Navigation'] return if g.BOARD.ID is 'f' or !Conf['JSON Navigation'] or g.VIEW isnt 'index'
if g.VIEW is 'thread' and Conf['Use 4chan X Catalog']
$.ready ->
for link in $$ '.navLinks.desktop a' when link.pathname is "/#{g.BOARD}/catalog"
link.href = "/#{g.BOARD}/#catalog"
return if g.VIEW isnt 'index'
@board = "#{g.BOARD}" @board = "#{g.BOARD}"
@ -14,8 +9,6 @@ Index =
name: 'Catalog Features' name: 'Catalog Features'
cb: @catalogNode cb: @catalogNode
if Conf['Use 4chan X Catalog'] and Conf['Index Mode'] is 'catalog'
Conf['Index Mode'] = Conf['Previous Index Mode']
if history.state?.mode if history.state?.mode
Conf['Index Mode'] = history.state?.mode Conf['Index Mode'] = history.state?.mode
@pushState @pushState
@ -72,11 +65,11 @@ Index =
@root = $.el 'div', className: 'board' @root = $.el 'div', className: 'board'
@pagelist = $.el 'div', className: 'pagelist' @pagelist = $.el 'div', className: 'pagelist'
$.extend @pagelist, <%= importHTML('Features/Index-pagelist') %> $.extend @pagelist, <%= importHTML('Features/Index-pagelist') %>
$('.cataloglink a', @pagelist).href = if Conf['Use 4chan X Catalog'] then '#catalog' else "/#{g.BOARD}/catalog" $('.cataloglink a', @pagelist).href = CatalogLinks.catalog()
@navLinks = $.el 'div', className: 'navLinks' @navLinks = $.el 'div', className: 'navLinks'
$.extend @navLinks, <%= importHTML('Features/Index-navlinks') %> $.extend @navLinks, <%= importHTML('Features/Index-navlinks') %>
$('.returnlink a', @navLinks).href = "/#{g.BOARD}/" $('.returnlink a', @navLinks).href = CatalogLinks.index()
$('.cataloglink a', @navLinks).href = if Conf['Use 4chan X Catalog'] then '#catalog' else "/#{g.BOARD}/catalog" $('.cataloglink a', @navLinks).href = CatalogLinks.catalog()
@searchInput = $ '#index-search', @navLinks @searchInput = $ '#index-search', @navLinks
@hideLabel = $ '#hidden-label', @navLinks @hideLabel = $ '#hidden-label', @navLinks
@selectSort = $ '#index-sort', @navLinks @selectSort = $ '#index-sort', @navLinks
@ -88,7 +81,6 @@ Index =
$.on @searchInput, 'input', @onSearchInput $.on @searchInput, 'input', @onSearchInput
$.on $('#index-search-clear', @navLinks), 'click', @clearSearch $.on $('#index-search-clear', @navLinks), 'click', @clearSearch
$.on $('#hidden-toggle a', @navLinks), 'click', @cb.toggleHiddenThreads $.on $('#hidden-toggle a', @navLinks), 'click', @cb.toggleHiddenThreads
$.on $('.returnlink a', @navLinks), 'click', @cb.frontPage
@selectSort.value = Conf[@selectSort.name] @selectSort.value = Conf[@selectSort.name]
$.on @selectSort, 'change', $.cb.value $.on @selectSort, 'change', $.cb.value
$.on @selectSort, 'change', @cb.sort $.on @selectSort, 'change', @cb.sort
@ -195,8 +187,7 @@ Index =
Index.buildIndex() Index.buildIndex()
mode: -> mode: ->
mode = @value mode = @value
unless mode is 'catalog' and Conf['Use 4chan X Catalog'] $.set 'Index Mode', mode
$.set 'Index Mode', mode
unless mode is 'catalog' unless mode is 'catalog'
Conf['Previous Index Mode'] = mode Conf['Previous Index Mode'] = mode
$.set 'Previous Index Mode', mode $.set 'Previous Index Mode', mode
@ -243,13 +234,6 @@ Index =
return if a.textContent is 'Catalog' return if a.textContent is 'Catalog'
e.preventDefault() e.preventDefault()
Index.userPageNav +a.pathname.split('/')[2] or 1 Index.userPageNav +a.pathname.split('/')[2] or 1
frontPage: (e) ->
return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0
e.preventDefault()
if Conf['Use 4chan X Catalog'] and Conf['Index Mode'] is 'catalog'
window.location = '#index'
else
Index.userPageNav 1
scrollToIndex: -> scrollToIndex: ->
Header.scrollToIfNeeded Index.navLinks Header.scrollToIfNeeded Index.navLinks
@ -273,6 +257,7 @@ Index =
state.mode = command.replace /-/g, ' ' state.mode = command.replace /-/g, ' '
when 'index' when 'index'
state.mode = Conf['Previous Index Mode'] state.mode = Conf['Previous Index Mode']
state.page = 1
else else
delete state.command delete state.command
{mode} = state {mode} = state

View File

@ -1,5 +1,17 @@
CatalogLinks = CatalogLinks =
init: -> init: ->
if Conf['External Catalog'] or Conf['JSON Navigation']
selector = switch g.VIEW
when 'thread' then '.navLinks.desktop > a'
when 'catalog' then '.navLinks > :first-child > a'
when 'index' then '.middlead + .desktop > a, .cataloglink > a'
$.ready ->
for link in $$ selector
switch link.pathname
when "/#{g.BOARD}/" then link.href = CatalogLinks.index()
when "/#{g.BOARD}/catalog" then link.href = CatalogLinks.catalog()
return
return unless Conf['Catalog Links'] return unless Conf['Catalog Links']
CatalogLinks.el = el = UI.checkbox 'Header catalog links', ' Catalog Links' CatalogLinks.el = el = UI.checkbox 'Header catalog links', ' Catalog Links'
el.id = 'toggleCatalog' el.id = 'toggleCatalog'
@ -24,16 +36,6 @@ CatalogLinks =
CatalogLinks.set @checked CatalogLinks.set @checked
set: (useCatalog) -> set: (useCatalog) ->
path = if useCatalog
if Conf['JSON Navigation'] and Conf['Use 4chan X Catalog'] then '#catalog' else 'catalog'
else
''
generateURL = if useCatalog and Conf['External Catalog']
CatalogLinks.external
else
(board) -> a.href = "/#{board}/#{path}"
for a in $$ """#board-list a:not([data-only]), #boardNavDesktopFoot a""" for a in $$ """#board-list a:not([data-only]), #boardNavDesktopFoot a"""
continue if a.hostname not in ['boards.4chan.org', 'catalog.neet.tv', '4index.gropes.us'] or continue if a.hostname not in ['boards.4chan.org', 'catalog.neet.tv', '4index.gropes.us'] or
!(board = a.pathname.split('/')[1]) or !(board = a.pathname.split('/')[1]) or
@ -42,12 +44,20 @@ CatalogLinks =
# Href is easier than pathname because then we don't have # Href is easier than pathname because then we don't have
# conditions where External Catalog has been disabled between switches. # conditions where External Catalog has been disabled between switches.
a.href = generateURL board a.href = CatalogLinks[if useCatalog then 'catalog' else 'index'] board
CatalogLinks.el.title = "Turn catalog links #{if useCatalog then 'off' else 'on'}." CatalogLinks.el.title = "Turn catalog links #{if useCatalog then 'off' else 'on'}."
external: (board) -> catalog: (board=g.BOARD.ID) ->
if board in ['a', 'c', 'g', 'biz', 'k', 'm', 'o', 'p', 'v', 'vg', 'vr', 'w', 'wg', 'cm', '3', 'adv', 'an', 'asp', 'cgl', 'ck', 'co', 'diy', 'fa', 'fit', 'gd', 'int', 'jp', 'lit', 'mlp', 'mu', 'n', 'out', 'po', 'sci', 'sp', 'tg', 'toy', 'trv', 'tv', 'vp', 'wsg', 'x', 'f', 'pol', 's4s', 'lgbt'] if Conf['External Catalog'] and board in ['a', 'c', 'g', 'biz', 'k', 'm', 'o', 'p', 'v', 'vg', 'vr', 'w', 'wg', 'cm', '3', 'adv', 'an', 'asp', 'cgl', 'ck', 'co', 'diy', 'fa', 'fit', 'gd', 'int', 'jp', 'lit', 'mlp', 'mu', 'n', 'out', 'po', 'sci', 'sp', 'tg', 'toy', 'trv', 'tv', 'vp', 'wsg', 'x', 'f', 'pol', 's4s', 'lgbt']
"http://catalog.neet.tv/#{board}" "http://catalog.neet.tv/#{board}"
else if Conf['JSON Navigation'] and Conf['Use 4chan X Catalog']
if g.BOARD.ID is board and g.VIEW is 'index' then '#catalog' else "/#{board}/\#catalog"
else else
"/#{board}/catalog" "/#{board}/catalog"
index: (board=g.BOARD.ID) ->
if Conf['JSON Navigation']
if g.BOARD.ID is board and g.VIEW is 'index' then '#index' else "/#{board}/\#index"
else
"/#{board}/"

View File

@ -102,15 +102,9 @@ Keybinds =
FappeTyme.cb.toggle.call {name: 'werk'} FappeTyme.cb.toggle.call {name: 'werk'}
# Board Navigation # Board Navigation
when Conf['Front page'] when Conf['Front page']
if Conf['JSON Navigation'] and g.VIEW is 'index' window.location = CatalogLinks.index()
if Conf['Use 4chan X Catalog'] and Conf['Index Mode'] is 'catalog'
window.location = '#index'
else
Index.userPageNav 1
else
window.location = "/#{g.BOARD}/"
when Conf['Open front page'] when Conf['Open front page']
$.open "/#{g.BOARD}/" $.open CatalogLinks.index()
when Conf['Next page'] when Conf['Next page']
return unless g.VIEW is 'index' return unless g.VIEW is 'index'
if Conf['JSON Navigation'] if Conf['JSON Navigation']
@ -133,12 +127,7 @@ Keybinds =
Header.scrollToIfNeeded searchInput Header.scrollToIfNeeded searchInput
searchInput.focus() searchInput.focus()
when Conf['Open catalog'] when Conf['Open catalog']
if Conf['External Catalog'] window.location = CatalogLinks.catalog()
window.location = CatalogLinks.external(g.BOARD.ID)
else if Conf['JSON Navigation'] and Conf['Use 4chan X Catalog']
window.location = if g.VIEW is 'index' then '#catalog' else "/#{g.BOARD}/#catalog"
else
window.location = "/#{g.BOARD}/catalog"
# Thread Navigation # Thread Navigation
when Conf['Next thread'] when Conf['Next thread']
return if g.VIEW isnt 'index' or !threadRoot return if g.VIEW isnt 'index' or !threadRoot