1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-12 11:15:04 +02:00

feat(component): attribute get/set/remove methods

This adds getter and setter and remover methods for attributes on
components.
This commit is contained in:
Owen Edwards 2016-08-25 21:05:18 -07:00 committed by Gary Katsevman
parent 028559ccb0
commit 202da2d468
2 changed files with 71 additions and 0 deletions

View File

@ -985,6 +985,42 @@ class Component {
return this;
}
/**
* Get the value of an attribute on the component's element
*
* @param {String} attribute Attribute to get
* @return {String}
* @method getAttribute
*/
getAttribute(attribute) {
return Dom.getAttribute(this.el_, attribute);
}
/**
* Set the value of an attribute on the component's element
*
* @param {String} attribute Attribute to set
* @param {String} value Value to set the attribute to
* @return {Component}
* @method setAttribute
*/
setAttribute(attribute, value) {
Dom.setAttribute(this.el_, attribute, value);
return this;
}
/**
* Remove an attribute from the component's element
*
* @param {String} attribute Attribute to remove
* @return {Component}
* @method removeAttribute
*/
removeAttribute(attribute) {
Dom.removeAttribute(this.el_, attribute);
return this;
}
/**
* Set or get the width of the component (CSS values)
* Setting the video tag dimension values only works with values in pixels.

View File

@ -404,6 +404,41 @@ export function getElAttributes(tag) {
return obj;
}
/**
* Get the value of an element's attribute
*
* @param {Element} el
* @param {String} attribute Attribute to get
* @return {String} value of the attribute
* @method getAttribute
*/
export function getAttribute(el, attribute) {
return el.getAttribute(attribute);
}
/**
* Set the value of an element's attribute
*
* @param {Element} el
* @param {String} attribute Attribute to set
* @param {String} value Value to set the attribute to
* @method setAttribute
*/
export function setAttribute(el, attribute, value) {
el.setAttribute(attribute, value);
}
/**
* Remove an element's attribute
*
* @param {Element} el
* @param {String} attribute Attribute to remove
* @method removeAttribute
*/
export function removeAttribute(el, attribute) {
el.removeAttribute(attribute);
}
/**
* Attempt to block the ability to select text while dragging controls
*