Global objects API

Contents


Objects

Name Description
Command

Command is an interface for extending the toolbar with your own commands. You must supply the Editor.addCommand method with an object that implements these methods. Note that you only need to implement that methods you need, since Xopus internally extends a base class with the object you supply.

Editor

Editor is a global object that represents the Xopus editor.

Editor.Canvas

Editor.Canvas is a namespace for methods related to Xopus Canvasses.

Editor.ChangeTracking

This object represents the change tracking module of Xopus.

Editor.Selection

The selection object provides a way to talk to Xopus's selection, range and cursor.

Editor.XML

This object is a namespace for XML related methods.

EmbeddedXopus

When you are running Xopus embedded in an <iframe>, odds are that you would like to communicate with the Xopus running in the frame, telling it what document to load for example. When you include the xopus/embedded.js a new global object will be available: EmbeddedXopus. It distributes the Editor object from your Xopus frames available in their parent frames.

HTTPTools

The global HTTPTools object provides a library of HTTP communication functions that can be used for accessing documents, xincludes or schema files in API functions such as IO.setLoadXML or IO.setLoadXSDFunction.

IO

IO is a global object that provides helper functions for interaction between Xopus and your web server.

ModalDialog

The ModalDialog object can be used to show and control a generic dialog window that displays any html page.

Scope

Scope objects can be used to store command state across command invocations.

WebDAVTools

It is possible to save documents to a server with WebDAV support. When using the WebDAV, you have to make sure that the web application has the right to access the files on your server. You also have to check that it is possible to set a cookie on the clients browser.

XopusCanvas

The XopusCanvas object is interface to a Xopus Canvas (a <div xopus="true"> element).

Methods

Command Methods

Name Description
configure

Initial setup of the command. Declare scope variables here.

execute

Execute the command

getAvailable

Returns true when the user can use the command. Unavailable commands are hidden from the user interface.

getChecked

A command is checked then the button looks activated. For example the bold command is checked when the text at the cursor is bold.

getEnabled

A command is enabled when the user can click on it. Disabled commands are grayed out.

getLabel

Command.getLabel returns the string label for the command.

getShortcuts

Returns an array of keyboard shortcuts for this command.

Editor Methods

Name Description
addCommand

Registers a command object with the editor. You can reference the command from a user interface component such as a custom toolbar button.

addEventListener

Add listeners to the load, unload, afterRedraw, loadError, XopusLoaded and XopusUnloaded events.

addSimpleListener

Deprecated. Use Editor.addEventListener instead.

alert

This is supposed to be a non-blocking alternative to the browsers' alert() function which blocks all scripts from running while the message is shown.

closeAttributesEditor

Closes the property panel / Attributes editor. This method can be used in conjunction with node.openAttributesEditor()

exit

This method is part of the Xopus public API and is used to exit Xopus if the exit URI has been set. If the URI has not been set, this function does nothing. In order to set the exit URI you can use the setExitURL method.

getActiveCanvas

Retrieve the currently active Xopus canvas or null when not one is active.

getActiveDocument

Get the document that the user is currently editing.

getCanvasCollection

Retrieve a collection containing all current Xopus canvasses.

getCommand

This method can be used to retrieve a command object.

getExitFunction

Retrieve the current exit Function. This Function is called when the user presses the exit button.

getExitURL

Retrieve the current exit URL. This URL is used when the user presses the exit button.

getHTMLElementsForXMLNode

Get all HTML representations for the given XML node. Beware, this function will return all elements, not subtrees. These HTML elements where rendered by the XSL while the given XML node was the context node.

getModalDialog

Retrieve the ModalDialog object, to show a generic dialog.

getScope

This return the Scope Object.

getSymbols

This function returns the array of symbols currently in use in "Insert Character" menu.

getUILanguage

This method returns the currently set UI language.

getURL

Retrieve the URL currently loaded in the Xopus content frame.

getVersion

This method returns the Xopus version string, 4.2 for example.

getXMLNodeForHTMLElement

Retrieve the XML node that was the context node in XSL for the given HTML output element.

hide

When Xopus runs inside in an iframe element, it will replace the xopusVisible class name with xopusHidden. This does require the xopusVisible class name to be set already.

loadDefaultConfig

Tell Xopus to load the default-config.xml file. Versions of Xopus before 4.2.5 will load this file automaticaly or try to by first using a HEAD request to check if the file exists.

loadGlobalConfig

Tell Xopus to load the global-config.xml file. Versions of Xopus before 4.2.5 will load this file automaticaly or try to by first using a HEAD request to check if the file exists.

maximizeEditorFrame

If Xopus runs in an iframe, it will show a button to maximize the editor frame. This function can be used to trigger the same function from the API.

removeEventListener

Remove event listeners added by Editor.addEventListener().

restoreEditorFrame

If Xopus runs in an iframe and is maximized, it will show a button to minimize the editor frame again. This function can also be used to trigger the same function from the API.

runInTransaction

This method allows for people to run code in an Xopus transaction, which allows the code to be validated and to be picked up by the undo stack in Xopus.

setExitFunction

Set the Function that Xopus should call when the exit button is clicked.

setExitURL

Set the URL that Xopus should use when the exit button is clicked.

setSymbols

This function sets the array of symbols currently in use in Xopus.

setUIGroupEnabled

This method sets the visibility of a uiGroup in the property panel when uiGroups have been configured.

setUILanguage

This methods sets the language of the interface

setURL

Load the specified URL in the Xopus document area. This will close all open documents.

show

When Xopus runs inside in an iframe element, it will replace the xopusHidden class name with xopusVisible. This does require the xopusHidden class name to be set already.

