@@ -171,13 +171,6 @@ function hideThemeButtonState() {
171
171
( function ( ) {
172
172
"use strict" ;
173
173
174
- function loadScript ( url , callback ) {
175
- var script = document . createElement ( 'script' ) ;
176
- script . src = url ;
177
- script . onload = callback ;
178
- document . head . append ( script ) ;
179
- }
180
-
181
174
window . searchState = {
182
175
loadingText : "Loading search results..." ,
183
176
input : document . getElementsByClassName ( "search-input" ) [ 0 ] ,
@@ -262,6 +255,12 @@ function hideThemeButtonState() {
262
255
return ;
263
256
}
264
257
258
+ function loadScript ( url ) {
259
+ var script = document . createElement ( 'script' ) ;
260
+ script . src = url ;
261
+ document . head . append ( script ) ;
262
+ }
263
+
265
264
var searchLoaded = false ;
266
265
function loadSearch ( ) {
267
266
if ( ! searchLoaded ) {
@@ -1009,51 +1008,33 @@ function hideThemeButtonState() {
1009
1008
//
1010
1009
// Handling the notable traits popup.
1011
1010
//
1012
- function getNotablePopup ( callback ) {
1013
- var elemId = "notable-traits-tooltiptext" ;
1014
- var elem = document . getElementById ( elemId ) ;
1015
-
1016
- if ( ! elem ) {
1017
- // If the element cannot be found, it means it hasn't been created yet and that the
1018
- // notable traits index wasn't loaded either.
1019
- var script = getVar ( "root-path" ) + window . currentCrate + "/notable-traits.js" ;
1020
- loadScript ( script , function ( ) {
1021
- elem = document . createElement ( "code" ) ;
1022
- elem . id = elemId ;
1023
- elem . classList = "docblock" ;
1024
- main . appendChild ( elem ) ;
1025
- callback ( elem ) ;
1026
- } ) ;
1011
+ function showNotableTraitPopup ( elem ) {
1012
+ if ( elem === window . currentNotableElem ) {
1013
+ window . currentNotablePopup . style . display = "" ;
1014
+ window . currentNotableElem = null ;
1027
1015
return ;
1016
+ } else if ( window . currentNotablePopup ) {
1017
+ window . currentNotablePopup . style . display = "" ;
1028
1018
}
1029
- callback ( elem ) ;
1030
- }
1031
- function showNotableTraitPopup ( elem ) {
1032
- getNotablePopup ( function ( popup ) {
1033
- if ( elem === window . currentNotableElem ) {
1034
- popup . style . display = "none" ;
1035
- window . currentNotableElem = null ;
1036
- return ;
1037
- }
1038
- var elemRect = elem . getBoundingClientRect ( ) ;
1039
- var containerRect = main . getBoundingClientRect ( ) ;
1040
-
1041
- var index = elem . getAttribute ( "data-index" ) ;
1042
- var notableTrait = window . NOTABLE_TRAITS [ parseInt ( index ) ] ;
1043
-
1044
- popup . innerHTML = "<div class=\"notable\">Notable traits for " + notableTrait [ 0 ] + "</div><code class=\"content\">" + notableTrait [ 1 ] + "</code>" ;
1045
- popup . style . top = ( elemRect . top - containerRect . top ) + "px" ;
1046
- // In here, if the "i" is too much on the right, better put the popup on its left.
1047
- if ( elem . offsetLeft > main . offsetWidth / 2 ) {
1048
- popup . style . left = "" ;
1049
- popup . style . right = ( main . offsetWidth - elem . offsetLeft + 2 ) + "px" ;
1050
- } else {
1051
- popup . style . right = "" ;
1052
- popup . style . left = ( elem . offsetLeft + 12 ) + "px" ;
1053
- }
1054
- popup . style . display = "" ;
1055
- window . currentNotableElem = elem ;
1056
- } ) ;
1019
+ var elemRect = elem . getBoundingClientRect ( ) ;
1020
+ var containerRect = main . getBoundingClientRect ( ) ;
1021
+
1022
+ var index = elem . getAttribute ( "data-index" ) ;
1023
+ var notableTraitContainer = document . getElementById ( "notable-traits" ) ;
1024
+ var notable = notableTraitContainer . children [ parseInt ( index ) ] ;
1025
+
1026
+ notable . style . top = ( elemRect . top - containerRect . top ) + "px" ;
1027
+ // In here, if the "i" is too much on the right, better put the popup on its left.
1028
+ if ( elem . offsetLeft > main . offsetWidth / 2 ) {
1029
+ notable . style . left = "" ;
1030
+ notable . style . right = ( main . offsetWidth - elem . offsetLeft + 2 ) + "px" ;
1031
+ } else {
1032
+ notable . style . right = "" ;
1033
+ notable . style . left = ( elem . offsetLeft + 12 ) + "px" ;
1034
+ }
1035
+ notable . style . display = "block" ;
1036
+ window . currentNotableElem = elem ;
1037
+ window . currentNotablePopup = notable ;
1057
1038
}
1058
1039
1059
1040
onEachLazy ( document . getElementsByClassName ( "notable-traits-tooltip" ) , function ( e ) {
0 commit comments