popup
attribute
All
Element
s
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
an
an
element,
then
the
element's
popup
attribute
is
considered
to
be
in
the
no
pop-up
state
.
Every
element
which
has
the
popup
attribute
not
in
the
no
pop-up
state
has
an
additional
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,100px);
transition: all 1.5s;
}
[popup]:open {
transform: translate(0,0);
opacity: 1;
}
</style>
The
Document
has
a
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
all
open
pop-ups
,
which
is
a
set
,
initially
empty.
The
Document
has
a
pop-up
mousedown
target
,
which
is
an
Element
or
null,
initially
null.
Every
element
which
has
the
popup
attribute
not
in
the
no
pop-up
state
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.
The
following
attribute
change
steps
are
used
for
the
popup
attribute:
If
localName
is
not
popup
,
return.
If oldValue is in the no pop-up state , return.
If value is not in the no pop-up state , return.
Run the hide pop-up algorithm given element , true, and false.
The
showPopUp()
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
,
then
throw
a
"
InvalidStateError
"
DOMException
.
If
this
is
not
connected
,
then
throw
a
"
InvalidStateError
"
DOMException
.
If show event 's canceled flag is true, then return.
If
this
's
popup
attribute
is
in
the
no
pop-up
state
,
return.
If this 's pop-up visibility state is showing , return.
Let document be this 's node document .
Let should restore focus be false.
If
this
's
popup
attribute
is
in
the
hint
state
,
then
run
the
following
steps:
If
document
's
currently-showing
hint
pop-up
is
not
null,
then
run
hidePopUp
on
document
's
currently-showing
hint
pop-up
.
Let ancestor be the result of running the nearest open ancestral pop-up algorithm with node set to this and inclusive set to false.
If ancestor is not null, then run hide all pop-ups until with endpoint set to ancestor , focus previous element set to false, hide immediately set to false, and hide unrelated set to true.
If
this
's
popup
attribute
is
in
the
auto
state
,
then
run
the
following
steps:
Let ancestor be the result of running the nearest open ancestral pop-up algorithm with node set to this and inclusive set to false.
Run hide all pop-ups until with endpoint set to ancestor , focus previous element set to false, hide immediately set to false, and hide unrelated set to true.
If
this
's
popup
attribute
is
in
the
auto
state
or
in
the
hint
state
,
then
run
the
following
steps:
The
validity
checks
below
are
repeated
because
running
hide
all
pop-ups
until
above
could
have
fired
the
hide
event,
and
an
event
handler
could
have
disconnected
this
element
or
changed
its
popup
attribute.
If
this
's
popup
attribute
is
in
the
no
pop-up
state
,
then
return.
If this 's pop-up visibility state is not , then return.
This ensures that focus is returned to the previously-focused element only for the first pop-up in a stack.
If the result of running topmost pop-up auto or hint on document is null, then set should restore focus to true. Otherwise, set should restore focus to false.
If
this
's
popup
attribute
is
in
the
auto
state
,
then
push
this
onto
document
's
pop-up
stack
.
If
this
's
popup
attribute
is
in
the
hint
state
,
then
set
document
's
currently-showing
hint
pop-up
to
this
.
Add this to document 's all open pop-ups .
Stop this from waiting for any animations to resolve before running pop-up hide finish if needed .
Set this 's pop-up previously focused element to null.
Let originally focused element the focused element.
Set this 's pop-up visibility state to transitioning .
Update the rendering for document .
Set this 's pop-up visibility state to showing .
Run the hide pop-up algorithm with element set to this , focus previous element set to true, and hide immediately set to false.
Run the pop-up focusing steps for this .
If
should
restore
focus
is
true
and
this
's
popup
attribute
is
not
in
the
no
pop-up
state
and
originally
focused
element
is
not
the
focused
element,
then
set
this
's
pop-up
previously
focused
element
to
originally
focused
element
.
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 with element set to this , focus previous element set to true, and hide immediately set to false.
element
.
showPopUp
()
element
.
hidePopUp
()
To
hide
a
pop-up
given
an
Element
element
,
a
boolean
focus
previous
element
,
and
a
boolean
hide
immediately
:
Let document be element 's node document .
If
element
's
popup
attribute
is
in
the
auto
state
or
the
hint
state
:
Run hide all pop-ups until with endpoint set to element , focus previous element set to focus previous element , hide immediately set to hide immediately , and hide unrelated set to false.
These
validity
checks
are
repeated
because
running
hide
all
pop-ups
until
above
could
have
fired
the
hide
event,
and
an
event
handler
could
have
disconnected
this
element
or
changed
its
popup
attribute.
If
element
's
popup
attribute
is
in
the
no
pop-up
state
,
return.
If element is not connected , return.
If element 's pop-up visibility state is not showing , return.
If
element
's
popup
attribute
is
in
the
auto
state
,
pop
the
top
value
from
document
's
pop-up
stack
.
If
element
's
popup
attribute
is
in
the
hint
state
,
set
document
's
currently-showing
hint
pop-up
to
null.
Remove element from document 's all open pop-ups .
Add element to document 's pop-ups waiting to hide .
Let previous animations be the result of running getAnimations on element .
Set element 's pop-up invoker to null.
Set element 's pop-up visibility state to transitioning .
If hide immediately is true:
Queue
a
global
task
on
the
user
interaction
task
source
given
element
's
relevant
global
object
to
fire
an
event
named
hide
at
element
.
Run pop-up hide finish if needed on element .
Return.
Fire
an
event
named
hide
at
element
.
If element is not connected , return.
If
element
's
popup
attribute
is
in
the
no
pop-up
state
,
return.
If element 's pop-up visibility state is transitioning , return.
Let animations be a set containing the result of running getAnimations on element .
Remove all items in animations which exist in previous animations .
If animations is empty, run pop-up hide finish if needed on element .
Let previously focused element be element 's previously focused element .
If previously focused element is not null:
Set element 's previously focused element to null.
If focus previous element is true, run focus on previously focused element with preventScroll set to true.
If animations is not empty:
Wait for each animation in animations to resolve as either canceled or finished .
Run pop-up hide finish if needed on 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 .
Stop element from waiting for any animations to resolve before running this algorithm.
To
hide
all
pop-ups
until
,
given
an
Element
endpoint
,
a
boolean
focus
previous
element
,
a
boolean
hide
immediately
,
and
a
boolean
hide
unrelated
:
Let document be endpoint 's node document .
If hide immediately is true, then run the following steps:
For each element waiting to hide in document 's pop-ups waiting to hide , run the following steps:
Run pop-up hide finish if needed with element set to element waiting to hide .
Clear document 's pop-ups waiting to hide .
If
endpoint
's
popup
attribute
is
in
the
hint
state
and
hide
unrelated
is
true,
then
run
the
following
steps:
If document 's currently-showing hint pop-up is not equal to endpoint , then run the hide pop-up algorithm with element set to endpoint , focus previous element set to focus previous element , and hide immediately set to hide immediately .
While document 's pop-up stack is not empty, run the following steps:
Run the hide pop-up algorithm with element set to endpoint , focus previous element set to focus previous element , and hide immediately set to hide immediately .
If
endpoint
's
popup
attribute
is
in
the
auto
state
or
endpoint
is
null,
then
run
the
following
steps:
Let hint ancestor be null.
If document's currently-showing hint pop-up is not null:
Let hint ancestor be the result of running the nearest open ancestral pop-up algorithm with node set to document 's currently-showing hint pop-up and inclusive set to false.
If hint ancestor is null and hide unrelated is true, then run the hide pop-up algorithm with element set to document 's currently-showing hint pop-up , focus previous element set to focus previous element and hide immediately set to hide immediately .
While document 's pop-up stack is not empty:
If document 's pop-up stack 's top element is hint ancestor , then run the hide pop-up algorithm with element set to document 's currently-showing hint pop-up with focus previous element set to focus previous element and hide immediately set to hide immediately .
If document 's pop-up stack 's top element is equal to endpoint , break .
Run the hide pop-up algorithm with element set to document 's pop-up stack 's top element, focus previous element set to focus previous element , and hide immediately set to hide immediately .
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
boolean
inclusive
,
perform
the
following
steps.
They
return
an
Element
or
null.
Let document be node 's node document .
Let hint showing be document 's currently-showing hint pop-up .
Let anchors to pop-ups be an empty map .
For each pop-up in document 's pop-up stack :
Let anchor be the result of getting the pop-up anchor element of pop-up .
If anchor is not null, map anchor to pop-up in anchors to pop-ups .
If hint showing is not null:
Let anchor be the result of running getting the pop-up anchor element of hint showing .
If anchor is not null, map anchor to hint showing in anchors to pop-ups .
Let pop-up positions be an empty map .
Let index be 0.
For each pop-up in document 's pop-up stack :
Map pop-up to index in pop-up positions .
Increment index by 1.
If hint showing is not null:
Map hint showing to index in pop-up positions .
Increment index by 1.
Let
new
element
be
true
if
node
's
popup
attribute
is
not
in
the
no
pop-up
state
and
node
's
pop-up
visibility
state
is
not
showing
.
If new element is true, then:
Map node to index in pop-up positions .
Let upper bound be 2147483647.
If pop-up positions has a value for node , set upper bound to pop-up position 's value for node .
If hint showing is not null and new element is true, set upper bound to pop-up position 's value for hint showing .
If inclusive is true:
Let current node be node .
While current node has a parent node within the flat tree :
If
current
node
's
popup
attribute
is
not
in
the
no
pop-up
state
and
current
node
's
pop-up
visibility
state
is
showing
and
current
node
's
popup
attribute
is
not
in
the
manual
state
Let current element plus one be pop-up position 's value for current node plus 1.
If current element plus one is greater than upper bound , then set upper bound to current element plus one .
Let target pop-up be current node 's pop-up target element .
If
target
pop-up
's
popup
attribute
is
not
null
and
target
pop-up
's
pop-up
visibility
state
is
showing
and
target
pop-up
's
popup
attribute
is
not
in
the
manual
state
:
Let target pop-up plus one be pop-up position 's value for target pop-up plus 1.
If target pop-up plus one is greater than upper bound , then set upper bound to target pop-up plus one .
Set current node to the parent node of current node within the flat tree .
Let seen be an empty set .
Return the result of running the nearest open ancestral pop-up recursive algorithm with node , pop-up positions , anchors to pop-ups , upper bound , and seen .
To
find
the
nearest
open
ancestral
pop-up
recursively
,
given
a
Node
node
,
a
map
pop-up
positions
,
a
map
anchors
to
pop-ups
,
an
integer
upper
bound
,
and
a
set
seen
,
perform
the
following
steps.
They
return
an
Element
or
null.
If node is null, return null.
If seen contains node , return null.
Add node to seen .
Let ancestor be null.
Let position be -1.
Let update be to run the following steps on pop-up :
If
pop-up
is
not
null
and
pop-up
's
pop-up
visibility
state
is
not
showing
and
pop-up
's
popup
attribute
is
not
is
not
in
the
manual
state
:
Let new position be pop-up position 's value for pop-up .
If new position is greater than position and new position is less than upper bound :
Set ancestor to pop-up .
Set position to new position .
Let recurse and update be to run the following steps on node :
Let
nearest
open
ancestor
be
the
result
of
running
nearest
open
ancestral
pop-up
recursive
with
node
,
pop-up
positions
,
anchors
to
pop-ups
,
upper
bound
,
and
seen
.
Run update with pop-up set to nearest open ancestor .
Run update with node .
If pop-up positions has a value for node :
Run recurse and update with node 's pop-up anchor element .
Run recurse and update with node 's pop-up invoker .
If node has a pop-up target element , then run recurse and update with node 's pop-up target element .
If anchors to pop-ups has a value for node , then run recurse and update with anchors to pop-ups 's value for node .
Run recurse and update on 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 anchor attribute be the result of running get an attribute by name on element with qualifiedName set to 'anchor'.
If anchor attribute is null, then return null.
Return
the
result
of
running
getElementById
on
element
's
root
with
elementId
set
to
anchor
attribute
.
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 pop-up stack is not empty, then return document 's 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 on subject .
Run the focusing steps for control .
Let top document 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 top document , then return.
Empty top document 's autofocus candidates .
Set top document '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 , continue.
If
node
does
not
have
the
autofocus
attribute,
continue.
Return node .
Return null.
interface mixin PopUpTargetElement {
[CEReactions] attribute DOMString? popUpToggleTarget;
[CEReactions] attribute DOMString? popUpHideTarget;
[CEReactions] attribute DOMString? popUpShowTarget;
};
Supported elements may have the following content attributes, known as the pop-up target attributes :
popuptoggletarget
popuphidetarget
popupshowtarget
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
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
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.
The pop-up target attributes are only supported on the following elements:
button
elements
input
elements
in
the
button
state
.
input
elements
in
the
submit
button
state
.
input
elements
in
the
image
button
state
.
input
elements
in
the
reset
button
state
.
To
run
the
pop-up
target
attribute
activation
behavior
given
a
Node
node
:
If
node
has
the
disabled
attribute,
then
return.
If node is not supported by the pop-up target attributes , then return.
Let pop-up be node 's pop-up target element .
If pop-up is null, then return.
If
node
doesn't
have
the
popuptoggletarget
attribute:
If
node
has
the
popupshowtarget
attribute
and
pop-up
's
pop-up
visibility
state
is
showing
,
then
return.
If
node
has
the
popuphidetarget
attribute
and
pop-up
'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 pop-up 's pop-up visibility state is showing , then run the hide pop-up algorithm with element set to pop-up , focus previous element set to true, and hide immediately set to false.
Otherwise, run the following steps:
Set pop-up 's pop-up invoker to node .
Run showPopUp on pop-up .
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 popup element be the result of running getElementById on node 's root with idref .
If popup element is null, then return null.
If
popup
element
'
popup
attribute
is
in
the
no
pop-up
state
,
then
return
null.
Return popup element .
"Light
dismiss"
means
that
pressing
the
escape
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,
run
the
following
steps:
Let topmost popup be the result of running topmost pop-up auto or hint on document .
If topmost popup is null, then return.
Let target be event 's target .
If target is null, then return.
If
event
is
a
mousedown
event
then:
Set document 's pop-up mousedown target to the result of running nearest open ancestral pop-up with node set to target and inclusive set to true.
If
event
is
a
mouseup
event
then:
Let ancestor be the result of running nearest open ancestral pop-up with node set to target and inclusive set to true.
Let same target be true if ancestor is document 's pop-up mousedown target .
Set document 's pop-up mousedown target to null.
If same target is true, then run hide all pop-ups until with endpoint set to ancestor , focus previous element set to false, hide immediately set to false, and hide unrelated set to true.
If
event
is
a
keydown
event
for
the
Escape
key:
Run the hide pop-up algorithm with element set to topmost popup , focus previous element set to true, and hide immediately set to false.
If
event
is
a
focus
event,
then:
Let ancestor be the result of running nearest open ancestral pop-up with node set to target and inclusive set to true.
Run hide all pop-ups until with endpoint set to ancestor , focus previous element set to false, hide immediately set to false, and hide unrelated set to true.
defaultopen
attribute
All
Element
s
may
have
the
defaultopen
content
attribute
set.
When
specified
on
a
pop-up
element,
it
makes
the
element
shown
automatically
when
the
page
is
loaded.
defaultopen
is
a
boolean
attribute
.
The
defaultOpen
IDL
attribute
must
reflect
the
defaultopen
attribute.