From 3dd0ed60262525b86fc75a807ddeacf37c615c41 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 20 Sep 2014 18:02:46 -0700 Subject: [PATCH] add setting to link to 4chan X catalog --- src/General/Config.coffee | 4 ++++ src/General/Header.coffee | 2 +- src/General/Index.coffee | 21 +++++++++++++------ src/General/html/Features/Index-navlinks.html | 4 ++-- src/Miscellaneous/CatalogLinks.coffee | 5 ++++- src/Miscellaneous/Keybinds.coffee | 5 ++++- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 063259202..2f995e035 100755 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -5,6 +5,10 @@ Config = true 'Replace the board index with a dynamically generated one supporting searching, sorting, and infinite scrolling.' ] + 'Use 4chan X Catalog': [ + false + 'Link to 4chan X\'s catalog instead of the native 4chan one.' + ] 'Catalog Links': [ true 'Add toggle link in header menu to turn Navigation links into links to each board\'s catalog.' diff --git a/src/General/Header.coffee b/src/General/Header.coffee index ec293a3f4..c5ee2a4fc 100755 --- a/src/General/Header.coffee +++ b/src/General/Header.coffee @@ -197,7 +197,7 @@ Header = if Conf['External Catalog'] a.href = CatalogLinks.external board else - a.href += 'catalog' + 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 '@' diff --git a/src/General/Index.coffee b/src/General/Index.coffee index ead8053b8..30100dfda 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -1,8 +1,12 @@ Index = showHiddenThreads: false init: -> - return if g.BOARD.ID is 'f' or g.VIEW isnt 'index' or !Conf['JSON Navigation'] - @cb.popstate() + 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' @board = "#{g.BOARD}" @@ -14,6 +18,10 @@ Index = name: 'Catalog Features' cb: @catalogNode + if Conf['Use 4chan X Catalog'] and Conf['Index Mode'] is 'catalog' + Index.setMode Conf['Previous Index Mode'] + @cb.popstate() + @button = $.el 'a', className: 'index-refresh-shortcut fa fa-refresh' title: 'Refresh' @@ -79,10 +87,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" @navLinks = $.el 'div', className: 'navLinks' $.extend @navLinks, <%= importHTML('Features/Index-navlinks') %> - $('.returnlink a', @navLinks).href = "//boards.4chan.org/#{g.BOARD}/" - $('.cataloglink a', @navLinks).href = "//boards.4chan.org/#{g.BOARD}/catalog" + $('.returnlink a', @navLinks).href = if Conf['Use 4chan X Catalog'] then '#index' else "/#{g.BOARD}/" + $('.cataloglink a', @navLinks).href = if Conf['Use 4chan X Catalog'] then '#catalog' else "/#{g.BOARD}/catalog" @searchInput = $ '#index-search', @navLinks @hideLabel = $ '#hidden-label', @navLinks @currentPage = @getCurrentPage() @@ -238,8 +247,8 @@ Index = Index.buildIndex() hashchange: (e) -> switch command = location.hash[1..] - when 'paged', 'infinite', 'all pages', 'catalog' - mode = command + when 'paged', 'infinite', 'all-pages', 'catalog' + mode = command.replace /-/g, ' ' when 'index' mode = Conf['Previous Index Mode'] if mode diff --git a/src/General/html/Features/Index-navlinks.html b/src/General/html/Features/Index-navlinks.html index 657978b5c..340331d5e 100644 --- a/src/General/html/Features/Index-navlinks.html +++ b/src/General/html/Features/Index-navlinks.html @@ -1,5 +1,5 @@ -Return -Catalog +Return +Catalog Bottom diff --git a/src/Miscellaneous/CatalogLinks.coffee b/src/Miscellaneous/CatalogLinks.coffee index 09f36ed06..8649a5e7c 100755 --- a/src/Miscellaneous/CatalogLinks.coffee +++ b/src/Miscellaneous/CatalogLinks.coffee @@ -24,7 +24,10 @@ CatalogLinks = CatalogLinks.set @checked set: (useCatalog) -> - path = if useCatalog then 'catalog' else '' + 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 diff --git a/src/Miscellaneous/Keybinds.coffee b/src/Miscellaneous/Keybinds.coffee index c8577d57c..0293783f5 100755 --- a/src/Miscellaneous/Keybinds.coffee +++ b/src/Miscellaneous/Keybinds.coffee @@ -103,6 +103,9 @@ Keybinds = # 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' + return return unless Conf['Index Mode'] in ['paged', 'infinite'] Index.userPageNav 1 else @@ -134,7 +137,7 @@ Keybinds = if Conf['External Catalog'] window.location = CatalogLinks.external(g.BOARD.ID) else - window.location = "/#{g.BOARD}/catalog" + window.location = "/#{g.BOARD}/" + if Conf['JSON Navigation'] and Conf['Use 4chan X Catalog'] then '#catalog' else 'catalog' # Thread Navigation when Conf['Next thread'] return if g.VIEW isnt 'index' or !threadRoot