Don't display the index refreshing notice on intial page load for fast connections. #1322
This commit is contained in:
parent
66189e449c
commit
1c66c6a604
@ -137,7 +137,17 @@ Index =
|
|||||||
return unless navigator.onLine
|
return unless navigator.onLine
|
||||||
Index.req?.abort()
|
Index.req?.abort()
|
||||||
Index.notice?.close()
|
Index.notice?.close()
|
||||||
Index.notice = new Notice 'info', 'Refreshing index...'
|
if d.readyState isnt 'loading'
|
||||||
|
Index.notice = new Notice 'info', 'Refreshing index...'
|
||||||
|
else
|
||||||
|
# Delay the notice on initial page load
|
||||||
|
# and only display it for slow connections.
|
||||||
|
now = Date.now()
|
||||||
|
$.ready ->
|
||||||
|
setTimeout (->
|
||||||
|
return unless Index.req and !Index.notice
|
||||||
|
Index.notice = new Notice 'info', 'Refreshing index...'
|
||||||
|
), $.SECOND - (Date.now() - now)
|
||||||
Index.req = $.ajax "//api.4chan.org/#{g.BOARD}/catalog.json",
|
Index.req = $.ajax "//api.4chan.org/#{g.BOARD}/catalog.json",
|
||||||
onabort: Index.load
|
onabort: Index.load
|
||||||
onloadend: Index.load
|
onloadend: Index.load
|
||||||
@ -160,14 +170,18 @@ Index =
|
|||||||
catch err
|
catch err
|
||||||
c.error 'Index failure:', err.stack
|
c.error 'Index failure:', err.stack
|
||||||
# network error or non-JSON content for example.
|
# network error or non-JSON content for example.
|
||||||
notice.setType 'error'
|
if notice
|
||||||
notice.el.lastElementChild.textContent = 'Index refresh failed.'
|
notice.setType 'error'
|
||||||
setTimeout notice.close, 2 * $.SECOND
|
notice.el.lastElementChild.textContent = 'Index refresh failed.'
|
||||||
|
setTimeout notice.close, 2 * $.SECOND
|
||||||
|
else
|
||||||
|
new Notice 'error', 'Index refresh failed.', 2
|
||||||
return
|
return
|
||||||
|
|
||||||
notice.setType 'success'
|
if notice
|
||||||
notice.el.lastElementChild.textContent = 'Index refreshed!'
|
notice.setType 'success'
|
||||||
setTimeout notice.close, $.SECOND
|
notice.el.lastElementChild.textContent = 'Index refreshed!'
|
||||||
|
setTimeout notice.close, $.SECOND
|
||||||
|
|
||||||
Index.scrollToIndex()
|
Index.scrollToIndex()
|
||||||
parse: (pages) ->
|
parse: (pages) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user