Skip to content

Commit

Permalink
main.DomAccess: getAttributes() => breaks when not passing an array f…
Browse files Browse the repository at this point in the history
…or attributes #6315
  • Loading branch information
tobiu committed Jan 27, 2025
1 parent 1ac142c commit a0a1c9e
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/main/DomAccess.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -420,36 +420,33 @@ class DomAccess extends Base {

/**
* Returns the attributes for a given dom node id
* @param {Object} data
* @param {Array|String} data.id either an id or an array of ids
* @param {Array|String} data.attributes either an attribute or an array of attributes
* @param {Object} data
* @param {String|String[]} data.attributes either an attribute or an array of attributes
* @param {String|String[]} data.id either an id or an array of ids
* @returns {Array|Object} In case id is an array, an array of attribute objects is returned, otherwise an object
*/
getAttributes(data) {
getAttributes({attributes, id}) {
let returnData;

if (Array.isArray(data.id)) {
if (Array.isArray(id)) {
returnData = [];

data.id.forEach(id => {
returnData.push(this.getAttributes({
attributes: data.attributes,
id : id
}))
id.forEach(id => {
returnData.push(this.getAttributes({attributes, id}))
})
} else {
let node = this.getElementOrBody(data.id);
let node = this.getElementOrBody(id);

returnData = {};

if (node) {
if (!Array.isArray(data.attributes)) {
data.attributes = [data.attributes];

data.attributes.forEach(attribute => {
returnData[attribute] = node[attribute]
})
if (!Array.isArray(attributes)) {
attributes = [attributes]
}

attributes.forEach(attribute => {
returnData[attribute] = node[attribute]
})
}
}

Expand Down

0 comments on commit a0a1c9e

Please sign in to comment.