The goog.ui.HoverCard Class

goog.ui.HoverCard
> goog.ui.AdvancedTooltip
> goog.ui.Tooltip
> goog.ui.Popup
> goog.ui.PopupBase
> goog.events.EventTarget
> goog.Disposable

goog.ui.HoverCard(isAnchor, opt_checkDescendants, opt_domHelper, opt_triggeringDocument)

Create a hover card object. Hover cards extend tooltips in that they don't have to be manually attached to each element that can cause them to display. Instead, you can create a function that gets called when the mouse goes over any element on your page, and returns whether or not the hovercard should be shown for that element. Alternatively, you can define a map of tag names to the attribute name each tag should have for that tag to trigger the hover card. See example below. Hovercards can also be triggered manually by calling {@code triggerForElement}, shown without a delay by calling {@code showForElement}, or triggered over other elements by calling {@code attach}. For the latter two cases, the application is responsible for calling {@code detach} when finished. HoverCard objects fire a TRIGGER event when the mouse moves over an element that can trigger a hovercard, and BEFORE_SHOW when the hovercard is about to be shown. Clients can respond to these events and can prevent the hovercard from being triggered or shown.

isAnchor {Function|Object}
Function that returns true if a given element should trigger the hovercard. Alternatively, it can be a map of tag names to the attribute that the tag should have in order to trigger the hovercard, e.g., {A: 'href'} for all links. Tag names must be all upper case; attribute names are case insensitive.
opt_checkDescendants {boolean=}
Use false for a performance gain if you are sure that none of your triggering elements have child elements. Default is true.
opt_domHelper {goog.dom.DomHelper=}
Optional DOM helper to use for creating and rendering the hovercard element.
opt_triggeringDocument {Document=}
Optional document to use in place of the one included in the DomHelper for finding triggering elements. Defaults to the document included in the DomHelper.

The goog.ui.HoverCard.EventType Enum

Enum for event type fired by HoverCard. … more

The goog.ui.HoverCard.TriggerEvent Class

Create a trigger event for specified anchor and optional data. … more

.addEventListener(type, handler, opt_capture, opt_handlerScope)

Inherited from goog.events.EventTarget .

Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched. Supported for legacy but use goog.events.listen(src, type, handler) instead.

type {string}
The type of the event to listen for.
handler {Function|Object}
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture {boolean=}
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope {Object=}
Object in whose scope to call the listener.

.addOnDisposeCallback(callback, opt_scope)

Inherited from goog.Disposable .

Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.

callback {!Function}
The callback function.
opt_scope {Object=}
An optional scope to call the callback in.

.attach(el)

Inherited from goog.ui.Tooltip .

Attach to element. Tooltip will be displayed when the cursor is over the element or when the element has been active for a few milliseconds.

el {Element|string}
Element to display tooltip for, either element reference or string id.

.cancelTrigger()

Abort pending hovercard showing, if any.

.className {string}

Inherited from goog.ui.Tooltip .

CSS class name for tooltip.

.creationStack {string}

Inherited from goog.Disposable .

If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.

.detach(opt_el)

Inherited from goog.ui.Tooltip .

Detach from element(s).

opt_el {Element|string=}
Element to detach from, either element reference or string id. If no element is specified all are detached.

.dispatchEvent(e)

Inherited from goog.events.EventTarget .

Dispatches an event (or event like object) and calls all listeners listening for events of this type. The type of the event is decided by the type property on the event object. If any of the listeners returns false OR calls preventDefault then this function will return false. If one of the capture listeners calls stopPropagation, then the bubble listeners won't fire.

