@@ -2,6 +2,7 @@ MSU.NestedTooltip = {
2
2
__regexp : / (?: \[ | & # 9 1 ; ) t o o l t i p = ( [ \w \. ] + ?) \. ( .+ ?) (?: \] | & # 9 3 ; ) ( .* ?) (?: \[ | & # 9 1 ; ) \/ t o o l t i p (?: \] | & # 9 3 ; ) / gm,
3
3
__imgRegexp : / (?: \[ | & # 9 1 ; ) i m g t o o l t i p = ( [ \w \. ] + ?) \. ( .+ ?) (?: \] | & # 9 3 ; ) ( .* ?) (?: \[ | & # 9 1 ; ) \/ i m g t o o l t i p (?: \] | & # 9 3 ; ) / gm,
4
4
__tooltipStack : [ ] ,
5
+ __passThroughData : { } ,
5
6
__getTooltipHideDelay : function ( ) { return MSU . getSettingValue ( MSU . ID , "hideDelay" ) } , // default 100,
6
7
__getTooltipShowDelay : function ( ) { return MSU . getSettingValue ( MSU . ID , "showDelay" ) } , // default 200,
7
8
__getTooltipLockDelay : function ( ) { return MSU . getSettingValue ( MSU . ID , "lockDelay" ) } , // default 1000,
@@ -100,18 +101,19 @@ MSU.NestedTooltip = {
100
101
// ghetto clone to get new ref
101
102
_tooltipParams = JSON . parse ( JSON . stringify ( _tooltipParams ) ) ;
102
103
103
- if ( this . __tooltipStack . length > 0 )
104
+ if ( ! this . isStackEmpty ( ) )
104
105
{
105
106
// check if this is within the same chain of nested tooltips, or if we need to clear the stack and start a new chain
106
- if ( this . __tooltipStack [ this . __tooltipStack . length - 1 ] . tooltip . container . find ( _sourceContainer ) . length === 0 )
107
+ if ( this . getTopOfStack ( ) . tooltip . container . find ( _sourceContainer ) . length === 0 )
107
108
{
108
109
self . clearStack ( ) ;
109
110
}
110
111
// If we already have tooltips in the stack, we want to fetch the one from the first tooltip that will have received the entityId from the vanilla function
111
112
else
112
113
{
113
- $ . each ( this . __tooltipStack [ 0 ] . dataToPass , function ( _key , _value )
114
+ $ . each ( self . __passThroughData , function ( _key , _value )
114
115
{
116
+ // don't overwrite parameters we already have
115
117
if ( _key in _tooltipParams )
116
118
return ;
117
119
_tooltipParams [ _key ] = _value ;
@@ -139,6 +141,9 @@ MSU.NestedTooltip = {
139
141
} ,
140
142
updateStack : function ( )
141
143
{
144
+ // descends the stack and removes tooltips until it finds one that should remain:
145
+ // - Either its source is hovered and it's still on the screen
146
+ // - Or the resulting tooltip is hovered and still on the screen
142
147
for ( var i = this . __tooltipStack . length - 1 ; i >= 0 ; i -- )
143
148
{
144
149
var pairData = this . __tooltipStack [ i ] ;
@@ -162,7 +167,7 @@ MSU.NestedTooltip = {
162
167
{
163
168
return this . isStackEmpty ( ) ? null : this . __tooltipStack [ this . __tooltipStack . length - 1 ] ;
164
169
} ,
165
- removeTopTooltip : function ( )
170
+ removeTopOfStack : function ( )
166
171
{
167
172
this . removeTooltip ( this . __tooltipStack [ this . __tooltipStack . length - 1 ] ) ;
168
173
} ,
@@ -171,6 +176,11 @@ MSU.NestedTooltip = {
171
176
this . cleanSourceContainer ( _pairData . source . container ) ;
172
177
this . cleanTooltipContainer ( _pairData . tooltip . container ) ;
173
178
this . __tooltipStack . pop ( ) ;
179
+ if ( this . isStackEmpty ( ) )
180
+ {
181
+ // clear refs out of data
182
+ this . __passThroughData = { } ;
183
+ }
174
184
} ,
175
185
cleanSourceContainer : function ( _sourceContainer )
176
186
{
@@ -214,20 +224,18 @@ MSU.NestedTooltip = {
214
224
source : sourceData ,
215
225
tooltip : tooltipData
216
226
}
227
+ this . __tooltipStack . push ( stackData ) ;
217
228
218
229
// Add data that we'll want to pass to any nested tooltips, such as entityId
219
- if ( this . __tooltipStack . length == 0 )
230
+ if ( this . isStackEmpty ( ) )
220
231
{
221
- var dataToPass = { } ;
222
232
$ . each ( _tooltipParams , function ( _key , _value )
223
233
{
224
234
if ( _key === "contentType" || _key === "elementId" )
225
235
return ;
226
- dataToPass [ _key ] = _value ;
236
+ self . __passThroughData [ _key ] = _value ;
227
237
} )
228
- stackData . dataToPass = dataToPass ;
229
238
}
230
- this . __tooltipStack . push ( stackData ) ;
231
239
232
240
this . addTooltipLockHandler ( tooltipContainer , _sourceContainer ) ;
233
241
@@ -329,10 +337,10 @@ MSU.NestedTooltip = {
329
337
if ( _event . which == 1 )
330
338
{
331
339
_event . stopPropagation ( ) ;
332
- self . removeTopTooltip ( ) ;
333
- if ( self . __tooltipStack . length > 0 )
340
+ self . removeTopOfStack ( ) ;
341
+ if ( ! self . isStackEmpty ( ) )
334
342
{
335
- self . __tooltipStack [ self . __tooltipStack . length - 1 ] . tooltip . container . trigger ( 'mouseenter.msu-tooltip-container' ) ;
343
+ self . getTopOfStack ( ) . tooltip . container . trigger ( 'mouseenter.msu-tooltip-container' ) ;
336
344
}
337
345
}
338
346
} ) ;
0 commit comments