Namespace for all public DrPublish methods available from apps.
Methods
callExtendedApi(group, name, data, callback)
Call the extended PluginAPI
Parameters:
Name
Type
Description
group
String
Group name for functionality to call
name
String
Name of the specific function to call
data
Object
Data object to pass as parameter to the api call
callback
function
function(Object) Function to recieve the API response, parameter is the response from the API call
clearRequiredActionCounter(callback)
Clear the counter of actions required by the user, used to tell the user that the plugin requires input of some kind
Parameters:
Name
Type
Description
callback
function
function(Object) function to call once the counter has been cleared
closeModal(destroy)
Closes and optionally deletes the modal. Has no effect if the modal does not exists.
Parameters:
Name
Type
Description
destroy
Boolean
Whether or not to delete the modal
Returns:
Type
Boolean
convertDomToHTML(dom)
Generates proper html code to represent the dom element. This is NOT an asynchronous function
Parameters:
Name
Type
Description
dom
Object
The dom node to convert
Returns:
The html code
Type
String
createEmbeddedObject(typeId, callback)
Create an embedded object of the given type
Parameters:
Name
Type
Description
typeId
Number
Type Id of the embedded object to create
callback
function
function(embeddedObjectId) called once the object has been created, first parameter is the new embedded object id
createModal(content, options)
Creates a jQuery UI modal in the main editor window, detached from the plugin itself. Modals are unique on a
per-plugin basis, meaning that a plugin can only have a single modal at a time. Creating a new modal will
overwrite the previous.
PluginAPI.createModal('<h1>This is a modal</h1>', {
buttons: {
Ok: function () {
alert('Ok!');
}
}
});
PluginAPI.updateModal('<h1>This is the same modal</h1>');
PluginAPI.createModal('<h1>This is a brand new modal</h1>', {
buttons: {
cancel: function() {
PluginAPI.closeModal(true);
}
}
});
createTag(tag, callback)
Creates a new tag
Parameters:
Name
Type
Description
tag
String
JSON object with the tag to create, must contain tagTypeId and name properties
callback
function
function(Boolean)
decreaseRequiredActionCounter(callback)
Decrease the counter of actions required by the user, used to tell the user that the plugin requires input of some kind
Parameters:
Name
Type
Description
callback
function
function(Object) function to call once the counter has been decrease, returns current counter value
emit(name, data)
Emits an event to DrPublish, and possibly other apps
Parameters:
Name
Type
Description
name
String
Name of the event
data
String
Data object to send with the event
extendApi(group, name, action)
Extends the PluginAPI with custom functionality that other apps can use
Parameters:
Name
Type
Description
group
String
Group name for functionality to add
name
String
Name of the specific function to add
action
function
function(Object) Function to call when the API is invoked, recieves one parameter as given in PluginAPI.callExtendedApi and return value is passed back to the caller
generateArticleUrl(id, callback)
Generates an url to a published article
Parameters:
Name
Type
Description
id
String
The id of the article to generate url for
callback
function
function(String), where the parameter is the generated url
getAppName()
Get the name of the loaded app
Returns:
The name of the app, or false if it couldn't be detected
Type
String
getConfiguration(callback)
Get configuration information about the app
Parameters:
Name
Type
Description
callback
function
function(Object)
getCurrentUser(callback)
Gets logged in user
Parameters:
Name
Type
Description
callback
function
function(Object)
getDrPublishConfiguration(callback)
Get DrPublish configuratin
Parameters:
Name
Type
Description
callback
function
function(Object)
getEmbeddedObjectTypes(callback)
Get information about the available embedded object types
Parameters:
Name
Type
Description
callback
function
function([Object]) recieves an array with objects describing the available embedded object types in the form of `{typeId: 'embedded object type id', cssClass: 'css class used to style the objects'}`
getModalInputs(callback)
Returns the values of all input or select elements within a modal.
The values are keyed by one of the following properties in order of priority: element ID, element name
or input type + index.
Parameters:
Name
Type
Description
callback
function
Example
Given a modal with the following HTML content:
<form>
<input type="number">
<input name="name" type="text">
<select id="languages">
<option selected>en</option>
<option>no</option>
</select>
</form>
getModalInputs would return:
{
"number-0": {VALUE}
"name": {VALUE},
"languages": "en"
}
giveFocus(pluginName, argument, start)
Gives focus to another plugin
Parameters:
Name
Type
Description
pluginName
String
The name of the plugin to recieve focus
argument
Object
Optional option argument to pass along to the plugin recieving focus
start
Boolean
Flag to decide if the plugin should be started if it has not been loaded previously, default true
Returns:
Type
Boolean
hide()
Hide the plugin, so it is no longer visible on the list of open plugins
Returns:
Type
Boolean
hideLoader()
Hide the loader
increaseRequiredActionCounter(callback)
Increase the counter of actions required by the user, used to tell the user that the plugin requires input of some kind
Parameters:
Name
Type
Description
callback
function
function(Object) function to call once the counter has been increased, returns the new counter value
on(name, callback)
Listen for an event. If the callback returns false the event may cancel continued actions, e.g beforeSave can cancel article save. Look at documentation for Listeners to learn more.
Parameters:
Name
Type
Description
name
String
Name of the event
callback
function
function(Object) Function to call when the event is triggered. Recieves one data object parameter of the form {source: , data: }
openTagCreationDialog(tag, callback)
Creates a new tag
Parameters:
Name
Type
Description
tag
String
The tag to create
callback
function
function(Boolean)
reloadIframe()
Reloads the app's iframe
request(callSpec, data, callback)
Dispatches a request to DrPublish, and returns the reply to callback On error, notifies all error listeners based on the index .type of the thrown object
Parameters:
Name
Type
Argument
Description
callSpec
String
What do you want to call?
data
Object
The data attached to the request
callback
function
<optional>
The function to call upon return
searchDrLib(data, callback)
Sends a query to DrLib
Parameters:
Name
Type
Description
data
Object
Object with three properties; 'query' which is the query to send to DrLib, 'success' which is the callback to execute on success, and 'secure' a boolean to add the internal API key to the query and thus allow searching on unpublished article. This callback's parameter is an object which is the query result as an object. See the json output of DrLib to learn more about this object
Object, can have three keys.
'onlyPublication' (boolean) If true the configuration is set for the current publication only
'success' (function) Called if the configuration was saved successfully
'error' (function) Called if there was an error, recieves and error object as first parameter
callback
function
function()
setRequiredActionCounter(count, callback)
Set the counter of actions required by the user, used to tell the user that the plugin requires input of some kind
Parameters:
Name
Type
Description
count
Number
The value to set the counter to
callback
function
function(Object) function to call once the counter has been cleared
showErrorMsg(msg)
Show error-message to the user
Parameters:
Name
Type
Description
msg
String
Message to be displayed
showInfoMsg(msg)
Show info-message to the user
Parameters:
Name
Type
Description
msg
String
Message to be displayed
showLoader(msg)
Show the loader
Parameters:
Name
Type
Description
msg
String
Message to display in progress loader
showWarningMsg(msg)
Show warning-message to the user
Parameters:
Name
Type
Description
msg
String
Message to be displayed
updateModal(content)
Updates the HTML content of a live modal. Has no effect if the modal does not exist.