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 = PostJumper =
init: -> init: ->
@capcodeMap = new Map() @capcode = new Map()
@uniqueIDMap = new Map() @uniqueID = new Map()
return unless g.VIEW in ['index', 'thread'] return unless g.VIEW in ['index', 'thread']
Callbacks.Post.push Callbacks.Post.push
@ -9,10 +9,12 @@ PostJumper =
cb: @node cb: @node
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' PostJumper.addButtons @,'uniqueID'
if @nodes.capcode and Conf['Capcode Navigation'] and not @nodes.capcodeJumperRoot if @nodes.capcode and not @isClone
PostJumper.addButtons @,'capcode' PostJumper.addButtons @,'capcode'
addButtons: (post,type) -> addButtons: (post,type) ->
@ -21,32 +23,42 @@ PostJumper =
$.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 post,type,-1 $.on buttons.firstChild, 'click', PostJumper.buttonClick post,type,-1
$.on buttons.lastChild, 'click', PostJumper.buttonClick post,type,1 $.on buttons.lastChild, 'click', PostJumper.buttonClick post,type,1
if not PostJumper[type+'Map'].has value if not PostJumper[type].has value
PostJumper[type+'Map'].set value, [] PostJumper[type].set value, []
PostJumper[type+'Map'].get(value).push post.nodes.quote.innerText 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) -> -> 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] value = (if type is 'capcode' then '## ' else '') + post.info[type]
fromID = post.ID.toString() fromID = post.ID
idx = PostJumper[type+'Map'].get(value).indexOf(fromID); idx = PostJumper.indexOfPair PostJumper[type].get(value),fromID
fromID = PostJumper[type].get(value)[idx].val
return if idx is -1 return if idx is -1
idx = (idx + dir) %% PostJumper[type+'Map'].get(value).length idx = (idx + dir) %% PostJumper[type].get(value).length
toID= PostJumper[type+'Map'].get(value)[idx] toID= PostJumper[type].get(value)[idx].val
PostJumper.scroll fromID,toID PostJumper.scroll fromID,toID
makeButtons: (cl) -> makeButtons: ->
charPrev = '\u{23EB}' charPrev = '\u{23EB}'
charNext = '\u{23EC}' charNext = '\u{23EC}'
classPrev = 'prev' classPrev = 'prev'
classNext = 'next' classNext = 'next'
span = $.el 'span', 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>') %> $.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: (fromID,toID) ->
prevPos = $.id("pc"+fromID).getBoundingClientRect().top prevPos = g.posts[fromID].nodes.root.getBoundingClientRect().top
destPos = $.id("pc"+toID).getBoundingClientRect().top destPos = g.posts[toID].nodes.root.getBoundingClientRect().top
window.scrollBy 0, destPos-prevPos 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 false
'Add buttons to navigate to top / bottom of thread.' 'Add buttons to navigate to top / bottom of thread.'
] ]
'Unique ID Navigation': [ 'Unique ID and capcode Navigation': [
false false
'Add buttons to navigate to posts having the same unique ID.' 'Add buttons to navigate to posts having the same unique ID or capcode.'
]
'Capcode Navigation': [
false
'Add buttons to navigate to posts having the same capcode.'
] ]
'Custom Board Titles': [ 'Custom Board Titles': [
true true

View File

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

View File

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