Initial work for index navigation improvements.

This commit is contained in:
Mayhem 2013-10-29 19:13:34 +01:00
parent a22bce79ab
commit ef38269981
7 changed files with 59 additions and 13 deletions

View File

@ -170,9 +170,9 @@ Config =
'Eqn tags': ['Alt+e', 'Insert eqn tags.'] 'Eqn tags': ['Alt+e', 'Insert eqn tags.']
'Math tags': ['Alt+m', 'Insert math tags.'] 'Math tags': ['Alt+m', 'Insert math tags.']
'Submit QR': ['Alt+s', 'Submit post.'] 'Submit QR': ['Alt+s', 'Submit post.']
# Thread related # Index/Thread related
'Update': ['r', 'Refresh the index/thread.']
'Watch': ['w', 'Watch thread.'] 'Watch': ['w', 'Watch thread.']
'Update': ['r', 'Update the thread.']
# Images # Images
'Expand image': ['Shift+e', 'Expand selected image.'] 'Expand image': ['Shift+e', 'Expand selected image.']
'Expand images': ['e', 'Expand all images.'] 'Expand images': ['e', 'Expand all images.']

View File

@ -246,8 +246,8 @@ Header =
hashScroll: -> hashScroll: ->
return unless (hash = @location.hash[1..]) and post = $.id hash return unless (hash = @location.hash[1..]) and post = $.id hash
return if (Get.postFromRoot post).isHidden return if (Get.postFromRoot post).isHidden
Header.scrollToPost post Header.scrollTo post
scrollToPost: (post) -> scrollTo: (post) ->
{top} = post.getBoundingClientRect() {top} = post.getBoundingClientRect()
unless Conf['Bottom header'] unless Conf['Bottom header']
headRect = Header.toggle.getBoundingClientRect() headRect = Header.toggle.getBoundingClientRect()
@ -268,8 +268,8 @@ Header =
createNotification: (e) -> createNotification: (e) ->
{type, content, lifetime, cb} = e.detail {type, content, lifetime, cb} = e.detail
notif = new Notice type, content, lifetime notice = new Notice type, content, lifetime
cb notif if cb cb notice if cb
areNotificationsEnabled: false areNotificationsEnabled: false
enableDesktopNotifications: -> enableDesktopNotifications: ->

View File

@ -69,6 +69,7 @@ Main =
initFeature 'Polyfill', Polyfill initFeature 'Polyfill', Polyfill
initFeature 'Header', Header initFeature 'Header', Header
initFeature 'Settings', Settings initFeature 'Settings', Settings
initFeature 'Index Pager', Index
initFeature 'Announcement Hiding', PSAHiding initFeature 'Announcement Hiding', PSAHiding
initFeature 'Fourchan thingies', Fourchan initFeature 'Fourchan thingies', Fourchan
initFeature 'Custom CSS', CustomCSS initFeature 'Custom CSS', CustomCSS

View 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

View File

@ -58,11 +58,15 @@ Keybinds =
Keybinds.tags 'math', target Keybinds.tags 'math', target
when Conf['Submit QR'] when Conf['Submit QR']
QR.submit() if QR.nodes and !QR.status() 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'] when Conf['Watch']
ThreadWatcher.toggle thread ThreadWatcher.toggle thread
when Conf['Update']
ThreadUpdater.update()
# Images # Images
when Conf['Expand image'] when Conf['Expand image']
Keybinds.img threadRoot Keybinds.img threadRoot

View File

@ -145,7 +145,7 @@ ThreadUpdater =
return unless navigator.onLine return unless navigator.onLine
ThreadUpdater.count() ThreadUpdater.count()
ThreadUpdater.set 'timer', '...' ThreadUpdater.set 'timer', '...'
ThreadUpdater.req.abort() if ThreadUpdater.req ThreadUpdater.req?.abort()
url = "//api.4chan.org/#{ThreadUpdater.thread.board}/res/#{ThreadUpdater.thread}.json" url = "//api.4chan.org/#{ThreadUpdater.thread.board}/res/#{ThreadUpdater.thread}.json"
ThreadUpdater.req = $.ajax url, ThreadUpdater.req = $.ajax url,
onabort: ThreadUpdater.cb.load onabort: ThreadUpdater.cb.load
@ -258,7 +258,7 @@ ThreadUpdater =
if Conf['Bottom Scroll'] if Conf['Bottom Scroll']
window.scrollTo 0, d.body.clientHeight window.scrollTo 0, d.body.clientHeight
else else
Header.scrollToPost nodes[0] Header.scrollTo nodes[0]
# Enable 4chan features. # Enable 4chan features.
threadID = ThreadUpdater.thread.ID threadID = ThreadUpdater.thread.ID

View File

@ -47,7 +47,7 @@ Unread =
# Scroll to the last read post. # Scroll to the last read post.
posts = Object.keys Unread.thread.posts posts = Object.keys Unread.thread.posts
{root} = Unread.thread.posts[posts[posts.length - 1]].nodes {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) -> checkPosition = (target) ->
# Scroll to the target unless we scrolled past it. # Scroll to the target unless we scrolled past it.
target.getBoundingClientRect().bottom > doc.clientHeight target.getBoundingClientRect().bottom > doc.clientHeight
@ -102,7 +102,7 @@ Unread =
body: post.info.comment body: post.info.comment
icon: Favicon.logo icon: Favicon.logo
notif.onclick = -> notif.onclick = ->
Header.scrollToPost post.nodes.root Header.scrollTo post.nodes.root
window.focus() window.focus()
notif.onshow = -> notif.onshow = ->
setTimeout -> setTimeout ->