Bulk of changes after code review

- comment on css and single class for postJumper
- single Conf setting
- post number sorting
- renamed maps
- removed selectors from SW.yotsuba.coffee
- used the g object and other smarter ways to get the needed stuff
This commit is contained in:
ebinBuddha 2019-04-16 07:28:28 +02:00
parent f6e038a72e
commit 7a2f431008
4 changed files with 34 additions and 32 deletions

View File

@ -1,7 +1,7 @@
PostJumper =
init: ->
@capcodeMap = new Map()
@uniqueIDMap = new Map()
@capcode = new Map()
@uniqueID = new Map()
return unless g.VIEW in ['index', 'thread']
Callbacks.Post.push
@ -9,10 +9,12 @@ PostJumper =
cb: @node
node: ->
if @nodes.uniqueIDRoot and Conf['Unique ID Navigation'] and not @nodes.uniqueIDJumperRoot
return unless Conf['Unique ID and capcode Navigation']
if @nodes.uniqueIDRoot and not @isClone
PostJumper.addButtons @,'uniqueID'
if @nodes.capcode and Conf['Capcode Navigation'] and not @nodes.capcodeJumperRoot
if @nodes.capcode and not @isClone
PostJumper.addButtons @,'capcode'
addButtons: (post,type) ->
@ -21,32 +23,42 @@ PostJumper =
$.after post.nodes[type+(if type is 'capcode' then '' else 'Root')], buttons
$.on buttons.firstChild, 'click', PostJumper.buttonClick post,type,-1
$.on buttons.lastChild, 'click', PostJumper.buttonClick post,type,1
if not PostJumper[type+'Map'].has value
PostJumper[type+'Map'].set value, []
PostJumper[type+'Map'].get(value).push post.nodes.quote.innerText
if not PostJumper[type].has value
PostJumper[type].set value, []
PostJumper[type].get(value).push {key: post.ID, val: post.fullID}
PostJumper[type].get(value).sort (first,second) -> first.key-second.key
buttonClick: (post,type,dir) -> ->
return if PostJumper[type+'Map'].size is 0
return if PostJumper[type].size is 0
value = (if type is 'capcode' then '## ' else '') + post.info[type]
fromID = post.ID.toString()
idx = PostJumper[type+'Map'].get(value).indexOf(fromID);
fromID = post.ID
idx = PostJumper.indexOfPair PostJumper[type].get(value),fromID
fromID = PostJumper[type].get(value)[idx].val
return if idx is -1
idx = (idx + dir) %% PostJumper[type+'Map'].get(value).length
toID= PostJumper[type+'Map'].get(value)[idx]
idx = (idx + dir) %% PostJumper[type].get(value).length
toID= PostJumper[type].get(value)[idx].val
PostJumper.scroll fromID,toID
makeButtons: (cl) ->
makeButtons: ->
charPrev = '\u{23EB}'
charNext = '\u{23EC}'
classPrev = 'prev'
classNext = 'next'
span = $.el 'span',
className: cl
className: 'postJumper'
$.extend span, <%= html('<a href="javascript:void(0);" class="${classPrev}">${charPrev}</a><a href="javascript:void(0);" class="${classNext}">${charNext}</a>') %>
span
scroll: (fromID,toID) ->
prevPos = $.id("pc"+fromID).getBoundingClientRect().top
destPos = $.id("pc"+toID).getBoundingClientRect().top
prevPos = g.posts[fromID].nodes.root.getBoundingClientRect().top
destPos = g.posts[toID].nodes.root.getBoundingClientRect().top
window.scrollBy 0, destPos-prevPos
indexOfPair: (array,key) ->
result = -1;
for i in [0..array.length-1] by 1
if array[i].key is key
result = i
break
result

View File

@ -92,13 +92,9 @@ Config =
false
'Add buttons to navigate to top / bottom of thread.'
]
'Unique ID Navigation': [
'Unique ID and capcode Navigation': [
false
'Add buttons to navigate to posts having the same unique ID.'
]
'Capcode Navigation': [
false
'Add buttons to navigate to posts having the same capcode.'
'Add buttons to navigate to posts having the same unique ID or capcode.'
]
'Custom Board Titles': [
true

View File

@ -2405,9 +2405,9 @@ a:only-of-type > .remove {
:root.gallery-open.fixed #header-bar:not(.autohide) #shortcuts .fa::before {
visibility: hidden;
}
.capcodeJumper > .prev,
.capcodeJumper > .next,
.uniqueIDJumper > .prev,
.uniqueIDJumper > .next {
/* PostJumper */
.postJumper > .prev,
.postJumper > .next {
font-size: 120%;
}

View File

@ -27,12 +27,6 @@ SW.yotsuba =
uniqueIDRoot: '.posteruid'
uniqueID: '.posteruid > .hand'
capcode: '.capcode.hand'
capcodeJumperRoot: '.capcodeJumper'
capcodeJumperPrev: '.capcodeJumper > .prev'
capcodeJumperNext: '.capcodeJumper > .next'
uniqueIDJumperRoot: '.uniqueIDJumper'
uniqueIDJumperPrev: '.uniqueIDJumper > .prev'
uniqueIDJumperNext: '.uniqueIDJumper > .next'
pass: '.n-pu'
flag: '.flag, .countryFlag'
date: '.dateTime'