Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to customize the submenu of Insert? (tree editor) #377

Closed
ShaiTeller opened this issue Mar 25, 2017 · 2 comments
Closed

How to customize the submenu of Insert? (tree editor) #377

ShaiTeller opened this issue Mar 25, 2017 · 2 comments
Labels

Comments

@ShaiTeller
Copy link

ShaiTeller commented Mar 25, 2017

jsoneditor - class

I would like to add "class" in the submenu of Insert. I managed to do that by changing the code in jsoneditor.min.js (adding it to the submenu of Insert)

, { // THIS HAS BEEN CHANGED
                        text: "Class",
                        className: "jsoneditor-type-object",
                        title: r.class,
                        click: function() {
                            i._onInsertBefore("", {})
                        } //

now some of the things I dont understand how to do (from most important to least):

  1. Change the function that happens when i click on it (as in inserting a class), inserting a class in my example would be to insert an object that has 2 objects in it already (2 empty strings) of module and path. example:
    jsoneditor - class2

It would create a new instance of a class object (the values of the fields would be empty at first).

From what i saw it calls the function _onInsertBefore so i tried to find the implementation of the function and found this: (line 5927 when unminified)

n.prototype._onInsertBefore = function(e, t, i) { var r = this.editor.getSelection(), o = new n(this.editor, { field: void 0 != e ? e : "", value: void 0 != t ? t : "", type: i }); o.expand(!0), this.parent.insertBefore(o, this), this.editor.highlighter.unhighlight(), o.focus("field"); var s = this.editor.getSelection(); this.editor._onAction("insertBeforeNodes", { nodes: [o], beforeNode: this, parent: this.parent, oldSelection: r, newSelection: s }) }

but not really sure what exactly needs to be changed in order to do what I want to do.

  1. How do I change the icon? I dont understand how each element gets a different icon in the code.

Any chance for some guidance? (I hope I made it clear enough)

@ShaiTeller
Copy link
Author

ShaiTeller commented Mar 25, 2017

OK I just changed the object that gets passed:

, { // THIS HAS BEEN CHANGED
                        text: "Class",
                        className: "jsoneditor-type-object",
                        title: r.class,
                        click: function() {
                            i._onInsertBefore("", {module: "", class: ""})
                        } //

i._onInsertBefore("", {module: "", class: ""})

that solved question 1.

@josdejong
Copy link
Owner

Customizing the context menu isn't supported, though you may be able to hack something in the code of the editor.

Related issues: #267, #337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants