Constructor
new OO.ui.Element([config])abstract
#
Each Element represents a rendering in the DOM—a button or an icon, for example, or anything
that is visible to a user. Unlike widgets
, plain elements usually do not
have events connected to them and can't be interacted with.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object |
optional |
Configuration options Properties:
|
- Source:
Each Element represents a rendering in the DOM—a button or an icon, for example, or anything that is visible to a user.
Properties
tagNamestatic
#
The name of the HTML tag used by the element.
The static value may be ignored if the #getTagName method is overridden.
Properties:
Type | Description |
---|---|
string |
- Source:
Methods
computeNativeScrollLeft(normalizedOffset, el) → {number}static
#
Convert our normalized scrollLeft
value to a value for current browser. See #getScrollLeft.
Parameters:
Name | Type | Description |
---|---|---|
normalizedOffset |
number | Normalized |
el |
HTMLElement | Window | Element on which the value will be set |
- Source:
Returns:
- Type
- number
scrollLeft
value to a value for current browser.
computeNormalizedScrollLeft(nativeOffset, el) → {number}static
#
Convert native scrollLeft
value to a value consistent between browsers. See #getScrollLeft.
Parameters:
Name | Type | Description |
---|---|---|
nativeOffset |
number | Native |
el |
HTMLElement | Window | Element from which the value was obtained |
- Source:
Returns:
- Type
- number
scrollLeft
value to a value consistent between browsers.
gatherPreInfuseState(node, config) → {Object}protectedstatic
#
Gather the dynamic state (focus, value of form inputs, scroll position, etc.) of an HTML DOM node (and its children) that represent an Element of the same class and the given configuration, generated by the PHP implementation.
This method is called just before node
is detached from the DOM. The return value of this
function will be passed to #restorePreInfuseState after the newly created widget's #$element
is inserted into DOM to replace node
.
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement | |
config |
Object |
- Source:
Returns:
- Type
- Object
Gather the dynamic state (focus, value of form inputs, scroll position, etc.) of an HTML DOM node (and its children) that represent an Element of the same class and the given configuration, generated by the PHP implementation.
getBorders(el) → {Object}static
#
Get element border sizes.
Parameters:
Name | Type | Description |
---|---|---|
el |
HTMLElement | Element to measure |
- Source:
Returns:
Dimensions object with top
, left
, bottom
and right
properties
- Type
- Object
getClosestScrollableContainer(el, [dimension]) → {HTMLElement}static
#
Get closest scrollable container.
Traverses up until either a scrollable element or the root is reached, in which case the root scrollable element will be returned (see #getRootScrollableElement).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
el |
HTMLElement | Element to find scrollable container for |
|
dimension |
string |
optional |
Dimension of scrolling to look for; |
- Source:
Returns:
Closest scrollable container
- Type
- HTMLElement
getDimensions(el) → {Object}static
#
Get dimensions of an element or window.
Parameters:
Name | Type | Description |
---|---|---|
el |
HTMLElement | Window | Element to measure |
- Source:
Returns:
Dimensions object with borders
, scroll
, scrollbar
and rect
properties
- Type
- Object
getDir(obj) → {string}static
#
Get the direction of an element or document.
Parameters:
Name | Type | Description |
---|---|---|
obj |
jQuery | HTMLElement | HTMLDocument | Window | Context to get the direction for |
- Source:
Returns:
Text direction, either 'ltr' or 'rtl'
- Type
- string
getDocument(obj) → {HTMLDocument|null
}static
#
null
}static
#
Get the document of an element.
Parameters:
Name | Type | Description |
---|---|---|
obj |
jQuery | HTMLElement | HTMLDocument | Window | Object to get the document for |
- Source:
Returns:
Document object
- Type
-
HTMLDocument
|
null
getFrameOffset(from, [to], [offset]) → {Object}static
#
Get the offset between two frames.
TODO: Make this function not use recursion.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
from |
Window | Window of the child frame |
||
to |
Window |
optional |
window | Window of the parent frame |
offset |
Object |
optional |
Offset to start with, used internally |
- Source:
Returns:
Offset object, containing left and top properties
- Type
- Object
getRelativePosition($element, $anchor) → {Object}static
#
Get the offset between two elements.
The two elements may be in a different frame, but in that case the frame $element is in must be contained in the frame $anchor is in.
Parameters:
Name | Type | Description |
---|---|---|
$element |
jQuery | Element whose position to get |
$anchor |
jQuery | Element to get $element's position relative to |
- Source:
Returns:
Translated position coordinates, containing top and left properties
- Type
- Object
getRootScrollableElement(el) → {HTMLBodyElement|HTMLHtmlElement}static
#
Get the root scrollable element of given element's document.
Support: Chrome <= 60
On older versions of Blink, document.documentElement
can't be used to get or set
the scrollTop property; instead we have to use document.body
. Changing and testing the value
lets us use 'body' or 'documentElement' based on what is working.
Parameters:
Name | Type | Description |
---|---|---|
el |
HTMLElement | Element to find root scrollable parent for |
- Source:
Returns:
Scrollable parent, <body>
or <html>
- Type
- HTMLBodyElement | HTMLHtmlElement
getScrollLeft(el) → {number}static
#
Get the number of pixels that an element's content is scrolled to the left.
This function smooths out browser inconsistencies (nicely described in the README at https://github.com/othree/jquery.rtl-scroll-type) and produces a result consistent with Firefox's 'scrollLeft', which seems the most sensible.
(Firefox's scrollLeft handling is nice because it increases from left to right, consistently
with getBoundingClientRect().left
and related APIs; because initial value is zero, so
resetting it is easy; because adapting a hardcoded scroll position to a symmetrical RTL
interface requires just negating it, rather than involving clientWidth
and scrollWidth
;
and because if you mess up and don't adapt your code to RTL, it will scroll to the beginning
rather than somewhere randomly in the middle but not where you wanted.)
Parameters:
Name | Type | Description |
---|---|---|
el |
HTMLElement | Window | Element to measure |
- Source:
Returns:
Scroll position from the left.
If the element's direction is LTR, this is a positive number between 0
(initial scroll
position) and el.scrollWidth - el.clientWidth
(furthest possible scroll position).
If the element's direction is RTL, this is a negative number between 0
(initial scroll
position) and -el.scrollWidth + el.clientWidth
(furthest possible scroll position).
- Type
- number
getWindow(obj) → {Window}static
#
Get the window of an element or document.
Parameters:
Name | Type | Description |
---|---|---|
obj |
jQuery | HTMLElement | HTMLDocument | Window | Context to get the window for |
- Source:
Returns:
Window object
- Type
- Window
infuse(node, [config]) → {OO.ui.Element}static
#
Reconstitute a JavaScript object corresponding to a widget created by the PHP implementation.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
node |
HTMLElement | jQuery | A single node for the widget to infuse. |
|
config |
Object |
optional |
Configuration options |
- Source:
Returns:
The OO.ui.Element
corresponding to this (infusable) document node.
For Tag
objects emitted on the HTML side (used occasionally for content)
the value returned is a newly-created Element wrapping around the existing
DOM node.
- Type
- OO.ui.Element
Reconstitute a JavaScript object corresponding to a widget created by the PHP implementation.
reconsiderScrollbars(el)static
#
Force the browser to reconsider whether it really needs to render scrollbars inside the element and reserve space for them, because it probably doesn't.
Workaround primarily for https://code.google.com/p/chromium/issues/detail?id=387290, but also similar bugs in other browsers. "Just" forcing a reflow is not sufficient in all cases, we need to first actually detach (or hide, but detaching is simpler) all children, then force a reflow, and then reattach (or show) them back.
Parameters:
Name | Type | Description |
---|---|---|
el |
HTMLElement | Element to reconsider the scrollbars on |
- Source:
Force the browser to reconsider whether it really needs to render scrollbars inside the element and reserve space for them, because it probably doesn't.
reusePreInfuseDOM(node, config) → {Object}protectedstatic
#
Pick out parts of node
's DOM to be reused when infusing a widget.
This method must not make any changes to the DOM, only find interesting pieces and add them
to config
(which should then be returned). Actual DOM juggling should then be done by the
constructor, which will be given the enhanced config.
Parameters:
Name | Type | Description |
---|---|---|
node |
HTMLElement | |
config |
Object |
- Source:
Returns:
- Type
- Object
node
's DOM to be reused when infusing a widget.
scrollIntoView(elOrPosition, [config]) → {jQuery.Promise}static
#
Scroll element into view.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
elOrPosition |
HTMLElement | Object | Element to scroll into view |
||||||||||||||||||||||||||||||||||||
config |
Object |
optional |
Configuration options Properties:
|
- Source:
Returns:
Promise which resolves when the scroll is complete
- Type
- jQuery.Promise
setScrollLeft(el, scrollLeft)static
#
Set the number of pixels that an element's content is scrolled to the left.
See #getScrollLeft.
Parameters:
Name | Type | Description |
---|---|---|
el |
HTMLElement | Window | Element to scroll (and to use in calculations) |
scrollLeft |
number | Scroll position from the left.
If the element's direction is LTR, this must be a positive number between
|
- Source:
getClosestScrollableElementContainer() → {HTMLElement}
#
getData() → {any}
#
getElementDocument() → {HTMLDocument}
#
getElementGroup() → {OO.ui.mixin.GroupElement|null
}
#
null
}
#
Get group element is in.
- Source:
Returns:
Group element, null if none
- Type
-
OO.ui.mixin.GroupElement
|
null
getElementId() → {string}
#
Ensure that the element has an 'id' attribute, setting it to an unique value if it's missing, and return its value.
- Source:
Returns:
- Type
- string
Ensure that the element has an 'id' attribute, setting it to an unique value if it's missing, and return its value.
getTagName() → {string}
#
Get the HTML tag name.
Override this method to base the result on instance information.
- Source:
Returns:
HTML tag name
- Type
- string
isElementAttached() → {boolean}
#
Check if the element is attached to the DOM
- Source:
Returns:
The element is attached to the DOM
- Type
- boolean
isVisible() → {boolean}
#
restorePreInfuseState(state)protected
#
Restore the pre-infusion dynamic state for this widget.
This method is called after #$element has been inserted into DOM. The parameter is the return value of #gatherPreInfuseState.
Parameters:
Name | Type | Description |
---|---|---|
state |
Object |
- Source:
scrollElementIntoView([config]) → {jQuery.Promise}
#
Scroll element into view.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
Object |
optional |
Configuration options |
- Source:
Returns:
Promise which resolves when the scroll is complete
- Type
- jQuery.Promise
setData(data) → {OO.ui.Element}chainable
#
Set element data.
Parameters:
Name | Type | Description |
---|---|---|
data |
any | Element data |
- Source:
Returns:
The element, for chaining
- Type
- OO.ui.Element
setElementGroup(group) → {OO.ui.Element}chainable
#
Set group element is in.
Parameters:
Name | Type | Description |
---|---|---|
group |
OO.ui.mixin.GroupElement
|
null
|
Group element, null if none |
- Source:
Returns:
The element, for chaining
- Type
- OO.ui.Element
setElementId(id) → {OO.ui.Element}chainable
#
Set the element has an 'id' attribute.
Parameters:
Name | Type | Description |
---|---|---|
id |
string |
- Source:
Returns:
The element, for chaining
- Type
- OO.ui.Element
supports(methods) → {boolean}
#
Check if element supports one or more methods.
Parameters:
Name | Type | Description |
---|---|---|
methods |
string | Array.<string> | Method or list of methods to check |
- Source:
Returns:
All methods are supported
- Type
- boolean
toggle([show]) → {OO.ui.Element}chainable
#
Toggle visibility of an element.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
show |
boolean |
optional |
Make element visible, omit to toggle visibility |
- Source:
Returns:
The element, for chaining
- Type
- OO.ui.Element
Fires:
updateThemeClasses()
#
Update the theme-provided classes.
This is called in element mixins and widget classes any time state changes. Updating is debounced, minimizing overhead of changing multiple attributes and guaranteeing that theme updates do not occur within an element's constructor
- Source: