Initial work for index navigation improvements.
This commit is contained in:
parent
a22bce79ab
commit
ef38269981
@ -170,9 +170,9 @@ Config =
|
||||
'Eqn tags': ['Alt+e', 'Insert eqn tags.']
|
||||
'Math tags': ['Alt+m', 'Insert math tags.']
|
||||
'Submit QR': ['Alt+s', 'Submit post.']
|
||||
# Thread related
|
||||
# Index/Thread related
|
||||
'Update': ['r', 'Refresh the index/thread.']
|
||||
'Watch': ['w', 'Watch thread.']
|
||||
'Update': ['r', 'Update the thread.']
|
||||
# Images
|
||||
'Expand image': ['Shift+e', 'Expand selected image.']
|
||||
'Expand images': ['e', 'Expand all images.']
|
||||
|
||||
@ -246,8 +246,8 @@ Header =
|
||||
hashScroll: ->
|
||||
return unless (hash = @location.hash[1..]) and post = $.id hash
|
||||
return if (Get.postFromRoot post).isHidden
|
||||
Header.scrollToPost post
|
||||
scrollToPost: (post) ->
|
||||
Header.scrollTo post
|
||||
scrollTo: (post) ->
|
||||
{top} = post.getBoundingClientRect()
|
||||
unless Conf['Bottom header']
|
||||
headRect = Header.toggle.getBoundingClientRect()
|
||||
@ -268,8 +268,8 @@ Header =
|
||||
|
||||
createNotification: (e) ->
|
||||
{type, content, lifetime, cb} = e.detail
|
||||
notif = new Notice type, content, lifetime
|
||||
cb notif if cb
|
||||
notice = new Notice type, content, lifetime
|
||||
cb notice if cb
|
||||
|
||||
areNotificationsEnabled: false
|
||||
enableDesktopNotifications: ->
|
||||
|
||||
@ -69,6 +69,7 @@ Main =
|
||||
initFeature 'Polyfill', Polyfill
|
||||
initFeature 'Header', Header
|
||||
initFeature 'Settings', Settings
|
||||
initFeature 'Index Pager', Index
|
||||
initFeature 'Announcement Hiding', PSAHiding
|
||||
initFeature 'Fourchan thingies', Fourchan
|
||||
initFeature 'Custom CSS', CustomCSS
|
||||
|
||||
41
src/Miscellaneous/Index.coffee
Normal file
41
src/Miscellaneous/Index.coffee
Normal file
@ -0,0 +1,41 @@
|
||||
Index =
|
||||
init: ->
|
||||
return if g.VIEW isnt 'index'
|
||||
|
||||
update: ->
|
||||
# return unless navigator.onLine
|
||||
Index.req?.abort()
|
||||
Index.notice?.close()
|
||||
Index.notice = new Notice 'info', 'Refreshing index...'
|
||||
Index.req = $.ajax "//api.4chan.org/#{g.BOARD}/catalog.json",
|
||||
onabort: Index.load
|
||||
onloadend: Index.load
|
||||
,
|
||||
whenModified: true
|
||||
load: (e) ->
|
||||
{req, notice} = Index
|
||||
delete Index.req
|
||||
delete Index.notice
|
||||
|
||||
if e.type is 'abort'
|
||||
req.onloadend = null
|
||||
notice.close()
|
||||
return
|
||||
|
||||
try
|
||||
Index.parse JSON.parse req.response
|
||||
catch e
|
||||
# network error or non-JSON content for example.
|
||||
notice.setType 'error'
|
||||
notice.el.lastElementChild.textContent = 'Index refresh failed.'
|
||||
setTimeout notice.close, 2 * $.SECOND
|
||||
return
|
||||
|
||||
notice.setType 'success'
|
||||
notice.el.lastElementChild.textContent = 'Index refreshed!'
|
||||
setTimeout notice.close, $.SECOND
|
||||
|
||||
Header.scrollTo $.id 'delform'
|
||||
parse: (pages) ->
|
||||
pageNum = +window.location.pathname.split('/')[2]
|
||||
threads = pages[pageNum].threads
|
||||
@ -58,11 +58,15 @@ Keybinds =
|
||||
Keybinds.tags 'math', target
|
||||
when Conf['Submit QR']
|
||||
QR.submit() if QR.nodes and !QR.status()
|
||||
# Thread related
|
||||
# Index/Thread related
|
||||
when Conf['Update']
|
||||
switch g.VIEW
|
||||
when 'thread'
|
||||
ThreadUpdater.update()
|
||||
when 'index'
|
||||
Index.update()
|
||||
when Conf['Watch']
|
||||
ThreadWatcher.toggle thread
|
||||
when Conf['Update']
|
||||
ThreadUpdater.update()
|
||||
# Images
|
||||
when Conf['Expand image']
|
||||
Keybinds.img threadRoot
|
||||
|
||||
@ -145,7 +145,7 @@ ThreadUpdater =
|
||||
return unless navigator.onLine
|
||||
ThreadUpdater.count()
|
||||
ThreadUpdater.set 'timer', '...'
|
||||
ThreadUpdater.req.abort() if ThreadUpdater.req
|
||||
ThreadUpdater.req?.abort()
|
||||
url = "//api.4chan.org/#{ThreadUpdater.thread.board}/res/#{ThreadUpdater.thread}.json"
|
||||
ThreadUpdater.req = $.ajax url,
|
||||
onabort: ThreadUpdater.cb.load
|
||||
@ -258,7 +258,7 @@ ThreadUpdater =
|
||||
if Conf['Bottom Scroll']
|
||||
window.scrollTo 0, d.body.clientHeight
|
||||
else
|
||||
Header.scrollToPost nodes[0]
|
||||
Header.scrollTo nodes[0]
|
||||
|
||||
# Enable 4chan features.
|
||||
threadID = ThreadUpdater.thread.ID
|
||||
|
||||
@ -47,7 +47,7 @@ Unread =
|
||||
# Scroll to the last read post.
|
||||
posts = Object.keys Unread.thread.posts
|
||||
{root} = Unread.thread.posts[posts[posts.length - 1]].nodes
|
||||
onload = -> Header.scrollToPost root if checkPosition root
|
||||
onload = -> Header.scrollTo root if checkPosition root
|
||||
checkPosition = (target) ->
|
||||
# Scroll to the target unless we scrolled past it.
|
||||
target.getBoundingClientRect().bottom > doc.clientHeight
|
||||
@ -102,7 +102,7 @@ Unread =
|
||||
body: post.info.comment
|
||||
icon: Favicon.logo
|
||||
notif.onclick = ->
|
||||
Header.scrollToPost post.nodes.root
|
||||
Header.scrollTo post.nodes.root
|
||||
window.focus()
|
||||
notif.onshow = ->
|
||||
setTimeout ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user