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 id
String Id of the element classes
Array Array of class names callback
function function(Boolean) -
clear(callback)
-
Clears the editor contents
Parameters:
Name Type Description callback
function function(Boolean) -
deleteElementById(id, callback)
-
Delete an element in the article
Parameters:
Name Type Description id
String Id of the element callback
function function(Boolean), called after deletion is done -
getActiveEditor(callback)
-
Get name of current active editor
Parameters:
Name Type Description callback
function function(String) -
getCategories(callback)
-
Get all categories
Parameters:
Name Type Description callback
function 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 callback
function function(String) -
getHTMLById(id, callback)
-
Get HTML code of an element
Parameters:
Name Type Description id
String The element id callback
function function(String), html content of the element -
getHTMLBySelector(selector, callback)
-
Get HTML code of all elements that match the selector
Parameters:
Name Type Description selector
String The CSS selector callback
function function([String]), html content of matching elements -
getParentCategories(category, callback)
-
Returns all the parent categories of the given category
Parameters:
Name Type Description category
Object The category to find parents of callback
function 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 id
String Id of element to find parents of selector
String Selector to filter parent elements with callback
function function([String]), array of ids -
getTagType(id, callback)
-
Get information about the given tagtype
Parameters:
Name Type Description id
String The element id callback
function function(Object Tagtype), tagtype object with id, name and config object -
getTagTypes(callback)
-
Retrieve information about all tagtypes
Parameters:
Name Type Description callback
function 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 callback
function 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 callback
function 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 menus
Array Array of menu names callback
function 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 element
Element The element that should be inserted options
Options/Function (can be omitted) Options object, supports option 'select' - set to true to automatically select the inserted element callback
function function(String), id of the newly inserted element -
insertString(string, callback)
-
Insert a string into the editor
Parameters:
Name Type Description string
String The string that should be inserted callback
function 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 id
String Id of the element callback
function function(Boolean) -
openPluginElementEditor(id)
-
Opens the plugin editor for a given element.
Parameters:
Name Type Description id
String 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 action
Object The action object callback
function 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 group
Object The action object callback
function 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 id
String Id of the element classes
Array Array of class names callback
function function(Boolean) -
replaceElementById(id, element, callback)
-
Replace an element in the article
Parameters:
Name Type Description id
String Id of the element element
String The new element callback
function 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 id
String The ID of the element to set the attribute on attribute
String The attribute to set value
String What to set the attribute to callback
function function(Boolean) -
setStyleById(id, attribute, value, callback)
-
Sets a style of the element with the given ID to value
Parameters:
Name Type Description id
String The ID of the element to set the attribute on attribute
String The style attribute to set value
String What to set the attribute to callback
function function(Boolean)