Only fire IndexRefresh when there are new posts. #1106
This commit is contained in:
parent
a18419a02f
commit
420368219c
@ -3,7 +3,13 @@ Index =
|
|||||||
changed: {}
|
changed: {}
|
||||||
|
|
||||||
init: ->
|
init: ->
|
||||||
return if g.BOARD.ID is 'f' or !Conf['JSON Index'] or g.VIEW isnt 'index'
|
return unless g.VIEW is 'index' and g.BOARD.ID isnt 'f'
|
||||||
|
|
||||||
|
# For IndexRefresh events
|
||||||
|
$.one d, '4chanXInitFinished', @cb.initFinished
|
||||||
|
$.on d, 'PostsInserted', @cb.postsInserted
|
||||||
|
|
||||||
|
return unless Conf['JSON Index']
|
||||||
|
|
||||||
Callbacks.CatalogThread.push
|
Callbacks.CatalogThread.push
|
||||||
name: 'Catalog Features'
|
name: 'Catalog Features'
|
||||||
@ -125,7 +131,7 @@ Index =
|
|||||||
board = $ '.board'
|
board = $ '.board'
|
||||||
$.replace board, Index.root
|
$.replace board, Index.root
|
||||||
if Index.nodes
|
if Index.nodes
|
||||||
Index.events()
|
$.event 'PostsInserted'
|
||||||
# Hacks:
|
# Hacks:
|
||||||
# - When removing an element from the document during page load,
|
# - When removing an element from the document during page load,
|
||||||
# its ancestors will still be correctly created inside of it.
|
# its ancestors will still be correctly created inside of it.
|
||||||
@ -147,15 +153,6 @@ Index =
|
|||||||
$.replace pagelist, Index.pagelist
|
$.replace pagelist, Index.pagelist
|
||||||
$.rmClass doc, 'index-loading'
|
$.rmClass doc, 'index-loading'
|
||||||
|
|
||||||
$.one d, '4chanXInitFinished', -> Index.initFinishedFired = true
|
|
||||||
|
|
||||||
events: ->
|
|
||||||
$.event 'PostsInserted'
|
|
||||||
if Index.initFinishedFired
|
|
||||||
$.event 'IndexRefresh'
|
|
||||||
else
|
|
||||||
$.one d, '4chanXInitFinished', -> $.queueTask $.event, 'IndexRefresh'
|
|
||||||
|
|
||||||
scroll: ->
|
scroll: ->
|
||||||
return if Index.req or !Index.liveThreadData or Conf['Index Mode'] isnt 'infinite' or (window.scrollY <= doc.scrollHeight - (300 + window.innerHeight))
|
return if Index.req or !Index.liveThreadData or Conf['Index Mode'] isnt 'infinite' or (window.scrollY <= doc.scrollHeight - (300 + window.innerHeight))
|
||||||
Index.pageNum ?= Index.currentPage # Avoid having to pushState to keep track of the current page
|
Index.pageNum ?= Index.currentPage # Avoid having to pushState to keep track of the current page
|
||||||
@ -222,6 +219,19 @@ Index =
|
|||||||
$.event 'change', null, Index.selectSort
|
$.event 'change', null, Index.selectSort
|
||||||
|
|
||||||
cb:
|
cb:
|
||||||
|
initFinished: ->
|
||||||
|
Index.initFinishedFired = true
|
||||||
|
$.queueTask -> Index.cb.postsInserted()
|
||||||
|
|
||||||
|
postsInserted: ->
|
||||||
|
return unless Index.initFinishedFired
|
||||||
|
n = 0
|
||||||
|
g.posts.forEach (post) ->
|
||||||
|
if !post.isFetchedQuote and !post.indexRefreshSeen and doc.contains(post.nodes.root)
|
||||||
|
post.indexRefreshSeen = true
|
||||||
|
n++
|
||||||
|
$.event 'IndexRefresh' if n
|
||||||
|
|
||||||
toggleHiddenThreads: ->
|
toggleHiddenThreads: ->
|
||||||
$('#hidden-toggle a', Index.navLinks).textContent = if Index.showHiddenThreads = !Index.showHiddenThreads
|
$('#hidden-toggle a', Index.navLinks).textContent = if Index.showHiddenThreads = !Index.showHiddenThreads
|
||||||
'Hide'
|
'Hide'
|
||||||
@ -780,7 +790,7 @@ Index =
|
|||||||
nodes.push Index.nodes[thread.ID], $.el('hr')
|
nodes.push Index.nodes[thread.ID], $.el('hr')
|
||||||
$.add Index.root, nodes
|
$.add Index.root, nodes
|
||||||
if doc.contains Index.root
|
if doc.contains Index.root
|
||||||
Index.events()
|
$.event 'PostsInserted'
|
||||||
|
|
||||||
buildCatalog: (threads) ->
|
buildCatalog: (threads) ->
|
||||||
Index.buildCatalogViews threads
|
Index.buildCatalogViews threads
|
||||||
@ -797,7 +807,7 @@ Index =
|
|||||||
nodes.push thread.catalogView.nodes.root
|
nodes.push thread.catalogView.nodes.root
|
||||||
$.add Index.root, nodes
|
$.add Index.root, nodes
|
||||||
if doc.contains Index.root
|
if doc.contains Index.root
|
||||||
Index.events()
|
$.event 'PostsInserted'
|
||||||
|
|
||||||
clearSearch: ->
|
clearSearch: ->
|
||||||
Index.searchInput.value = ''
|
Index.searchInput.value = ''
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user