e {string|Object|goog.events.Event}
Event object.
returns {boolean}
If anyone called preventDefault on the event object (or if any of the handlers returns false this will also return false.

.dispose()

Inherited from goog.Disposable .

Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.

returns {void}
Nothing.

.disposeInternal()

.getActiveElement()

Inherited from goog.ui.Tooltip .

returns {Element}
Active element reference.

.getAnchorElement()

Gets the DOM element that triggered the current hovercard. Note that in the TRIGGER or CANCEL_TRIGGER events, the current hovercard's anchor may not be the one that caused the event, so use the event's anchor property instead.

returns {Element}
Object that caused the currently displayed hovercard (or pending hovercard if none is displayed) to be triggered.

.getAutoHide()

Inherited from goog.ui.PopupBase .

Returns whether the Popup dismisses itself when the user clicks outside of it.

returns {boolean}
Whether the Popup autohides on an external click.

.getAutoHideRegion()

Inherited from goog.ui.PopupBase .

Returns the region inside which the Popup dismisses itself when the user clicks, or null if it's the entire document.

returns {Element}
The DOM element for autohide, or null if it hasn't been set.

.getCursorTracking()

Inherited from goog.ui.AdvancedTooltip .

returns {boolean}
Whether to track the cursor and thereby close the tooltip if it moves away from the tooltip and keep it open if it moves towards it.

.getCursorTrackingHideDelayMs()

Inherited from goog.ui.AdvancedTooltip .

returns {number}
The delay in milliseconds before tooltips are hidden if cursor tracking is enabled and the cursor is moving away from the tooltip.

.getDomHelper()

Inherited from goog.ui.Tooltip .

Returns the dom helper that is being used on this component.

returns {goog.dom.DomHelper}
The dom helper used on this component.

.getElement()

Inherited from goog.ui.PopupBase .

Returns the dom element that should be used for the popup.

returns {Element}
The popup element.

.getEnableCrossIframeDismissal()

Inherited from goog.ui.PopupBase .

returns {boolean}
Whether cross iframe dismissal is enabled.

.getHideDelayMs()

Inherited from goog.ui.AdvancedTooltip .

Override hide delay with cursor tracking hide delay while tracking.

returns {number}
Hide delay to use.

.getHideOnEscape()

Inherited from goog.ui.PopupBase .

returns {boolean}
Whether the Popup autohides on the escape key.

.getHotSpotPadding()

Inherited from goog.ui.AdvancedTooltip .

returns {goog.math.Box}
box The margin around the tooltip where the cursor is allowed without dismissing the tooltip.

.getHtml()

Inherited from goog.ui.Tooltip .

returns {string}
The tooltip message as HTML.

.getLastHideTime()

Inherited from goog.ui.PopupBase .

Returns the time when the popup was last hidden.

returns {number}
time in ms since epoch when the popup was last hidden, or -1 if the popup was never hidden or is currently showing.

.getLastShowTime()

Inherited from goog.ui.PopupBase .

Returns the time when the popup was last shown.

returns {number}
time in ms since epoch when the popup was last shown, or -1 if the popup was never shown.

.getMargin()

Inherited from goog.ui.Popup .

Returns the margin to place around the popup.

returns {goog.math.Box?}
The margin.

.getParentEventTarget()

Inherited from goog.events.EventTarget .

Returns the parent of this event target to use for bubbling.

returns {goog.events.EventTarget}
The parent EventTarget or null if there is no parent.

.getPinnedCorner()

Inherited from goog.ui.Popup .

Returns the corner of the popup to used in the positioning algorithm.

returns {goog.positioning.Corner}
The popup corner used for positioning.

.getPosition()

Inherited from goog.ui.Popup .

returns {goog.positioning.AbstractPosition}
The position helper object associated with the popup.

.getShowDelayMs()

Inherited from goog.ui.Tooltip .

returns {number}
The delay in milliseconds before tooltip is displayed for an element.

.getState()

Inherited from goog.ui.Tooltip .

returns {goog.ui.Tooltip.State}
Current state of tooltip.

.getText()

Inherited from goog.ui.Tooltip .

returns {string}
The tooltip message as plain text.

.getType()

Inherited from goog.ui.PopupBase .

returns {goog.ui.PopupBase.Type}
The type of popup this is.

.handleMouseOutAndBlur(event)

If the mouse moves out of the trigger while we're being triggered, then cancel it.

event {goog.events.BrowserEvent}
Mouse out or blur event.

.handleMouseOver(event)

This mouse over event is only received if the anchor is already attached. If it was attached manually, then it may need to be triggered.

event {goog.events.BrowserEvent}
Mouse over event.

.isCoordinateInTooltip(coord)

Inherited from goog.ui.AdvancedTooltip .

Checks whether the supplied coordinate is inside the tooltip, including padding if any.

coord {goog.math.Coordinate}
Coordinate being tested.
returns {boolean}
Whether the coord is in the tooltip.

.isDisposed()

Inherited from goog.Disposable .

returns {boolean}
Whether the object has been disposed of.

.isMouseInTooltip()

Inherited from goog.ui.AdvancedTooltip .

Returns true if the mouse is in the tooltip.

returns {boolean}
True if the mouse is in the tooltip.

.isOrWasRecentlyVisible()

Inherited from goog.ui.PopupBase .

Returns whether the popup is currently visible or was visible within about 150 ms ago. This is used by clients to handle a very specific, but common, popup scenario. The button that launches the popup should close the popup on mouse down if the popup is alrady open. The problem is that the popup closes itself during the capture phase of the mouse down and thus the button thinks it's hidden and this should show it again. This method provides a good heuristic for clients. Typically in their event handler they will have code that is: if (menu.isOrWasRecentlyVisible()) { menu.setVisible(false); } else { ... // code to position menu and initialize other state menu.setVisible(true); }

returns {boolean}
Whether the popup is currently visible or was visible within about 150 ms ago.

.isVisible()

Inherited from goog.ui.PopupBase .

Returns whether the popup is currently visible.

returns {boolean}
whether the popup is currently visible.

.maybeHide(el)

Inherited from goog.ui.AdvancedTooltip .

Called by timer from mouse out handler. Hides tooltip if cursor is still outside element and tooltip.

el {Element}
Anchor when hide timer was started.

.maybeShow(el, opt_pos)

Called by timer from mouse over handler. If this is called and the hovercard is not shown for whatever reason, then send a cancel trigger event.

el {Element}
Element to show tooltip for.
opt_pos {goog.positioning.AbstractPosition=}
Position to display popup at.

.registerDisposable(disposable)

Inherited from goog.Disposable .

Associates a disposable object with this object so that they will be disposed together.

disposable {goog.disposable.IDisposable}
that will be disposed when this object is disposed.

.removeEventListener(type, handler, opt_capture, opt_handlerScope)

Inherited from goog.events.EventTarget .

Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.

type {string}
The type of the event to listen for.
handler {Function|Object}
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture {boolean=}
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope {Object=}
Object in whose scope to call the listener.

.reposition()

Inherited from goog.ui.Popup .

Repositions the popup according to the current state.

.setAutoHide(autoHide)

Inherited from goog.ui.PopupBase .

Sets whether the Popup dismisses itself when the user clicks outside of it.

autoHide {boolean}
Whether to autohide on an external click.

.setAutoHideRegion(element)

Inherited from goog.ui.PopupBase .

Sets the region inside which the Popup dismisses itself when the user clicks.

element {Element}
The DOM element for autohide.

.setCursorTracking(b)

Inherited from goog.ui.AdvancedTooltip .

Sets whether to track the cursor and thereby close the tooltip if it moves away from the tooltip and keep it open if it moves towards it.

b {boolean}
Whether to track the cursor.

.setCursorTrackingHideDelayMs(delay)

Inherited from goog.ui.AdvancedTooltip .

Sets delay in milliseconds before tooltips are hidden if cursor tracking is enabled and the cursor is moving away from the tooltip.

delay {number}
The delay in milliseconds.

.setElement(el)

Inherited from goog.ui.Tooltip .

Sets tooltip element.

el {Element}
HTML element to use as the tooltip.

.setEnableCrossIframeDismissal(enable)

Inherited from goog.ui.PopupBase .

Sets whether clicks in other iframes should dismiss this popup. In some cases it should be disabled, because it can cause spurious

enable {boolean}
Whether to enable cross iframe dismissal.

.setHideDelayMs(delay)

Inherited from goog.ui.Tooltip .

Sets delay in milliseconds before tooltip is hidden once the cursor leavs the element.

delay {number}
The delay in milliseconds.

.setHideOnEscape(hideOnEscape)

Inherited from goog.ui.PopupBase .

Sets whether the Popup dismisses itself on the escape key.

hideOnEscape {boolean}
Whether to autohide on the escape key.

.setHotSpotPadding(opt_box)

Inherited from goog.ui.AdvancedTooltip .

Sets margin around the tooltip where the cursor is allowed without dismissing the tooltip.

opt_box {goog.math.Box=}
The margin around the tooltip.

.setHtml(str)

Inherited from goog.ui.Tooltip .

Sets tooltip message as HTML markup.

str {string}
HTML message to display in tooltip.

.setMargin(arg1, opt_arg2, opt_arg3, opt_arg4)

Inherited from goog.ui.Popup .

Sets the margin to place around the popup.

arg1 {goog.math.Box|number|null}
Top value or Box.
opt_arg2 {number=}
Right value.
opt_arg3 {number=}
Bottom value.
opt_arg4 {number=}
Left value.

.setMaxSearchSteps(maxSearchSteps)

Sets the max number of levels to search up the dom if checking descendants.

maxSearchSteps {number}
Maximum number of levels to search up the dom if checking descendants.

.setParentEventTarget(parent)

Inherited from goog.events.EventTarget .

Sets the parent of this event target to use for bubbling.

parent {goog.events.EventTarget?}
Parent EventTarget (null if none).

.setPinnedCorner(corner)

Inherited from goog.ui.Popup .

Sets the corner of the popup to used in the positioning algorithm.

corner {goog.positioning.Corner}
The popup corner used for positioning.

.setPosition(position)

Inherited from goog.ui.Popup .

Sets the position helper object associated with the popup.

position {goog.positioning.AbstractPosition}
A position helper object.

.setRequireInteraction(requireInteraction)

Inherited from goog.ui.Tooltip .

Sets whether tooltip requires the mouse to have moved or the anchor receive focus before the tooltip will be shown.

requireInteraction {boolean}
Whether tooltip should require some user interaction before showing tooltip.

.setShouldHideAsync(b)

Inherited from goog.ui.PopupBase .

Sets whether the popup should hide itself asynchronously using a timeout instead of synchronously.

b {boolean}
Whether to hide async.

.setShowDelayMs(delay)

Inherited from goog.ui.Tooltip .

Sets delay in milliseconds before tooltip is displayed for an element.

delay {number}
The delay in milliseconds.

.setText(str)

Inherited from goog.ui.Tooltip .

Sets tooltip message as plain text.

str {string}
Text message to display in tooltip.

.setTransition(opt_showTransition, opt_hideTransition)

Inherited from goog.ui.PopupBase .

Sets transition animation on showing and hiding the popup.

opt_showTransition {goog.fx.Transition=}
Transition to play on showing the popup.
opt_hideTransition {goog.fx.Transition=}
Transition to play on hiding the popup.

.setType(type)

Inherited from goog.ui.PopupBase .

Specifies the type of popup to use.

type {goog.ui.PopupBase.Type}
Type of popup.

.setVisible(visible)

Inherited from goog.ui.PopupBase .

Sets whether the popup should be visible. After this method returns, isVisible() will always return the new state, even if there is a transition.

visible {boolean}
Desired visibility state.

.shouldHideAsync()

Inherited from goog.ui.PopupBase .

Returns whether the popup should hide itself asynchronously using a timeout instead of synchronously.

returns {boolean}
Whether to hide async.

.showForElement(el, opt_pos)

Inherited from goog.ui.Tooltip .

Shows tooltip for a specific element.

el {Element}
Element to show tooltip for.
opt_pos {goog.positioning.AbstractPosition=}
Position to display popup at.

.triggerForElement(anchorElement, opt_pos, opt_data)

Triggers the hovercard to show after a delay.

anchorElement {Element}
Element that is triggering the hovercard.
opt_pos {goog.positioning.AbstractPosition=}
Position to display hovercard.
opt_data {Object=}
Data to pass to the onTrigger event.