--- wysiwyg/editors/jwysiwyg.inc 2010-04-02 16:05:54.000000000 +0200 +++ wysiwyg_dev/editors/jwysiwyg.inc 2010-07-24 09:44:42.000000000 +0200 @@ -25,6 +25,16 @@ function wysiwyg_jwysiwyg_editor() { ), ), 'version callback' => 'wysiwyg_jwysiwyg_version', + 'settings callback' => 'wysiwyg_jwysiwyg_settings', + 'plugin callback' => 'wysiwyg_jwysiwyg_plugins', + 'plugin settings callback' => 'wysiwyg_jwysiwyg_plugin_settings', + 'proxy plugin' => array( + 'drupal' => array( + 'load' => TRUE, + 'proxy' => TRUE, + ), + ), + 'proxy plugin settings callback' => 'wysiwyg_jwysiwyg_proxy_plugin_settings', // @todo Wrong property; add separate properties for editor requisites. 'css path' => wysiwyg_get_path('jwysiwyg'), 'versions' => array( @@ -61,3 +71,149 @@ function wysiwyg_jwysiwyg_version($edito fclose($script); } +/** + * Return runtime editor settings for a given wysiwyg profile. + * + * @param $editor + * A processed hook_editor() array of editor properties. + * @param $config + * An array containing wysiwyg editor profile settings. + * @param $theme + * The name of a theme/GUI/skin to use. + * + * @return + * A settings array to be populated in + * Drupal.settings.wysiwyg.configs.{editor} + */ +function wysiwyg_jwysiwyg_settings($editor, $config, $theme) { + // Default settings, present so they can be overridden by plugins, + // except for the template and button controls which are a bit too complex. + $settings = array( + 'debug' => FALSE, + 'rmUnwantedBr' => TRUE, + 'brIE' => TRUE, + 'messages' => array( + 'nonSelection' => FAlSE, + ), + ); + if (!empty($config['buttons'])) { + // Disable all default buttons since we have a custom config. + $button_statuses = array( + 'bold' => FALSE, 'italic' => FALSE, 'underline' => FALSE, 'strikeThrough' => FALSE, + 'justifyLeft' => FALSE, 'justifyCenter' => FALSE, 'justifyRight' => FALSE, 'justifyFull' => FALSE, + 'indent' => FALSE, 'outdent' => FALSE, + 'subscript' => FALSE, 'superscript' => FALSE, + 'undo' => FALSE, 'redo' => FALSE, + 'insertUnorderedList' => FALSE, 'insertOrderedList' => FALSE, + 'insertHorizontalRule' => FALSE, + 'createLink' => FALSE, + 'insertImage' => FALSE, + 'insertTable' => FALSE, + 'h1' => FALSE, 'h2' => FALSE, 'h3' => FALSE, + 'increaseFontSize' => FALSE, 'decreaseFontSize' => FALSE, + 'removeFormat' => FALSE, + 'rtl' => FALSE, 'ltr' => FALSE, + 'html' => FALSE, + ); + $plugins = wysiwyg_get_plugins($editor['name']); + foreach ($config['buttons'] as $plugin => $buttons) { + foreach ($buttons as $button => $enabled) { + // Iterate separately over buttons and extensions properties. + foreach (array('buttons', 'extensions') as $type) { + // Skip unavailable plugins. + if (!isset($plugins[$plugin][$type][$button])) { + continue; + } + // Add button. + if ($type == 'buttons') { + $button_statuses[$button] = TRUE; + } + // Allow plugins to add or override global configuration settings. + if (!empty($plugins[$plugin]['options'])) { + $settings = array_merge($settings, $plugins[$plugin]['options']); + } + } + } + } + $settings['buttons'] = $button_statuses; + } + // Add editor content stylesheet. + if (isset($config['css_setting'])) { + if ($config['css_setting'] == 'theme') { + $settings['content_css'] = wysiwyg_get_css(); + } + else if ($config['css_setting'] == 'self' && isset($config['css_path'])) { + $settings['content_css'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme())); + } + } + return $settings; +} + +/** + * Build a JS settings array of native external plugins that need to be loaded separately. + * + * @todo Required for jWYSIWYG? If not, wysiwyg_add_plugin_settings() needs + * an overhaul. + */ +function wysiwyg_jwysiwyg_plugin_settings($editor, $profile, $plugins) { + $settings = array(); + return $settings; +} + +/** + * Build a JS settings array for Drupal plugins loaded via the proxy plugin. + */ + +function wysiwyg_jwysiwyg_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 Whizzywig; semi-implementation of hook_wysiwyg_plugin(). + */ +function wysiwyg_jwysiwyg_plugins($editor) { + return array( + 'default' => array( + 'buttons' => array( + 'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'), 'strikeThrough' => t('Strikethrough'), +// 'separator00' => t('Separator 1'), + 'justifyLeft' => t('Align left'), 'justifyCenter' => t('Align center'), 'justifyRight' => t('Align right'), 'justifyFull' => t('Justify'), +// 'separator01' => t('Separator 2'), + 'indent' => t('Indent'), 'outdent' => t('Outdent'), +// 'separator02' => t('Separator 3'), + 'subscript' => t('Subscript'), 'superscript' => t('Superscript'), +// 'separator03' => t('Separator 4'), + 'undo' => t('Undo'), 'redo' => t('Redo'), +// 'separator04' => t('Separator 5'), + 'insertUnorderedList' => t('Bullet list'), 'insertOrderedList' => t('Numbered list'), + 'insertHorizontalRule' => t('Horizontal rule'), +// 'separator05' => t('Separator 6'), + 'createLink' => t('Link'), + 'insertImage' => t('Image'), +// 'separator06' => t('Separator 7'), + 'h1' => t('Header 1'), 'h2' => t('Header 2'), 'h3' => t('Header 3'), +// 'separator07' => t('Separator 8'), + 'cut' => t('Cut'), 'copy' => t('Copy'), 'paste' => t('Paste'), +// 'separator08' => t('Separator 9'), + 'increaseFontSize' => t('Increase font size'), 'decreaseFontSize' => t('Decrease font size'), +// 'separator09' => t('Separator 10'), + 'removeFormat' => t('Remove formatting'), + 'rtl' => t('Right to left'), 'ltr' => t('Left to right'), + 'html' => t('Source code'), + ), + 'internal' => TRUE, + ), + ); +} +