@@ -171,6 +171,13 @@ 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
+
174
181
window . searchState = {
175
182
loadingText : "Loading search results..." ,
176
183
input : document . getElementsByClassName ( "search-input" ) [ 0 ] ,
@@ -254,11 +261,6 @@ function hideThemeButtonState() {
254
261
if ( ! searchState . input ) {
255
262
return ;
256
263
}
257
- function loadScript ( url ) {
258
- var script = document . createElement ( 'script' ) ;
259
- script . src = url ;
260
- document . head . append ( script ) ;
261
- }
262
264
263
265
var searchLoaded = false ;
264
266
function loadSearch ( ) {
@@ -910,13 +912,6 @@ function hideThemeButtonState() {
910
912
} ) ;
911
913
} ) ;
912
914
913
- onEachLazy ( document . getElementsByClassName ( "notable-traits" ) , function ( e ) {
914
- e . onclick = function ( ) {
915
- this . getElementsByClassName ( 'notable-traits-tooltiptext' ) [ 0 ]
916
- . classList . toggle ( "force-tooltip" ) ;
917
- } ;
918
- } ) ;
919
-
920
915
var sidebar_menu = document . getElementsByClassName ( "sidebar-menu" ) [ 0 ] ;
921
916
if ( sidebar_menu ) {
922
917
sidebar_menu . onclick = function ( ) {
@@ -1010,6 +1005,62 @@ function hideThemeButtonState() {
1010
1005
onHashChange ( null ) ;
1011
1006
window . addEventListener ( "hashchange" , onHashChange ) ;
1012
1007
searchState . setup ( ) ;
1008
+
1009
+ //
1010
+ // Handling the notable traits popup.
1011
+ //
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
+ } ) ;
1027
+ return ;
1028
+ }
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
+ } ) ;
1057
+ }
1058
+
1059
+ onEachLazy ( document . getElementsByClassName ( "notable-traits-tooltip" ) , function ( e ) {
1060
+ e . onclick = function ( ) {
1061
+ showNotableTraitPopup ( this ) ;
1062
+ } ;
1063
+ } ) ;
1013
1064
} ( ) ) ;
1014
1065
1015
1066
( function ( ) {
0 commit comments