API - lokothodida/ckeditor-plugin-template GitHub Wiki

Index

(_)YourPlugin

This is just a helper object for you to store your own functions, shielded away from other globals and namespaced by YourPlugin.

Initialize

To use, simply rename YourPlugin (in your-plugin/js/helper-methods.js) to your desired name, then in the onLoad() method for your dialog (in `your-plugin/dialogs/main.js), insert the following JavaScript:

...
// dialog methods
...
onLoad: function() {
  // add id for easier styling of elements in the dialog
  $(this.getElement()).attr('id', plugin.dialog);

  // ADD THE BELOW CODE
  // initialize YourPlugin object (with your renamed variable)
  YourPlugin = new _YourPlugin(path); // path is the plugin path (defined at the top of the main.js file)
},
...

Note that in the helper-methods.js file, there is a _ prefix for YourPlugin. This is just to avoid a variable clash if the helper object is instantiated later on by the dialog (e.g. with the CKEditor AJAX sample file ajax.html).

The object is simply a helper, and you can use a completely different way to add helper functions to your plugin. This documentation is here for completeness; you may freely add/remove methods from the YourPlugin object template when you use it.

Methods

getHtml()

YourPlugin.getHtml(filename, $div)

Loads html template from /html folder into a <div>.

Parameters

@param type optional description
filename String name of html file in your-plugin/html directory (no .html suffix)
$div jQueryObject div container to load the content into

Example

/your-plugin/html/description.html
<h2>Plugin Title</h2>
<p>A short description for the top of your dialog.</p>
/your-plugin/dialogs/main.js
...
// fields
...
{
  // description field
  id: 'description',
  type: 'html',
  html: '',
  className: 'description', // for selecting the field more easily
  onLoad: function() {
    var $div = $('#' + plugin.dialog + ' .description');

    // load contents of description.html into this plain div
    YourPlugin.getHtml('description', $div);
  },
},
...
⚠️ **GitHub.com Fallback** ⚠️