-
Notifications
You must be signed in to change notification settings - Fork 2
/
editor.js
73 lines (56 loc) · 2.32 KB
/
editor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(function() {
var editor;
var editorJSONToSet = "";
// TODO: Узнать почему нельзя сделать редактор с развёрнутым деревом по умолчанию. Возможно нужно написать автору.
var options = {
mode: 'tree',
modes: ['tree', 'form', 'view', 'text', 'code'], // allowed modes ('code' не работает, разобраться, почему)
error: function (error) { console.dir(error); },
change: function () {
try {
var text = editor.getText();
var isTextValid = true;
try {
if(editor.editor) {
if(JSON.stringify(JSON.parse(text)) == editorJSONToSet)
return;
} else{
JSON.parse(text);
}
} catch (error) { isTextValid = false; }
if (isTextValid)
{
json = editor.get();
json = fixChain(json); // TODO: Попробовать возвращать true в том случае, если реально были применены исправления
var lastCursorPosition;
if(editor.editor)
{
lastCursorPosition = editor.editor.getCursorPosition();
editorJSONToSet = JSON.stringify(json);
}
editor.set(json);
if(editor.editor)
editor.editor.moveCursorTo(lastCursorPosition.row, lastCursorPosition.column);
copyDefaultChainToStorage(json);
if(editor.expandAll) editor.expandAll();
}
console.dir();
} catch(error) {
console.dir(error);
}
}
};
//var leftContainer = document.getElementById('left-json-editor-container');
//var rightContainer = document.getElementById('right-json-editor-container');
var container = $('#json-editor-container');
container.css("background-color", "#FFFFFF");
container.css("width", getSectionWidth());
container.css("height", getSectionHeight());
var json = copyDefaultChainFromStorage();
//var leftEditor = new JSONEditor(leftContainer, options, json);
//var rightEditor = new JSONEditor(rightContainer, options, json);
editor = new JSONEditor(container[0], options, json);
editor.expandAll();
// TODO: Решить проблему с конфликтами названий css классов json editor и bootstrap.
//window.parent.location.reload();
})();