22import { ContextComplete } from '../../context/bundles/context-bundle-button' ;
33import { Translator } from '../../i18n' ;
44import { NoJQ } from '../../plumbing' ;
5- import { TLB_FOLLOW_ALWAYS , TLB_FOLLOW_INITIAL , TLB_FOLLOW_SCROLL , TLB_SHOW_ALWAYS , TypeFollow } from '../config/toolbar-settings' ;
5+ import { TLB_FOLLOW_ALWAYS , TLB_FOLLOW_INITIAL , TLB_FOLLOW_SCROLL , TLB_SHOW_ALWAYS , TypeFollow , TLB_HOV_RIGHT , TLB_HOV_MID , TlbHoverPrefix } from '../config/toolbar-settings' ;
66import { ToolbarLifecycle } from '../toolbar-lifecycle' ;
77
8+ const TagToolbarPadding = 4 ;
9+ const TagToolbarPaddingRight = 0 ;
10+ const ToolbarHeight = 20 ;
11+
812/**
913 * This is the modern toolbar which is attached to a tag from whic it hovers.
1014 * Internally the toolbar Dom-Elements are hidden at the bottom of the page.
@@ -96,13 +100,15 @@ export class TagToolbar {
96100 bodyOffset : TagToolbarManager . getBodyScrollOffset ( ) ,
97101 tagScrollOffset : 0 ,
98102 tagOffset : NoJQ . offset ( this . hoverTag ) ,
99- tagWidth : NoJQ . outerWidth ( this . hoverTag ) ,
103+ tagWidth : this . hoverTag . offsetWidth ,
104+ tagHeight : this . hoverTag . offsetHeight ,
100105 mousePos : TagToolbarManager . mousePosition ,
101106 win : {
102107 scrollY : window . scrollY ,
103108 width : document . documentElement . clientWidth ,
104109 } ,
105- padding : tagToolbarPadding ,
110+ padding : TagToolbarPadding ,
111+ // tag: this.hoverTag, // just for debugging
106112 } ;
107113
108114 // If we scrolled down, the toolbar might not be visible - calculate offset
@@ -111,22 +117,30 @@ export class TagToolbar {
111117 // Update top coordinates
112118 // new: only do this on initial=true && follow != 'none' or not-initial
113119 // start by setting default-top
114- position . top = position . tagOffset . top + tagToolbarPadding - position . bodyOffset . top ;
120+ position . top = position . tagOffset . top + TagToolbarPadding - position . bodyOffset . top ;
115121 const trackMouse = ( this . follow === TLB_FOLLOW_ALWAYS )
116- || ( this . follow === TLB_FOLLOW_INITIAL && initial )
117- || ( this . follow === TLB_FOLLOW_SCROLL && position . tagScrollOffset !== 0 ) ;
122+ || ( this . follow === TLB_FOLLOW_INITIAL && initial )
123+ || ( this . follow === TLB_FOLLOW_SCROLL && position . tagScrollOffset !== 0 ) ;
124+
125+ const tagClasses = this . toolbarElement . classList ;
118126 if ( trackMouse )
119- position . top = position . mousePos . y + position . win . scrollY - position . bodyOffset . top - toolbarHeight / 2 ;
127+ position . top = position . mousePos . y + position . win . scrollY - position . bodyOffset . top - ( ToolbarHeight / 2 ) ;
128+ else
129+ if ( tagClasses . contains ( TlbHoverPrefix + TLB_HOV_MID ) )
130+ position . top = position . top + ( position . tagHeight / 2 ) - ToolbarHeight ;
120131
121132 // Update left / right coordinates
122- if ( this . toolbarElement . classList . contains ( 'sc-tb-hover-right' ) )
123- position . right = position . win . width - position . tagOffset . left - position . tagWidth + tagToolbarPaddingRight - position . bodyOffset . left ;
133+ if ( tagClasses . contains ( TlbHoverPrefix + TLB_HOV_RIGHT ) )
134+ position . right = position . win . width - position . tagOffset . left - position . tagWidth + TagToolbarPaddingRight - position . bodyOffset . left ;
124135 else
125- position . left = position . tagOffset . left + tagToolbarPadding + position . bodyOffset . left ;
136+ position . left = position . tagOffset . left + TagToolbarPadding + position . bodyOffset . left ;
137+
138+
126139
127- this . toolbarElement . style . top = typeof position . top === 'number' ? `${ position . top } px` : position . top ;
128- this . toolbarElement . style . left = typeof position . left === 'number' ? `${ position . left } px` : position . left ;
129- this . toolbarElement . style . right = typeof position . right === 'number' ? `${ position . right } px` : position . right ;
140+ const tlbStyle = this . toolbarElement . style ;
141+ tlbStyle . top = typeof position . top === 'number' ? `${ position . top } px` : position . top ;
142+ tlbStyle . left = typeof position . left === 'number' ? `${ position . left } px` : position . left ;
143+ tlbStyle . right = typeof position . right === 'number' ? `${ position . right } px` : position . right ;
130144 }
131145
132146
@@ -189,6 +203,3 @@ export class TagToolbar {
189203
190204}
191205
192- const tagToolbarPadding = 4 ;
193- const tagToolbarPaddingRight = 0 ;
194- const toolbarHeight = 20 ;
0 commit comments