@@ -379,7 +379,7 @@ function loadCss(cssUrl) {
379
379
}
380
380
ev . preventDefault ( ) ;
381
381
searchState . defocus ( ) ;
382
- window . hideAllModals ( true ) ; // true = reset focus for notable traits
382
+ window . hideAllModals ( true ) ; // true = reset focus for tooltips
383
383
}
384
384
385
385
function handleShortcut ( ev ) {
@@ -789,17 +789,17 @@ function loadCss(cssUrl) {
789
789
// we need to switch away from mobile mode and make the main content area scrollable.
790
790
hideSidebar ( ) ;
791
791
}
792
- if ( window . CURRENT_NOTABLE_ELEMENT ) {
793
- // As a workaround to the behavior of `contains: layout` used in doc togglers, the
794
- // notable traits popup is positioned using javascript.
792
+ if ( window . CURRENT_TOOLTIP_ELEMENT ) {
793
+ // As a workaround to the behavior of `contains: layout` used in doc togglers,
794
+ // tooltip popovers are positioned using javascript.
795
795
//
796
796
// This means when the window is resized, we need to redo the layout.
797
- const base = window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE ;
798
- const force_visible = base . NOTABLE_FORCE_VISIBLE ;
799
- hideNotable ( false ) ;
797
+ const base = window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE ;
798
+ const force_visible = base . TOOLTIP_FORCE_VISIBLE ;
799
+ hideTooltip ( false ) ;
800
800
if ( force_visible ) {
801
- showNotable ( base ) ;
802
- base . NOTABLE_FORCE_VISIBLE = true ;
801
+ showTooltip ( base ) ;
802
+ base . TOOLTIP_FORCE_VISIBLE = true ;
803
803
}
804
804
}
805
805
} ) ;
@@ -827,27 +827,35 @@ function loadCss(cssUrl) {
827
827
} ) ;
828
828
} ) ;
829
829
830
- function showNotable ( e ) {
831
- if ( ! window . NOTABLE_TRAITS ) {
830
+ function showTooltip ( e ) {
831
+ const notable_ty = e . getAttribute ( "data-notable-ty" ) ;
832
+ if ( ! window . NOTABLE_TRAITS && notable_ty ) {
832
833
const data = document . getElementById ( "notable-traits-data" ) ;
833
834
if ( data ) {
834
835
window . NOTABLE_TRAITS = JSON . parse ( data . innerText ) ;
835
836
} else {
836
- throw new Error ( "showNotable () called on page without any notable traits!" ) ;
837
+ throw new Error ( "showTooltip () called with notable without any notable traits!" ) ;
837
838
}
838
839
}
839
- if ( window . CURRENT_NOTABLE_ELEMENT && window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE === e ) {
840
+ if ( window . CURRENT_TOOLTIP_ELEMENT && window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE === e ) {
840
841
// Make this function idempotent.
841
842
return ;
842
843
}
843
844
window . hideAllModals ( false ) ;
844
- const ty = e . getAttribute ( "data-ty" ) ;
845
845
const wrapper = document . createElement ( "div" ) ;
846
- wrapper . innerHTML = "<div class=\"content\">" + window . NOTABLE_TRAITS [ ty ] + "</div>" ;
847
- wrapper . className = "notable popover" ;
846
+ if ( notable_ty ) {
847
+ wrapper . innerHTML = "<div class=\"content\">" +
848
+ window . NOTABLE_TRAITS [ notable_ty ] + "</div>" ;
849
+ } else if ( e . getAttribute ( "title" ) !== undefined ) {
850
+ const titleContent = document . createElement ( "div" ) ;
851
+ titleContent . className = "content" ;
852
+ titleContent . appendChild ( document . createTextNode ( e . getAttribute ( "title" ) ) ) ;
853
+ wrapper . appendChild ( titleContent ) ;
854
+ }
855
+ wrapper . className = "tooltip popover" ;
848
856
const focusCatcher = document . createElement ( "div" ) ;
849
857
focusCatcher . setAttribute ( "tabindex" , "0" ) ;
850
- focusCatcher . onfocus = hideNotable ;
858
+ focusCatcher . onfocus = hideTooltip ;
851
859
wrapper . appendChild ( focusCatcher ) ;
852
860
const pos = e . getBoundingClientRect ( ) ;
853
861
// 5px overlap so that the mouse can easily travel from place to place
@@ -869,62 +877,62 @@ function loadCss(cssUrl) {
869
877
) ;
870
878
}
871
879
wrapper . style . visibility = "" ;
872
- window . CURRENT_NOTABLE_ELEMENT = wrapper ;
873
- window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE = e ;
880
+ window . CURRENT_TOOLTIP_ELEMENT = wrapper ;
881
+ window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE = e ;
874
882
wrapper . onpointerleave = function ( ev ) {
875
883
// If this is a synthetic touch event, ignore it. A click event will be along shortly.
876
884
if ( ev . pointerType !== "mouse" ) {
877
885
return ;
878
886
}
879
- if ( ! e . NOTABLE_FORCE_VISIBLE && ! elemIsInParent ( event . relatedTarget , e ) ) {
880
- hideNotable ( true ) ;
887
+ if ( ! e . TOOLTIP_FORCE_VISIBLE && ! elemIsInParent ( event . relatedTarget , e ) ) {
888
+ hideTooltip ( true ) ;
881
889
}
882
890
} ;
883
891
}
884
892
885
- function notableBlurHandler ( event ) {
886
- if ( window . CURRENT_NOTABLE_ELEMENT &&
887
- ! elemIsInParent ( document . activeElement , window . CURRENT_NOTABLE_ELEMENT ) &&
888
- ! elemIsInParent ( event . relatedTarget , window . CURRENT_NOTABLE_ELEMENT ) &&
889
- ! elemIsInParent ( document . activeElement , window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE ) &&
890
- ! elemIsInParent ( event . relatedTarget , window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE )
893
+ function tooltipBlurHandler ( event ) {
894
+ if ( window . CURRENT_TOOLTIP_ELEMENT &&
895
+ ! elemIsInParent ( document . activeElement , window . CURRENT_TOOLTIP_ELEMENT ) &&
896
+ ! elemIsInParent ( event . relatedTarget , window . CURRENT_TOOLTIP_ELEMENT ) &&
897
+ ! elemIsInParent ( document . activeElement , window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE ) &&
898
+ ! elemIsInParent ( event . relatedTarget , window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE )
891
899
) {
892
900
// Work around a difference in the focus behaviour between Firefox, Chrome, and Safari.
893
- // When I click the button on an already-opened notable trait popover, Safari
901
+ // When I click the button on an already-opened tooltip popover, Safari
894
902
// hides the popover and then immediately shows it again, while everyone else hides it
895
903
// and it stays hidden.
896
904
//
897
905
// To work around this, make sure the click finishes being dispatched before
898
- // hiding the popover. Since `hideNotable ()` is idempotent, this makes Safari behave
906
+ // hiding the popover. Since `hideTooltip ()` is idempotent, this makes Safari behave
899
907
// consistently with the other two.
900
- setTimeout ( ( ) => hideNotable ( false ) , 0 ) ;
908
+ setTimeout ( ( ) => hideTooltip ( false ) , 0 ) ;
901
909
}
902
910
}
903
911
904
- function hideNotable ( focus ) {
905
- if ( window . CURRENT_NOTABLE_ELEMENT ) {
906
- if ( window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE . NOTABLE_FORCE_VISIBLE ) {
912
+ function hideTooltip ( focus ) {
913
+ if ( window . CURRENT_TOOLTIP_ELEMENT ) {
914
+ if ( window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . TOOLTIP_FORCE_VISIBLE ) {
907
915
if ( focus ) {
908
- window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE . focus ( ) ;
916
+ window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . focus ( ) ;
909
917
}
910
- window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE . NOTABLE_FORCE_VISIBLE = false ;
918
+ window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . TOOLTIP_FORCE_VISIBLE = false ;
911
919
}
912
920
const body = document . getElementsByTagName ( "body" ) [ 0 ] ;
913
- body . removeChild ( window . CURRENT_NOTABLE_ELEMENT ) ;
914
- window . CURRENT_NOTABLE_ELEMENT = null ;
921
+ body . removeChild ( window . CURRENT_TOOLTIP_ELEMENT ) ;
922
+ window . CURRENT_TOOLTIP_ELEMENT = null ;
915
923
}
916
924
}
917
925
918
- onEachLazy ( document . getElementsByClassName ( "notable-traits " ) , e => {
926
+ onEachLazy ( document . getElementsByClassName ( "tooltip " ) , e => {
919
927
e . onclick = function ( ) {
920
- this . NOTABLE_FORCE_VISIBLE = this . NOTABLE_FORCE_VISIBLE ? false : true ;
921
- if ( window . CURRENT_NOTABLE_ELEMENT && ! this . NOTABLE_FORCE_VISIBLE ) {
922
- hideNotable ( true ) ;
928
+ this . TOOLTIP_FORCE_VISIBLE = this . TOOLTIP_FORCE_VISIBLE ? false : true ;
929
+ if ( window . CURRENT_TOOLTIP_ELEMENT && ! this . TOOLTIP_FORCE_VISIBLE ) {
930
+ hideTooltip ( true ) ;
923
931
} else {
924
- showNotable ( this ) ;
925
- window . CURRENT_NOTABLE_ELEMENT . setAttribute ( "tabindex" , "0" ) ;
926
- window . CURRENT_NOTABLE_ELEMENT . focus ( ) ;
927
- window . CURRENT_NOTABLE_ELEMENT . onblur = notableBlurHandler ;
932
+ showTooltip ( this ) ;
933
+ window . CURRENT_TOOLTIP_ELEMENT . setAttribute ( "tabindex" , "0" ) ;
934
+ window . CURRENT_TOOLTIP_ELEMENT . focus ( ) ;
935
+ window . CURRENT_TOOLTIP_ELEMENT . onblur = tooltipBlurHandler ;
928
936
}
929
937
return false ;
930
938
} ;
@@ -933,16 +941,16 @@ function loadCss(cssUrl) {
933
941
if ( ev . pointerType !== "mouse" ) {
934
942
return ;
935
943
}
936
- showNotable ( this ) ;
944
+ showTooltip ( this ) ;
937
945
} ;
938
946
e . onpointerleave = function ( ev ) {
939
947
// If this is a synthetic touch event, ignore it. A click event will be along shortly.
940
948
if ( ev . pointerType !== "mouse" ) {
941
949
return ;
942
950
}
943
- if ( ! this . NOTABLE_FORCE_VISIBLE &&
944
- ! elemIsInParent ( ev . relatedTarget , window . CURRENT_NOTABLE_ELEMENT ) ) {
945
- hideNotable ( true ) ;
951
+ if ( ! this . TOOLTIP_FORCE_VISIBLE &&
952
+ ! elemIsInParent ( ev . relatedTarget , window . CURRENT_TOOLTIP_ELEMENT ) ) {
953
+ hideTooltip ( true ) ;
946
954
}
947
955
} ;
948
956
} ) ;
@@ -1044,14 +1052,14 @@ function loadCss(cssUrl) {
1044
1052
}
1045
1053
1046
1054
/**
1047
- * Hide popover menus, notable trait tooltips, and the sidebar (if applicable).
1055
+ * Hide popover menus, clickable tooltips, and the sidebar (if applicable).
1048
1056
*
1049
- * Pass "true" to reset focus for notable traits .
1057
+ * Pass "true" to reset focus for tooltip popovers .
1050
1058
*/
1051
1059
window . hideAllModals = function ( switchFocus ) {
1052
1060
hideSidebar ( ) ;
1053
1061
window . hidePopoverMenus ( ) ;
1054
- hideNotable ( switchFocus ) ;
1062
+ hideTooltip ( switchFocus ) ;
1055
1063
} ;
1056
1064
1057
1065
/**
0 commit comments