mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
property blur refactor
This commit is contained in:
parent
8d970a65c4
commit
6175775503
@ -8,7 +8,7 @@ import Tooltip from 'react-bootstrap/lib/Tooltip';
|
|||||||
|
|
||||||
import AppConstants from '../../constants/application_constants';
|
import AppConstants from '../../constants/application_constants';
|
||||||
|
|
||||||
import { mergeOptions } from '../../utils/general_utils';
|
import { mergeOptions, isDescendantOfDOMNode } from '../../utils/general_utils';
|
||||||
|
|
||||||
|
|
||||||
let Property = React.createClass({
|
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) {
|
handleChange(event) {
|
||||||
this.props.handleChange(event);
|
this.props.handleChange(event);
|
||||||
if (typeof this.props.onChange === 'function') {
|
if (typeof this.props.onChange === 'function') {
|
||||||
@ -166,7 +155,7 @@ let Property = React.createClass({
|
|||||||
|
|
||||||
handleBlur(event) {
|
handleBlur(event) {
|
||||||
let e = event.toElement || event.relatedTarget;
|
let e = event.toElement || event.relatedTarget;
|
||||||
if (this.isDescendant(this.getDOMNode(), e)){
|
if (isDescendantOfDOMNode(this.getDOMNode(), e)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.refs.input.getDOMNode() === document.activeElement) {
|
if (this.refs.input.getDOMNode() === document.activeElement) {
|
||||||
|
@ -233,3 +233,19 @@ export function getSubdomain() {
|
|||||||
let tokens = host.split('.');
|
let tokens = host.split('.');
|
||||||
return tokens.length > 2 ? tokens[0] : 'www';
|
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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user