From b79a640a533e6faa123de7d62e250864fd2bc017 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 6 Jul 2019 15:49:35 -0700 Subject: [PATCH] Make the buttons in clones work. #2282 --- src/Miscellaneous/PostJumper.coffee | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Miscellaneous/PostJumper.coffee b/src/Miscellaneous/PostJumper.coffee index ecad7702b..448c7af83 100644 --- a/src/Miscellaneous/PostJumper.coffee +++ b/src/Miscellaneous/PostJumper.coffee @@ -12,10 +12,15 @@ PostJumper = cb: @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' - if @nodes.capcode and not @isClone + if @nodes.capcode PostJumper.addButtons @,'capcode' addButtons: (post,type) -> @@ -23,13 +28,16 @@ PostJumper = buttons = PostJumper.buttons.cloneNode(true) buttons.dataset.type = type $.after post.nodes[type+(if type is 'capcode' then '' else 'Root')], buttons - $.on buttons.firstChild, 'click', PostJumper.buttonClick - $.on buttons.lastChild, 'click', PostJumper.buttonClick + PostJumper.addListeners buttons if value not of PostJumper.maps[type] PostJumper.maps[type][value] = [] PostJumper.maps[type][value].push {key: post.ID, val: post.fullID} 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: -> post = Get.postFromNode @ {type} = @parentNode.dataset @@ -37,11 +45,10 @@ PostJumper = value = (if type is 'capcode' then '## ' else '') + post.info[type] fromID = post.ID idx = PostJumper.indexOfPair PostJumper.maps[type][value],fromID - fromID = PostJumper.maps[type][value][idx].val return if idx is -1 idx = (idx + dir) %% PostJumper.maps[type][value].length toID= PostJumper.maps[type][value][idx].val - PostJumper.scroll fromID,toID + PostJumper.scroll post, g.posts[toID] makeButtons: -> charPrev = '\u23EB' @@ -53,9 +60,9 @@ PostJumper = $.extend span, <%= html('${charPrev}${charNext}') %> span - scroll: (fromID,toID) -> - prevPos = g.posts[fromID].nodes.nameBlock.getBoundingClientRect().top - destPos = g.posts[toID].nodes.nameBlock.getBoundingClientRect().top + scroll: (fromPost, toPost) -> + prevPos = fromPost.nodes.nameBlock.getBoundingClientRect().top + destPos = toPost.nodes.nameBlock.getBoundingClientRect().top window.scrollBy 0, destPos-prevPos indexOfPair: (array,key) ->