Skip to content

Commit

Permalink
feat(component): attribute get/set/remove methods
Browse files Browse the repository at this point in the history
This adds getter and setter and remover methods for attributes on
components.
  • Loading branch information
OwenEdwards authored and gkatsev committed Nov 3, 2016
1 parent 028559c commit 202da2d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 35 additions & 0 deletions src/js/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 202da2d

Please sign in to comment.