@@ -379,7 +379,7 @@ function loadCss(cssUrl) {
379379 }
380380 ev . preventDefault ( ) ;
381381 searchState . defocus ( ) ;
382- window . hideAllModals ( true ) ; // true = reset focus for notable traits
382+ window . hideAllModals ( true ) ; // true = reset focus for tooltips
383383 }
384384
385385 function handleShortcut ( ev ) {
@@ -789,17 +789,17 @@ function loadCss(cssUrl) {
789789 // we need to switch away from mobile mode and make the main content area scrollable.
790790 hideSidebar ( ) ;
791791 }
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.
795795 //
796796 // 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 ) ;
800800 if ( force_visible ) {
801- showNotable ( base ) ;
802- base . NOTABLE_FORCE_VISIBLE = true ;
801+ showTooltip ( base ) ;
802+ base . TOOLTIP_FORCE_VISIBLE = true ;
803803 }
804804 }
805805 } ) ;
@@ -827,27 +827,35 @@ function loadCss(cssUrl) {
827827 } ) ;
828828 } ) ;
829829
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 ) {
832833 const data = document . getElementById ( "notable-traits-data" ) ;
833834 if ( data ) {
834835 window . NOTABLE_TRAITS = JSON . parse ( data . innerText ) ;
835836 } 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!" ) ;
837838 }
838839 }
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 ) {
840841 // Make this function idempotent.
841842 return ;
842843 }
843844 window . hideAllModals ( false ) ;
844- const ty = e . getAttribute ( "data-ty" ) ;
845845 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" ;
848856 const focusCatcher = document . createElement ( "div" ) ;
849857 focusCatcher . setAttribute ( "tabindex" , "0" ) ;
850- focusCatcher . onfocus = hideNotable ;
858+ focusCatcher . onfocus = hideTooltip ;
851859 wrapper . appendChild ( focusCatcher ) ;
852860 const pos = e . getBoundingClientRect ( ) ;
853861 // 5px overlap so that the mouse can easily travel from place to place
@@ -869,62 +877,62 @@ function loadCss(cssUrl) {
869877 ) ;
870878 }
871879 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 ;
874882 wrapper . onpointerleave = function ( ev ) {
875883 // If this is a synthetic touch event, ignore it. A click event will be along shortly.
876884 if ( ev . pointerType !== "mouse" ) {
877885 return ;
878886 }
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 ) ;
881889 }
882890 } ;
883891 }
884892
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 )
891899 ) {
892900 // 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
894902 // hides the popover and then immediately shows it again, while everyone else hides it
895903 // and it stays hidden.
896904 //
897905 // 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
899907 // consistently with the other two.
900- setTimeout ( ( ) => hideNotable ( false ) , 0 ) ;
908+ setTimeout ( ( ) => hideTooltip ( false ) , 0 ) ;
901909 }
902910 }
903911
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 ) {
907915 if ( focus ) {
908- window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE . focus ( ) ;
916+ window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . focus ( ) ;
909917 }
910- window . CURRENT_NOTABLE_ELEMENT . NOTABLE_BASE . NOTABLE_FORCE_VISIBLE = false ;
918+ window . CURRENT_TOOLTIP_ELEMENT . TOOLTIP_BASE . TOOLTIP_FORCE_VISIBLE = false ;
911919 }
912920 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 ;
915923 }
916924 }
917925
918- onEachLazy ( document . getElementsByClassName ( "notable-traits " ) , e => {
926+ onEachLazy ( document . getElementsByClassName ( "tooltip " ) , e => {
919927 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 ) ;
923931 } 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 ;
928936 }
929937 return false ;
930938 } ;
@@ -933,16 +941,16 @@ function loadCss(cssUrl) {
933941 if ( ev . pointerType !== "mouse" ) {
934942 return ;
935943 }
936- showNotable ( this ) ;
944+ showTooltip ( this ) ;
937945 } ;
938946 e . onpointerleave = function ( ev ) {
939947 // If this is a synthetic touch event, ignore it. A click event will be along shortly.
940948 if ( ev . pointerType !== "mouse" ) {
941949 return ;
942950 }
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 ) ;
946954 }
947955 } ;
948956 } ) ;
@@ -1044,14 +1052,14 @@ function loadCss(cssUrl) {
10441052 }
10451053
10461054 /**
1047- * Hide popover menus, notable trait tooltips, and the sidebar (if applicable).
1055+ * Hide popover menus, clickable tooltips, and the sidebar (if applicable).
10481056 *
1049- * Pass "true" to reset focus for notable traits .
1057+ * Pass "true" to reset focus for tooltip popovers .
10501058 */
10511059 window . hideAllModals = function ( switchFocus ) {
10521060 hideSidebar ( ) ;
10531061 window . hidePopoverMenus ( ) ;
1054- hideNotable ( switchFocus ) ;
1062+ hideTooltip ( switchFocus ) ;
10551063 } ;
10561064
10571065 /**
0 commit comments