Skip to content
This repository was archived by the owner on Oct 27, 2025. It is now read-only.

Javascript API

t-animal edited this page Dec 1, 2015 · 9 revisions

Javascript API (THIS IS STILL A DRAFT!)

Method Summary

close(doc)

Closes the currently opened document

Parameters:

  • doc CMEditor.Doc (optional): if supplied this document will be closed else the current document

deleteDoc()

Deletes the currently opened document asks for confirmation first


diff(additionalButtons, defaultButton)

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 the options.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

Related Projects

  • 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

Clone this wiki locally