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

View File

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