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
'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': [
false
'Link to 4chan X\'s catalog instead of the native 4chan one.'
@ -13,10 +17,6 @@ Config =
true
'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': [
false,
'Adds a small [QR] link in the header.'

View File

@ -194,13 +194,8 @@ Header =
if m = t.match /-(index|catalog)/
a.dataset.only = m[1]
a.href = "//boards.4chan.org/#{board}/"
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'
a.href = CatalogLinks[m[1]] board
$.addClass a, 'catalog' if m[1] is 'catalog'
$.addClass a, 'navSmall' if board is '@'
return a

View File

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

View File

@ -1,5 +1,17 @@
CatalogLinks =
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']
CatalogLinks.el = el = UI.checkbox 'Header catalog links', ' Catalog Links'
el.id = 'toggleCatalog'
@ -24,16 +36,6 @@ CatalogLinks =
CatalogLinks.set @checked
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"""
continue if a.hostname not in ['boards.4chan.org', 'catalog.neet.tv', '4index.gropes.us'] or
!(board = a.pathname.split('/')[1]) or
@ -42,12 +44,20 @@ CatalogLinks =
# Href is easier than pathname because then we don't have
# 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'}."
external: (board) ->
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']
catalog: (board=g.BOARD.ID) ->
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}"
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
"/#{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'}
# Board Navigation
when Conf['Front page']
if Conf['JSON Navigation'] and g.VIEW is '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}/"
window.location = CatalogLinks.index()
when Conf['Open front page']
$.open "/#{g.BOARD}/"
$.open CatalogLinks.index()
when Conf['Next page']
return unless g.VIEW is 'index'
if Conf['JSON Navigation']
@ -133,12 +127,7 @@ Keybinds =
Header.scrollToIfNeeded searchInput
searchInput.focus()
when Conf['Open catalog']
if Conf['External 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"
window.location = CatalogLinks.catalog()
# Thread Navigation
when Conf['Next thread']
return if g.VIEW isnt 'index' or !threadRoot