Finally fix Index from Thread navigation

This commit is contained in:
Zixaphir 2014-01-09 14:09:19 -07:00
parent 3327c9cf36
commit 22c244ce69
4 changed files with 107 additions and 154 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

@ -66,13 +66,7 @@ Index =
order: 98 order: 98
subEntries: [repliesEntry, anchorEntry, refNavEntry, modeEntry, sortEntry] subEntries: [repliesEntry, anchorEntry, refNavEntry, modeEntry, sortEntry]
return if g.VIEW isnt 'index'
@connect.call @
connect: ->
$.addClass doc, 'index-loading' $.addClass doc, 'index-loading'
@update()
@root = $.el 'div', className: 'board' @root = $.el 'div', className: 'board'
@pagelist = $.el 'div', @pagelist = $.el 'div',
className: 'pagelist' className: 'pagelist'
@ -83,11 +77,14 @@ Index =
innerHTML: <%= importHTML('Features/Index-navlinks') %> innerHTML: <%= importHTML('Features/Index-navlinks') %>
@searchInput = $ '#index-search', @navLinks @searchInput = $ '#index-search', @navLinks
@currentPage = @getCurrentPage() @currentPage = @getCurrentPage()
$.on window, 'popstate', @cb.popstate
$.on @pagelist, 'click', @cb.pageNav $.on @pagelist, 'click', @cb.pageNav
$.on @searchInput, 'input', @onSearchInput $.on @searchInput, 'input', @onSearchInput
$.on $('#index-search-clear', @navLinks), 'click', @clearSearch $.on $('#index-search-clear', @navLinks), 'click', @clearSearch
@update() if g.VIEW is 'index'
$.asap (-> $('.board', doc) or d.readyState isnt 'loading'), -> $.asap (-> $('.board', doc) or d.readyState isnt 'loading'), ->
if g.VIEW is 'index'
board = $ '.board' board = $ '.board'
$.replace board, Index.root $.replace board, Index.root
# Hacks: # Hacks:
@ -99,11 +96,11 @@ Index =
# Does not work on Firefox unfortunately. bugzil.la/939713 # Does not work on Firefox unfortunately. bugzil.la/939713
d.implementation.createDocument(null, null, null).appendChild board d.implementation.createDocument(null, null, null).appendChild board
for navLink in $$ '.navLinks' $.rm navLink for navLink in $$ '.navLinks'
$.rm navLink
$.after $.x('child::form/preceding-sibling::hr[1]'), Index.navLinks $.after $.x('child::form/preceding-sibling::hr[1]'), Index.navLinks
$.rmClass doc, 'index-loading' $.rmClass doc, 'index-loading'
$.asap (-> $('.pagelist') or d.readyState isnt 'loading'), ->
$.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), ->
if pagelist = $('.pagelist') if pagelist = $('.pagelist')
$.replace pagelist, Index.pagelist $.replace pagelist, Index.pagelist
else else
@ -120,9 +117,6 @@ Index =
Index.buildThreads() Index.buildThreads()
Index.sort() Index.sort()
Index.buildIndex() Index.buildIndex()
popstate: (e) ->
pageNum = Index.getCurrentPage()
Index.pageLoad pageNum if Index.currentPage isnt pageNum
pageNav: (e) -> pageNav: (e) ->
return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0 return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0
switch e.target.nodeName switch e.target.nodeName
@ -209,6 +203,9 @@ Index =
update: (pageNum) -> update: (pageNum) ->
return unless navigator.onLine return unless navigator.onLine
unless Index.root.parentElement
board = $ '.board'
$.replace board, Index.root
Index.req?.abort() Index.req?.abort()
Index.notice?.close() Index.notice?.close()

View File

@ -327,8 +327,10 @@ Main =
{posts, threads} = g {posts, threads} = g
# Garbage collection # Garbage collection
delete posts[id] for id of posts when posts.hasOwnProperty id g.posts = {}
delete threads[id] for id of threads when threads.hasOwnProperty id g.threads = {}
g.BOARD.posts = {}
g.BOARD.threads = {}
# Delete nodes # Delete nodes
$.rmAll $ '.board' $.rmAll $ '.board'
@ -352,9 +354,7 @@ Main =
Main.handleErrors errors if errors Main.handleErrors errors if errors
# Clean Post and Thread callbacks return
# Post.callbacks.clear()
# Thread.callbacks.clear()
navigate: (e) -> navigate: (e) ->
return if @hostname isnt 'boards.4chan.org' return if @hostname isnt 'boards.4chan.org'
@ -380,13 +380,9 @@ Main =
if view is 'index' if view is 'index'
Main.updateBoard boardID unless boardID is g.BOARD.ID Main.updateBoard boardID unless boardID is g.BOARD.ID
if Index.root
Index.connect()
else
Index.update() Index.update()
# Moving from thread to thread or index to index. # Moving from index to thread or thread to thread
else else
c.error 'How?' c.error 'How?'
Main.refresh {boardID, view, threadID} Main.refresh {boardID, view, threadID}