Index: wysiwyg.init.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.init.js,v retrieving revision 1.2 diff -u -p -r1.2 wysiwyg.init.js --- wysiwyg.init.js 30 Nov 2008 17:16:27 -0000 1.2 +++ wysiwyg.init.js 1 Dec 2008 15:17:34 -0000 @@ -2,7 +2,7 @@ Drupal.wysiwyg = Drupal.wysiwyg || { 'instances': {} }; -Drupal.wysiwyg.editor = Drupal.wysiwyg.editor || { 'init': {}, 'attach': {}, 'detach': {} }; +Drupal.wysiwyg.editor = Drupal.wysiwyg.editor || { 'init': {}, 'attach': {}, 'detach': {}, 'instance': {} }; Drupal.wysiwyg.plugins = Drupal.wysiwyg.plugins || {}; Index: wysiwyg.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.js,v retrieving revision 1.7 diff -u -p -r1.7 wysiwyg.js --- wysiwyg.js 18 Jan 2009 22:04:13 -0000 1.7 +++ wysiwyg.js 19 Jan 2009 01:39:55 -0000 @@ -76,8 +76,14 @@ Drupal.wysiwygAttach = function(context, if (typeof Drupal.wysiwyg.editor.attach[params.editor] == 'function') { // (Re-)initialize field instance. Drupal.wysiwyg.instances[params.field] = {}; + // Provide editor callbacks for plugins. + if (typeof Drupal.wysiwyg.editor.instance[params.editor] == 'object') { + Drupal.wysiwyg.instances[params.field] = Drupal.wysiwyg.editor.instance[params.editor]; + } // Store new editor name and status for this field. Drupal.wysiwyg.instances[params.field].editor = params.editor; + // Store this field id, so (external) plugins can use it. + Drupal.wysiwyg.activeId = params.field; // Attach or update toggle link. Drupal.wysiwygAttachToggleLink(context, params); // Attach editor, if enabled by default or last state was enabled. @@ -131,6 +137,7 @@ Drupal.wysiwygAttachToggleLink = functio Drupal.wysiwygDetach(context, params); // After disabling the editor, re-attach default behaviors. Drupal.wysiwyg.editor.attach.none(context, params); + Drupal.wysiwyg.instances[params.field] = Drupal.wysiwyg.editor.instance.none; Drupal.wysiwyg.instances[params.field].editor = 'none'; $(this).html(Drupal.settings.wysiwyg.enable).blur(); } Index: wysiwyg.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.module,v retrieving revision 1.20 diff -u -p -r1.20 wysiwyg.module --- wysiwyg.module 24 Jan 2009 23:32:02 -0000 1.20 +++ wysiwyg.module 25 Jan 2009 03:21:28 -0000 @@ -124,10 +124,10 @@ function wysiwyg_process_form(&$form) { // Check editor theme (and reset it if not/no longer available). $theme = wysiwyg_get_editor_themes($profile, (isset($profile->settings['theme']) ? $profile->settings['theme'] : '')); + // Add plugin settings (first) for this input format. + wysiwyg_add_plugin_settings($profile); // Add profile settings for this input format. wysiwyg_add_editor_settings($profile, $theme); - // Add plugin settings for this input format. - wysiwyg_add_plugin_settings($profile); } // Use a prefix/suffix for a single input format, or attach to input @@ -320,24 +320,55 @@ function wysiwyg_add_editor_settings($pr function wysiwyg_add_plugin_settings($profile) { static $plugins_added = array(); - if (!isset($plugins_added[$profile->editor])) { - $plugins = array(); - $editor = wysiwyg_get_editor($profile->editor); - // Collect editor plugins provided via hook_wysiwyg_plugin(). - $info = module_invoke_all('wysiwyg_plugin', $editor['name'], $editor['installed version']); - // Only keep enabled plugins in this profile. - foreach ($info as $plugin => $meta) { + // External plugins must only be loaded once. + // @todo Actually, each native plugin must not be added twice, but different + // profiles can have different plugin-sets for the same editor. We should + // check each plugin for each editor. + if (isset($plugins_added[$profile->editor])) { + return; + } + + $editor = wysiwyg_get_editor($profile->editor); + // Assume that this editor does not support neither native external plugins, + // nor Drupal plugins if it does not provide a callback. + if (isset($editor['plugin settings callback']) && function_exists($editor['plugin settings callback'])) { + // Collect native editor plugins provided via hook_wysiwyg_plugin(). + $plugins = module_invoke_all('wysiwyg_plugin', $editor['name'], $editor['installed version']); + // Only keep enabled native plugins in this profile. + foreach ($plugins as $plugin => $meta) { if (!isset($profile->settings['buttons'][$plugin])) { - unset($info[$plugin]); + unset($plugins[$plugin]); } } - - if (isset($editor['plugin settings callback']) && function_exists($editor['plugin settings callback'])) { - $plugins = $editor['plugin settings callback']($editor, $profile, $info); + // Invoke the editor's plugin settings callback, so it can populate the + // settings for external plugins with custom, required values. + $plugins = $editor['plugin settings callback']($editor, $profile, $plugins); + + drupal_add_js(array('wysiwyg' => array('plugins' => array($profile->editor => array('native' => $plugins)))), 'setting'); + + // Collect, load, and add API plugins provided by Drupal modules. + if (isset($editor['proxy plugin']) && isset($editor['proxy plugin settings callback']) && function_exists($editor['proxy plugin settings callback'])) { + $plugins += $editor['proxy plugin']; + $proxy = key($editor['proxy plugin']); + $proxy_plugins = array(); + foreach (wysiwyg_get_all_plugins() as $plugin_name => $meta) { + if (isset($profile->settings['buttons'][$proxy][$plugin_name])) { + $proxy_plugins[$plugin_name] = $meta; + // Load the Drupal plugin's JavaScript. + drupal_add_js($meta['js path'] .'/'. $meta['js file']); + // Add plugin specific settings. + if (isset($meta['settings'])) { + drupal_add_js(array('wysiwyg' => array('plugins' => array('drupal' => array($plugin_name => $meta['settings'])))), 'setting'); + } + } + } + // Invoke the editor's proxy plugin settings callback, so it can populate + // the settings for Drupal plugins with custom, required values. + $proxy_plugins = $editor['proxy plugin settings callback']($editor, $profile, $proxy_plugins); + + drupal_add_js(array('wysiwyg' => array('plugins' => array($profile->editor => array('drupal' => $proxy_plugins)))), 'setting'); } - drupal_add_js(array('wysiwyg' => array('plugins' => array($profile->editor => $plugins))), 'setting'); - $plugins_added[$profile->editor] = TRUE; } } @@ -398,11 +429,17 @@ function wysiwyg_get_plugins($editor_nam if (isset($editor['plugin callback']) && function_exists($editor['plugin callback'])) { $plugins = $editor['plugin callback']($editor); } - // Load our own plugins. - include_once drupal_get_path('module', 'wysiwyg') .'/wysiwyg.plugins.inc'; - // Add editor plugins provided via hook_wysiwyg_plugin(). $plugins = array_merge($plugins, module_invoke_all('wysiwyg_plugin', $editor['name'], $editor['installed version'])); + // Add API plugins provided by Drupal modules. + // @todo We need to pass the filepath to the plugin icon for Drupal plugins. + if (isset($editor['proxy plugin'])) { + $plugins += $editor['proxy plugin']; + $proxy = key($editor['proxy plugin']); + foreach (wysiwyg_get_all_plugins() as $plugin_name => $info) { + $plugins[$proxy]['buttons'][$plugin_name] = $info['title']; + } + } } return $plugins; } @@ -566,6 +603,46 @@ function wysiwyg_get_all_editors() { } /** + * Invoke hook_wysiwyg_plugin() in all modules. + */ +function wysiwyg_get_all_plugins() { + static $plugins; + + if (isset($plugins)) { + return $plugins; + } + + $plugins = wysiwyg_load_includes('plugins', 'plugin'); + foreach ($plugins as $name => $properties) { + $plugin = &$plugins[$name]; + // Fill in required/default properties. + $plugin += array( + 'title' => $plugin['name'], + 'vendor url' => '', + 'js path' => $plugin['path'] . '/' . $plugin['name'], + 'js file' => $plugin['name'] . '.js', + 'css path' => $plugin['path'] . '/' . $plugin['name'], + 'css file' => $plugin['name'] . '.css', + 'icon path' => $plugin['path'] . '/' . $plugin['name'] . '/images', + 'icon file' => $plugin['name'] . '.png', + 'dialog path' => $plugin['name'], + 'dialog settings' => array(), + 'settings callback' => NULL, + 'settings form callback' => NULL, + ); + // Fill in default settings. + $plugin['settings'] += array( + 'path' => base_path() . $plugin['path'] . '/' . $plugin['name'], + ); + // Check whether library is present. + if (!($plugin['installed'] = file_exists($plugin['js path'] . '/' . $plugin['js file']))) { + continue; + } + } + return $plugins; +} + +/** * Load include files for wysiwyg implemented by all modules. * * @param $type Index: wysiwyg.plugins.inc =================================================================== RCS file: wysiwyg.plugins.inc diff -N wysiwyg.plugins.inc --- wysiwyg.plugins.inc 14 Oct 2008 21:45:07 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,23 +0,0 @@ - array( - 'path' => drupal_get_path('module', 'wysiwyg') .'/plugins/break/editor_plugin.js', - 'buttons' => array('break' => t('Teaser break')), - 'url' => 'http://drupal.org/project/wysiwyg', - ), - ); - } - break; - } -} - Index: editors/tinymce.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/editors/tinymce.inc,v retrieving revision 1.21 diff -u -p -r1.21 tinymce.inc --- editors/tinymce.inc 7 Jan 2009 09:02:25 -0000 1.21 +++ editors/tinymce.inc 19 Jan 2009 01:39:56 -0000 @@ -33,12 +33,19 @@ function wysiwyg_tinymce_editor() { 'settings callback' => 'wysiwyg_tinymce_settings', 'plugin callback' => 'wysiwyg_tinymce_plugins', 'plugin settings callback' => 'wysiwyg_tinymce_plugin_settings', + 'proxy plugin settings callback' => 'wysiwyg_tinymce_proxy_plugin_settings', 'versions' => array( // Each version can override global editor properties. '2.1' => array( // 'include files' => array('tinymce-2.inc'), 'js files' => array('tinymce-2.js'), 'css files' => array('tinymce-2.css'), 'download url' => 'http://sourceforge.net/project/showfiles.php?group_id=103281&package_id=111430&release_id=557383', + 'proxy plugin' => array( + 'drupal' => array( + 'load' => TRUE, + 'internal' => TRUE, + ), + ), ), '3.2' => array( // 'include files' => array('tinymce-3.inc'), @@ -61,6 +68,12 @@ function wysiwyg_tinymce_editor() { 'files' => array('tiny_mce_src.js'), ), ), + 'proxy plugin' => array( + 'drupal' => array( + 'load' => TRUE, + 'internal' => TRUE, + ), + ), ), ), // Optional properties @@ -191,7 +204,12 @@ function wysiwyg_tinymce_settings($edito } // Add internal buttons that also need to be loaded as extension. else if ($type == 'buttons' && !empty($plugins[$plugin]['load'])) { - $init['extensions'][$plugin] = 1; + if ($plugin == 'drupal') { + $init['extensions'][$button] = 1; + } + else { + $init['extensions'][$plugin] = 1; + } } // Add plain extensions. else if ($type == 'extensions' && !empty($plugins[$plugin]['load'])) { @@ -293,10 +311,10 @@ function wysiwyg_tinymce_themes($editor, } /** - * Build a JS settings array of external plugins that need to be loaded separately. + * Build a JS settings array of native external plugins that need to be loaded separately. * * TinyMCE requires that external plugins (i.e. not residing in the editor's - * directory) are loaded (once) after the editor has been initialized. + * directory) are loaded (once) upon initializing the editor. */ function wysiwyg_tinymce_plugin_settings($editor, $profile, $plugins) { $settings = array(); @@ -309,6 +327,23 @@ function wysiwyg_tinymce_plugin_settings } /** + * Build a JS settings array for Drupal plugins loaded via the proxy plugin. + */ +function wysiwyg_tinymce_proxy_plugin_settings($editor, $profile, $plugins) { + $settings = array(); + foreach ($plugins as $name => $plugin) { + $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; +} + +/** * Add or remove leading hiven to/of external plugin names. * * TinyMCE requires that external plugins, which should not be loaded from Index: editors/js/none.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/editors/js/none.js,v retrieving revision 1.3 diff -u -p -r1.3 none.js --- editors/js/none.js 28 Oct 2008 22:46:05 -0000 1.3 +++ editors/js/none.js 25 Jan 2009 03:33:32 -0000 @@ -43,3 +43,28 @@ Drupal.wysiwyg.editor.detach.none = func } }; +/** + * Instance methods for plain text areas. + */ +Drupal.wysiwyg.editor.instance.none = { + insert: function(instanceId, content) { + var editor = document.getElementById(instanceId); + + // IE support. + if (document.selection) { + editor.focus(); + sel = document.selection.createRange(); + sel.text = content; + } + // Mozilla/Firefox/Netscape 7+ support. + else if (editor.selectionStart || editor.selectionStart == '0') { + var startPos = editor.selectionStart; + var endPos = editor.selectionEnd; + editor.value = editor.value.substring(0, startPos) + content + editor.value.substring(endPos, editor.value.length); + } + // Fallback, just add to the end of the content. + else { + editor.value += content; + } + } +}; Index: editors/js/tinymce-2.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/editors/js/tinymce-2.js,v retrieving revision 1.7 diff -u -p -r1.7 tinymce-2.js --- editors/js/tinymce-2.js 1 Dec 2008 14:14:41 -0000 1.7 +++ editors/js/tinymce-2.js 25 Jan 2009 03:55:13 -0000 @@ -21,8 +21,13 @@ Drupal.wysiwyg.editor.init.tinymce = fun for (var format in settings) { tinyMCE.init(settings[format]); } - for (var plugin in Drupal.settings.wysiwyg.plugins.tinymce) { - tinyMCE.loadPlugin(plugin, Drupal.settings.wysiwyg.plugins.tinymce[plugin]); + // Load native external plugins. + for (var plugin in Drupal.settings.wysiwyg.plugins.tinymce.native) { + tinyMCE.loadPlugin(plugin, Drupal.settings.wysiwyg.plugins.tinymce.native[plugin]); + } + // Load Drupal plugins. + for (var plugin in Drupal.settings.wysiwyg.plugins.tinymce.drupal) { + Drupal.wysiwyg.editor.instance.tinymce.addPlugin(plugin, Drupal.settings.wysiwyg.plugins.tinymce.drupal[plugin], Drupal.settings.wysiwyg.plugins.drupal[plugin]); } }; @@ -56,3 +61,125 @@ Drupal.wysiwyg.editor.detach.tinymce = f // } }; +Drupal.wysiwyg.editor.instance.tinymce = { + addPlugin: function(plugin, settings, pluginSettings) { + // Register plugin. + tinyMCE.addPlugin(plugin, { + + // Register an editor command for this plugin, invoked by the plugin's button. + execCommand: function(editor_id, element, command, user_interface, value) { + switch (command) { + case plugin: + if (typeof Drupal.wysiwyg.plugins[plugin].invoke == 'function') { + var ed = tinyMCE.getInstanceById(editor_id); + var data = { format: 'html', node: ed.getFocusElement(), content: ed.getFocusElement() }; + Drupal.wysiwyg.plugins[plugin].invoke(data, pluginSettings, ed.formTargetElementId); + return true; + } + } + // Pass to next handler in chain. + return false; + }, + + // Register the plugin button. + getControlHTML: function(control_name) { + switch (control_name) { + case plugin: + return tinyMCE.getButtonHTML(control_name, settings.iconTitle, settings.icon, plugin); + } + return ''; + }, + + // Load custom CSS for editor contents on startup. + initInstance: function(ed) { + if (settings.css) { + tinyMCE.importCSS(ed.getDoc(), settings.css); + } + }, + + cleanup: function(type, content) { + switch (type) { + case 'insert_to_editor': + // Attach: Replace plain text with HTML representations. + if (typeof Drupal.wysiwyg.plugins[plugin].attach == 'function') { + content = Drupal.wysiwyg.plugins[plugin].attach(content, pluginSettings, tinyMCE.selectedInstance.editorId); + content = Drupal.wysiwyg.editor.instance.tinymce.prepareContent(content); + } + break; + + case 'get_from_editor': + // Detach: Replace HTML representations with plain text. + if (typeof Drupal.wysiwyg.plugins[plugin].detach == 'function') { + content = Drupal.wysiwyg.plugins[plugin].detach(content, pluginSettings, tinyMCE.selectedInstance.editorId); + } + break; + } + // Pass through to next handler in chain + return content; + }, + + // isNode: Return whether the plugin button should be enabled for the + // current selection. + handleNodeChange: function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) { + if (node == null) { + return; + } + if (typeof Drupal.wysiwyg.plugins[plugin].isNode == 'function') { + if (Drupal.wysiwyg.plugins[plugin].isNode(node)) { + tinyMCE.switchClass(editor_id + '_' + plugin, 'mceButtonSelected'); + return true; + } + } + tinyMCE.switchClass(editor_id + '_' + plugin, 'mceButtonNormal'); + return true; + }, + + /** + * Return information about the plugin as a name/value array. + */ + getInfo: function() { + return { + longname: settings.title + }; + } + }); + }, + + openDialog: function() { + }, + + closeDialog: function() { + tinyMCEPopup.close(); + }, + + prepareContent: function(content) { + // Certain content elements need to have additional DOM properties applied + // to prevent this editor from highlighting an internal button in addition + // to the button of a Drupal plugin. + var specialProperties = { + img: { name: 'mce_drupal' } + }; + $content = $('
';
+ }
+};
Index: plugins/break/editor_plugin.js
===================================================================
RCS file: plugins/break/editor_plugin.js
diff -N plugins/break/editor_plugin.js
--- plugins/break/editor_plugin.js 10 Jun 2008 18:20:14 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,148 +0,0 @@
-// $Id: editor_plugin.js,v 1.1 2008/06/10 18:20:14 sun Exp $
-
-// Import plugin language.
-tinyMCE.importPluginLanguagePack('wysiwyg', 'en');
-
-var TinyMCE_wysiwygBreakPlugin = {
- getInfo: function() {
- return {
- longname: 'Teaser break',
- author: 'Nathan Haug',
- authorurl: 'http://www.quicksketch.org',
- infourl: 'http://drupal.org/project/wysiwyg'
- };
- },
-
- initInstance: function(inst) {
- tinyMCE.importCSS(inst.getDoc(), this.baseURL + '/break.css');
- },
-
- getControlHTML: function (control_name) {
- switch (control_name) {
- case 'break':
- return tinyMCE.getButtonHTML(control_name, 'lang_break_desc', '{$pluginurl}/images/break.gif', 'break', false, 'null');
- }
- return '';
- },
-
- execCommand: function(editor_id, element, command, user_interface, value) {
- switch (command) {
- case 'break':
- var classValue = '';
- var template = new Array();
- var inst = tinyMCE.getInstanceById(editor_id);
- var focusElm = inst.getFocusElement();
-
- // Check whether selection is an image and belongs to this plugin.
- if (focusElm != null && focusElm.nodeName.toLowerCase() == 'img') {
- classValue = this.getAttrib(focusElm, 'class');
- if (classValue != 'wysiwyg-break') {
- return true;
- }
- }
-
- html = '
';
- tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, html);
- return true;
- }
- // Pass to next handler in chain.
- return false;
- },
-
- cleanup: function(type, content) {
- switch (type) {
- case 'insert_to_editor':
- // Parse all tags and replace them with images.
- var startPos = 0;
- while ((startPos = content.indexOf('', startPos)) != -1) {
- // Insert image.
- var contentAfter = content.substring(startPos + 12);
- content = content.substring(0, startPos);
- content += '
';
- content += contentAfter;
- startPos++;
- }
- break;
-
- case 'get_from_editor':
- // Parse all img tags and replace them with .
- var startPos = -1;
- while ((startPos = content.indexOf('
';
- tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, html);
- return true;
- }
- // Pass to next handler in chain.
- return false;
- },
-
- cleanup: function(type, content) {
- switch (type) {
- case 'insert_to_editor':
- // Parse all tags and replace them with images.
- var startPos = 0;
- while ((startPos = content.indexOf('', startPos)) != -1) {
- // Insert image.
- var contentAfter = content.substring(startPos + 12);
- content = content.substring(0, startPos);
- content += '
';
- content += contentAfter;
- startPos++;
- }
- break;
-
- case 'get_from_editor':
- // Parse all img tags and replace them with .
- var startPos = -1;
- while ((startPos = content.indexOf('