Editor
Provided by www.vision-media.ca
Developed by Tj Holowaychuk [tj@vision-media.ca]
Icons provided www.famfamfam.com
-------------------------------------------------------------------------------
INSTALLATION
-------------------------------------------------------------------------------
Simply enable the module, along with the 'plugins' and 'visibility_api' modules.
http://drupal.org/project/plugins
http://drupal.org/project/visibility_api
-------------------------------------------------------------------------------
PLUGIN DEVELOPMENT
-------------------------------------------------------------------------------
To provide a plugin or several plugins simply invoke hook_editor_plugins(). This
hook expects you to return an array of 'editor plugin objects'. These objects
can be created manually however editor_plugin_create() is available to assist in
this process.
/**
* Implementation of hook_editor_plugins();
*/
function editor_editor_plugins() {
$plugins = array();
$plugins[] = editor_plugin_create('link', t('Link'), 'button', t('Link selected text or content to a website or page.'), editor_plugin_link_options());
return $plugins;
}
The editor_plugin_create() function allows you to provide form fields, which are
presented as settings to the end-user.
/**
* Link options.
*/
function editor_plugin_link_options() {
return '
<input type="text" class="href click-clear" value="Location" />
<select class="window">
<option value="same">' . t('Open in same window') . '</option>
<option value="_blank">' . t('Open in new window') . '</option>
</select>
<input type="button" class="submit" value="Go" />
';
}
In our JavaScript file we can now extend the Editor object with
Drupal.editor.prototype.[PIDInit] = function(){}; where [PIDInit]
is your plugin id (link, mailto, undo, etc).
The plugins DOM node is passed into the method. We then listen or
bind to the linkMouseDown event.
From here we can show our options using this.showOptions(); where
the value should be this.settings.plugins.[PID].options;
/**
* Link plugin. Provides options for customizing anchor tags.
*/
Drupal.editor.prototype.linkInit = function(plugin) {
$(this).bind('linkMouseDown', function(e){
var ed = e.target;
this.showOptions(this.settings.plugins.link.options);
// Apply anchor tag
$('.submit', this.options).click(function(){
var uri = $('.href', this.options).val();
var window = $('.window', this.options).val();
// Validation
if (uri == 'Location'){
ed.setMessage('Enter a location.', 'error');
return;
}
if (window == 'same'){
ed.execCommand('createlink', uri);
}
else {
var node = ed.createNode('a');
$(node).attr('href', uri).attr('target', '_blank');
ed.wrap(node);
}
ed.hideOptions();
});
});
};
-------------------------------------------------------------------------------
PERMISSIONS
-------------------------------------------------------------------------------
access editor
administer editor visibility
administer editor profiles
To provide a plugin or several plugins simply invoke hook_editor_plugins(). This
hook expects you to return an array of 'editor plugin objects'. These objects
can be created manually however editor_plugin_create() is available to assist in
this process.
/**
* Implementation of hook_editor_plugins();
*/
function editor_editor_plugins() {
$plugins = array();
$plugins[] = editor_plugin_create('link', t('Link'), 'button', t('Link selected text or content to a website or page.'), editor_plugin_link_options());
return $plugins;
}
The editor_plugin_create() function allows you to provide form fields, which are
presented as settings to the end-user.
/**
* Link options.
*/
function editor_plugin_link_options() {
return '
';
}
In our JavaScript file we can now extend the Editor object with
Drupal.editor.prototype.[PIDInit] = function(){}; where [PIDInit]
is your plugin id (link, mailto, undo, etc).
The plugins DOM node is passed into the method. We then listen or
bind to the linkMouseDown event.
From here we can show our options using this.showOptions(); where
the value should be this.settings.plugins.[PID].options;
/**
* Link plugin. Provides options for customizing anchor tags.