Implemented function `focus()` for tree, view, and form mode.
This commit is contained in:
parent
a6778ddebd
commit
fcfac08fc3
|
@ -3,6 +3,11 @@
|
|||
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
|
||||
|
||||
- Ace editor and jsonlint are now packed with jsoneditor.js by default.
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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'.
|
||||
|
||||
#### `JSONEditor.focus()`
|
||||
|
||||
Set focus to the JSONEditor.
|
||||
|
||||
#### `JSONEditor.set(json)`
|
||||
|
||||
Set JSON data.
|
||||
|
|
|
@ -178,6 +178,33 @@ treemode.getName = function () {
|
|||
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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue