diff --git a/js/components/ascribe_forms/property.js b/js/components/ascribe_forms/property.js index 821fc0e6..f4540ba4 100644 --- a/js/components/ascribe_forms/property.js +++ b/js/components/ascribe_forms/property.js @@ -8,7 +8,7 @@ import Tooltip from 'react-bootstrap/lib/Tooltip'; import AppConstants from '../../constants/application_constants'; -import { mergeOptions } from '../../utils/general_utils'; +import { mergeOptions, isDescendantOfDOMNode } from '../../utils/general_utils'; let Property = React.createClass({ @@ -125,17 +125,6 @@ let Property = React.createClass({ } }, - isDescendant(parent, child) { - let node = child.parentNode; - while (node != null) { - if (node === parent) { - return true; - } - node = node.parentNode; - } - return false; - }, - handleChange(event) { this.props.handleChange(event); if (typeof this.props.onChange === 'function') { @@ -166,7 +155,7 @@ let Property = React.createClass({ handleBlur(event) { let e = event.toElement || event.relatedTarget; - if (this.isDescendant(this.getDOMNode(), e)){ + if (isDescendantOfDOMNode(this.getDOMNode(), e)){ return; } if (this.refs.input.getDOMNode() === document.activeElement) { diff --git a/js/utils/general_utils.js b/js/utils/general_utils.js index 2cba98b9..e3dbe03f 100644 --- a/js/utils/general_utils.js +++ b/js/utils/general_utils.js @@ -232,4 +232,20 @@ export function getSubdomain() { let { host } = window.location; let tokens = host.split('.'); return tokens.length > 2 ? tokens[0] : 'www'; +} + + +/** + * Checks if the child DOM node is a descendant of the parent DOM node + * @return {boolean} + */ +export function isDescendantOfDOMNode(parent, child) { + let node = child.parentNode; + while (node != null) { + if (node === parent) { + return true; + } + node = node.parentNode; + } + return false; } \ No newline at end of file