-
Notifications
You must be signed in to change notification settings - Fork 1
Javascript API
Returns an instance of this class. This is not a factory method, but the instance has to be initialised beforehand, usually by using a <cmeditor:
-Tag in a grails template.
Parameters:
- identifier (String|Number): the instance name or number
Returns all instances of this class
Call these methods on a menu, which you can get by calling CMEditor.getInstance('instancename').menu
or by CMEditorMenu.getInstance('instancename')
.
Appends an entry to the menu bar
Parameters:
- menuName String: the new menu's name
Returns: A handle which can be used to add new submenu entries with addSubMenuEntry
Appends a submenu entry to the menu bar
Parameters:
- superMenu Object: a handle returned by this method or
addRootMenuEntry
- menuName String: the new menu entry's name
- callbackFunction function (optional): if supplied, this function will be called when the entry is clicked
Returns: A handle which can be used to add new sub-submenu entries with this method
Update the menu entries which depend on the corresponding CMEditor instance (e.g. mode)
Returns an instance of this class. This is not a factory method, but the instance has to be initialised beforehand, usually by using a <cmeditor:
-Tag in a grails template.
Parameters:
- identifier (String|Number): the instance name or number
Returns all instances of this class
Can be used to register callbacks for events statically (i.e. for all instances)
Events in CMEditor which can be set only statically:
preMenuInit: Fired before the menu of this CMEditor is initiated, i.e. before its constructor is called
Your callback will be called in the context of the menu's root element
postMenuInit: Fired after the menu of this CMEditor is initiated, i.e. after its constructor has been called
Your callback will be called in the context of the menu's root element and passed the menu object as first
argument
preInitialization: Fired inside the constructor of the CMEditor, after a minimal state of the object was created
Your callback will be called in the context of the CMEditor to be created and it will be passed the same arguments
as the constructor (the rootElement, the options and the instance name)
postInitialization: Fired inside the constructor of the CMEditor, after any other instruction was executed (right before return)
Your callback will be called in the context of the CMEditor to be created and it will be passed the same arguments
as the constructor (the rootElement, the options and the instance name)
Parameters:
- eventName String: the event's name as mentioned above
- hook Function: the function to call
- nameFilter String (optional): execute only for instances whose name matches this String
Call these methods on a CMEditor isntance, which you can get by calling CMEditor.getInstance('instancename')
Closes the currently opened document
Parameters:
-
doc
CMEditor.Doc
(optional): if supplied this document will be closed else the current document
Deletes the currently opened document asks for confirmation first
Shows a diff of the current document.
Parameters:
-
additionalButtons
Object: The keys are the button labels and the values are the callbacks for when the associated button is clicked. -
defaultButton
function (optional): if supplied, this function will be called when the user hits enter while the dialog has focus
###displayMessage(message)
Displays a message for 3 seconds
Parameters:
-
message
String: The message to be displayed
###exportDoc()
Exports the current document as a download
###focus()
Sets focus to the text editor
###getCurDoc()
Returns the currently opened CMEditor.Doc
###getCurrentCMEditorMode()
Returns the mode in which the current document is opened
###getUnambiguousName(name, folder)
Appends a number to a filename so that it is unambigous
Parameters:
- name String: The name of the document
- folder String (optional): if supplied, will only search for collisions within this directory;
null
matches all folders
###getCodeMirror()
Returns the underlying codeMirror instance
###importDoc(fileName, fileContent, fileMode)
Imports a file into the editor
Parameters:
-
fileName
String: the filename of the document to import -
fileContent
String: the content of the file to import -
fileMode
String (optional): if set the file will have this mode, else theoptions.default
mode
###isReadOnly()
Returns whether the whole editor is read only
###moveDoc(newFolder)
Moves the current file to another folder
###newDoc(fileName, folder)
Creates a new document with a name supplied by the user
Parameters:
-
fileName
String: the new filename -
folder
String: the folder (or null)
###on(eventName, hook)
Can be used to register callbacks for events.
Available Events in CMEditor: Where not noted otherwise the Callbacks are executed in the context of the CMEditor (i.e. 'this' points to the CMEditor instance). The post-Hooks might not be called if an error occurs (e.g. server is unreachable)
preSerializeDoc: Fired before the content of the current document is serialized to the form used to send the data to server.
Basically this happens everytime something in the document changes.
Arguments: <The current document>
postSerializeDoc: Fired after the content of the current document is serialized to the form used to send the data to server.
Basically this happens everytime something in the document changes.
Arguments: <The current document>
preDeleteDoc: Fired when the user requests deleting the current document (this.state.curDoc).
postDeleteDoc: Fired when the user requests document deletion, after all user interaction has been performed and the deletion
was triggered (i.e. `prePerformDeleteDoc` was fired)
prePerformDeleteDoc: Fired before the request to delete a document is sent to the server.
postPerformDeleteDoc: Fired after the request to delete a document was executed by the server (successfully or unsuccessfully).
Arguments: <The data sent to the server>, <The server's response>
preCloseDoc: Fired when the user requests closing a document. Arguments: <The document to close>
postCloseDoc: Fired when the user requests closing a document, after all user interaction was performed and the document was closed
Arguments: <The document which was closed>
preSaveDoc: Fired when the user requests saving the current document (this.state.curDoc)
postSaveDoc: Fired when the user requests document saving, after all user interaction has been performed and the saving was
triggered (i.e. `prePerformSaveDoc` was fired).
prePerformSaveDoc: Fired before the request to save a document is sent to the server. Arguments: <The data to send>
postPerformSaveDoc: Fired after the request to save a document was executed by the server (successfully or unsuccessfully).
Arguments: <The data sent to the server>, <The server's response>
preOpenDoc: Fired when the user requests opening a document. Arguments: <The fileId to open>
postOpenDoc: Fired after a document was opened. Arguments: <The document which was opened>
prePerformLoadDoc: Fired before a document is (re-)loaded from the server. This happens on opening or saving a document.
Arguments: <The data to send to the server>
postPerformLoadDoc: Fired after a document was (re-)loaded from the server. This happens on opening or saving a document.
Arguments: <The data to sent to the server>, <The server's response>
preEnterFullscreen: Fired before entering fullscreen mode, before any layout changes occur.
postEnterFullscreen: Fired after the layout was reset for fullscreen mode.
preLeaveFullscreen: Fired before leaving fullscreen mode, before any layout changes occur.
postLeaveFullscreen: Fired after the layout was reset for non-fullscreen mode.
###open(fileId, readWrite)
Opens a file if it is not opened yet
Parameters:
- fileId Integer: The id of the file
- readWrite Boolean: If true document will always be writable, else it will be readOnly if options.readOnly or options.defaultReadOnly is set to true
###rename(newName)
Renames the currently opened document. Shows an error message if the document is read only
Parameters:
- newName String: the new name of the document
###save()
Saves the currently opened document. If it is opened read-only only displays a dialog.
###saveas()
Prompts the user for a filename, renames the current document and then saves it
###setDoDiffBeforeSaving(value)
Sets whether this CMEditor should show a diff before it saves
###setMode(mode)
Sets the mode (CM lingo for filetype) of the current document; triggers loading the mode first if necessary
Parameters:
- mode (String): The name of the mode to set
###toggleFullscreen()
Enters or leaves fullscreen mode
###update()
Updates mode and read-onlyness of the current document to the corresponding properties of the underlying codeMirror
###writeCurrentDocToForm()
Serializes the currently opened document to the editor's form
- Grails CMEditor Demo: A very simple demo application
- Cedit: A larger application using multiple CMEditors for dynamic scripts, templates and DSLs in a Grails application