@@ -378,7 +378,7 @@ function loadCss(cssUrl) {
378378 }
379379 ev . preventDefault ( ) ;
380380 searchState . defocus ( ) ;
381- window . hideAllModals ( true ) ; // true = reset focus for notable traits
381+ window . hideAllModals ( true ) ; // true = reset focus for tooltips
382382 }
383383
384384 function handleShortcut ( ev ) {
@@ -784,17 +784,17 @@ function loadCss(cssUrl) {
784784 // we need to switch away from mobile mode and make the main content area scrollable.
785785 hideSidebar ( ) ;
786786 }
787- if ( window . CURRENT_NOTABLE_ELEMENT ) {
788- // As a workaround to the behavior of `contains: layout` used in doc togglers, the
789- // notable traits popup is positioned using javascript.
787+ if ( window . CURRENT_TOOLTIP_ELEMENT ) {
788+ // As a workaround to the behavior of `contains: layout` used in doc togglers,
789+ // tooltip popovers are positioned using javascript.
790790 //
791791 // This means when the window is resized, we need to redo the layout.
792- const base = window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE ;
793- const force_visible = base . NOTABLE_FORCE_VISIBLE ;
794- hideNotable ( false ) ;
792+ const base = window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE ;
793+ const force_visible = base . TOOLTIP_FORCE_VISIBLE ;
794+ hideTooltip ( false ) ;
795795 if ( force_visible ) {
796- showNotable ( base ) ;
797- base . NOTABLE_FORCE_VISIBLE = true ;
796+ showTooltip ( base ) ;
797+ base . TOOLTIP_FORCE_VISIBLE = true ;
798798 }
799799 }
800800 } ) ;
@@ -822,27 +822,35 @@ function loadCss(cssUrl) {
822822 } ) ;
823823 } ) ;
824824
825- function showNotable ( e ) {
826- if ( ! window . NOTABLE_TRAITS ) {
825+ function showTooltip ( e ) {
826+ const notable_ty = e . getAttribute ( "data-notable-ty" ) ;
827+ if ( ! window . NOTABLE_TRAITS && notable_ty ) {
827828 const data = document . getElementById ( "notable-traits-data" ) ;
828829 if ( data ) {
829830 window . NOTABLE_TRAITS = JSON . parse ( data . innerText ) ;
830831 } else {
831- throw new Error ( "showNotable () called on page without any notable traits!" ) ;
832+ throw new Error ( "showTooltip () called with notable without any notable traits!" ) ;
832833 }
833834 }
834- if ( window . CURRENT_NOTABLE_ELEMENT && window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE === e ) {
835+ if ( window . CURRENT_TOOLTIP_ELEMENT && window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE === e ) {
835836 // Make this function idempotent.
836837 return ;
837838 }
838839 window . hideAllModals ( false ) ;
839- const ty = e . getAttribute ( "data-ty" ) ;
840840 const wrapper = document . createElement ( "div" ) ;
841- wrapper . innerHTML = "<div class=\"content\">" + window . NOTABLE_TRAITS [ ty ] + "</div>" ;
842- wrapper . className = "notable popover" ;
841+ if ( notable_ty ) {
842+ wrapper . innerHTML = "<div class=\"content\">" +
843+ window . NOTABLE_TRAITS [ notable_ty ] + "</div>" ;
844+ } else if ( e . getAttribute ( "title" ) !== undefined ) {
845+ const titleContent = document . createElement ( "div" ) ;
846+ titleContent . className = "content" ;
847+ titleContent . appendChild ( document . createTextNode ( e . getAttribute ( "title" ) ) ) ;
848+ wrapper . appendChild ( titleContent ) ;
849+ }
850+ wrapper . className = "tooltip popover" ;
843851 const focusCatcher = document . createElement ( "div" ) ;
844852 focusCatcher . setAttribute ( "tabindex" , "0" ) ;
845- focusCatcher . onfocus = hideNotable ;
853+ focusCatcher . onfocus = hideTooltip ;
846854 wrapper . appendChild ( focusCatcher ) ;
847855 const pos = e . getBoundingClientRect ( ) ;
848856 // 5px overlap so that the mouse can easily travel from place to place
@@ -864,62 +872,62 @@ function loadCss(cssUrl) {
864872 ) ;
865873 }
866874 wrapper . style . visibility = "" ;
867- window . CURRENT_NOTABLE_ELEMENT = wrapper ;
868- window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE = e ;
875+ window . CURRENT_TOOLTIP_ELEMENT = wrapper ;
876+ window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE = e ;
869877 wrapper . onpointerleave = function ( ev ) {
870878 // If this is a synthetic touch event, ignore it. A click event will be along shortly.
871879 if ( ev . pointerType !== "mouse" ) {
872880 return ;
873881 }
874- if ( ! e . NOTABLE_FORCE_VISIBLE && ! elemIsInParent ( event . relatedTarget , e ) ) {
875- hideNotable ( true ) ;
882+ if ( ! e . TOOLTIP_FORCE_VISIBLE && ! elemIsInParent ( event . relatedTarget , e ) ) {
883+ hideTooltip ( true ) ;
876884 }
877885 } ;
878886 }
879887
880- function notableBlurHandler ( event ) {
881- if ( window . CURRENT_NOTABLE_ELEMENT &&
882- ! elemIsInParent ( document . activeElement , window . CURRENT_NOTABLE_ELEMENT ) &&
883- ! elemIsInParent ( event . relatedTarget , window . CURRENT_NOTABLE_ELEMENT ) &&
884- ! elemIsInParent ( document . activeElement , window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE ) &&
885- ! elemIsInParent ( event . relatedTarget , window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE )
888+ function tooltipBlurHandler ( event ) {
889+ if ( window . CURRENT_TOOLTIP_ELEMENT &&
890+ ! elemIsInParent ( document . activeElement , window . CURRENT_TOOLTIP_ELEMENT ) &&
891+ ! elemIsInParent ( event . relatedTarget , window . CURRENT_TOOLTIP_ELEMENT ) &&
892+ ! elemIsInParent ( document . activeElement , window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE ) &&
893+ ! elemIsInParent ( event . relatedTarget , window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE )
886894 ) {
887895 // Work around a difference in the focus behaviour between Firefox, Chrome, and Safari.
888- // When I click the button on an already-opened notable trait popover, Safari
896+ // When I click the button on an already-opened tooltip popover, Safari
889897 // hides the popover and then immediately shows it again, while everyone else hides it
890898 // and it stays hidden.
891899 //
892900 // To work around this, make sure the click finishes being dispatched before
893- // hiding the popover. Since `hideNotable ()` is idempotent, this makes Safari behave
901+ // hiding the popover. Since `hideTooltip ()` is idempotent, this makes Safari behave
894902 // consistently with the other two.
895- setTimeout ( ( ) => hideNotable ( false ) , 0 ) ;
903+ setTimeout ( ( ) => hideTooltip ( false ) , 0 ) ;
896904 }
897905 }
898906
899- function hideNotable ( focus ) {
900- if ( window . CURRENT_NOTABLE_ELEMENT ) {
901- if ( window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE . NOTABLE_FORCE_VISIBLE ) {
907+ function hideTooltip ( focus ) {
908+ if ( window . CURRENT_TOOLTIP_ELEMENT ) {
909+ if ( window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . TOOLTIP_FORCE_VISIBLE ) {
902910 if ( focus ) {
903- window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE . focus ( ) ;
911+ window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . focus ( ) ;
904912 }
905- window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE . NOTABLE_FORCE_VISIBLE = false ;
913+ window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . TOOLTIP_FORCE_VISIBLE = false ;
906914 }
907915 const body = document . getElementsByTagName ( "body" ) [ 0 ] ;
908- body . removeChild ( window . CURRENT_NOTABLE_ELEMENT ) ;
909- window . CURRENT_NOTABLE_ELEMENT = null ;
916+ body . removeChild ( window . CURRENT_TOOLTIP_ELEMENT ) ;
917+ window . CURRENT_TOOLTIP_ELEMENT = null ;
910918 }
911919 }
912920
913- onEachLazy ( document . getElementsByClassName ( "notable-traits " ) , e => {
921+ onEachLazy ( document . getElementsByClassName ( "tooltip " ) , e => {
914922 e . onclick = function ( ) {
915- this . NOTABLE_FORCE_VISIBLE = this . NOTABLE_FORCE_VISIBLE ? false : true ;
916- if ( window . CURRENT_NOTABLE_ELEMENT && ! this . NOTABLE_FORCE_VISIBLE ) {
917- hideNotable ( true ) ;
923+ this . TOOLTIP_FORCE_VISIBLE = this . TOOLTIP_FORCE_VISIBLE ? false : true ;
924+ if ( window . CURRENT_TOOLTIP_ELEMENT && ! this . TOOLTIP_FORCE_VISIBLE ) {
925+ hideTooltip ( true ) ;
918926 } else {
919- showNotable ( this ) ;
920- window . CURRENT_NOTABLE_ELEMENT . setAttribute ( "tabindex" , "0" ) ;
921- window . CURRENT_NOTABLE_ELEMENT . focus ( ) ;
922- window . CURRENT_NOTABLE_ELEMENT . onblur = notableBlurHandler ;
927+ showTooltip ( this ) ;
928+ window . CURRENT_TOOLTIP_ELEMENT . setAttribute ( "tabindex" , "0" ) ;
929+ window . CURRENT_TOOLTIP_ELEMENT . focus ( ) ;
930+ window . CURRENT_TOOLTIP_ELEMENT . onblur = tooltipBlurHandler ;
923931 }
924932 return false ;
925933 } ;
@@ -928,16 +936,16 @@ function loadCss(cssUrl) {
928936 if ( ev . pointerType !== "mouse" ) {
929937 return ;
930938 }
931- showNotable ( this ) ;
939+ showTooltip ( this ) ;
932940 } ;
933941 e . onpointerleave = function ( ev ) {
934942 // If this is a synthetic touch event, ignore it. A click event will be along shortly.
935943 if ( ev . pointerType !== "mouse" ) {
936944 return ;
937945 }
938- if ( ! this . NOTABLE_FORCE_VISIBLE &&
939- ! elemIsInParent ( ev . relatedTarget , window . CURRENT_NOTABLE_ELEMENT ) ) {
940- hideNotable ( true ) ;
946+ if ( ! this . TOOLTIP_FORCE_VISIBLE &&
947+ ! elemIsInParent ( ev . relatedTarget , window . CURRENT_TOOLTIP_ELEMENT ) ) {
948+ hideTooltip ( true ) ;
941949 }
942950 } ;
943951 } ) ;
@@ -1039,14 +1047,14 @@ function loadCss(cssUrl) {
10391047 }
10401048
10411049 /**
1042- * Hide popover menus, notable trait tooltips, and the sidebar (if applicable).
1050+ * Hide popover menus, clickable tooltips, and the sidebar (if applicable).
10431051 *
1044- * Pass "true" to reset focus for notable traits .
1052+ * Pass "true" to reset focus for tooltip popovers .
10451053 */
10461054 window . hideAllModals = function ( switchFocus ) {
10471055 hideSidebar ( ) ;
10481056 window . hidePopoverMenus ( ) ;
1049- hideNotable ( switchFocus ) ;
1057+ hideTooltip ( switchFocus ) ;
10501058 } ;
10511059
10521060 /**
0 commit comments