Remove activationChar, update documentation.
This commit is contained in:
parent
00ba443acf
commit
4036f5cd28
|
@ -161,10 +161,6 @@ Constructs a new JSONEditor.
|
|||
|
||||
Indicate where the autocomplete is going to be activated, under field in json node or/and under value in a json node, default is: ['field','value']
|
||||
|
||||
- `{string} activationChar`
|
||||
|
||||
This is a single char string, indicates that the text should starts with this char in order to process and display the autocompletion, a typical example is in some editors you type '@' and then you see a dropdownbox where you can link to an specific author.
|
||||
|
||||
- `{Function} getOptions (autocomplete, node, text, elementType)`
|
||||
|
||||
This function will return your possible options for create the autocomplete selection, you can control dynamically which options you want to display according to the current active editing node.
|
||||
|
|
|
@ -32,19 +32,20 @@
|
|||
|
||||
<script>
|
||||
// create the editor
|
||||
var container = document.getElementById('jsoneditor');
|
||||
var container = document.getElementById('jsoneditor');
|
||||
var activationChar = '*';
|
||||
var options = {
|
||||
modes: ['text', 'tree'],
|
||||
autocomplete: {
|
||||
confirmKeys: [39, 35, 9, 190], // Confirm Autocomplete Keys: [right, end, tab, '.'] // By default are only [right, end, tab]
|
||||
activationChar: '*', // ActivationChar indicate if the value starts with this Char then autocompletion will be activated. ('' will be ignored).
|
||||
applyTo:['value'],
|
||||
getOptions: function (autocomplete, node, text) {
|
||||
if (!text.startsWith(activationChar)) return [];
|
||||
var data = {};
|
||||
autocomplete.startFrom = 0;
|
||||
var lastPoint = text.lastIndexOf('.');
|
||||
if ((lastPoint > 0) && (text.length > 1)) {
|
||||
var fnode = node.editor.node.findNode('.' + text.substring(this.activationChar.length, lastPoint));
|
||||
var fnode = node.editor.node.findNode('.' + text.substring(activationChar.length, lastPoint));
|
||||
if (fnode && typeof fnode.getValue() == 'object') {
|
||||
data = fnode.getValue();
|
||||
// Indicate that autocompletion should start after the . (ignoring the first part)
|
||||
|
@ -54,13 +55,13 @@
|
|||
else
|
||||
data = node.editor.get();
|
||||
|
||||
var optionsStr = YaskON.stringify(data, null, this.activationChar);
|
||||
var optionsStr = YaskON.stringify(data, null, activationChar);
|
||||
var options = optionsStr.split("\n");
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var YaskON = {
|
||||
// Return first level json paths by the node 'o'
|
||||
stringify: function (o, prefix, activationChar) {
|
||||
|
@ -89,6 +90,7 @@
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
var json = {
|
||||
'array': [{ 'field1': 'v1', 'field2': 'v2' }, 2, 3],
|
||||
'boolean': true,
|
||||
|
|
|
@ -1111,28 +1111,24 @@ treemode._onKeyDown = function (event) {
|
|||
if (event.target.className.indexOf("jsoneditor-value") >= 0) jsonElementType = "value";
|
||||
if (event.target.className.indexOf("jsoneditor-field") >= 0) jsonElementType = "field";
|
||||
|
||||
if ((this.options.autocomplete.applyTo.indexOf('value') >= 0 && jsonElementType == "value") ||
|
||||
if ((this.options.autocomplete.applyTo.indexOf('value') >= 0 && jsonElementType == "value") ||
|
||||
(this.options.autocomplete.applyTo.indexOf('field') >= 0 && jsonElementType == "field")) {
|
||||
var node = Node.getNodeFromTarget(event.target);
|
||||
if (this.options.autocomplete.activationChar == null || event.target.innerText.startsWith(this.options.autocomplete.activationChar)) { // Activate autocomplete
|
||||
setTimeout(function (hnode, element) {
|
||||
if (element.innerText.length > 0) {
|
||||
var result = this.options.autocomplete.getOptions(this.autocomplete, hnode, element.innerText, jsonElementType);
|
||||
if (typeof result.then === 'function') {
|
||||
// probably a promise
|
||||
if (result.then(function (options) {
|
||||
this.autocomplete.show(element, options);
|
||||
}.bind(this)));
|
||||
} else {
|
||||
// definitely not a promise
|
||||
this.autocomplete.show(element, result);
|
||||
}
|
||||
}
|
||||
else
|
||||
this.autocomplete.hideDropDown();
|
||||
|
||||
}.bind(this, node, event.target), 100);
|
||||
// Activate autocomplete
|
||||
if (event.target.innerText.length > 0) {
|
||||
var result = this.options.autocomplete.getOptions(this.autocomplete, node, event.target.innerText, jsonElementType);
|
||||
if (typeof result.then === 'function') {
|
||||
// probably a promise
|
||||
if (result.then(function (options) {
|
||||
this.autocomplete.show(event.target, options);
|
||||
}.bind(this)));
|
||||
} else {
|
||||
// definitely not a promise
|
||||
this.autocomplete.show(event.target, result);
|
||||
}
|
||||
}
|
||||
else
|
||||
this.autocomplete.hideDropDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue