Constructor
new Editor(parentopt, defaultCodeopt) → {Editor}
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
parent | JQuery.<HTMLElement> | <optional> | $("#editor") | Element to place editor on |
defaultCode | string | <optional> | "" | Element to place editor on |
Returns:
- New editor object
- Type:
- Editor
Example
const editor = new Editor()
const editor = new Editor($("#SOMEELEMENT")) // with parent
const editor = new Editor($("#SOMEELEMENT"), SOMECODEVAR) // with parent & default codeClasses
Methods
addCustomButton(e, backopt)
Adds an element to the editors buttons
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
e | JQuery.<HTMLElement> | Element to add | ||
back | boolean | <optional> | false | Place on the backside or frontside |
Example
editor.addCustomButton($("#SOMEELMT"))
editor.addCustomButton($("#SOMEELMT"), true) // adds to other sidedisableTerminal()
Disables the editors terminal
Example
editor.disableTerminal() // Terminal gets hiddenenableTerminal()
Enables the editors terminal
Example
editor.enableTerminal() // Terminal gets unhiddengetContent() → {string}
Gets the editors current content
Returns:
- Editors current content
- Type:
- string
Example
editor.getContent() // "Some string"safeEval(input, testopt)
Safely evaluate users js on the frontend with a test case added if wanted
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
input | string | Code to test | ||
test | string | <optional> | null | Test case or null for none |
Example
editor.saveEval(editor.getContent()) // tests current content
editor.saveEval(editor.getContent(), ";test == true") // tests current content with test casesetContent(input)
Sets editor content to a piece of code
Parameters:
| Name | Type | Description |
|---|---|---|
input | code | Code to set content to |
Example
editor.setContent("// This is some codes")