@@ -779,6 +779,13 @@ function preLoadCss(cssUrl) {
779
779
} ) ;
780
780
} ) ;
781
781
782
+ /**
783
+ * Show a tooltip immediately.
784
+ *
785
+ * @param {DOMElement } e - The tooltip's anchor point. The DOM is consulted to figure
786
+ * out what the tooltip should contain, and where it should be
787
+ * positioned.
788
+ */
782
789
function showTooltip ( e ) {
783
790
const notable_ty = e . getAttribute ( "data-notable-ty" ) ;
784
791
if ( ! window . NOTABLE_TRAITS && notable_ty ) {
@@ -789,8 +796,9 @@ function preLoadCss(cssUrl) {
789
796
throw new Error ( "showTooltip() called with notable without any notable traits!" ) ;
790
797
}
791
798
}
799
+ // Make this function idempotent. If the tooltip is already shown, avoid doing extra work
800
+ // and leave it alone.
792
801
if ( window . CURRENT_TOOLTIP_ELEMENT && window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE === e ) {
793
- // Make this function idempotent.
794
802
clearTooltipHoverTimeout ( window . CURRENT_TOOLTIP_ELEMENT ) ;
795
803
return ;
796
804
}
@@ -800,6 +808,7 @@ function preLoadCss(cssUrl) {
800
808
wrapper . innerHTML = "<div class=\"content\">" +
801
809
window . NOTABLE_TRAITS [ notable_ty ] + "</div>" ;
802
810
} else {
811
+ // Replace any `title` attribute with `data-title` to avoid double tooltips.
803
812
if ( e . getAttribute ( "title" ) !== null ) {
804
813
e . setAttribute ( "data-title" , e . getAttribute ( "title" ) ) ;
805
814
e . removeAttribute ( "title" ) ;
@@ -859,6 +868,17 @@ function preLoadCss(cssUrl) {
859
868
} ;
860
869
}
861
870
871
+ /**
872
+ * Show or hide the tooltip after a timeout. If a timeout was already set before this function
873
+ * was called, that timeout gets cleared. If the tooltip is already in the requested state,
874
+ * this function will still clear any pending timeout, but otherwise do nothing.
875
+ *
876
+ * @param {DOMElement } element - The tooltip's anchor point. The DOM is consulted to figure
877
+ * out what the tooltip should contain, and where it should be
878
+ * positioned.
879
+ * @param {boolean } show - If true, the tooltip will be made visible. If false, it will
880
+ * be hidden.
881
+ */
862
882
function setTooltipHoverTimeout ( element , show ) {
863
883
clearTooltipHoverTimeout ( element ) ;
864
884
if ( ! show && ! window . CURRENT_TOOLTIP_ELEMENT ) {
@@ -883,6 +903,13 @@ function preLoadCss(cssUrl) {
883
903
} , show ? window . RUSTDOC_TOOLTIP_HOVER_MS : window . RUSTDOC_TOOLTIP_HOVER_EXIT_MS ) ;
884
904
}
885
905
906
+ /**
907
+ * If a show/hide timeout was set by `setTooltipHoverTimeout`, cancel it. If none exists,
908
+ * do nothing.
909
+ *
910
+ * @param {DOMElement } element - The tooltip's anchor point,
911
+ * as passed to `setTooltipHoverTimeout`.
912
+ */
886
913
function clearTooltipHoverTimeout ( element ) {
887
914
if ( element . TOOLTIP_HOVER_TIMEOUT !== undefined ) {
888
915
removeClass ( window . CURRENT_TOOLTIP_ELEMENT , "fade-out" ) ;
@@ -910,6 +937,12 @@ function preLoadCss(cssUrl) {
910
937
}
911
938
}
912
939
940
+ /**
941
+ * Hide the current tooltip immediately.
942
+ *
943
+ * @param {boolean } focus - If set to `true`, move keyboard focus to the tooltip anchor point.
944
+ * If set to `false`, leave keyboard focus alone.
945
+ */
913
946
function hideTooltip ( focus ) {
914
947
if ( window . CURRENT_TOOLTIP_ELEMENT ) {
915
948
if ( window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . TOOLTIP_FORCE_VISIBLE ) {
0 commit comments