@@ -779,6 +779,13 @@ function preLoadCss(cssUrl) {
779779 } ) ;
780780 } ) ;
781781
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+ */
782789 function showTooltip ( e ) {
783790 const notable_ty = e . getAttribute ( "data-notable-ty" ) ;
784791 if ( ! window . NOTABLE_TRAITS && notable_ty ) {
@@ -789,8 +796,9 @@ function preLoadCss(cssUrl) {
789796 throw new Error ( "showTooltip() called with notable without any notable traits!" ) ;
790797 }
791798 }
799+ // Make this function idempotent. If the tooltip is already shown, avoid doing extra work
800+ // and leave it alone.
792801 if ( window . CURRENT_TOOLTIP_ELEMENT && window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE === e ) {
793- // Make this function idempotent.
794802 clearTooltipHoverTimeout ( window . CURRENT_TOOLTIP_ELEMENT ) ;
795803 return ;
796804 }
@@ -800,6 +808,7 @@ function preLoadCss(cssUrl) {
800808 wrapper . innerHTML = "<div class=\"content\">" +
801809 window . NOTABLE_TRAITS [ notable_ty ] + "</div>" ;
802810 } else {
811+ // Replace any `title` attribute with `data-title` to avoid double tooltips.
803812 if ( e . getAttribute ( "title" ) !== null ) {
804813 e . setAttribute ( "data-title" , e . getAttribute ( "title" ) ) ;
805814 e . removeAttribute ( "title" ) ;
@@ -859,6 +868,17 @@ function preLoadCss(cssUrl) {
859868 } ;
860869 }
861870
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+ */
862882 function setTooltipHoverTimeout ( element , show ) {
863883 clearTooltipHoverTimeout ( element ) ;
864884 if ( ! show && ! window . CURRENT_TOOLTIP_ELEMENT ) {
@@ -883,6 +903,13 @@ function preLoadCss(cssUrl) {
883903 } , show ? window . RUSTDOC_TOOLTIP_HOVER_MS : window . RUSTDOC_TOOLTIP_HOVER_EXIT_MS ) ;
884904 }
885905
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+ */
886913 function clearTooltipHoverTimeout ( element ) {
887914 if ( element . TOOLTIP_HOVER_TIMEOUT !== undefined ) {
888915 removeClass ( window . CURRENT_TOOLTIP_ELEMENT , "fade-out" ) ;
@@ -910,6 +937,12 @@ function preLoadCss(cssUrl) {
910937 }
911938 }
912939
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+ */
913946 function hideTooltip ( focus ) {
914947 if ( window . CURRENT_TOOLTIP_ELEMENT ) {
915948 if ( window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . TOOLTIP_FORCE_VISIBLE ) {
0 commit comments