Skip to content

Commit

Permalink
Added isInShadowRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
eterna2 committed Nov 16, 2017
1 parent 180e3c0 commit 713b307
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,15 @@ into the shadowRoot.
```js
PolymerVis.insertCssIntoShadowRoot('https://some.css', ele.shadowRoot, 'custom');
```
<a name="exp_module_isInShadowRoot--PolymerVis.isInShadowRoot"></a>

## PolymerVis.isInShadowRoot(node) ⇒ <code>Node</code> ⏏
Check if the node is inside a [`shadowRoot`](https://developer.mozilla.org/en-US/docs/Web/API/shadowRoot) or not.
Return the `shadowRoot` otherwise return `false`.

**Kind**: global method of [<code>PolymerVis.isInShadowRoot</code>](#exp_module_isInShadowRoot--PolymerVis.isInShadowRoot)

| Param | Type | Description |
| --- | --- | --- |
| node | <code>Node</code> | the node to check |

17 changes: 17 additions & 0 deletions polymer-vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,21 @@
httpRequest.open('GET', cssSrc);
httpRequest.send();
};

/**
* Check if the node is inside a [`shadowRoot`](https://developer.mozilla.org/en-US/docs/Web/API/shadowRoot) or not.
* Return the `shadowRoot` otherwise return `false`.
* @alias module:isInShadowRoot
* @param {Node} node the node to check
* @return {Node}
*/
PolymerVis.isInShadowRoot = function isInShadowRoot(node) {
while (node) {
if (node.toString() === '[object ShadowRoot]') {
return node;
}
node = node.parentNode;
}
return false;
};
})((window.PolymerVis = window.PolymerVis || {}));

0 comments on commit 713b307

Please sign in to comment.