Implemented function `focus()` for tree, view, and form mode.

This commit is contained in:
jos 2015-03-02 20:51:03 +01:00
parent a6778ddebd
commit fcfac08fc3
6 changed files with 876 additions and 813 deletions

View File

@ -3,6 +3,11 @@
https://github.com/josdejong/jsoneditor https://github.com/josdejong/jsoneditor
## not yet released, version 4.1.0
- Implemented a function `focus()` for modes tree, view, and form.
## 2015-02-28, version 4.0.0 ## 2015-02-28, version 4.0.0
- Ace editor and jsonlint are now packed with jsoneditor.js by default. - Ace editor and jsonlint are now packed with jsoneditor.js by default.

1633
dist/jsoneditor.js vendored

File diff suppressed because it is too large Load Diff

2
dist/jsoneditor.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -54,6 +54,10 @@ Collapse all fields. Only applicable for mode 'tree', 'view', and 'form'.
Expand all fields. Only applicable for mode 'tree', 'view', and 'form'. Expand all fields. Only applicable for mode 'tree', 'view', and 'form'.
#### `JSONEditor.focus()`
Set focus to the JSONEditor.
#### `JSONEditor.set(json)` #### `JSONEditor.set(json)`
Set JSON data. Set JSON data.

View File

@ -178,6 +178,33 @@ treemode.getName = function () {
return this.options.name; return this.options.name;
}; };
/**
* Set focus to the editor. Focus will be set to:
* - the first editable field or value, or else
* - to the expand button of the root node, or else
* - to the context menu button of the root node, or else
* - to the first button in the top menu
*/
treemode.focus = function () {
var input = this.content.querySelector('[contenteditable=true]');
if (input) {
input.focus();
}
else if (this.node.dom.expand) {
this.node.dom.expand.focus();
}
else if (this.node.dom.menu) {
this.node.dom.menu.focus();
}
else {
// focus to the first button in the menu
input = this.frame.querySelector('button');
if (input) {
input.focus();
}
}
};
/** /**
* Remove the root node from the editor * Remove the root node from the editor
*/ */