adjust public methods to camelCase and refine examples.

This commit is contained in:
Israel Garcia 2017-05-31 17:53:24 -04:00
parent 5411ad19ac
commit 0391ad11b4
4 changed files with 16 additions and 15 deletions

View File

@ -36,8 +36,8 @@
var options = {
modes: ['text', 'tree'],
autocomplete: {
ApplyTo:['name','value'], // This indicates the autocomplete is going to be applied to json properties names and values.
GetOptions: function () {
applyTo:['name','value'], // This indicates the autocomplete is going to be applied to json properties names and values.
getOptions: function () {
return ["apple","cranberry","raspberry","pie"];
}
}

View File

@ -36,8 +36,8 @@
var options = {
modes: ['text', 'tree'],
autocomplete: {
ApplyTo:['value'],
GetOptions: function (autocomplete, node, text) {
applyTo:['value'],
getOptions: function (autocomplete, node, text) {
// Return all strings in json
function stringify(o, prefix) {

View File

@ -25,6 +25,7 @@
<body>
<p>
This example demonstrates how to autocomplete works with an ActivationChar option, press "*" in any value and continue with autocompletion.
The autocomplete returns the posible jsonpaths of the existing json document.
</p>
<div id="jsoneditor"></div>
@ -35,12 +36,12 @@
var options = {
modes: ['text', 'tree'],
autocomplete: {
Config: {
config: {
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) {
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) {
var YaskON = {
// Return first level json paths by the node 'o'
@ -74,7 +75,7 @@
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(this.activationChar.length, lastPoint));
if (fnode && typeof fnode.getValue() == 'object') {
data = fnode.getValue();
// Indicate that autocompletion should start after the . (ignoring the first part)
@ -84,7 +85,7 @@
else
data = node.editor.get();
var optionsStr = YaskON.stringify(data, null, this.ActivationChar);
var optionsStr = YaskON.stringify(data, null, this.activationChar);
var options = optionsStr.split("\n");
return options;

View File

@ -53,7 +53,7 @@ treemode.create = function (container, options) {
this._setOptions(options);
if (options.autocomplete)
this.autocomplete = new autocomplete(options.autocomplete.Config);
this.autocomplete = new autocomplete(options.autocomplete.config);
if (this.options.history && this.options.mode !== 'view') {
this.history = new History(this);
@ -1107,13 +1107,13 @@ treemode._onKeyDown = function (event) {
if ((this.options.autocomplete) && (!handled)) {
if (!ctrlKey && !altKey && !metaKey && (event.key.length == 1 || keynum == 8 || keynum == 46)) {
handled = false;
if ((this.options.autocomplete.ApplyTo.indexOf('value') >= 0 && event.target.className.indexOf("jsoneditor-value") >= 0) ||
(this.options.autocomplete.ApplyTo.indexOf('name') >= 0 && event.target.className.indexOf("jsoneditor-field") >= 0)) {
if ((this.options.autocomplete.applyTo.indexOf('value') >= 0 && event.target.className.indexOf("jsoneditor-value") >= 0) ||
(this.options.autocomplete.applyTo.indexOf('name') >= 0 && event.target.className.indexOf("jsoneditor-field") >= 0)) {
var node = Node.getNodeFromTarget(event.target);
if (this.options.autocomplete.ActivationChar == null || event.target.innerText.startsWith(this.options.autocomplete.ActivationChar)) { // Activate autocomplete
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 options = this.options.autocomplete.GetOptions(this.autocomplete, hnode, element.innerText);
var options = this.options.autocomplete.getOptions(this.autocomplete, hnode, element.innerText);
if (options.length > 0)
this.autocomplete.Show(element, options);
}