This will be used by editor apps to communicate with the editor
Should be used like this:
PluginAPI.Editor.insertString('string');
Methods
-
addClasses(id, classes, callback)
-
Add new classes to an element
Parameters:
Name Type Description idString Id of the element classesArray Array of class names callbackfunction function(Boolean) -
clear(callback)
-
Clears the editor contents
Parameters:
Name Type Description callbackfunction function(Boolean) -
deleteElementById(id, callback)
-
Delete an element in the article
Parameters:
Name Type Description idString Id of the element callbackfunction function(Boolean), called after deletion is done -
getActiveEditor(callback)
-
Get name of current active editor
Parameters:
Name Type Description callbackfunction function(String) -
getCategories(callback)
-
Get all categories
Parameters:
Name Type Description callbackfunction function([Object Category]), list of Category objects with id, name and pid -
getEditorType(callback)
-
Retrieves the type of editor that currently has focus
Parameters:
Name Type Description callbackfunction function(String) -
getHTMLById(id, callback)
-
Get HTML code of an element
Parameters:
Name Type Description idString The element id callbackfunction function(String), html content of the element -
getHTMLBySelector(selector, callback)
-
Get HTML code of all elements that match the selector
Parameters:
Name Type Description selectorString The CSS selector callbackfunction function([String]), html content of matching elements -
getParentCategories(category, callback)
-
Returns all the parent categories of the given category
Parameters:
Name Type Description categoryObject The category to find parents of callbackfunction function([Object Category]), array of parent Category objects -
getParentIds(id, selector, callback)
-
Returns all the parent elements that match the selector
Parameters:
Name Type Description idString Id of element to find parents of selectorString Selector to filter parent elements with callbackfunction function([String]), array of ids -
getTagType(id, callback)
-
Get information about the given tagtype
Parameters:
Name Type Description idString The element id callbackfunction function(Object Tagtype), tagtype object with id, name and config object -
getTagTypes(callback)
-
Retrieve information about all tagtypes
Parameters:
Name Type Description callbackfunction function([Object Tagtype]), array of tagtypes with id, name and config object -
getTotalCharCount(callback)
-
Returns the total number of characters in the currently open article.
Parameters:
Name Type Description callbackfunction Receives the total character count as its single parameter -
getTotalWordCount(callback)
-
Returns the total number of words in the currently open article.
Parameters:
Name Type Description callbackfunction Receives the total word count as its single parameter -
initMenu(menus, callback)
-
Initialize pre registered menus Available options are: simplePluginMenu, editContext, deleteButton, floatButtons
Parameters:
Name Type Description menusArray Array of menu names callbackfunction function(Boolean) -
insertElement(element, options, callback)
-
Insert an element into the editor Note that the HTML of the element is what will be transferred, and nothing else! The element will be given the class dp-app-element, and given a unique ID (if none is present)
Parameters:
Name Type Description elementElement The element that should be inserted optionsOptions/Function (can be omitted) Options object, supports option 'select' - set to true to automatically select the inserted element callbackfunction function(String), id of the newly inserted element -
insertString(string, callback)
-
Insert a string into the editor
Parameters:
Name Type Description stringString The string that should be inserted callbackfunction function(String), id of the newly inserted element if it has one -
markAsActive(id, callback)
-
Mark an element as currently selected (green border with default styling)
Parameters:
Name Type Description idString Id of the element callbackfunction function(Boolean) -
openPluginElementEditor(id)
-
Opens the plugin editor for a given element.
Parameters:
Name Type Description idString Plugin element ID -
registerMenuAction(action, callback)
-
Registers/Modifies a context menu items for a app element The object send should have the following structure
Parameters:
Name Type Description actionObject The action object callbackfunction function() Example
PluginAPI.Editor.registerMenuAction({ label: 'label in the menu', icon: '[Optional] url to possible icon image', trigger: '[Optional] css selector, only show menu element when this matches the element', callback: function(id, clickedElementId) { // callback function // first parameter is id of the app element // second paramter is id of closest element to the trigger element that has an id // in code: $(event.triggerElement).closest('[id]').attr('id'); } }) -
registerMenuActionGroup(group, callback)
-
Registers/Modifies a group of items to in the context menu The object send should have the following structure
Parameters:
Name Type Description groupObject The action object callbackfunction function() Example
PluginAPI.Editor.registerMenuActionGroup({ label: 'label for the group in the menu', icon: '[Optional] url to possible icon image', actions: [ { label: 'label for the action #1', callback: function(id, clickedElementId) { // same as for registerMenuAction } }, { label: 'label for the action #2', callback: function(id, clickedElementId) { // same as for registerMenuAction } } ] }) -
removeClasses(id, classes, callback)
-
Remove classes from the element an element in the article
Parameters:
Name Type Description idString Id of the element classesArray Array of class names callbackfunction function(Boolean) -
replaceElementById(id, element, callback)
-
Replace an element in the article
Parameters:
Name Type Description idString Id of the element elementString The new element callbackfunction function(Boolean), called after replacement is done -
setAttributeById(id, attribute, value, callback)
-
Sets the attribute of the element with the given ID to value
Parameters:
Name Type Description idString The ID of the element to set the attribute on attributeString The attribute to set valueString What to set the attribute to callbackfunction function(Boolean) -
setStyleById(id, attribute, value, callback)
-
Sets a style of the element with the given ID to value
Parameters:
Name Type Description idString The ID of the element to set the attribute on attributeString The style attribute to set valueString What to set the attribute to callbackfunction function(Boolean)