1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | var EditorState = require("./EditorState");
|
14 |
|
15 | var containsNode = require("fbjs/lib/containsNode");
|
16 |
|
17 | var getActiveElement = require("fbjs/lib/getActiveElement");
|
18 |
|
19 | function editOnBlur(editor, e) {
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | var ownerDocument = e.currentTarget.ownerDocument;
|
29 |
|
30 | if (
|
31 |
|
32 | !Boolean(editor.props.preserveSelectionOnBlur) && getActiveElement(ownerDocument) === ownerDocument.body) {
|
33 | var _selection = ownerDocument.defaultView.getSelection();
|
34 |
|
35 | var editorNode = editor.editor;
|
36 |
|
37 | if (_selection.rangeCount === 1 && containsNode(editorNode, _selection.anchorNode) && containsNode(editorNode, _selection.focusNode)) {
|
38 | _selection.removeAllRanges();
|
39 | }
|
40 | }
|
41 |
|
42 | var editorState = editor._latestEditorState;
|
43 | var currentSelection = editorState.getSelection();
|
44 |
|
45 | if (!currentSelection.getHasFocus()) {
|
46 | return;
|
47 | }
|
48 |
|
49 | var selection = currentSelection.set('hasFocus', false);
|
50 | editor.props.onBlur && editor.props.onBlur(e);
|
51 | editor.update(EditorState.acceptSelection(editorState, selection));
|
52 | }
|
53 |
|
54 | module.exports = editOnBlur; |
\ | No newline at end of file |