popup attributeAll elements may have the popup content attribute set. When specified, the element won't be
rendered until it becomes shown, at which point it will be rendered on top of other page
content.
The popup attribute is an enumerated attribute.
The following table lists the states for this attribute:
| State | Keywords | Description |
|---|---|---|
| Auto state | auto
| Closes other pop-ups when opened; has light dismiss. |
| The empty string | ||
| Hint state | hint
| Closes other hint pop-ups when opened; has light dismiss. |
| Manual state | manual
| Does not close other pop-ups; does not light dismiss. |
The popUp IDL attribute
must reflect the popup attribute.
The attribute may be omitted. The invalid value default and the missing value default are both the manual state.
When the popup attribute is not set on an element, then the
element's popup attribute is considered to be in the no pop-up state.
Every element has a pop-up visibility state with these potential values:
hidden
transitioning
showing
The pop-up visibility transitioning state and :open pseudo selectors exist to allow pop-ups to animate open or
closed because animating between display: none and other
'display' values is not possible.
The following is an example of an animated pop-up:
< div popup = "auto" id = "foo" >
A fancy pop-up with no Javascript
</ div >
< style >
[ popup ] {
opacity : 0 ;
transform : translate( -100px , 100 px );
transition : all 1.5 s ;
}
[ popup ] : open {
transform : translate( 0 , 0 );
opacity : 1 ;
}
</ style >
The Document has an auto pop-up stack, which is a stack,
initially empty.
The Document has a currently-showing hint pop-up, which is an
Element or null, initially null.
The Document has pop-ups waiting to hide, which is a set,
initially empty.
The Document has a pop-up mousedown target, which is an
Element or null, initially null.
Every element has the following members:
A pop-up previously focused element, which is an Element or null,
initially set to null.
A pop-up invoker, which is an Element or null, initially set to
null.
Waiting to hide pop-up, which is a boolean, initially set to false.
The following attribute change steps
are used for the popup attribute:
If localName is not popup, then
return.
If oldValue is in the no pop-up state, then return.
If value is not in the no pop-up state, then return.
Run the hide pop-up algorithm given element, true, and false.
element.showPopUp()popup attribute is in the auto state or hint
state, then this will also close all other auto and hint
pop-ups unless they are an ancestor of element according to the nearest open
ancestral pop-up algorithm.element.hidePopUp()display: none to it.The showPopUp() method steps
are:
Run show pop-up given this.
To show pop-up, given an Element element:
If element's popup attribute is in the no pop-up state, then throw a
"NotSupportedError" DOMException.
If element's pop-up visibility state is not , then throw a
"InvalidStateError" DOMException.
If element is not connected, then throw a
"InvalidStateError" DOMException.
If the result of firing an event named popupshow at element is false, then return.
If element is not connected, then return.
If element's popup attribute is in the no pop-up state, then return.
If element's pop-up visibility state is showing, then return.
Let document be element's node document.
Let shouldRestoreFocus be false.
If element's popup attribute is in the hint state, then:
If document's currently-showing hint pop-up is not null, then run the hide pop-up algorithm given document's currently-showing hint pop-up, true, and false.
Let ancestor be the result of running the nearest open ancestral
pop-up algorithm given element and "new-pop-up".
If ancestor is not null, then run hide all pop-ups until given ancestor, false, false, and true.
If element's popup attribute is in the auto state, then:
Let ancestor be the result of running the nearest open ancestral
pop-up algorithm given element and "new-pop-up".
Run hide all pop-ups until given ancestor, false, false, and true.
If element's popup attribute is in the auto state or in the hint state, then:
If element's popup attribute is in the no pop-up state, then return.
If element's pop-up visibility state is not , then return.
If element is not connected, then return.
These validity checks are repeated because running hide all pop-ups until above could have fired the
popuphide event, and an event handler could have
disconnected this element or changed its popup
attribute.
If the result of running topmost pop-up auto or hint on document is null, then set shouldRestoreFocus to true. Otherwise, set shouldRestoreFocus to false.
This ensures that focus is returned to the previously-focused element only for the first pop-up in a stack.
If element's popup attribute is in the auto state, then push element onto
document's auto pop-up stack.
If element's popup attribute is in the hint state, then set document's
currently-showing hint pop-up to element.
Set element's waiting to hide pop-up to false.
Set element's pop-up previously focused element to null.
Let originallyFocusedElement be document's focused area of the document.
Add element to document's top layer.
Set element's pop-up visibility state to transitioning.
Recalculate styles and update layout for document.
Set element's pop-up visibility state to showing.
Run the pop-up focusing steps given element.
If shouldRestoreFocus is true, element's popup attribute is not in the no
pop-up state, and originallyFocusedElement is not the focused
element, then set element's pop-up previously focused element to
originallyFocusedElement.
The hidePopUp() method steps
are:
If this's popup attribute is in the no pop-up state, then throw a
"NotSupportedError" DOMException.
If this's pop-up visibility state is not showing, then throw a
"InvalidStateError" DOMException.
Run the hide pop-up algorithm given this, true, and false.
To hide a pop-up given an Element
element, a boolean focusPreviousElement, and a boolean
hideImmediately:
Let document be element's node document.
If element's popup attribute is in the auto state or the hint state, then:
Run hide all pop-ups until given element, focusPreviousElement, hideImmediately, and false.
If element's popup attribute is in the no pop-up state, then return.
If element is not connected, then return.
If element's pop-up visibility state is not showing, then return.
These validity checks are repeated because running hide all pop-ups until above could have fired the
popuphide event, and an event handler could have
disconnected this element or changed its popup
attribute.
If element's popup attribute is in the auto state, then pop from
document's auto pop-up stack.
If element's popup attribute is in the hint state, then set document's
currently-showing hint pop-up to null.
Add element to document's pop-ups waiting to hide.
Let previousAnimations be the set of all relevant Animation objects that contain at least one
animation effect whose effect target is element.
Set element's pop-up invoker to null.
Set element's pop-up visibility state to transitioning.
If hideImmediately is true, then:
Queue an element task given user interaction task source and
element to fire an event named popuphide at element.
Run pop-up hide finish if needed given element.
Return.
Fire an event named popuphide at element.
If element is not connected, then return.
If element's popup attribute is in the no pop-up state, then return.
If element's pop-up visibility state is transitioning, then return.
Let animations be the set of all relevant Animation objects that contain at least one
animation effect whose effect target is element.
Remove all items in animations which exist in previousAnimations.
If animations is empty, then run pop-up hide finish if needed given element.
Let previouslyFocusedElement be element's previously focused element.
If previouslyFocusedElement is not null, then:
Set element's previously focused element to null.
If focusPreviousElement is true, then run the focusing steps for previouslyFocusedElement.
If animations is not empty, then run these steps in parallel:
Set element's waiting to hide pop-up to true.
Wait for each animation in animations to resolve as either canceled or finished.
If element's waiting to hide pop-up is true, then run pop-up hide finish if needed given element.
To finish hiding a pop-up if needed, given an
Element element:
Remove element from element's node document's pop-ups waiting to hide.
Remove element from the top layer.
Set element's pop-up visibility state to .
Set element's waiting to hide pop-up to false.
To hide all pop-ups until, given an
Element endpoint, a boolean focusPreviousElement, a boolean
hideImmediately, and a boolean hideUnrelated:
Let document be endpoint's node document.
If hideImmediately is true, then:
For each elementWaitingToHide in document's pop-ups waiting to hide:
Run pop-up hide finish if needed given elementWaitingToHide.
Clear document's pop-ups waiting to hide.
If endpoint's popup attribute is in the hint state and hideUnrelated is true, then:
If document's currently-showing hint pop-up is not equal to endpoint, then run the hide pop-up algorithm given endpoint, focusPreviousElement, and hideImmediately.
While document's auto pop-up stack is not empty:
Run the hide pop-up algorithm given endpoint, focusPreviousElement, and hideImmediately.
If endpoint's popup attribute is in the auto state or endpoint is null, then:
Let hintAncestor be null.
If document's currently-showing hint pop-up is not null, then:
Let hintAncestor be the result of running the nearest open ancestral
pop-up algorithm given document's currently-showing hint
pop-up and "default"
If hintAncestor is null and hideUnrelated is true, then run the hide pop-up algorithm given document's currently-showing hint pop-up, focusPreviousElement and hideImmediately.
While document's auto pop-up stack is not empty:
If document's auto pop-up stack's top element is hintAncestor, then run the hide pop-up algorithm given document's currently-showing hint pop-up, focusPreviousElement and hideImmediately.
If document's auto pop-up stack's top element is equal to endpoint, then break.
Run the hide pop-up algorithm given document's auto pop-up stack's top element, focusPreviousElement, and hideImmediately.
The hide all pop-ups until algorithm is used in
several cases to hide all pop-ups that don't stay open when something happens. For example,
during light-dismiss of a pop-up, this algorithm ensures that we close only the pop-ups that
aren't related to the node clicked by the user. The interaction between popup=auto and
popup=hint is captured here, where a popup=hint that is
"nested" inside a popup=auto is only hidden at the appropriate time.
To find the nearest open ancestral pop-up,
given a Node node and a string ancestorType, perform the
following steps. They return an Element or null.
Let document be node's node document.
Let hintShowing be document's currently-showing hint pop-up.
Let anchorsToPopUps be an empty map.
For each popUp in document's auto pop-up stack:
Let anchor be the result of getting the pop-up anchor element of popUp.
If anchor is not null, then set anchorsToPopUps[anchor] to popUp.
If hintShowing is not null, then:
Let anchor be the result of running getting the pop-up anchor element of hintShowing.
If anchor is not null, then set anchorsToPopUps[anchor] to hintShowing.
Let popUpPositions be an empty map.
Let index be 0.
For each popUp in document's auto pop-up stack:
Set popUpPositions[popUp] to index.
Increment index by 1.
If hintShowing is not null, then:
Set popUpPositions[hintShowing] to index.
Increment index by 1.
If ancestorType is "new-pop-up", then:
Set popUpPositions[node] to index.
Let upperBound be 2147483647.
If popUpPositions[node] exists, then set upperBound to popUpPositions[node].
If hintShowing is not null and ancestorType is "new-pop-up", then set upperBound to
popUpPositions[hintShowing].
If ancestorType is "inclusive", then:
Let currentNode be node.
While currentNode has a parent node within the flat tree:
If currentNode's popup attribute is not in
the no pop-up state and currentNode's
pop-up visibility state is showing
and currentNode's popup attribute is not in the
manual state, then:
If popUpPositions[currentNode] + 1 is greater than upperBound, then set upperBound to popUpPositions[currentNode] + 1.
Let targetPopUp be currentNode's pop-up target element.
If targetPopUp's popup attribute is not
null and targetPopUp's pop-up visibility state is showing and targetPopUp's popup attribute is not in the manual state, then:
If popUpPositions[targetPopUp] + 1 is greater than upperBound, then set upperBound to popUpPositions[targetPopUp] + 1.
Set currentNode to the parent node of currentNode within the flat tree.
Let seen be an empty set.
Return the result of finding the nearest open ancestral pop-up recursively given node, popUpPositions, anchorsToPopUps, upperBound, and seen.
To find the nearest open ancestral pop-up
recursively, given a Node node, a map
popUpPositions, a map anchorsToPopUps, an integer upperBound,
and a set seen, perform the following steps. They return an
Element or null.
If node is null, then return null.
If seen contains node, then return null.
Add node to seen.
Let ancestor be null.
Let position be −1.
Let update be an algorithm which performs the following steps given popUp:
If popUp is not null and popUp's pop-up visibility state
is not showing and popUp's popup attribute is not in the manual state, then:
Let newPosition be popUpPositions[popUp].
If newPosition is greater than position and newPosition is less than upperBound, then:
Set ancestor to popUp.
Set position to newPosition.
Let recurseAndUpdate be an algorithm which performs the following steps given node:
Let nearestOpenAncestor be the result of finding the nearest open ancestral pop-up recursively given node, popUpPositions, anchorsToPopUps, upperBound, and seen.
Run update given nearestOpenAncestor.
Run update given node.
If popUpPositions[node] exists, then:
Run recurseAndUpdate given node's pop-up anchor element.
Run recurseAndUpdate given node's pop-up invoker.
If node has a pop-up target element, then run recurseAndUpdate given node's pop-up target element.
If anchorsToPopUps[node] exists, then run recurseAndUpdate given anchorsToPopUps[node].
Run recurseAndUpdate given node's parent node in the flat tree.
Return ancestor.
To get the pop-up anchor element of an
Element element, perform the following steps. They return an
Element or null.
If element's popup attribute is in the no pop-up state, then return null.
Let anchorAttribute be the result of running get an attribute by
name given element and anchor.
If anchorAttribute is null, then return null.
Return the first element, in tree order, within element's root's descendants, whose ID is anchorAttribute; otherwise, if there is no such element, null.
To find the topmost pop-up auto or hint given a
Document document, perform the following steps. They return an
Element or null.
If document's currently-showing hint pop-up is not null, then return document's currently-showing hint pop-up.
If document's auto pop-up stack is not empty, then return document's auto pop-up stack's last element.
Return null.
To perform the pop-up focusing steps for an Element
subject:
Let control be the result of running pop-up focusable area given subject.
If control is null, then return.
Run the focusing steps given control.
Let topDocument be the active document of control's node document's browsing context's top-level browsing context.
If control's node document's origin is not the same as the origin of topDocument, then return.
Empty topDocument's autofocus candidates.
Set topDocument's autofocus processed flag to true.
To get the pop-up focusable area given an element subject, perform the
following steps. They return an Element or null.
If subject has the autofocus attribute,
then return subject.
For each node in the flat tree within subject:
If node is a dialog element or node's popup attribute is not in the no pop-up state, then continue without traversing into
the child nodes of node.
If node is not focusable, then continue.
If node does not have the autofocus
attribute, then continue.
Return node.
Return null.
Supported elements may have the following content attributes, known as the pop-up target attributes:
popuptoggletarget
popuphidetarget
popupshowtarget
The pop-up target attributes allow certain types of buttons to show and hide
element with the popup attribute. If a pop-up target attribute is
specified, then that attribute's value must be the ID of element with the popup attribute.
The following shows how popupshowtarget can be
used to open a pop-up:
< div popup = auto id = "foo" >
This is a pop-up!
</ div >
< button popupshowtarget = "foo" >
Show a pop-up
</ button >
The following shows how popuptoggletarget can
open and close a manual pop-up, which can't be closed with light dismiss:
< div popup = manual id = "foo" >
This is a pop-up!
</ div >
< button popuptoggletarget = "foo" >
Show or hide a pop-up
</ button >
The pop-up target attributes are only supported on the following elements:
button elements
input elements in the Submit
Button state.
input elements in the Image
Button state.
input elements in the Reset
Button state.
The popUpToggleTarget IDL attribute must
reflect the popuptoggletarget
attribute.
The popUpHideTarget IDL attribute must reflect
the popuphidetarget attribute.
The popUpShowTarget IDL attribute must reflect
the popupshowtarget attribute.
To run the pop-up target attribute activation behavior given a Node
node:
If node is disabled, then return.
If node is not supported by the pop-up target attributes, then return.
Let popUp be node's pop-up target element.
If popUp is null, then return.
If node doesn't have the popuptoggletarget attribute, then:
If node has the popupshowtarget
attribute and popUp's pop-up visibility state is showing, then return.
If node has the popuphidetarget
attribute and popUp's pop-up visibility state is , then return.
If node doesn't have the popupshowtarget attribute and node doesn't
have the popuphidetarget attribute, then
return.
If node has a form owner and node is in any of the following states, then return:
node is a button element in the submit state.
node is an input element in the submit state.
node is an input element in the image state.
If popUp's pop-up visibility state is showing, then run the hide pop-up algorithm given popUp, true, and false.
Otherwise:
Set popUp's pop-up invoker to node.
Run show pop-up given popUp.
To get the pop-up target element given a Node node, perform
the following steps. They return an Element or null.
If node is not supported, then return null.
Let idref be null.
If node has the popuptoggletarget attribute, then set idref
to the value of node's popuptoggletarget attribute.
Otherwise, if node has the popupshowtarget attribute, then set idref to
the value of node's popupshowtarget
attribute.
Otherwise, if node has the popuphidetarget attribute, then set idref to
the value of node's popuphidetarget
attribute.
If idref is null, then return null.
Let popupElement be the first element, in tree order, within node's root's descendants, whose ID is idref; otherwise, if there is no such element, null.
If popupElement is null, then return null.
If popupElement's popup attribute is in the
no pop-up state, then return null.
Return popupElement.
"Light dismiss" means that pressing the Esc key or clicking outside of a pop-up
whose popup attribute is in the auto or hint
states will close the pop-up.
When a Document document receives an Event
event in the capture phase:
Let topmostPopup be the result of running topmost pop-up auto or hint given document.
If topmostPopup is null, then return.
Let target be event's target.
If event is a mousedown event, then:
Set document's pop-up mousedown target to the result of running
nearest open ancestral pop-up given target and "inclusive".
If event is a mouseup event, then:
Let ancestor be the result of running nearest open ancestral
pop-up given target and "inclusive".
Let sameTarget be true if ancestor is document's pop-up mousedown target.
Set document's pop-up mousedown target to null.
If sameTarget is true, then run hide all pop-ups until given ancestor, false, false, and true.
If event is a keydown event for the
Escape key, then:
Run the hide pop-up algorithm given topmostPopup, true, and false.
defaultopen attributeAll elements may have the defaultopen content attribute set. When specified on an
element whose popup attribute is not in the no pop-up state, it makes the element shown automatically
when the page is loaded. defaultopen is a boolean
attribute.
The defaultOpen
IDL attribute must reflect the defaultopen
content attribute.
anchor attributeAll elements may have the anchor attribute set. When specified on an element whose popup attribute is not in the no
pop-up state, the value of the attribute is used as an ID to refer to another element. If
the other element's popup attribute is also not in the no pop-up state, then the other element is considered to be
a parent in the pop-up hierarchy. This means, for example, that if the element and parent
element's popup attributes are in the auto state, then both of them can be open at the same time
even though only one auto pop-up is supposed to be
open at a time.