wrapInTransaction

 

Editor.Canvas Methods

Name Description
getActiveCanvas

Retrieve the currently active Xopus canvas or null when not one is active.

getCanvasCollection

Retrieve a collection containing all current Xopus canvasses.

Editor.ChangeTracking Methods

Name Description
getUserName

Retrieve the name that has been set for change tracking.

setUserName

Set a name for the user that is currently editing the document, for use in the changetracking information.

Editor.Selection Methods

Name Description
getRange

Get the XopusRange object for the current selection or cursor position in the editor.

setRange

Change the selection in the Editor to the supplied range.

unselect

Change the selection to be nothing and remove the cursor.

Editor.XML Methods

Name Description
createNativeXMLDocument

Create a browser XMLDocument() instance that is compatible with Xopus.

createNativeXMLHttpRequest

Creates a instance of XMLHttpRequest() similar to the one used by Xopus itself.

getContextNode

Get the node the cursor is currently in, generally the last element in the status bar.

EmbeddedXopus Methods

Name Description
addListener

Information on using addListener can be found on the EmbeddedXopus page.

getAPI

getAPI() can be used to gain access to the Xopus API from outside an <iframe>, without using event listeners. It requires the frame to have a name attribute defined, which is supplied as the only argument of this method.

removeListener

When disposing of a component of your framework that contains Xopus (that has an event listener attached to EmbeddedXopus), it is best to remove the listener to prevent errors.

HTTPTools Methods

Name Description
fileExists

Send a HTTP HEAD request to check if a file exists.

getXML

Retrieve an XML document from the given URI using HTTP GET.

postXML

Send a document to your server using a HTTP POST request. This function allows you to specify the encoding explicitly.

putXML

See HTTPTools.postXML which works similar to this HTTP PUT method.

IO Methods

Name Description
getAsyncSaveXMLFunction

Returns the JavaScript function previously set using IO.setAsyncSaveXMLFunction, or null for there is not default save handler.

getLoadIncludedXMLFunction

Returns the function used for loading included XML files, such as XIncludes.

getLoadXMLFunction

This method returns the method you've set previously using IO.setLoadXMLFunction(fn), or the default load function for XML files. This way you can extend the default Xopus load behavior by re-using the default load function.

getLoadXSDFunction

This method returns the method you've set previously using IO.setLoadXSDFunction(fn), or the default load function for XML Schemas. This way you can extend the default Xopus load behavior by re-using the default load function.

getLoadXSLFunction

This method returns the method you've set previously using IO.setLoadXSLFunction(fn), or the default load function for XSL stylesheets. This way you can extend the default Xopus load behavior by re-using the default load function.

getSaveXMLFunction

This function returns the save function set with IO.setSaveXMLFunction.

loadCatalog

Using loadCatalog you can force Xopus to run every URI to load against the catalog to redirect the load.

setAsyncSaveXMLFunction

Use this function to configure Xopus to save your document using in an asynchronous fashion. It has but one difference with IO.setSaveXMLFunction, namely the callback argument. Until the callback function is executed, Xopus will show busy notification in the user interface, and the saving button will be disabled.

setLoadIncludedXMLFunction

Set a new function that is used to load included XML documents. Documents can be included using the document() function in XSL or using XIncludes.

setLoadXMLFunction

Set a new function to load XML documents that will be edited.

setLoadXSDFunction

Set a new function to load XML Schemas.

setLoadXSLFunction

Set a new function to load XSL stylesheets that will be used to render the edit view.

setSaveXMLFunction

Set a new function to save XML documents.

ModalDialog Methods

Name Description
close

Close the dialog window.

open

Open the dialog window with the specified URI.

resizeTo

Resize the dialog window.

Scope Methods

Name Description
declare

Any scope variable that you want to set or get, must first be declared.

get

Get the variable value. Note that you have the variable before you can retrieve it.

set

Set the variable to the given value. Note that you have to declare the variable before it can be set.

setListener

This method can be used to listen to changes to a Scope variable.

WebDAVTools Methods

Name Description
getXML

Opens the document for reading and puts a write lock (if possible) on the document.

putXML

Use a HTTPPUT request for for saving a document to your WebDAV server.

releaseLock

Release the lock on opened document

XopusCanvas Methods

Name Description
enable

Enables a canvas that is not yet started or enabled. When the canvas is already started this function will return and nothing will happen.

getActiveView

Get the name of the view that is currently active for the canvas.

getCanvasElement

Retrieves the HTML element that represents the Xopus canvas for this instance of Xopus.

getDocument

Get the current document that this Xopus canvas is editing.

getViewCollection

Gets the collection of view names that are available for this canvas.

getViewParam

This method can be used to get values from parameters that have been declared in the XSL.

loadDocument

The loadDocument function loads a new XML document in the Xopus canvas.

setActiveView

Set the active view for this canvas. The view is identified by name or by index.

setViewParam

This method can be used to set the value of parameters in the XSL of the canvas.

Events

Name Description
afterRedraw

This event will be fired after each change to the document.

load

This event will be fired when a new document is being loaded.

loadError

This event will be fired when a document fails to load properly.

unload

This event will be fired when a document is being closed and unloaded by the editor.

xmlContextChange

This event fires when the cursor is moved to a different node.

XopusLoaded

This event will be fired when the Xopus window is completely loaded.

XopusUnloaded

This event will be fired when the Xopus window is closed.

Exceptions

Name Description
Editor.RevertingException

When this exception is thrown in a event handler of a mutation event, the changes made to the document will be reverted immediately. The exception is thrown by executing new Editor.RevertingException.