diff --git a/src/cmd/body.js b/src/cmd/body.js index 69c077f..5ef4f5a 100644 --- a/src/cmd/body.js +++ b/src/cmd/body.js @@ -24,7 +24,7 @@ return true; } - const xElt = dom.getInnerObject(target, attr); + const xElt = dom.getInnerObject(attr, target); if (xElt !== null) { xElt.node[xElt.attr] = value; } @@ -52,7 +52,7 @@ return true; } - const xElt = dom.getInnerObject(target, attr); + const xElt = dom.getInnerObject(attr, target); if (xElt !== null) { xElt.node[xElt.attr] = xElt.node[xElt.attr] + value; } @@ -80,7 +80,7 @@ return true; } - const xElt = dom.getInnerObject(target, attr); + const xElt = dom.getInnerObject(attr, target); if (xElt !== null) { xElt.node[xElt.attr] = value + xElt.node[xElt.attr]; } @@ -120,7 +120,7 @@ */ self.replace = ({ target, attr, search, replace }) => { const sSearch = attr === 'innerHTML' ? dom.getBrowserHTML(search) : search; - const xElt = dom.getInnerObject(target, attr); + const xElt = dom.getInnerObject(attr, target); if (xElt !== null) { replaceText(xElt.node, xElt.attr, sSearch, replace); } diff --git a/src/utils/dom.js b/src/utils/dom.js index a14151b..0ff3448 100644 --- a/src/utils/dom.js +++ b/src/utils/dom.js @@ -107,21 +107,21 @@ * Given an element and an attribute with 0 or more dots, * get the inner object and the corresponding attribute name. * - * @param {object} xElement The outer element. - * @param {string} attribute The attribute name. + * @param {string} sAttrName The attribute name. + * @param {object=} xElement The outer element. * * @returns {object|null} The inner object and the attribute name in an object. */ - self.getInnerObject = (xElement, attribute) => { - const aNames = attribute.split('.'); + self.getInnerObject = (sAttrName, xElement = window) => { + const aNames = sAttrName.split('.'); // Get the last element in the array. - attribute = aNames.pop(); + sAttrName = aNames.pop(); // Move to the inner object. const nLength = aNames.length; for (let i = 0; i < nLength && (xElement); i++) { // The real name for the "css" object is "style". xElement = xElement[aNames[i] === 'css' ? 'style' : aNames[i]]; } - return !xElement ? null : { node: xElement, attr: attribute }; + return !xElement ? null : { node: xElement, attr: sAttrName }; }; })(jaxon.utils.dom, jaxon.utils.types, jaxon.config.baseDocument);