Make the buttons in clones work. #2282
This commit is contained in:
parent
39fe93e73c
commit
b79a640a53
@ -12,10 +12,15 @@ PostJumper =
|
|||||||
cb: @node
|
cb: @node
|
||||||
|
|
||||||
node: ->
|
node: ->
|
||||||
if @nodes.uniqueIDRoot and not @isClone
|
if @isClone
|
||||||
|
for buttons in $$ '.postJumper', @nodes.info
|
||||||
|
PostJumper.addListeners buttons
|
||||||
|
return
|
||||||
|
|
||||||
|
if @nodes.uniqueIDRoot
|
||||||
PostJumper.addButtons @,'uniqueID'
|
PostJumper.addButtons @,'uniqueID'
|
||||||
|
|
||||||
if @nodes.capcode and not @isClone
|
if @nodes.capcode
|
||||||
PostJumper.addButtons @,'capcode'
|
PostJumper.addButtons @,'capcode'
|
||||||
|
|
||||||
addButtons: (post,type) ->
|
addButtons: (post,type) ->
|
||||||
@ -23,13 +28,16 @@ PostJumper =
|
|||||||
buttons = PostJumper.buttons.cloneNode(true)
|
buttons = PostJumper.buttons.cloneNode(true)
|
||||||
buttons.dataset.type = type
|
buttons.dataset.type = type
|
||||||
$.after post.nodes[type+(if type is 'capcode' then '' else 'Root')], buttons
|
$.after post.nodes[type+(if type is 'capcode' then '' else 'Root')], buttons
|
||||||
$.on buttons.firstChild, 'click', PostJumper.buttonClick
|
PostJumper.addListeners buttons
|
||||||
$.on buttons.lastChild, 'click', PostJumper.buttonClick
|
|
||||||
if value not of PostJumper.maps[type]
|
if value not of PostJumper.maps[type]
|
||||||
PostJumper.maps[type][value] = []
|
PostJumper.maps[type][value] = []
|
||||||
PostJumper.maps[type][value].push {key: post.ID, val: post.fullID}
|
PostJumper.maps[type][value].push {key: post.ID, val: post.fullID}
|
||||||
PostJumper.maps[type][value].sort (first,second) -> first.key-second.key
|
PostJumper.maps[type][value].sort (first,second) -> first.key-second.key
|
||||||
|
|
||||||
|
addListeners: (buttons) ->
|
||||||
|
$.on buttons.firstChild, 'click', PostJumper.buttonClick
|
||||||
|
$.on buttons.lastChild, 'click', PostJumper.buttonClick
|
||||||
|
|
||||||
buttonClick: ->
|
buttonClick: ->
|
||||||
post = Get.postFromNode @
|
post = Get.postFromNode @
|
||||||
{type} = @parentNode.dataset
|
{type} = @parentNode.dataset
|
||||||
@ -37,11 +45,10 @@ PostJumper =
|
|||||||
value = (if type is 'capcode' then '## ' else '') + post.info[type]
|
value = (if type is 'capcode' then '## ' else '') + post.info[type]
|
||||||
fromID = post.ID
|
fromID = post.ID
|
||||||
idx = PostJumper.indexOfPair PostJumper.maps[type][value],fromID
|
idx = PostJumper.indexOfPair PostJumper.maps[type][value],fromID
|
||||||
fromID = PostJumper.maps[type][value][idx].val
|
|
||||||
return if idx is -1
|
return if idx is -1
|
||||||
idx = (idx + dir) %% PostJumper.maps[type][value].length
|
idx = (idx + dir) %% PostJumper.maps[type][value].length
|
||||||
toID= PostJumper.maps[type][value][idx].val
|
toID= PostJumper.maps[type][value][idx].val
|
||||||
PostJumper.scroll fromID,toID
|
PostJumper.scroll post, g.posts[toID]
|
||||||
|
|
||||||
makeButtons: ->
|
makeButtons: ->
|
||||||
charPrev = '\u23EB'
|
charPrev = '\u23EB'
|
||||||
@ -53,9 +60,9 @@ PostJumper =
|
|||||||
$.extend span, <%= html('<a href="javascript:void(0);" class="${classPrev}">${charPrev}</a><a href="javascript:void(0);" class="${classNext}">${charNext}</a>') %>
|
$.extend span, <%= html('<a href="javascript:void(0);" class="${classPrev}">${charPrev}</a><a href="javascript:void(0);" class="${classNext}">${charNext}</a>') %>
|
||||||
span
|
span
|
||||||
|
|
||||||
scroll: (fromID,toID) ->
|
scroll: (fromPost, toPost) ->
|
||||||
prevPos = g.posts[fromID].nodes.nameBlock.getBoundingClientRect().top
|
prevPos = fromPost.nodes.nameBlock.getBoundingClientRect().top
|
||||||
destPos = g.posts[toID].nodes.nameBlock.getBoundingClientRect().top
|
destPos = toPost.nodes.nameBlock.getBoundingClientRect().top
|
||||||
window.scrollBy 0, destPos-prevPos
|
window.scrollBy 0, destPos-prevPos
|
||||||
|
|
||||||
indexOfPair: (array,key) ->
|
indexOfPair: (array,key) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user