wiki:0.3/API

API

Note: in the code examples below, wym is a variable which refers to the WYMeditor instance, and which must be initialized.

box

Return the WYMeditor container.

html(sHtml)

Get or set the editor's HTML value.

Example:

  wym.html("<p>Hello, World.</p>");

xhtml

Get the cleaned up editor's HTML value.

exec(cmd)

Execute a command.

Supported command identifiers

  • Bold: set/unset strong on the selection
  • Italic: set/unset em on the selection
  • Superscript: set/unset sup on the selection
  • Subscript: set/unset sub on the selection
  • InsertOrderedList: create/remove an ordered list, based on the selection
  • InsertUnorderedList: create/remove an unordered list, based on the selection
  • Indent: 'indent' the list element
  • Outdent: 'outdent' the list element
  • Undo: undo an action
  • Redo: redo an action
  • CreateLink: open the link dialog and create/update a link on the selection
  • Unlink: remove a link, based on the selection
  • InsertImage: open the image dialog and insert/update an image
  • InsertTable: open the table dialog and insert a table
  • Paste: opens the paste dialog and paste raw paragraphs from an external application, e.g. Word
  • ToggleHtml: show/hide the HTML value
  • Preview: open the preview dialog

paste(sData)

Paste raw text, inserting new paragraphs.

container(sType)

Get or set the selected container.

Example: switch the container to Heading 1.

  wym.container('H1');

Example: get the selected container.

  wym.status(wym.container().tagName);

toggleClass(sClass, jqexpr)

Set or remove the class sClass on the selected container/parent matching the jQuery expression jqexpr.

Example: set the class my-class on the selected paragraph with the class {{{my-other-class}}.

  wym.toggleClass('.my-class', 'P.my-other-class')

status(sMessage)

Update the HTML value of WYMeditor' status bar.

Example:

  wym.status("This is the status bar.");

update

Update the value of the element replaced by WYMeditor and the value of the HTML source textarea.

dialog(sType)

Open a dialog of type sType.

Supported values: Link, Image, Table, Paste_From_Word.

Example:

  wym.dialog('Link');

toggleHtml

Show/hide the HTML source.

replaceStrings(sVal)

Localize the strings included in sVal.

encloseString(sVal)

Enclose a string in string delimiters.