summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsun2009-03-21 23:16:29 (GMT)
committer sun2009-03-21 23:16:29 (GMT)
commit533e74dc1a9c00b8e52cbb515bcef7f9d9edc900 (patch)
tree462a746063fd8e145b8c316b7ef62a75efb0d8dd
parent78fe4c3530faa0a50c254c7961c423ca6dcb1554 (diff)
#380698 by TwoD, sun: Added Drupal plugin support for FCKeditor (part I).
-rw-r--r--CHANGELOG.txt1
-rw-r--r--editors/fckeditor.inc37
-rw-r--r--editors/js/fckeditor-2.6.js109
-rw-r--r--editors/js/fckeditor.config.js35
4 files changed, 158 insertions, 24 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index aba2c66..f1a62a5 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -6,6 +6,7 @@ Wysiwyg x.x-x.x, xxxx-xx-xx
Wysiwyg 5.x-2.x, xxxx-xx-xx
---------------------------
+#380698 by TwoD, sun: Added Drupal plugin support for FCKeditor (part I).
#398848 by sun: Added support for TinyMCE 3.1.
#319363 by Grugnog2: Fixed theme_render_template() does not exist in 5.x.
#394068 by StephaneC: markItUp: Fixed icons not displayed due to #385736.
diff --git a/editors/fckeditor.inc b/editors/fckeditor.inc
index d843a8c..ff6eaa0 100644
--- a/editors/fckeditor.inc
+++ b/editors/fckeditor.inc
@@ -27,6 +27,14 @@ function wysiwyg_fckeditor_editor() {
'themes callback' => 'wysiwyg_fckeditor_themes',
'settings callback' => 'wysiwyg_fckeditor_settings',
'plugin callback' => 'wysiwyg_fckeditor_plugins',
+ 'plugin settings callback' => 'wysiwyg_fckeditor_plugin_settings',
+ 'proxy plugin' => array(
+ 'drupal' => array(
+ 'load' => TRUE,
+ 'proxy' => TRUE,
+ ),
+ ),
+ 'proxy plugin settings callback' => 'wysiwyg_fckeditor_proxy_plugin_settings',
'versions' => array(
2.6 => array(
'js files' => array('fckeditor-2.6.js'),
@@ -157,6 +165,35 @@ function wysiwyg_fckeditor_themes($editor, $profile) {
}
/**
+ * Build a JS settings array of native external plugins that need to be loaded separately.
+ *
+ * @todo Required for FCKeditor? If not, wysiwyg_add_plugin_settings() needs
+ * an overhaul.
+ */
+function wysiwyg_fckeditor_plugin_settings($editor, $profile, $plugins) {
+ $settings = array();
+ return $settings;
+}
+
+/**
+ * Build a JS settings array for Drupal plugins loaded via the proxy plugin.
+ */
+function wysiwyg_fckeditor_proxy_plugin_settings($editor, $profile, $plugins) {
+ $settings = array();
+ foreach ($plugins as $name => $plugin) {
+ // Populate required plugin settings.
+ $settings[$name] = $plugin['dialog settings'] + array(
+ 'title' => $plugin['title'],
+ 'icon' => base_path() . $plugin['icon path'] .'/'. $plugin['icon file'],
+ 'iconTitle' => $plugin['icon title'],
+ // @todo These should only be set if the plugin defined them.
+ 'css' => base_path() . $plugin['css path'] .'/'. $plugin['css file'],
+ );
+ }
+ return $settings;
+}
+
+/**
* Return internal plugins for FCKeditor; semi-implementation of hook_wysiwyg_plugin().
*/
function wysiwyg_fckeditor_plugins($editor) {
diff --git a/editors/js/fckeditor-2.6.js b/editors/js/fckeditor-2.6.js
index 726f3d5..803aa04 100644
--- a/editors/js/fckeditor-2.6.js
+++ b/editors/js/fckeditor-2.6.js
@@ -4,20 +4,18 @@
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.fckeditor = function(context, params, settings) {
- var FCKinstance = new FCKeditor(params.field, settings.Width, settings.Height);
+ var FCKinstance = new FCKeditor(params.field, settings.Width, settings.Height, settings.ToolbarSet);
// Apply editor instance settings.
FCKinstance.BasePath = settings.EditorPath;
// Apply 'Wysiwyg' toolbar, if defined.
- if (settings.buttons) {
- FCKinstance.ToolbarSet = settings.ToolbarSet;
+ if (settings.CustomConfigurationsPath) {
+ FCKinstance.Config.wysiwygFormat = params.format;
+ FCKinstance.Config.CustomConfigurationsPath = settings.CustomConfigurationsPath;
}
- // Apply input format configuration.
- FCKinstance.Config.format = params.format;
- delete settings.buttons;
- for (var setting in settings) {
- FCKinstance.Config[setting] = settings[setting];
- }
+ // Load Drupal plugins and apply format specific settings.
+ // @see fckeditor.config.js
+
// Attach editor.
FCKinstance.ReplaceTextarea();
};
@@ -26,22 +24,97 @@ Drupal.wysiwyg.editor.attach.fckeditor = function(context, params, settings) {
* Detach a single or all editors.
*/
Drupal.wysiwyg.editor.detach.fckeditor = function(context, params) {
+ var instances = [];
if (typeof params != 'undefined' && typeof FCKeditorAPI != 'undefined') {
var instance = FCKeditorAPI.GetInstance(params.field);
if (instance) {
- $('#' + params.field).val(instance.GetXHTML()).show();
- $('#' + params.field + '___Config').remove();
- $('#' + params.field + '___Frame').remove();
- delete FCKeditorAPI.__Instances[params.field];
+ instances[params.field] = instance;
}
}
else {
- for (var instance in FCKeditorAPI.__Instances) {
- $('#' + instance).val(instance.GetXHTML()).show();
- $('#' + instance + '___Config').remove();
- $('#' + instance + '___Frame').remove();
- delete FCKeditorAPI.__Instances[instance];
+ instances = FCKeditorAPI.__Instances;
+ }
+
+ for (var instanceName in instances) {
+ // Shut down the instance and give plugins a chance to detach by changing status first.
+ instances[instanceName].SetStatus(FCK_STATUS_NOTLOADED);
+ instances[instanceName].UpdateLinkedField();
+ $('#' + instanceName).show();
+ $('#' + instanceName + '___Config').remove();
+ $('#' + instanceName + '___Frame').remove();
+ delete FCKeditorAPI.__Instances[instanceName];
+ }
+};
+
+Drupal.wysiwyg.editor.instance.fckeditor = {
+ addPlugin: function(plugin, settings, pluginSettings, instance) {
+ if (typeof Drupal.wysiwyg.plugins[plugin] != 'object') {
+ return;
+ }
+
+ if (Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal[plugin].css) {
+ instance.FCKConfig.EditorAreaCSS += ',' + Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal[plugin].css;
}
+
+ // @see fckcommands.js, fck_othercommands.js, fckpastewordcommand.js
+ instance.FCKCommands.RegisterCommand(plugin, {
+ // Invoke the plugin's button.
+ Execute: function () {
+ if (typeof Drupal.wysiwyg.plugins[plugin].invoke == 'function') {
+ var data = { format: 'html', node: instance.FCKSelection.GetParentElement() };
+ // @todo This is NOT the same as data.node.
+ data.content = data.node.innerHTML;
+ Drupal.wysiwyg.plugins[plugin].invoke(data, pluginSettings, instance.FCK.Name);
+ }
+ },
+
+ // isNode: Return whether the plugin button should be enabled for the
+ // current selection.
+ // @see FCKUnlinkCommand.prototype.GetState()
+ GetState: function () {
+ // Disabled if not in WYSIWYG mode.
+ if (instance.FCK.EditMode != FCK_EDITMODE_WYSIWYG) {
+ return FCK_TRISTATE_DISABLED;
+ }
+
+ var state = instance.FCK.GetNamedCommandState(this.Name);
+ if (state == FCK_TRISTATE_OFF && instance.FCK.EditMode == FCK_EDITMODE_WYSIWYG) {
+ if (typeof Drupal.wysiwyg.plugins[plugin].isNode == 'function') {
+ var node = instance.FCKSelection.GetSelectedElement();
+ state = Drupal.wysiwyg.plugins[plugin].isNode(node) ? FCK_TRISTATE_ON : FCK_TRISTATE_OFF;
+ }
+ }
+ return state;
+ },
+
+ /**
+ * Return information about the plugin as a name/value array.
+ */
+ Name: plugin
+ });
+
+ // Register the plugin button.
+ // var FCKToolbarButton = function(commandName, label, tooltip, style, sourceView, contextSensitive, icon)
+ instance.FCKToolbarItems.RegisterItem(plugin, new instance.FCKToolbarButton(plugin, settings.iconTitle, settings.iconTitle, null, false, true, settings.icon));
+ },
+
+ openDialog: function(dialog, params) {
+ // @todo Implement open dialog.
+ },
+
+ closeDialog: function(dialog) {
+ // @todo Implement close dialog.
+ },
+
+ prepareContent: function(content) {
+ // @todo Not needed for FCKeditor?
+ return content;
+ },
+
+ insert: function(content) {
+ var instance = FCKeditorAPI.GetInstance(this.field);
+ // @see FCK.InsertHtml(), FCK.InsertElement()
+ instance.InsertHtml(content);
}
};
diff --git a/editors/js/fckeditor.config.js b/editors/js/fckeditor.config.js
index 02fa60b..28c0d6f 100644
--- a/editors/js/fckeditor.config.js
+++ b/editors/js/fckeditor.config.js
@@ -1,17 +1,40 @@
// $Id$
+Drupal = window.parent.Drupal;
+
/**
* Fetch and provide original editor settings as local variable.
*
* FCKeditor does not support to pass complex variable types to the editor.
- *
- * For whatever reason, our custom 'format' property is not available in
- * FCKConfig.format, but in FCKConfig.PageConfig.format instead.
+ * Instance settings passed to FCKinstance.Config are temporarily stored in
+ * FCKConfig.PageConfig.
+ */
+var wysiwygFormat = FCKConfig.PageConfig.wysiwygFormat;
+var wysiwygSettings = Drupal.settings.wysiwyg.configs.fckeditor[wysiwygFormat];
+
+/**
+ * Apply format-specific settings.
*/
-var wysiwygSettings = window.parent.Drupal.settings.wysiwyg.configs.fckeditor[FCKConfig.PageConfig.format];
+for (var setting in wysiwygSettings) {
+ if (setting == 'buttons') {
+ // Apply custom Wysiwyg toolbar for this format.
+ FCKConfig.ToolbarSets['Wysiwyg'] = wysiwygSettings.buttons;
+ }
+ else {
+ FCKConfig[setting] = wysiwygSettings[setting];
+ }
+}
/**
- * Apply custom Wysiwyg API toolbar for input format.
+ * Register Drupal plugins for this input format.
+ *
+ * Parameters to addPlugin() are:
+ * - Plugin name.
+ * - Format specific plugin settings.
+ * - General plugin settings.
+ * - A reference to this window so the plugin setup can access FCKConfig.
*/
-FCKConfig.ToolbarSets['Wysiwyg'] = wysiwygSettings.buttons;
+for (var plugin in Drupal.settings.wysiwyg.plugins[wysiwygFormat].drupal) {
+ Drupal.wysiwyg.editor.instance.fckeditor.addPlugin(plugin, Drupal.settings.wysiwyg.plugins[wysiwygFormat].drupal[plugin], Drupal.settings.wysiwyg.plugins.drupal[plugin], window);
+}