Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
b6e34ea476
|
@ -162,7 +162,7 @@ JSONEditor.VALID_OPTIONS = [
|
|||
'ajv', 'schema', 'schemaRefs','templates',
|
||||
'ace', 'theme', 'autocomplete',
|
||||
'onChange', 'onChangeJSON', 'onChangeText',
|
||||
'onEditable', 'onError', 'onEvent', 'onModeChange', 'onValidate',
|
||||
'onEditable', 'onError', 'onEvent', 'onModeChange', 'onNodeName', 'onValidate',
|
||||
'onSelectionChange', 'onTextSelectionChange',
|
||||
'colorPicker', 'onColorPicker',
|
||||
'timestampTag',
|
||||
|
|
|
@ -2458,13 +2458,12 @@ Node.prototype.updateDom = function (options) {
|
|||
// apply value to DOM
|
||||
var domValue = this.dom.value;
|
||||
if (domValue) {
|
||||
var count = this.childs ? this.childs.length : 0;
|
||||
if (this.type == 'array') {
|
||||
domValue.innerHTML = '[' + count + ']';
|
||||
this.updateNodeName();
|
||||
util.addClassName(this.dom.tr, 'jsoneditor-expandable');
|
||||
}
|
||||
else if (this.type == 'object') {
|
||||
domValue.innerHTML = '{' + count + '}';
|
||||
this.updateNodeName();
|
||||
util.addClassName(this.dom.tr, 'jsoneditor-expandable');
|
||||
}
|
||||
else {
|
||||
|
@ -4464,6 +4463,46 @@ Node.prototype._escapeJSON = function (text) {
|
|||
return escaped;
|
||||
};
|
||||
|
||||
/**
|
||||
* update the object name according to the callback onNodeName
|
||||
* @private
|
||||
*/
|
||||
Node.prototype.updateNodeName = function () {
|
||||
try {
|
||||
var count = this.childs ? this.childs.length : 0;
|
||||
var nodeName;
|
||||
if (this.type === 'object' || this.type === 'array') {
|
||||
nodeName = this.editor.options.onNodeName({
|
||||
path: this.getPath(),
|
||||
size: count,
|
||||
type: this.type
|
||||
});
|
||||
this.dom.value.innerHTML = (this.type === 'object')
|
||||
? '{' + (nodeName || count) + '}'
|
||||
: '[' + (nodeName || count) + ']';
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.error('Error in onNodeName callback: ', err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* update recursively the object's and its children's name.
|
||||
* @private
|
||||
*/
|
||||
Node.prototype.recursivelyUpdateNodeName = function () {
|
||||
if (this.expanded) {
|
||||
this.updateNodeName();
|
||||
if (this.childs !== 'undefined') {
|
||||
var i;
|
||||
for (i in this.childs) {
|
||||
this.childs[i].recursivelyUpdateNodeName();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to get the internal path of a node
|
||||
function getInternalPath (node) {
|
||||
return node.getInternalPath();
|
||||
|
|
|
@ -549,6 +549,15 @@ treemode._onChange = function () {
|
|||
console.error('Error in onChangeText callback: ', err);
|
||||
}
|
||||
}
|
||||
|
||||
// trigger the onNodeName callback
|
||||
if (this.options.onNodeName && this.node.childs) {
|
||||
try {
|
||||
this.node.recursivelyUpdateNodeName();
|
||||
} catch (err) {
|
||||
console.error("Error in onNodeName callback: ", err);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue