Improve navigation between boards

Also allow navigation to indexes from boards.
This commit is contained in:
Zixaphir 2014-01-08 11:40:58 -07:00
parent 41e3fa05ad
commit fca2645787
6 changed files with 160 additions and 270 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -134,6 +134,7 @@ Header =
id: 'scroll-marker' id: 'scroll-marker'
setBoardList: -> setBoardList: ->
$.rmAll Header.bar if Header.bar.children.length
fourchannav = $.id 'boardNavDesktop' fourchannav = $.id 'boardNavDesktop'
boardList = $.el 'span', boardList = $.el 'span',
id: 'board-list' id: 'board-list'

View File

@ -144,7 +144,7 @@ Index =
Header.scrollToIfNeeded Index.root Header.scrollToIfNeeded Index.root
getCurrentPage: -> getCurrentPage: ->
+window.location.pathname.split('/')[2] +window.location.pathname.split('/')[2] or 0
userPageNav: (pageNum) -> userPageNav: (pageNum) ->
if Conf['Refreshed Navigation'] and Conf['Index Mode'] is 'paged' if Conf['Refreshed Navigation'] and Conf['Index Mode'] is 'paged'
Index.update pageNum Index.update pageNum

View File

@ -55,10 +55,10 @@ Main =
return return
# c.time 'All initializations' # c.time 'All initializations'
for name, module of Main.features for [name, feature] in Main.features
# c.time "#{name} initialization" # c.time "#{name} initialization"
try try
module.init() feature.init()
catch err catch err
Main.handleErrors Main.handleErrors
message: "\"#{name}\" initialization crashed." message: "\"#{name}\" initialization crashed."
@ -188,7 +188,6 @@ Main =
len = nodes.length len = nodes.length
softTask() softTask()
addCallback: (e) -> addCallback: (e) ->
obj = e.detail obj = e.detail
unless typeof obj.callback.name is 'string' unless typeof obj.callback.name is 'string'
@ -254,81 +253,86 @@ Main =
<%= grunt.file.read('src/General/css/photon.css').replace(/\s+/g, ' ').trim() %> <%= grunt.file.read('src/General/css/photon.css').replace(/\s+/g, ' ').trim() %>
""" """
features: features: [
'Polyfill': Polyfill ['Polyfill', Polyfill]
'Redirect': Redirect ['Redirect', Redirect]
'Header': Header ['Header', Header]
'Catalog Links': CatalogLinks ['Catalog Links', CatalogLinks]
'Settings': Settings ['Settings', Settings]
'Index Generator': Index ['Index Generator', Index]
'Announcement Hiding': PSAHiding ['Announcement Hiding', PSAHiding]
'Fourchan thingies': Fourchan ['Fourchan thingies', Fourchan]
'Emoji': Emoji ['Emoji', Emoji]
'Color User IDs': IDColor ['Color User IDs', IDColor]
'Custom CSS': CustomCSS ['Custom CSS', CustomCSS]
'Linkify': Linkify ['Linkify', Linkify]
'Reveal Spoilers': RemoveSpoilers ['Reveal Spoilers', RemoveSpoilers]
'Resurrect Quotes': Quotify ['Resurrect Quotes', Quotify]
'Filter': Filter ['Filter', Filter]
'Thread Hiding Buttons': ThreadHiding ['Thread Hiding Buttons', ThreadHiding]
'Reply Hiding Buttons': PostHiding ['Reply Hiding Buttons', PostHiding]
'Recursive': Recursive ['Recursive', Recursive]
'Strike-through Quotes': QuoteStrikeThrough ['Strike-through Quotes', QuoteStrikeThrough]
'Quick Reply': QR ['Quick Reply', QR]
'Menu': Menu ['Menu', Menu]
'Report Link': ReportLink ['Report Link', ReportLink]
'Thread Hiding (Menu)': ThreadHiding.menu ['Thread Hiding (Menu)', ThreadHiding.menu]
'Reply Hiding (Menu)': PostHiding.menu ['Reply Hiding (Menu)', PostHiding.menu]
'Delete Link': DeleteLink ['Delete Link', DeleteLink]
'Filter (Menu)': Filter.menu ['Filter (Menu)', Filter.menu]
'Download Link': DownloadLink ['Download Link', DownloadLink]
'Archive Link': ArchiveLink ['Archive Link', ArchiveLink]
'Quote Inlining': QuoteInline ['Quote Inlining', QuoteInline]
'Quote Previewing': QuotePreview ['Quote Previewing', QuotePreview]
'Quote Backlinks': QuoteBacklink ['Quote Backlinks', QuoteBacklink]
'Mark Quotes of You': QuoteYou ['Mark Quotes of You', QuoteYou]
'Mark OP Quotes': QuoteOP ['Mark OP Quotes', QuoteOP]
'Mark Cross-thread Quotes': QuoteCT ['Mark Cross-thread Quotes', QuoteCT]
'Anonymize': Anonymize ['Anonymize', Anonymize]
'Time Formatting': Time ['Time Formatting', Time]
'Relative Post Dates': RelativeDates ['Relative Post Dates', RelativeDates]
'File Info Formatting': FileInfo ['File Info Formatting', FileInfo]
'Fappe Tyme': FappeTyme ['Fappe Tyme', FappeTyme]
'Gallery': Gallery ['Gallery', Gallery]
'Gallery (menu)': Gallery.menu ['Gallery (menu)', Gallery.menu]
'Sauce': Sauce ['Sauce', Sauce]
'Image Expansion': ImageExpand ['Image Expansion', ImageExpand]
'Image Expansion (Menu)': ImageExpand.menu ['Image Expansion (Menu)', ImageExpand.menu]
'Reveal Spoiler Thumbnails': RevealSpoilers ['Reveal Spoiler Thumbnails', RevealSpoilers]
'Image Loading': ImageLoader ['Image Loading', ImageLoader]
'Image Hover': ImageHover ['Image Hover', ImageHover]
'Thread Expansion': ExpandThread ['Thread Expansion', ExpandThread]
'Thread Excerpt': ThreadExcerpt ['Thread Excerpt', ThreadExcerpt]
'Favicon': Favicon ['Favicon', Favicon]
'Unread': Unread ['Unread', Unread]
'Quote Threading': QuoteThreading ['Quote Threading', QuoteThreading]
'Thread Stats': ThreadStats ['Thread Stats', ThreadStats]
'Thread Updater': ThreadUpdater ['Thread Updater', ThreadUpdater]
'Thread Watcher': ThreadWatcher ['Thread Watcher', ThreadWatcher]
'Thread Watcher (Menu)': ThreadWatcher.menu ['Thread Watcher (Menu)', ThreadWatcher.menu]
'Index Navigation': Nav ['Index Navigation', Nav]
'Keybinds': Keybinds ['Keybinds', Keybinds]
'Show Dice Roll': Dice ['Show Dice Roll', Dice]
'Banner': Banner ['Banner', Banner]
]
clean: -> clean: ->
{posts, threads} = g {posts, threads} = g
delete posts[id] for id of posts when posts.hasOwnProperty id delete posts[id] for id of posts when posts.hasOwnProperty id
delete threads[id] for id of threads when threads.hasOwnProperty id delete threads[id] for id of threads when threads.hasOwnProperty id
g.threads = threads
g.posts = posts
disconnect: -> disconnect: (view) ->
if g.VIEW is 'thread' if g.VIEW is 'thread'
features = features = [
'Thread Updater': ThreadUpdater ['Thread Updater', ThreadUpdater]
'Unread Count': Unread ['Unread Count', Unread]
'Quote Threading': QuoteThreading ['Quote Threading', QuoteThreading]
]
for name, feature of features for [name, feature] in features
try try
feature.disconnect.call feature feature.disconnect.call feature
catch err catch err
@ -344,20 +348,26 @@ Main =
# Thread.callbacks.clear() # Thread.callbacks.clear()
# Clean the board, as we'll be dumping shit here # Clean the board, as we'll be dumping shit here
$.rmAll $ '.board' # $.rmAll $ '.board'
g.VIEW = view
navigate: (e) -> navigate: (e) ->
return unless @hostname is 'boards.4chan.org' return unless @hostname is 'boards.4chan.org'
# Lets have a good idea of what we should we should be expecting for this kind of feature # Lets have a good idea of what we should we should be expecting for this kind of feature
[_, boardID, view, threadID] = @pathname.split '/' path = @pathname.split '/'
path.shift() if path[0] is ''
[boardID, view, threadID] = path
return if view is 'catalog' return if view is 'catalog'
e.preventDefault() e.preventDefault()
history.pushState null, '', @pathname
if threadID view = if threadID
view = 'thread' 'thread'
else else
view = view or 'index' view or 'index' # path is "/boardID/". See the problem?
# Moving from thread to thread or index to index. # Moving from thread to thread or index to index.
if view is g.VIEW if view is g.VIEW
@ -372,15 +382,16 @@ Main =
Main.refresh {boardID, view, threadID} Main.refresh {boardID, view, threadID}
else else
g.VIEW = view
if view is 'index' if view is 'index'
Main.disconnect() Main.disconnect view
Main.clean() Main.clean()
Main.updateBoard() unless boardID is g.BOARD.ID Main.updateBoard boardID unless boardID is g.BOARD.ID
Index.connect.call Index Index.connect.call Index
else else
Main.refresh {boardID, view, threadID} Main.refresh {boardID, view, threadID}
Header.setBoardList()
updateBoard: (boardID) -> updateBoard: (boardID) ->
g.BOARD = new Board boardID g.BOARD = new Board boardID

View File

@ -64,7 +64,7 @@ ThreadUpdater =
disconnect: -> disconnect: ->
if Conf['Updater and Stats in Header'] if Conf['Updater and Stats in Header']
Header.rmShortcut @dialog Header.rmShortcut @dialog
else else
$.rmClass doc, 'float' $.rmClass doc, 'float'
$.rm @dialog $.rm @dialog