bee_api 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/bee_api +84 -0
- data/lib/mdpreview.rb +80 -0
- data/lib/mdpreview/translator.rb +60 -0
- data/lib/mdpreview/version.rb +3 -0
- data/test/mdptest.rb +100 -0
- data/vendor/HISTORY.md +237 -0
- data/vendor/Jakefile.js +316 -0
- data/vendor/LICENSE +176 -0
- data/vendor/NOTICE +17 -0
- data/vendor/README.md +102 -0
- data/vendor/app/chrome/documentation.txt +12 -0
- data/vendor/app/chrome/manifest.json +24 -0
- data/vendor/app/web/ajax.js +43 -0
- data/vendor/app/web/app.css +292 -0
- data/vendor/app/web/app.js +377 -0
- data/vendor/app/web/beta/index.html +17 -0
- data/vendor/app/web/datapolicy.txt +48 -0
- data/vendor/app/web/doc/doc.css +60 -0
- data/vendor/app/web/doc/img/actions_menu.png +0 -0
- data/vendor/app/web/doc/img/button_actions_menu.png +0 -0
- data/vendor/app/web/doc/img/button_dragarea.png +0 -0
- data/vendor/app/web/doc/img/jsoneditor.png +0 -0
- data/vendor/app/web/doc/img/jsonformatter.png +0 -0
- data/vendor/app/web/doc/img/main_menu.png +0 -0
- data/vendor/app/web/doc/img/splitter.png +0 -0
- data/vendor/app/web/doc/index.html +201 -0
- data/vendor/app/web/favicon.ico +0 -0
- data/vendor/app/web/fileretriever.css +54 -0
- data/vendor/app/web/fileretriever.js +567 -0
- data/vendor/app/web/fileretriever.php +120 -0
- data/vendor/app/web/googlea47c4a0b36d11021.html +1 -0
- data/vendor/app/web/hash.js +133 -0
- data/vendor/app/web/img/description.txt +20 -0
- data/vendor/app/web/img/header_background.png +0 -0
- data/vendor/app/web/img/icon_128.png +0 -0
- data/vendor/app/web/img/icon_16.png +0 -0
- data/vendor/app/web/img/icon_gray.svg +151 -0
- data/vendor/app/web/img/icon_gray_16.svg +150 -0
- data/vendor/app/web/img/icon_orange.svg +151 -0
- data/vendor/app/web/img/logo.png +0 -0
- data/vendor/app/web/img/logo.xcf +0 -0
- data/vendor/app/web/img/logo_app.png +0 -0
- data/vendor/app/web/img/logo_app.xcf +0 -0
- data/vendor/app/web/index.html +191 -0
- data/vendor/app/web/notify.js +150 -0
- data/vendor/app/web/queryparams.js +71 -0
- data/vendor/app/web/robots.txt +0 -0
- data/vendor/app/web/splitter.js +179 -0
- data/vendor/app/web/test.html +224 -0
- data/vendor/component.json +33 -0
- data/vendor/docs/api.md +188 -0
- data/vendor/docs/usage.md +137 -0
- data/vendor/examples/01_basic_usage.html +45 -0
- data/vendor/examples/02_viewer.html +38 -0
- data/vendor/examples/03_switch_mode.html +98 -0
- data/vendor/examples/cur.file +1 -0
- data/vendor/examples/jquery.js +2 -0
- data/vendor/examples/meta.js +1 -0
- data/vendor/examples/requirejs_demo/requirejs_demo.html +19 -0
- data/vendor/examples/requirejs_demo/scripts/main.js +25 -0
- data/vendor/examples/requirejs_demo/scripts/require.js +35 -0
- data/vendor/img/jsoneditor-icons.png +0 -0
- data/vendor/jsoneditor-min.css +1 -0
- data/vendor/jsoneditor-min.js +34 -0
- data/vendor/jsoneditor.css +597 -0
- data/vendor/jsoneditor.js +6069 -0
- data/vendor/jsoneditor/css/contextmenu.css +219 -0
- data/vendor/jsoneditor/css/img/description.txt +13 -0
- data/vendor/jsoneditor/css/img/export.sh +16 -0
- data/vendor/jsoneditor/css/img/jsoneditor-icons.png +0 -0
- data/vendor/jsoneditor/css/img/jsoneditor-icons.svg +861 -0
- data/vendor/jsoneditor/css/jsoneditor.css +220 -0
- data/vendor/jsoneditor/css/menu.css +81 -0
- data/vendor/jsoneditor/css/searchbox.css +73 -0
- data/vendor/jsoneditor/js/appendnode.js +211 -0
- data/vendor/jsoneditor/js/contextmenu.js +440 -0
- data/vendor/jsoneditor/js/header.js +32 -0
- data/vendor/jsoneditor/js/highlighter.js +82 -0
- data/vendor/jsoneditor/js/history.js +218 -0
- data/vendor/jsoneditor/js/jsoneditor.js +206 -0
- data/vendor/jsoneditor/js/module.js +50 -0
- data/vendor/jsoneditor/js/node.js +2864 -0
- data/vendor/jsoneditor/js/searchbox.js +288 -0
- data/vendor/jsoneditor/js/texteditor.js +311 -0
- data/vendor/jsoneditor/js/treeeditor.js +770 -0
- data/vendor/jsoneditor/js/util.js +582 -0
- data/vendor/lib/ace/ace.js +11 -0
- data/vendor/lib/ace/mode-json.js +1 -0
- data/vendor/lib/ace/theme-jsoneditor.js +144 -0
- data/vendor/lib/ace/theme-textmate.js +163 -0
- data/vendor/lib/ace/worker-json.js +1 -0
- data/vendor/lib/jsonlint/README.md +62 -0
- data/vendor/lib/jsonlint/jsonlint.js +432 -0
- data/vendor/misc/screenshots/actionsmenu_640x400.png +0 -0
- data/vendor/misc/screenshots/codeeditor_640x400.png +0 -0
- data/vendor/misc/screenshots/description.json +17 -0
- data/vendor/misc/screenshots/jsoneditoronline.png +0 -0
- data/vendor/misc/screenshots/jsoneditoronline_640x400.png +0 -0
- data/vendor/misc/screenshots/search_640x400.png +0 -0
- data/vendor/misc/screenshots/small_tile.xcf +0 -0
- data/vendor/misc/screenshots/small_tile_440x280.png +0 -0
- data/vendor/misc/todo.txt +101 -0
- data/vendor/package.json +28 -0
- data/vendor/test/couchdbeditor.html +100 -0
- data/vendor/test/largefile.json +12605 -0
- data/vendor/test/test_ace.html +60 -0
- data/vendor/test/test_editable_div.html +449 -0
- metadata +154 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The highlighter can highlight/unhighlight a node, and
|
|
3
|
+
* animate the visibility of a context menu.
|
|
4
|
+
* @constructor Highlighter
|
|
5
|
+
*/
|
|
6
|
+
function Highlighter () {
|
|
7
|
+
this.locked = false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hightlight given node and its childs
|
|
12
|
+
* @param {Node} node
|
|
13
|
+
*/
|
|
14
|
+
Highlighter.prototype.highlight = function (node) {
|
|
15
|
+
if (this.locked) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (this.node != node) {
|
|
20
|
+
// unhighlight current node
|
|
21
|
+
if (this.node) {
|
|
22
|
+
this.node.setHighlight(false);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// highlight new node
|
|
26
|
+
this.node = node;
|
|
27
|
+
this.node.setHighlight(true);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// cancel any current timeout
|
|
31
|
+
this._cancelUnhighlight();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Unhighlight currently highlighted node.
|
|
36
|
+
* Will be done after a delay
|
|
37
|
+
*/
|
|
38
|
+
Highlighter.prototype.unhighlight = function () {
|
|
39
|
+
if (this.locked) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
var me = this;
|
|
44
|
+
if (this.node) {
|
|
45
|
+
this._cancelUnhighlight();
|
|
46
|
+
|
|
47
|
+
// do the unhighlighting after a small delay, to prevent re-highlighting
|
|
48
|
+
// the same node when moving from the drag-icon to the contextmenu-icon
|
|
49
|
+
// or vice versa.
|
|
50
|
+
this.unhighlightTimer = setTimeout(function () {
|
|
51
|
+
me.node.setHighlight(false);
|
|
52
|
+
me.node = undefined;
|
|
53
|
+
me.unhighlightTimer = undefined;
|
|
54
|
+
}, 0);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Cancel an unhighlight action (if before the timeout of the unhighlight action)
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
Highlighter.prototype._cancelUnhighlight = function () {
|
|
63
|
+
if (this.unhighlightTimer) {
|
|
64
|
+
clearTimeout(this.unhighlightTimer);
|
|
65
|
+
this.unhighlightTimer = undefined;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Lock highlighting or unhighlighting nodes.
|
|
71
|
+
* methods highlight and unhighlight do not work while locked.
|
|
72
|
+
*/
|
|
73
|
+
Highlighter.prototype.lock = function () {
|
|
74
|
+
this.locked = true;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Unlock highlighting or unhighlighting nodes
|
|
79
|
+
*/
|
|
80
|
+
Highlighter.prototype.unlock = function () {
|
|
81
|
+
this.locked = false;
|
|
82
|
+
};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @constructor History
|
|
3
|
+
* Store action history, enables undo and redo
|
|
4
|
+
* @param {JSONEditor} editor
|
|
5
|
+
*/
|
|
6
|
+
function History (editor) {
|
|
7
|
+
this.editor = editor;
|
|
8
|
+
this.clear();
|
|
9
|
+
|
|
10
|
+
// map with all supported actions
|
|
11
|
+
this.actions = {
|
|
12
|
+
'editField': {
|
|
13
|
+
'undo': function (params) {
|
|
14
|
+
params.node.updateField(params.oldValue);
|
|
15
|
+
},
|
|
16
|
+
'redo': function (params) {
|
|
17
|
+
params.node.updateField(params.newValue);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
'editValue': {
|
|
21
|
+
'undo': function (params) {
|
|
22
|
+
params.node.updateValue(params.oldValue);
|
|
23
|
+
},
|
|
24
|
+
'redo': function (params) {
|
|
25
|
+
params.node.updateValue(params.newValue);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
'appendNode': {
|
|
29
|
+
'undo': function (params) {
|
|
30
|
+
params.parent.removeChild(params.node);
|
|
31
|
+
},
|
|
32
|
+
'redo': function (params) {
|
|
33
|
+
params.parent.appendChild(params.node);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
'insertBeforeNode': {
|
|
37
|
+
'undo': function (params) {
|
|
38
|
+
params.parent.removeChild(params.node);
|
|
39
|
+
},
|
|
40
|
+
'redo': function (params) {
|
|
41
|
+
params.parent.insertBefore(params.node, params.beforeNode);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
'insertAfterNode': {
|
|
45
|
+
'undo': function (params) {
|
|
46
|
+
params.parent.removeChild(params.node);
|
|
47
|
+
},
|
|
48
|
+
'redo': function (params) {
|
|
49
|
+
params.parent.insertAfter(params.node, params.afterNode);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
'removeNode': {
|
|
53
|
+
'undo': function (params) {
|
|
54
|
+
var parent = params.parent;
|
|
55
|
+
var beforeNode = parent.childs[params.index] || parent.append;
|
|
56
|
+
parent.insertBefore(params.node, beforeNode);
|
|
57
|
+
},
|
|
58
|
+
'redo': function (params) {
|
|
59
|
+
params.parent.removeChild(params.node);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
'duplicateNode': {
|
|
63
|
+
'undo': function (params) {
|
|
64
|
+
params.parent.removeChild(params.clone);
|
|
65
|
+
},
|
|
66
|
+
'redo': function (params) {
|
|
67
|
+
params.parent.insertAfter(params.clone, params.node);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
'changeType': {
|
|
71
|
+
'undo': function (params) {
|
|
72
|
+
params.node.changeType(params.oldType);
|
|
73
|
+
},
|
|
74
|
+
'redo': function (params) {
|
|
75
|
+
params.node.changeType(params.newType);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
'moveNode': {
|
|
79
|
+
'undo': function (params) {
|
|
80
|
+
params.startParent.moveTo(params.node, params.startIndex);
|
|
81
|
+
},
|
|
82
|
+
'redo': function (params) {
|
|
83
|
+
params.endParent.moveTo(params.node, params.endIndex);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
'sort': {
|
|
87
|
+
'undo': function (params) {
|
|
88
|
+
var node = params.node;
|
|
89
|
+
node.hideChilds();
|
|
90
|
+
node.sort = params.oldSort;
|
|
91
|
+
node.childs = params.oldChilds;
|
|
92
|
+
node.showChilds();
|
|
93
|
+
},
|
|
94
|
+
'redo': function (params) {
|
|
95
|
+
var node = params.node;
|
|
96
|
+
node.hideChilds();
|
|
97
|
+
node.sort = params.newSort;
|
|
98
|
+
node.childs = params.newChilds;
|
|
99
|
+
node.showChilds();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// TODO: restore the original caret position and selection with each undo
|
|
104
|
+
// TODO: implement history for actions "expand", "collapse", "scroll", "setDocument"
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The method onChange is executed when the History is changed, and can
|
|
110
|
+
* be overloaded.
|
|
111
|
+
*/
|
|
112
|
+
History.prototype.onChange = function () {};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Add a new action to the history
|
|
116
|
+
* @param {String} action The executed action. Available actions: "editField",
|
|
117
|
+
* "editValue", "changeType", "appendNode",
|
|
118
|
+
* "removeNode", "duplicateNode", "moveNode"
|
|
119
|
+
* @param {Object} params Object containing parameters describing the change.
|
|
120
|
+
* The parameters in params depend on the action (for
|
|
121
|
+
* example for "editValue" the Node, old value, and new
|
|
122
|
+
* value are provided). params contains all information
|
|
123
|
+
* needed to undo or redo the action.
|
|
124
|
+
*/
|
|
125
|
+
History.prototype.add = function (action, params) {
|
|
126
|
+
this.index++;
|
|
127
|
+
this.history[this.index] = {
|
|
128
|
+
'action': action,
|
|
129
|
+
'params': params,
|
|
130
|
+
'timestamp': new Date()
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// remove redo actions which are invalid now
|
|
134
|
+
if (this.index < this.history.length - 1) {
|
|
135
|
+
this.history.splice(this.index + 1, this.history.length - this.index - 1);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// fire onchange event
|
|
139
|
+
this.onChange();
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Clear history
|
|
144
|
+
*/
|
|
145
|
+
History.prototype.clear = function () {
|
|
146
|
+
this.history = [];
|
|
147
|
+
this.index = -1;
|
|
148
|
+
|
|
149
|
+
// fire onchange event
|
|
150
|
+
this.onChange();
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Check if there is an action available for undo
|
|
155
|
+
* @return {Boolean} canUndo
|
|
156
|
+
*/
|
|
157
|
+
History.prototype.canUndo = function () {
|
|
158
|
+
return (this.index >= 0);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Check if there is an action available for redo
|
|
163
|
+
* @return {Boolean} canRedo
|
|
164
|
+
*/
|
|
165
|
+
History.prototype.canRedo = function () {
|
|
166
|
+
return (this.index < this.history.length - 1);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Undo the last action
|
|
171
|
+
*/
|
|
172
|
+
History.prototype.undo = function () {
|
|
173
|
+
if (this.canUndo()) {
|
|
174
|
+
var obj = this.history[this.index];
|
|
175
|
+
if (obj) {
|
|
176
|
+
var action = this.actions[obj.action];
|
|
177
|
+
if (action && action.undo) {
|
|
178
|
+
action.undo(obj.params);
|
|
179
|
+
if (obj.params.oldSelection) {
|
|
180
|
+
this.editor.setSelection(obj.params.oldSelection);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
util.log('Error: unknown action "' + obj.action + '"');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
this.index--;
|
|
188
|
+
|
|
189
|
+
// fire onchange event
|
|
190
|
+
this.onChange();
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Redo the last action
|
|
196
|
+
*/
|
|
197
|
+
History.prototype.redo = function () {
|
|
198
|
+
if (this.canRedo()) {
|
|
199
|
+
this.index++;
|
|
200
|
+
|
|
201
|
+
var obj = this.history[this.index];
|
|
202
|
+
if (obj) {
|
|
203
|
+
var action = this.actions[obj.action];
|
|
204
|
+
if (action && action.redo) {
|
|
205
|
+
action.redo(obj.params);
|
|
206
|
+
if (obj.params.newSelection) {
|
|
207
|
+
this.editor.setSelection(obj.params.newSelection);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
util.log('Error: unknown action "' + obj.action + '"');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// fire onchange event
|
|
216
|
+
this.onChange();
|
|
217
|
+
}
|
|
218
|
+
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @constructor JSONEditor
|
|
3
|
+
* @param {Element} container Container element
|
|
4
|
+
* @param {Object} [options] Object with options. available options:
|
|
5
|
+
* {String} mode Editor mode. Available values:
|
|
6
|
+
* 'tree' (default), 'view',
|
|
7
|
+
* 'form', 'text', and 'code'.
|
|
8
|
+
* {function} change Callback method, triggered
|
|
9
|
+
* on change of contents
|
|
10
|
+
* {Boolean} search Enable search box.
|
|
11
|
+
* True by default
|
|
12
|
+
* Only applicable for modes
|
|
13
|
+
* 'tree', 'view', and 'form'
|
|
14
|
+
* {Boolean} history Enable history (undo/redo).
|
|
15
|
+
* True by default
|
|
16
|
+
* Only applicable for modes
|
|
17
|
+
* 'tree', 'view', and 'form'
|
|
18
|
+
* {String} name Field name for the root node.
|
|
19
|
+
* Only applicable for modes
|
|
20
|
+
* 'tree', 'view', and 'form'
|
|
21
|
+
* {Number} indentation Number of indentation
|
|
22
|
+
* spaces. 4 by default.
|
|
23
|
+
* Only applicable for
|
|
24
|
+
* modes 'text' and 'code'
|
|
25
|
+
* @param {Object | undefined} json JSON object
|
|
26
|
+
*/
|
|
27
|
+
function JSONEditor (container, options, json) {
|
|
28
|
+
if (!(this instanceof JSONEditor)) {
|
|
29
|
+
throw new Error('JSONEditor constructor called without "new".');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (arguments.length) {
|
|
33
|
+
this._create(container, options, json);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Configuration for all registered modes. Example:
|
|
39
|
+
* {
|
|
40
|
+
* tree: {
|
|
41
|
+
* editor: TreeEditor,
|
|
42
|
+
* data: 'json'
|
|
43
|
+
* },
|
|
44
|
+
* text: {
|
|
45
|
+
* editor: TextEditor,
|
|
46
|
+
* data: 'text'
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* @type { Object.<String, {editor: Object, data: String} > }
|
|
51
|
+
*/
|
|
52
|
+
JSONEditor.modes = {};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Create the JSONEditor
|
|
56
|
+
* @param {Element} container Container element
|
|
57
|
+
* @param {Object} [options] See description in constructor
|
|
58
|
+
* @param {Object | undefined} json JSON object
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
JSONEditor.prototype._create = function (container, options, json) {
|
|
62
|
+
this.container = container;
|
|
63
|
+
this.options = options || {};
|
|
64
|
+
this.json = json || {};
|
|
65
|
+
|
|
66
|
+
var mode = this.options.mode || 'tree';
|
|
67
|
+
this.setMode(mode);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Detach the editor from the DOM
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
74
|
+
JSONEditor.prototype._delete = function () {};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Set JSON object in editor
|
|
78
|
+
* @param {Object | undefined} json JSON data
|
|
79
|
+
*/
|
|
80
|
+
JSONEditor.prototype.set = function (json) {
|
|
81
|
+
this.json = json;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get JSON from the editor
|
|
86
|
+
* @returns {Object} json
|
|
87
|
+
*/
|
|
88
|
+
JSONEditor.prototype.get = function () {
|
|
89
|
+
return this.json;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Set string containing JSON for the editor
|
|
94
|
+
* @param {String | undefined} jsonText
|
|
95
|
+
*/
|
|
96
|
+
JSONEditor.prototype.setText = function (jsonText) {
|
|
97
|
+
this.json = util.parse(jsonText);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Get stringified JSON contents from the editor
|
|
102
|
+
* @returns {String} jsonText
|
|
103
|
+
*/
|
|
104
|
+
JSONEditor.prototype.getText = function () {
|
|
105
|
+
return JSON.stringify(this.json);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Set a field name for the root node.
|
|
110
|
+
* @param {String | undefined} name
|
|
111
|
+
*/
|
|
112
|
+
JSONEditor.prototype.setName = function (name) {
|
|
113
|
+
if (!this.options) {
|
|
114
|
+
this.options = {};
|
|
115
|
+
}
|
|
116
|
+
this.options.name = name;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Get the field name for the root node.
|
|
121
|
+
* @return {String | undefined} name
|
|
122
|
+
*/
|
|
123
|
+
JSONEditor.prototype.getName = function () {
|
|
124
|
+
return this.options && this.options.name;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Change the mode of the editor.
|
|
129
|
+
* JSONEditor will be extended with all methods needed for the chosen mode.
|
|
130
|
+
* @param {String} mode Available modes: 'tree' (default), 'view', 'form',
|
|
131
|
+
* 'text', and 'code'.
|
|
132
|
+
*/
|
|
133
|
+
JSONEditor.prototype.setMode = function (mode) {
|
|
134
|
+
var container = this.container,
|
|
135
|
+
options = util.extend({}, this.options),
|
|
136
|
+
data,
|
|
137
|
+
name;
|
|
138
|
+
|
|
139
|
+
options.mode = mode;
|
|
140
|
+
var config = JSONEditor.modes[mode];
|
|
141
|
+
if (config) {
|
|
142
|
+
try {
|
|
143
|
+
if (config.data == 'text') {
|
|
144
|
+
// text
|
|
145
|
+
name = this.getName();
|
|
146
|
+
data = this.getText();
|
|
147
|
+
|
|
148
|
+
this._delete();
|
|
149
|
+
util.clear(this);
|
|
150
|
+
util.extend(this, config.editor.prototype);
|
|
151
|
+
this._create(container, options);
|
|
152
|
+
|
|
153
|
+
this.setName(name);
|
|
154
|
+
this.setText(data);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
// json
|
|
158
|
+
name = this.getName();
|
|
159
|
+
data = this.get();
|
|
160
|
+
|
|
161
|
+
this._delete();
|
|
162
|
+
util.clear(this);
|
|
163
|
+
util.extend(this, config.editor.prototype);
|
|
164
|
+
this._create(container, options);
|
|
165
|
+
|
|
166
|
+
this.setName(name);
|
|
167
|
+
this.set(data);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (typeof config.load === 'function') {
|
|
171
|
+
try {
|
|
172
|
+
config.load.call(this);
|
|
173
|
+
}
|
|
174
|
+
catch (err) {}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
this._onError(err);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
throw new Error('Unknown mode "' + options.mode + '"');
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Throw an error. If an error callback is configured in options.error, this
|
|
188
|
+
* callback will be invoked. Else, a regular error is thrown.
|
|
189
|
+
* @param {Error} err
|
|
190
|
+
* @private
|
|
191
|
+
*/
|
|
192
|
+
JSONEditor.prototype._onError = function(err) {
|
|
193
|
+
// TODO: onError is deprecated since version 2.2.0. cleanup some day
|
|
194
|
+
if (typeof this.onError === 'function') {
|
|
195
|
+
util.log('WARNING: JSONEditor.onError is deprecated. ' +
|
|
196
|
+
'Use options.error instead.');
|
|
197
|
+
this.onError(err);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (typeof this.options.error === 'function') {
|
|
201
|
+
this.options.error(err);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
throw err;
|
|
205
|
+
}
|
|
206
|
+
};
|