first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,333 @@
<?php
/**
* @file
* Editor integration functions for CKEditor.
*/
/**
* Plugin implementation of hook_editor().
*/
function wysiwyg_ckeditor_editor() {
$editor['ckeditor'] = array(
'title' => 'CKEditor',
'vendor url' => 'http://ckeditor.com',
'download url' => 'http://ckeditor.com/download',
'libraries' => array(
'' => array(
'title' => 'Default',
'files' => array(
'ckeditor.js' => array('preprocess' => FALSE),
),
),
'src' => array(
'title' => 'Source',
'files' => array(
'ckeditor_source.js' => array('preprocess' => FALSE),
),
),
),
'version callback' => 'wysiwyg_ckeditor_version',
'themes callback' => 'wysiwyg_ckeditor_themes',
'settings callback' => 'wysiwyg_ckeditor_settings',
'plugin callback' => 'wysiwyg_ckeditor_plugins',
'plugin settings callback' => 'wysiwyg_ckeditor_plugin_settings',
'proxy plugin' => array(
'drupal' => array(
'load' => TRUE,
'proxy' => TRUE,
),
),
'proxy plugin settings callback' => 'wysiwyg_ckeditor_proxy_plugin_settings',
'versions' => array(
'3.0.0.3665' => array(
'js files' => array('ckeditor-3.0.js'),
),
),
);
return $editor;
}
/**
* Detect editor version.
*
* @param $editor
* An array containing editor properties as returned from hook_editor().
*
* @return
* The installed editor version.
*/
function wysiwyg_ckeditor_version($editor) {
$library = $editor['library path'] . '/ckeditor.js';
if (!file_exists($library)) {
return;
}
$library = fopen($library, 'r');
$max_lines = 8;
while ($max_lines && $line = fgets($library, 500)) {
// version:'CKEditor 3.0 SVN',revision:'3665'
// version:'3.0 RC',revision:'3753'
// version:'3.0.1',revision:'4391'
if (preg_match('@version:\'(?:CKEditor )?([\d\.]+)(?:.+revision:\'([\d]+))?@', $line, $version)) {
fclose($library);
// Version numbers need to have three parts since 3.0.1.
$version[1] = preg_replace('/^(\d+)\.(\d+)$/', '${1}.${2}.0', $version[1]);
return $version[1] . '.' . $version[2];
}
$max_lines--;
}
fclose($library);
}
/**
* Determine available editor themes or check/reset a given one.
*
* @param $editor
* A processed hook_editor() array of editor properties.
* @param $profile
* A wysiwyg editor profile.
*
* @return
* An array of theme names. The first returned name should be the default
* theme name.
*/
function wysiwyg_ckeditor_themes($editor, $profile) {
// @todo Skins are not themes but this will do for now.
$path = $editor['library path'] . '/skins/';
if (file_exists($path) && ($dir_handle = opendir($path))) {
$themes = array();
while ($file = readdir($dir_handle)) {
if (is_dir($path . $file) && substr($file, 0, 1) != '.' && $file != 'CVS') {
$themes[] = $file;
}
}
closedir($dir_handle);
natcasesort($themes);
$themes = array_values($themes);
return !empty($themes) ? $themes : array('default');
}
else {
return array('default');
}
}
/**
* 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_ckeditor_settings($editor, $config, $theme) {
$settings = array(
'baseHref' => $GLOBALS['base_url'] . '/',
'width' => '100%',
// For better compatibility with smaller textareas.
'resize_minWidth' => 450,
'height' => 420,
// @todo Do not use skins as themes and add separate skin handling.
'theme' => 'default',
'skin' => !empty($theme) ? $theme : 'kama',
// By default, CKEditor converts most characters into HTML entities. Since
// it does not support a custom definition, but Drupal supports Unicode, we
// disable at least the additional character sets. CKEditor always converts
// XML default characters '&', '<', '>'.
// @todo Check whether completely disabling ProcessHTMLEntities is an option.
'entities_latin' => FALSE,
'entities_greek' => FALSE,
);
// Add HTML block format settings; common block formats are already predefined
// by CKEditor.
if (isset($config['block_formats'])) {
$block_formats = explode(',', drupal_strtolower($config['block_formats']));
$predefined_formats = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'pre', 'address', 'div');
foreach (array_diff($block_formats, $predefined_formats) as $tag) {
$tag = trim($tag);
$settings["format_$tag"] = array('element' => $tag);
}
$settings['format_tags'] = implode(';', $block_formats);
}
if (isset($config['apply_source_formatting'])) {
$settings['apply_source_formatting'] = $config['apply_source_formatting'];
}
if (isset($config['css_setting'])) {
// Versions below 3.0.1 could only handle one stylesheet.
if (version_compare($editor['installed version'], '3.0.1.4391', '<')) {
if ($config['css_setting'] == 'theme') {
$settings['contentsCss'] = reset(wysiwyg_get_css());
}
elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['contentsCss'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
}
}
else {
if ($config['css_setting'] == 'theme') {
$settings['contentsCss'] = wysiwyg_get_css();
}
elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['contentsCss'] = explode(',', strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme())));
}
}
}
if (isset($config['language'])) {
$settings['language'] = $config['language'];
}
if (isset($config['resizing'])) {
// CKEditor tests "!== false", so ensure it is a Boolean.
$settings['resize_enabled'] = (bool) $config['resizing'];
}
if (isset($config['toolbar_loc'])) {
$settings['toolbarLocation'] = $config['toolbar_loc'];
}
$settings['toolbar'] = array();
if (!empty($config['buttons'])) {
$extra_plugins = array();
$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 buttons.
if ($type == 'buttons') {
$settings['toolbar'][] = $button;
}
// Add external Drupal plugins to the list of extensions.
if ($type == 'buttons' && !empty($plugins[$plugin]['proxy'])) {
$extra_plugins[] = $button;
}
// Add external plugins to the list of extensions.
elseif ($type == 'buttons' && empty($plugins[$plugin]['internal'])) {
$extra_plugins[] = $plugin;
}
// Add internal buttons that also need to be loaded as extension.
elseif ($type == 'buttons' && !empty($plugins[$plugin]['load'])) {
$extra_plugins[] = $plugin;
}
// Add plain extensions.
elseif ($type == 'extensions' && !empty($plugins[$plugin]['load'])) {
$extra_plugins[] = $plugin;
}
// Allow plugins to add or override global configuration settings.
if (!empty($plugins[$plugin]['options'])) {
$settings = array_merge($settings, $plugins[$plugin]['options']);
}
}
}
}
if (!empty($extra_plugins)) {
$settings['extraPlugins'] = implode(',', $extra_plugins);
}
}
// For now, all buttons are placed into one row.
$settings['toolbar'] = array($settings['toolbar']);
return $settings;
}
/**
* Build a JS settings array of native external plugins that need to be loaded separately.
*/
function wysiwyg_ckeditor_plugin_settings($editor, $profile, $plugins) {
$settings = array();
foreach ($plugins as $name => $plugin) {
// Register all plugins that need to be loaded.
if (!empty($plugin['load'])) {
$settings[$name] = array();
// Add path for native external plugins.
if (empty($plugin['internal']) && isset($plugin['path'])) {
$settings[$name]['path'] = base_path() . $plugin['path'] . '/';
}
// Force native internal plugins to use the standard path.
else {
$settings[$name]['path'] = base_path() . $editor['library path'] . '/plugins/' . $name . '/';
}
// CKEditor defaults to 'plugin.js' on its own when filename is not set.
if (!empty($plugin['filename'])) {
$settings[$name]['fileName'] = $plugin['filename'];
}
}
}
return $settings;
}
/**
* Build a JS settings array for Drupal plugins loaded via the proxy plugin.
*/
function wysiwyg_ckeditor_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 this editor; semi-implementation of hook_wysiwyg_plugin().
*/
function wysiwyg_ckeditor_plugins($editor) {
$plugins = array(
'default' => array(
'buttons' => array(
'Bold' => t('Bold'), 'Italic' => t('Italic'), 'Underline' => t('Underline'),
'Strike' => t('Strike-through'),
'JustifyLeft' => t('Align left'), 'JustifyCenter' => t('Align center'), 'JustifyRight' => t('Align right'), 'JustifyBlock' => t('Justify'),
'BulletedList' => t('Bullet list'), 'NumberedList' => t('Numbered list'),
'Outdent' => t('Outdent'), 'Indent' => t('Indent'),
'Undo' => t('Undo'), 'Redo' => t('Redo'),
'Link' => t('Link'), 'Unlink' => t('Unlink'), 'Anchor' => t('Anchor'),
'Image' => t('Image'),
'TextColor' => t('Forecolor'), 'BGColor' => t('Backcolor'),
'Superscript' => t('Superscript'), 'Subscript' => t('Subscript'),
'Blockquote' => t('Blockquote'), 'Source' => t('Source code'),
'HorizontalRule' => t('Horizontal rule'),
'Cut' => t('Cut'), 'Copy' => t('Copy'), 'Paste' => t('Paste'),
'PasteText' => t('Paste Text'), 'PasteFromWord' => t('Paste from Word'),
'ShowBlocks' => t('Show blocks'),
'RemoveFormat' => t('Remove format'),
'SpecialChar' => t('Character map'),
'Format' => t('HTML block format'), 'Font' => t('Font'), 'FontSize' => t('Font size'), 'Styles' => t('Font style'),
'Table' => t('Table'),
'SelectAll' => t('Select all'), 'Find' => t('Search'), 'Replace' => t('Replace'),
'Flash' => t('Flash'), 'Smiley' => t('Smiley'),
'CreateDiv' => t('Div container'),
'Iframe' => t('iFrame'),
'Maximize' => t('Maximize'),
'SpellChecker' => t('Check spelling'), 'Scayt' => t('Check spelling as you type'),
'About' => t('About'),
),
'internal' => TRUE,
),
);
if (version_compare($editor['installed version'], '3.1.0.4885', '<')) {
unset($plugins['default']['buttons']['CreateDiv']);
}
if (version_compare($editor['installed version'], '3.5.0.6260', '<')) {
unset($plugins['default']['buttons']['Iframe']);
}
return $plugins;
}

View File

@@ -0,0 +1,11 @@
/**
* openWYSIWYG.
*/
table.tableTextareaEditor, table.tableTextareaEditor table {
margin: 0;
border-collapse: separate;
}
table.tableTextareaEditor td {
padding: 0;
}

View File

@@ -0,0 +1,27 @@
/**
* TinyMCE 2.x
*/
table.mceEditor {
clear: left;
}
/**
* Align all buttons and separators in a single row, so they wrap into multiple
* rows if required.
*/
.mceToolbarTop a, .mceToolbarBottom a {
float: left;
}
.mceSeparatorLine {
float: left;
margin-top: 3px;
}
.mceSelectList {
float: left;
margin-bottom: 1px;
}
/* Place table plugin buttons into new row */
#mce_editor_0_table, #mce_editor_1_table {
clear: left;
}

View File

@@ -0,0 +1,24 @@
/**
* TinyMCE 3.x
*/
table.mceLayout {
clear: left;
}
/**
* Align all buttons and separators in a single row, so they wrap into multiple
* rows if required.
*/
.mceToolbar td {
display: inline;
}
.mceToolbar a,
.mceSeparator {
float: left;
}
.mceListBox,
.mceSplitButton {
float: left;
margin-bottom: 1px;
}

View File

@@ -0,0 +1,292 @@
<?php
/**
* @file
* Editor integration functions for FCKeditor.
*/
/**
* Plugin implementation of hook_editor().
*/
function wysiwyg_fckeditor_editor() {
$editor['fckeditor'] = array(
'title' => 'FCKeditor',
'vendor url' => 'http://www.fckeditor.net',
'download url' => 'http://www.fckeditor.net/download',
'libraries' => array(
'' => array(
'title' => 'Default',
'files' => array('fckeditor.js'),
),
),
'version callback' => 'wysiwyg_fckeditor_version',
'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'),
),
),
);
return $editor;
}
/**
* Detect editor version.
*
* @param $editor
* An array containing editor properties as returned from hook_editor().
*
* @return
* The installed editor version.
*/
function wysiwyg_fckeditor_version($editor) {
$library = $editor['library path'] . '/fckeditor.js';
if (!file_exists($library)) {
return;
}
$library = fopen($library, 'r');
$max_lines = 100;
while ($max_lines && $line = fgets($library, 60)) {
if (preg_match('@^FCKeditor.prototype.Version\s*= \'([\d\.]+)@', $line, $version)) {
fclose($library);
return $version[1];
}
$max_lines--;
}
fclose($library);
}
/**
* Determine available editor themes or check/reset a given one.
*
* @param $editor
* A processed hook_editor() array of editor properties.
* @param $profile
* A wysiwyg editor profile.
*
* @return
* An array of theme names. The first returned name should be the default
* theme name.
*/
function wysiwyg_fckeditor_themes($editor, $profile) {
return array('default', 'office2003', 'silver');
}
/**
* 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_fckeditor_settings($editor, $config, $theme) {
$settings = array(
'EditorPath' => base_path() . $editor['library path'] . '/',
'SkinPath' => base_path() . $editor['library path'] . '/editor/skins/' . $theme . '/',
'CustomConfigurationsPath' => base_path() . drupal_get_path('module', 'wysiwyg') . '/editors/js/fckeditor.config.js',
'Width' => '100%',
'Height' => 420,
'LinkBrowser' => FALSE,
'LinkUpload' => FALSE,
'ImageBrowser' => FALSE,
'ImageUpload' => FALSE,
'FlashBrowser' => FALSE,
'FlashUpload' => FALSE,
// By default, FCKeditor converts most characters into HTML entities. Since
// it does not support a custom definition, but Drupal supports Unicode, we
// disable at least the additional character sets. FCKeditor always converts
// XML default characters '&', '<', '>'.
// @todo Check whether completely disabling ProcessHTMLEntities is an option.
'IncludeLatinEntities' => FALSE,
'IncludeGreekEntities' => FALSE,
);
if (isset($config['block_formats'])) {
$settings['FontFormats'] = strtr($config['block_formats'], array(',' => ';'));
}
if (isset($config['apply_source_formatting'])) {
$settings['FormatOutput'] = $settings['FormatSource'] = $config['apply_source_formatting'];
}
if (isset($config['paste_auto_cleanup_on_paste'])) {
$settings['AutoDetectPasteFromWord'] = $config['paste_auto_cleanup_on_paste'];
}
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
$settings['EditorAreaCSS'] = implode(',', wysiwyg_get_css());
}
else if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['EditorAreaCSS'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
}
}
// Use our custom toolbar set.
$settings['ToolbarSet'] = 'Wysiwyg';
// Populate our custom toolbar set for fckeditor.config.js.
$settings['buttons'] = array();
if (!empty($config['buttons'])) {
$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 buttons.
if ($type == 'buttons') {
$settings['buttons'][] = $button;
}
// Allow plugins to add or override global configuration settings.
if (!empty($plugins[$plugin]['options'])) {
$settings = array_merge($settings, $plugins[$plugin]['options']);
}
}
}
}
}
// For now, all buttons are placed into one row.
$settings['buttons'] = array($settings['buttons']);
return $settings;
}
/**
* Build a JS settings array of native external plugins that need to be loaded separately.
*/
function wysiwyg_fckeditor_plugin_settings($editor, $profile, $plugins) {
$settings = array();
foreach ($plugins as $name => $plugin) {
// Register all plugins that need to be loaded.
if (!empty($plugin['load'])) {
$settings[$name] = array();
// Add path for native external plugins; internal ones do not need a path.
if (empty($plugin['internal']) && isset($plugin['path'])) {
// All native FCKeditor plugins use the filename fckplugin.js.
$settings[$name]['path'] = base_path() . $plugin['path'] . '/';
}
if (!empty($plugin['languages'])) {
$settings[$name]['languages'] = $plugin['languages'];
}
}
}
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 this editor; semi-implementation of hook_wysiwyg_plugin().
*/
function wysiwyg_fckeditor_plugins($editor) {
$plugins = array(
'default' => array(
'buttons' => array(
'Bold' => t('Bold'), 'Italic' => t('Italic'), 'Underline' => t('Underline'),
'StrikeThrough' => t('Strike-through'),
'JustifyLeft' => t('Align left'), 'JustifyCenter' => t('Align center'), 'JustifyRight' => t('Align right'), 'JustifyFull' => t('Justify'),
'UnorderedList' => t('Bullet list'), 'OrderedList' => t('Numbered list'),
'Outdent' => t('Outdent'), 'Indent' => t('Indent'),
'Undo' => t('Undo'), 'Redo' => t('Redo'),
'Link' => t('Link'), 'Unlink' => t('Unlink'), 'Anchor' => t('Anchor'),
'Image' => t('Image'),
'TextColor' => t('Forecolor'), 'BGColor' => t('Backcolor'),
'Superscript' => t('Superscript'), 'Subscript' => t('Subscript'),
'Blockquote' => t('Blockquote'), 'Source' => t('Source code'),
'Rule' => t('Horizontal rule'),
'Cut' => t('Cut'), 'Copy' => t('Copy'), 'Paste' => t('Paste'),
'PasteText' => t('Paste Text'), 'PasteWord' => t('Paste from Word'),
'ShowBlocks' => t('Show blocks'),
'RemoveFormat' => t('Remove format'),
'SpecialChar' => t('Character map'),
'About' => t('About'),
'FontFormat' => t('HTML block format'), 'FontName' => t('Font'), 'FontSize' => t('Font size'), 'Style' => t('Font style'),
'Table' => t('Table'),
'Find' => t('Search'), 'Replace' => t('Replace'), 'SelectAll' => t('Select all'),
'CreateDiv' => t('Create DIV container'),
'Flash' => t('Flash'), 'Smiley' => t('Smiley'),
'FitWindow' => t('FitWindow'),
'SpellCheck' => t('Check spelling'),
),
'internal' => TRUE,
),
'autogrow' => array(
'path' => $editor['library path'] . '/editor/plugins',
'extensions' => array(
'autogrow' => t('Autogrow'),
),
'options' => array(
'AutoGrowMax' => 800,
),
'internal' => TRUE,
'load' => TRUE,
),
'bbcode' => array(
'path' => $editor['library path'] . '/editor/plugins',
'extensions' => array(
'bbcode' => t('BBCode'),
),
'internal' => TRUE,
'load' => TRUE,
),
'dragresizetable' => array(
'path' => $editor['library path'] . '/editor/plugins',
'extensions' => array(
'dragresizetable' => t('Table drag/resize'),
),
'internal' => TRUE,
'load' => TRUE,
),
'tablecommands' => array(
'path' => $editor['library path'] . '/editor/plugins',
'buttons' => array(
'TableCellProp' => t('Table: Cell properties'),
'TableInsertRowAfter' => t('Table: Insert row after'),
'TableInsertColumnAfter' => t('Table: Insert column after'),
'TableInsertCellAfter' => t('Table: Insert cell after'),
'TableDeleteRows' => t('Table: Delete rows'),
'TableDeleteColumns' => t('Table: Delete columns'),
'TableDeleteCells' => t('Table: Delete cells'),
'TableMergeCells' => t('Table: Merge cells'),
'TableHorizontalSplitCell' => t('Table: Horizontal split cell'),
),
'internal' => TRUE,
'load' => TRUE,
),
);
return $plugins;
}

View File

@@ -0,0 +1,217 @@
(function($) {
Drupal.wysiwyg.editor.init.ckeditor = function(settings) {
// Plugins must only be loaded once. Only the settings from the first format
// will be used but they're identical anyway.
var registeredPlugins = {};
for (var format in settings) {
if (Drupal.settings.wysiwyg.plugins[format]) {
// Register native external plugins.
// Array syntax required; 'native' is a predefined token in JavaScript.
for (var pluginName in Drupal.settings.wysiwyg.plugins[format]['native']) {
if (!registeredPlugins[pluginName]) {
var plugin = Drupal.settings.wysiwyg.plugins[format]['native'][pluginName];
CKEDITOR.plugins.addExternal(pluginName, plugin.path, plugin.fileName);
registeredPlugins[pluginName] = true;
}
}
// Register Drupal plugins.
for (var pluginName in Drupal.settings.wysiwyg.plugins[format].drupal) {
if (!registeredPlugins[pluginName]) {
Drupal.wysiwyg.editor.instance.ckeditor.addPlugin(pluginName, Drupal.settings.wysiwyg.plugins[format].drupal[pluginName], Drupal.settings.wysiwyg.plugins.drupal[pluginName]);
registeredPlugins[pluginName] = true;
}
}
}
}
};
/**
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.ckeditor = function(context, params, settings) {
// Apply editor instance settings.
CKEDITOR.config.customConfig = '';
settings.on = {
instanceReady: function(ev) {
var editor = ev.editor;
// Get a list of block, list and table tags from CKEditor's XHTML DTD.
// @see http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Output_Formatting.
var dtd = CKEDITOR.dtd;
var tags = CKEDITOR.tools.extend({}, dtd.$block, dtd.$listItem, dtd.$tableContent);
// Set source formatting rules for each listed tag except <pre>.
// Linebreaks can be inserted before or after opening and closing tags.
if (settings.apply_source_formatting) {
// Mimic FCKeditor output, by breaking lines between tags.
for (var tag in tags) {
if (tag == 'pre') {
continue;
}
this.dataProcessor.writer.setRules(tag, {
indent: true,
breakBeforeOpen: true,
breakAfterOpen: false,
breakBeforeClose: false,
breakAfterClose: true
});
}
}
else {
// CKEditor adds default formatting to <br>, so we want to remove that
// here too.
tags.br = 1;
// No indents or linebreaks;
for (var tag in tags) {
if (tag == 'pre') {
continue;
}
this.dataProcessor.writer.setRules(tag, {
indent: false,
breakBeforeOpen: false,
breakAfterOpen: false,
breakBeforeClose: false,
breakAfterClose: false
});
}
}
},
pluginsLoaded: function(ev) {
// Override the conversion methods to let Drupal plugins modify the data.
var editor = ev.editor;
if (editor.dataProcessor && Drupal.settings.wysiwyg.plugins[params.format]) {
editor.dataProcessor.toHtml = CKEDITOR.tools.override(editor.dataProcessor.toHtml, function(originalToHtml) {
// Convert raw data for display in WYSIWYG mode.
return function(data, fixForBody) {
for (var plugin in Drupal.settings.wysiwyg.plugins[params.format].drupal) {
if (typeof Drupal.wysiwyg.plugins[plugin].attach == 'function') {
data = Drupal.wysiwyg.plugins[plugin].attach(data, Drupal.settings.wysiwyg.plugins.drupal[plugin], editor.name);
data = Drupal.wysiwyg.instances[params.field].prepareContent(data);
}
}
return originalToHtml.call(this, data, fixForBody);
};
});
editor.dataProcessor.toDataFormat = CKEDITOR.tools.override(editor.dataProcessor.toDataFormat, function(originalToDataFormat) {
// Convert WYSIWYG mode content to raw data.
return function(data, fixForBody) {
data = originalToDataFormat.call(this, data, fixForBody);
for (var plugin in Drupal.settings.wysiwyg.plugins[params.format].drupal) {
if (typeof Drupal.wysiwyg.plugins[plugin].detach == 'function') {
data = Drupal.wysiwyg.plugins[plugin].detach(data, Drupal.settings.wysiwyg.plugins.drupal[plugin], editor.name);
}
}
return data;
};
});
}
},
selectionChange: function (event) {
var pluginSettings = Drupal.settings.wysiwyg.plugins[params.format];
if (pluginSettings && pluginSettings.drupal) {
$.each(pluginSettings.drupal, function (name) {
var plugin = Drupal.wysiwyg.plugins[name];
if ($.isFunction(plugin.isNode)) {
var node = event.data.selection.getSelectedElement();
var state = plugin.isNode(node ? node.$ : null) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF;
event.editor.getCommand(name).setState(state);
}
});
}
},
focus: function(ev) {
Drupal.wysiwyg.activeId = ev.editor.name;
}
};
// Attach editor.
CKEDITOR.replace(params.field, settings);
};
/**
* Detach a single or all editors.
*
* @todo 3.x: editor.prototype.getInstances() should always return an array
* containing all instances or the passed in params.field instance, but
* always return an array to simplify all detach functions.
*/
Drupal.wysiwyg.editor.detach.ckeditor = function(context, params) {
if (typeof params != 'undefined') {
var instance = CKEDITOR.instances[params.field];
if (instance) {
instance.destroy();
}
}
else {
for (var instanceName in CKEDITOR.instances) {
CKEDITOR.instances[instanceName].destroy();
}
}
};
Drupal.wysiwyg.editor.instance.ckeditor = {
addPlugin: function(pluginName, settings, pluginSettings) {
CKEDITOR.plugins.add(pluginName, {
// Wrap Drupal plugin in a proxy pluygin.
init: function(editor) {
if (settings.css) {
editor.on('mode', function(ev) {
if (ev.editor.mode == 'wysiwyg') {
// Inject CSS files directly into the editing area head tag.
$('head', $('#cke_contents_' + ev.editor.name + ' iframe').eq(0).contents()).append('<link rel="stylesheet" href="' + settings.css + '" type="text/css" >');
}
});
}
if (typeof Drupal.wysiwyg.plugins[pluginName].invoke == 'function') {
var pluginCommand = {
exec: function (editor) {
var data = { format: 'html', node: null, content: '' };
var selection = editor.getSelection();
if (selection) {
data.node = selection.getSelectedElement();
if (data.node) {
data.node = data.node.$;
}
if (selection.getType() == CKEDITOR.SELECTION_TEXT) {
if (CKEDITOR.env.ie) {
data.content = selection.getNative().createRange().text;
}
else {
data.content = selection.getNative().toString();
}
}
else if (data.node) {
// content is supposed to contain the "outerHTML".
data.content = data.node.parentNode.innerHTML;
}
}
Drupal.wysiwyg.plugins[pluginName].invoke(data, pluginSettings, editor.name);
}
};
editor.addCommand(pluginName, pluginCommand);
}
editor.ui.addButton(pluginName, {
label: settings.iconTitle,
command: pluginName,
icon: settings.icon
});
// @todo Add button state handling.
}
});
},
prepareContent: function(content) {
// @todo Don't know if we need this yet.
return content;
},
insert: function(content) {
content = this.prepareContent(content);
CKEDITOR.instances[this.field].insertHtml(content);
}
};
})(jQuery);

View File

@@ -0,0 +1,181 @@
(function($) {
/**
* 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, settings.ToolbarSet);
// Apply editor instance settings.
FCKinstance.BasePath = settings.EditorPath;
FCKinstance.Config.wysiwygFormat = params.format;
FCKinstance.Config.CustomConfigurationsPath = settings.CustomConfigurationsPath;
// Load Drupal plugins and apply format specific settings.
// @see fckeditor.config.js
// @see Drupal.wysiwyg.editor.instance.fckeditor.init()
// Attach editor.
FCKinstance.ReplaceTextarea();
};
/**
* 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) {
instances[params.field] = instance;
}
}
else {
instances = FCKeditorAPI.__Instances;
}
for (var instanceName in instances) {
var instance = instances[instanceName];
instance.UpdateLinkedField();
// Since we already detach the editor and update the textarea, the submit
// event handler needs to be removed to prevent data loss (in IE).
// FCKeditor uses 2 nested iFrames; instance.EditingArea.Window is the
// deepest. Its parent is the iFrame containing the editor.
var instanceScope = instance.EditingArea.Window.parent;
instanceScope.FCKTools.RemoveEventListener(instance.GetParentForm(), 'submit', instance.UpdateLinkedField);
// Run cleanups before forcing an unload of the iFrames or IE crashes.
// This also deletes the instance from the FCKeditorAPI.__Instances array.
instanceScope.FCKTools.RemoveEventListener(instanceScope, 'unload', instanceScope.FCKeditorAPI_Cleanup);
instanceScope.FCKTools.RemoveEventListener(instanceScope, 'beforeunload', instanceScope.FCKeditorAPI_ConfirmCleanup);
if (jQuery.isFunction(instanceScope.FCKIECleanup_Cleanup)) {
instanceScope.FCKIECleanup_Cleanup();
}
instanceScope.FCKeditorAPI_ConfirmCleanup();
instanceScope.FCKeditorAPI_Cleanup();
// Remove the editor elements.
$('#' + instanceName + '___Config').remove();
$('#' + instanceName + '___Frame').remove();
$('#' + instanceName).show();
}
};
Drupal.wysiwyg.editor.instance.fckeditor = {
init: function(instance) {
// Track which editor instance is active.
instance.FCK.Events.AttachEvent('OnFocus', function(editorInstance) {
Drupal.wysiwyg.activeId = editorInstance.Name;
});
// Create a custom data processor to wrap the default one and allow Drupal
// plugins modify the editor contents.
var wysiwygDataProcessor = function() {};
wysiwygDataProcessor.prototype = new instance.FCKDataProcessor();
// Attach: Convert text into HTML.
wysiwygDataProcessor.prototype.ConvertToHtml = function(data) {
// Called from SetData() with stripped comments/scripts, revert those
// manipulations and attach Drupal plugins.
var data = instance.FCKConfig.ProtectedSource.Revert(data);
if (Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat] && Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal) {
for (var plugin in Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal) {
if (typeof Drupal.wysiwyg.plugins[plugin].attach == 'function') {
data = Drupal.wysiwyg.plugins[plugin].attach(data, Drupal.settings.wysiwyg.plugins.drupal[plugin], instance.FCK.Name);
data = Drupal.wysiwyg.editor.instance.fckeditor.prepareContent(data);
}
}
}
// Re-protect the source and use the original data processor to convert it
// into XHTML.
data = instance.FCKConfig.ProtectedSource.Protect(data);
return instance.FCKDataProcessor.prototype.ConvertToHtml.call(this, data);
};
// Detach: Convert HTML into text.
wysiwygDataProcessor.prototype.ConvertToDataFormat = function(rootNode, excludeRoot, ignoreIfEmptyParagraph, format) {
// Called from GetData(), convert the content's DOM into a XHTML string
// using the original data processor and detach Drupal plugins.
var data = instance.FCKDataProcessor.prototype.ConvertToDataFormat.call(this, rootNode, excludeRoot, ignoreIfEmptyParagraph, format);
if (Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat] && Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal) {
for (var plugin in Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal) {
if (typeof Drupal.wysiwyg.plugins[plugin].detach == 'function') {
data = Drupal.wysiwyg.plugins[plugin].detach(data, Drupal.settings.wysiwyg.plugins.drupal[plugin], instance.FCK.Name);
}
}
}
return data;
};
instance.FCK.DataProcessor = new wysiwygDataProcessor();
},
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 () {
// Always disabled if not in WYSIWYG mode.
if (instance.FCK.EditMode != FCK_EDITMODE_WYSIWYG) {
return FCK_TRISTATE_DISABLED;
}
var state = instance.FCK.GetNamedCommandState(this.Name);
// FCKeditor sets the wrong state in WebKit browsers.
if (!$.support.queryCommandEnabled && state == FCK_TRISTATE_DISABLED) {
state = FCK_TRISTATE_OFF;
}
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.
// Arguments: 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);
}
};
})(jQuery);

View File

@@ -0,0 +1,73 @@
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.
* 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];
var pluginSettings = (Drupal.settings.wysiwyg.plugins[wysiwygFormat] ? Drupal.settings.wysiwyg.plugins[wysiwygFormat] : { 'native': {}, 'drupal': {} });
/**
* Apply format-specific settings.
*/
for (var setting in wysiwygSettings) {
if (setting == 'buttons') {
// Apply custom Wysiwyg toolbar for this format.
// FCKConfig.ToolbarSets['Wysiwyg'] = wysiwygSettings.buttons;
// Temporarily stack buttons into multiple button groups and remove
// separators until #277954 is solved.
FCKConfig.ToolbarSets['Wysiwyg'] = [];
for (var i = 0; i < wysiwygSettings.buttons[0].length; i++) {
FCKConfig.ToolbarSets['Wysiwyg'].push([wysiwygSettings.buttons[0][i]]);
}
FCKTools.AppendStyleSheet(document, '#xToolbar .TB_Start { display:none; }');
// Set valid height of select element in silver and office2003 skins.
if (FCKConfig.SkinPath.match(/\/office2003\/$/)) {
FCKTools.AppendStyleSheet(document, '#xToolbar .SC_FieldCaption { height: 24px; } #xToolbar .TB_End { display: none; }');
}
else if (FCKConfig.SkinPath.match(/\/silver\/$/)) {
FCKTools.AppendStyleSheet(document, '#xToolbar .SC_FieldCaption { height: 27px; }');
}
}
else {
FCKConfig[setting] = wysiwygSettings[setting];
}
}
/**
* Initialize this editor instance.
*/
Drupal.wysiwyg.editor.instance.fckeditor.init(window);
/**
* Register native plugins for this input format.
*
* Parameters to Plugins.Add are:
* - Plugin name.
* - Languages the plugin is available in.
* - Location of the plugin folder; <plugin_name>/fckplugin.js is appended.
*/
for (var plugin in pluginSettings['native']) {
// Languages and path may be undefined for internal plugins.
FCKConfig.Plugins.Add(plugin, pluginSettings['native'][plugin].languages, pluginSettings['native'][plugin].path);
}
/**
* 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.
*/
for (var plugin in pluginSettings.drupal) {
Drupal.wysiwyg.editor.instance.fckeditor.addPlugin(plugin, pluginSettings.drupal[plugin], Drupal.settings.wysiwyg.plugins.drupal[plugin], window);
}

View File

@@ -0,0 +1,25 @@
(function($) {
/**
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.jwysiwyg = function(context, params, settings) {
// Attach editor.
$('#' + params.field).wysiwyg();
};
/**
* Detach a single or all editors.
*/
Drupal.wysiwyg.editor.detach.jwysiwyg = function(context, params) {
var $field = $('#' + params.field);
var editor = $field.data('wysiwyg');
if (typeof editor != 'undefined') {
editor.saveContent();
editor.element.remove();
}
$field.removeData('wysiwyg');
$field.show();
};
})(jQuery);

View File

@@ -0,0 +1,29 @@
(function($) {
/**
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.markitup = function(context, params, settings) {
$('#' + params.field, context).markItUp(settings);
// Adjust CSS for editor buttons.
$.each(settings.markupSet, function (button) {
$('.' + settings.nameSpace + ' .' + this.className + ' a')
.css({ backgroundImage: 'url(' + settings.root + 'sets/default/images/' + button + '.png' + ')' })
.parents('li').css({ backgroundImage: 'none' });
});
};
/**
* Detach a single or all editors.
*/
Drupal.wysiwyg.editor.detach.markitup = function(context, params) {
if (typeof params != 'undefined') {
$('#' + params.field, context).markItUpRemove();
}
else {
$('.markItUpEditor', context).markItUpRemove();
}
};
})(jQuery);

View File

@@ -0,0 +1,95 @@
(function($) {
/**
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.nicedit = function(context, params, settings) {
// Intercept and ignore submit handlers or they will revert changes made
// since the instance was removed. The handlers are anonymous and hidden out
// of scope in a closure so we can't unbind them. The same operations are
// performed when the instance is detached anyway.
var oldAddEvent = bkLib.addEvent;
bkLib.addEvent = function(obj, type, fn) {
if (type != 'submit') {
oldAddEvent(obj, type, fn);
}
}
// Attach editor.
var editor = new nicEditor(settings);
editor.panelInstance(params.field);
// The old addEvent() must be restored after creating a new instance, as
// plugins with dialogs use it to bind submit handlers to their forms.
bkLib.addEvent = oldAddEvent;
editor.addEvent('focus', function () {
Drupal.wysiwyg.activeId = params.field;
});
};
/**
* Detach a single or all editors.
*
* See Drupal.wysiwyg.editor.detach.none() for a full description of this hook.
*/
Drupal.wysiwyg.editor.detach.nicedit = function(context, params) {
if (typeof params != 'undefined') {
var instance = nicEditors.findEditor(params.field);
if (instance) {
instance.ne.removeInstance(params.field);
instance.ne.removePanel();
}
}
else {
for (var e in nicEditors.editors) {
// Save contents of all editors back into textareas.
var instances = nicEditors.editors[e].nicInstances;
for (var i = 0; i < instances.length; i++) {
instances[i].remove();
}
// Remove all editor instances.
nicEditors.editors[e].nicInstances = [];
}
}
};
/**
* Instance methods for nicEdit.
*/
Drupal.wysiwyg.editor.instance.nicedit = {
insert: function (content) {
var instance = nicEditors.findEditor(this.field);
var editingArea = instance.getElm();
var sel = instance.getSel();
// IE.
if (document.selection) {
editingArea.focus();
sel.createRange().text = content;
}
else {
// Convert selection to a range.
var range;
// W3C compatible.
if (sel.getRangeAt) {
range = sel.getRangeAt(0);
}
// Safari.
else {
range = editingArea.ownerDocument.createRange();
range.setStart(sel.anchorNode, sel.anchorOffset);
range.setEnd(sel.focusNode, userSeletion.focusOffset);
}
// The code below doesn't work in IE, but it never gets here.
var fragment = editingArea.ownerDocument.createDocumentFragment();
// Fragments don't support innerHTML.
var wrapper = editingArea.ownerDocument.createElement('div');
wrapper.innerHTML = content;
while (wrapper.firstChild) {
fragment.appendChild(wrapper.firstChild);
}
range.deleteContents();
// Only fragment children are inserted.
range.insertNode(fragment);
}
}
};
})(jQuery);

View File

@@ -0,0 +1,71 @@
(function($) {
/**
* Attach this editor to a target element.
*
* @param context
* A DOM element, supplied by Drupal.attachBehaviors().
* @param params
* An object containing input format parameters. Default parameters are:
* - editor: The internal editor name.
* - theme: The name/key of the editor theme/profile to use.
* - field: The CSS id of the target element.
* @param settings
* An object containing editor settings for all enabled editor themes.
*/
Drupal.wysiwyg.editor.attach.none = function(context, params, settings) {
if (params.resizable) {
var $wrapper = $('#' + params.field).parents('.form-textarea-wrapper:first');
$wrapper.addClass('resizable');
if (Drupal.behaviors.textarea.attach) {
Drupal.behaviors.textarea.attach();
}
}
};
/**
* Detach a single or all editors.
*
* @param context
* A DOM element, supplied by Drupal.attachBehaviors().
* @param params
* (optional) An object containing input format parameters. If defined,
* only the editor instance in params.field should be detached. Otherwise,
* all editors should be detached and saved, so they can be submitted in
* AJAX/AHAH applications.
*/
Drupal.wysiwyg.editor.detach.none = function(context, params) {
if (typeof params != 'undefined') {
var $wrapper = $('#' + params.field).parents('.form-textarea-wrapper:first');
$wrapper.removeOnce('textarea').removeClass('.resizable-textarea')
.find('.grippie').remove();
}
};
/**
* Instance methods for plain text areas.
*/
Drupal.wysiwyg.editor.instance.none = {
insert: function(content) {
var editor = document.getElementById(this.field);
// IE support.
if (document.selection) {
editor.focus();
var 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;
}
}
};
})(jQuery);

View File

@@ -0,0 +1,68 @@
// Backup $ and reset it to jQuery.
Drupal.wysiwyg._openwysiwyg = $;
$ = jQuery;
// Wrap openWYSIWYG's methods to temporarily use its version of $.
jQuery.each(WYSIWYG, function (key, value) {
if (jQuery.isFunction(value)) {
WYSIWYG[key] = function () {
var old$ = $;
$ = Drupal.wysiwyg._openwysiwyg;
var result = value.apply(this, arguments);
$ = old$;
return result;
};
}
});
// Override editor functions.
WYSIWYG.getEditor = function (n) {
return Drupal.wysiwyg._openwysiwyg("wysiwyg" + n);
};
(function($) {
/**
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.openwysiwyg = function(context, params, settings) {
// Initialize settings.
settings.ImagesDir = settings.path + 'images/';
settings.PopupsDir = settings.path + 'popups/';
settings.CSSFile = settings.path + 'styles/wysiwyg.css';
//settings.DropDowns = [];
var config = new WYSIWYG.Settings();
for (var setting in settings) {
config[setting] = settings[setting];
}
// Attach editor.
WYSIWYG.setSettings(params.field, config);
WYSIWYG_Core.includeCSS(WYSIWYG.config[params.field].CSSFile);
WYSIWYG._generate(params.field, config);
};
/**
* Detach a single or all editors.
*/
Drupal.wysiwyg.editor.detach.openwysiwyg = function(context, params) {
if (typeof params != 'undefined') {
var instance = WYSIWYG.config[params.field];
if (typeof instance != 'undefined') {
WYSIWYG.updateTextArea(params.field);
jQuery('#wysiwyg_div_' + params.field).remove();
delete instance;
}
jQuery('#' + params.field).show();
}
else {
jQuery.each(WYSIWYG.config, function(field) {
WYSIWYG.updateTextArea(field);
jQuery('#wysiwyg_div_' + field).remove();
delete this;
jQuery('#' + field).show();
});
}
};
})(jQuery);

View File

@@ -0,0 +1,213 @@
(function($) {
/**
* Initialize editor instances.
*
* This function needs to be called before the page is fully loaded, as
* calling tinyMCE.init() after the page is loaded breaks IE6.
*
* @param editorSettings
* An object containing editor settings for each input format.
*/
Drupal.wysiwyg.editor.init.tinymce = function(settings) {
// If JS compression is enabled, TinyMCE is unable to autodetect its global
// settinge, hence we need to define them manually.
// @todo Move global library settings somewhere else.
tinyMCE.baseURL = settings.global.editorBasePath;
tinyMCE.srcMode = (settings.global.execMode == 'src' ? '_src' : '');
tinyMCE.gzipMode = (settings.global.execMode == 'gzip');
// Initialize editor configurations.
for (var format in settings) {
if (format == 'global') {
continue;
}
tinyMCE.init(settings[format]);
if (Drupal.settings.wysiwyg.plugins[format]) {
// Load native external plugins.
// Array syntax required; 'native' is a predefined token in JavaScript.
for (var plugin in Drupal.settings.wysiwyg.plugins[format]['native']) {
tinyMCE.loadPlugin(plugin, Drupal.settings.wysiwyg.plugins[format]['native'][plugin]);
}
// Load Drupal plugins.
for (var plugin in Drupal.settings.wysiwyg.plugins[format].drupal) {
Drupal.wysiwyg.editor.instance.tinymce.addPlugin(plugin, Drupal.settings.wysiwyg.plugins[format].drupal[plugin], Drupal.settings.wysiwyg.plugins.drupal[plugin]);
}
}
}
};
/**
* Attach this editor to a target element.
*
* See Drupal.wysiwyg.editor.attach.none() for a full desciption of this hook.
*/
Drupal.wysiwyg.editor.attach.tinymce = function(context, params, settings) {
// Configure editor settings for this input format.
for (var setting in settings) {
tinyMCE.settings[setting] = settings[setting];
}
// Remove TinyMCE's internal mceItem class, which was incorrectly added to
// submitted content by Wysiwyg <2.1. TinyMCE only temporarily adds the class
// for placeholder elements. If preemptively set, the class prevents (native)
// editor plugins from gaining an active state, so we have to manually remove
// it prior to attaching the editor. This is done on the client-side instead
// of the server-side, as Wysiwyg has no way to figure out where content is
// stored, and the class only affects editing.
$field = $('#' + params.field);
$field.val($field.val().replace(/(<.+?\s+class=['"][\w\s]*?)\bmceItem\b([\w\s]*?['"].*?>)/ig, '$1$2'));
// Attach editor.
tinyMCE.execCommand('mceAddControl', true, params.field);
};
/**
* Detach a single or all editors.
*
* See Drupal.wysiwyg.editor.detach.none() for a full desciption of this hook.
*/
Drupal.wysiwyg.editor.detach.tinymce = function(context, params) {
if (typeof params != 'undefined') {
tinyMCE.removeMCEControl(tinyMCE.getEditorId(params.field));
$('#' + params.field).removeAttr('style');
}
// else if (tinyMCE.activeEditor) {
// tinyMCE.triggerSave();
// tinyMCE.activeEditor.remove();
// }
};
Drupal.wysiwyg.editor.instance.tinymce = {
addPlugin: function(plugin, settings, pluginSettings) {
if (typeof Drupal.wysiwyg.plugins[plugin] != 'object') {
return;
}
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(dialog, params) {
var editor = tinyMCE.getInstanceById(this.field);
tinyMCE.openWindow({
file: dialog.url + '/' + this.field,
width: dialog.width,
height: dialog.height,
inline: 1
}, params);
},
closeDialog: function(dialog) {
var editor = tinyMCE.getInstanceById(this.field);
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' }
};
var $content = $('<div>' + content + '</div>'); // No .outerHTML() in jQuery :(
jQuery.each(specialProperties, function(element, properties) {
$content.find(element).each(function() {
for (var property in properties) {
if (property == 'class') {
$(this).addClass(properties[property]);
}
else {
$(this).attr(property, properties[property]);
}
}
});
});
return $content.html();
},
insert: function(content) {
content = this.prepareContent(content);
var editor = tinyMCE.getInstanceById(this.field);
editor.execCommand('mceInsertContent', false, content);
editor.repaint();
}
};
})(jQuery);

View File

@@ -0,0 +1,235 @@
(function($) {
/**
* Initialize editor instances.
*
* @todo Is the following note still valid for 3.x?
* This function needs to be called before the page is fully loaded, as
* calling tinyMCE.init() after the page is loaded breaks IE6.
*
* @param editorSettings
* An object containing editor settings for each input format.
*/
Drupal.wysiwyg.editor.init.tinymce = function(settings) {
// If JS compression is enabled, TinyMCE is unable to autodetect its global
// settinge, hence we need to define them manually.
// @todo Move global library settings somewhere else.
tinyMCE.baseURL = settings.global.editorBasePath;
tinyMCE.srcMode = (settings.global.execMode == 'src' ? '_src' : '');
tinyMCE.gzipMode = (settings.global.execMode == 'gzip');
// Initialize editor configurations.
for (var format in settings) {
if (format == 'global') {
continue;
};
tinyMCE.init(settings[format]);
if (Drupal.settings.wysiwyg.plugins[format]) {
// Load native external plugins.
// Array syntax required; 'native' is a predefined token in JavaScript.
for (var plugin in Drupal.settings.wysiwyg.plugins[format]['native']) {
tinymce.PluginManager.load(plugin, Drupal.settings.wysiwyg.plugins[format]['native'][plugin]);
}
// Load Drupal plugins.
for (var plugin in Drupal.settings.wysiwyg.plugins[format].drupal) {
Drupal.wysiwyg.editor.instance.tinymce.addPlugin(plugin, Drupal.settings.wysiwyg.plugins[format].drupal[plugin], Drupal.settings.wysiwyg.plugins.drupal[plugin]);
}
}
}
};
/**
* Attach this editor to a target element.
*
* See Drupal.wysiwyg.editor.attach.none() for a full desciption of this hook.
*/
Drupal.wysiwyg.editor.attach.tinymce = function(context, params, settings) {
// Configure editor settings for this input format.
var ed = new tinymce.Editor(params.field, settings);
// Reset active instance id on any event.
ed.onEvent.add(function(ed, e) {
Drupal.wysiwyg.activeId = ed.id;
});
// Make toolbar buttons wrappable (required for IE).
ed.onPostRender.add(function (ed) {
var $toolbar = $('<div class="wysiwygToolbar"></div>');
$('#' + ed.editorContainer + ' table.mceToolbar > tbody > tr > td').each(function () {
$('<div></div>').addClass(this.className).append($(this).children()).appendTo($toolbar);
});
$('#' + ed.editorContainer + ' table.mceLayout td.mceToolbar').append($toolbar);
$('#' + ed.editorContainer + ' table.mceToolbar').remove();
});
// Remove TinyMCE's internal mceItem class, which was incorrectly added to
// submitted content by Wysiwyg <2.1. TinyMCE only temporarily adds the class
// for placeholder elements. If preemptively set, the class prevents (native)
// editor plugins from gaining an active state, so we have to manually remove
// it prior to attaching the editor. This is done on the client-side instead
// of the server-side, as Wysiwyg has no way to figure out where content is
// stored, and the class only affects editing.
$field = $('#' + params.field);
$field.val($field.val().replace(/(<.+?\s+class=['"][\w\s]*?)\bmceItem\b([\w\s]*?['"].*?>)/ig, '$1$2'));
// Attach editor.
ed.render();
};
/**
* Detach a single or all editors.
*
* See Drupal.wysiwyg.editor.detach.none() for a full desciption of this hook.
*/
Drupal.wysiwyg.editor.detach.tinymce = function(context, params) {
if (typeof params != 'undefined') {
var instance = tinyMCE.get(params.field);
if (instance) {
instance.save();
instance.remove();
}
}
else {
// Save contents of all editors back into textareas.
tinyMCE.triggerSave();
// Remove all editor instances.
for (var instance in tinyMCE.editors) {
tinyMCE.editors[instance].remove();
}
}
};
Drupal.wysiwyg.editor.instance.tinymce = {
addPlugin: function(plugin, settings, pluginSettings) {
if (typeof Drupal.wysiwyg.plugins[plugin] != 'object') {
return;
}
tinymce.create('tinymce.plugins.' + plugin, {
/**
* Initialize the plugin, executed after the plugin has been created.
*
* @param ed
* The tinymce.Editor instance the plugin is initialized in.
* @param url
* The absolute URL of the plugin location.
*/
init: function(ed, url) {
// Register an editor command for this plugin, invoked by the plugin's button.
ed.addCommand(plugin, function() {
if (typeof Drupal.wysiwyg.plugins[plugin].invoke == 'function') {
var data = { format: 'html', node: ed.selection.getNode(), content: ed.selection.getContent() };
// TinyMCE creates a completely new instance for fullscreen mode.
var instanceId = ed.id == 'mce_fullscreen' ? ed.getParam('fullscreen_editor_id') : ed.id;
Drupal.wysiwyg.plugins[plugin].invoke(data, pluginSettings, instanceId);
}
});
// Register the plugin button.
ed.addButton(plugin, {
title : settings.iconTitle,
cmd : plugin,
image : settings.icon
});
// Load custom CSS for editor contents on startup.
ed.onInit.add(function() {
if (settings.css) {
ed.dom.loadCSS(settings.css);
}
});
// Attach: Replace plain text with HTML representations.
ed.onBeforeSetContent.add(function(ed, data) {
if (typeof Drupal.wysiwyg.plugins[plugin].attach == 'function') {
data.content = Drupal.wysiwyg.plugins[plugin].attach(data.content, pluginSettings, ed.id);
data.content = Drupal.wysiwyg.editor.instance.tinymce.prepareContent(data.content);
}
});
// Detach: Replace HTML representations with plain text.
ed.onGetContent.add(function(ed, data) {
if (typeof Drupal.wysiwyg.plugins[plugin].detach == 'function') {
data.content = Drupal.wysiwyg.plugins[plugin].detach(data.content, pluginSettings, ed.id);
}
});
// isNode: Return whether the plugin button should be enabled for the
// current selection.
ed.onNodeChange.add(function(ed, command, node) {
if (typeof Drupal.wysiwyg.plugins[plugin].isNode == 'function') {
command.setActive(plugin, Drupal.wysiwyg.plugins[plugin].isNode(node));
}
});
},
/**
* Return information about the plugin as a name/value array.
*/
getInfo: function() {
return {
longname: settings.title
};
}
});
// Register plugin.
tinymce.PluginManager.add(plugin, tinymce.plugins[plugin]);
},
openDialog: function(dialog, params) {
var instanceId = this.isFullscreen() ? 'mce_fullscreen' : this.field;
var editor = tinyMCE.get(instanceId);
editor.windowManager.open({
file: dialog.url + '/' + instanceId,
width: dialog.width,
height: dialog.height,
inline: 1
}, params);
},
closeDialog: function(dialog) {
var instanceId = this.isFullscreen() ? 'mce_fullscreen' : this.field;
var editor = tinyMCE.get(instanceId);
editor.windowManager.close(dialog);
},
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: { 'class': 'mceItem' }
};
var $content = $('<div>' + content + '</div>'); // No .outerHTML() in jQuery :(
// Find all placeholder/replacement content of Drupal plugins.
$content.find('.drupal-content').each(function() {
// Recursively process DOM elements below this element to apply special
// properties.
var $drupalContent = $(this);
$.each(specialProperties, function(element, properties) {
$drupalContent.find(element).andSelf().each(function() {
for (var property in properties) {
if (property == 'class') {
$(this).addClass(properties[property]);
}
else {
$(this).attr(property, properties[property]);
}
}
});
});
});
return $content.html();
},
insert: function(content) {
content = this.prepareContent(content);
var instanceId = this.isFullscreen() ? 'mce_fullscreen' : this.field;
tinyMCE.execInstanceCommand(instanceId, 'mceInsertContent', false, content);
},
isFullscreen: function() {
// TinyMCE creates a completely new instance for fullscreen mode.
return tinyMCE.activeEditor.id == 'mce_fullscreen' && tinyMCE.activeEditor.getParam('fullscreen_editor_id') == this.field;
}
};
})(jQuery);

View File

@@ -0,0 +1,133 @@
var wysiwygWhizzywig = { currentField: null, fields: {} };
var buttonPath = null;
/**
* Override Whizzywig's document.write() function.
*
* Whizzywig uses document.write() by default, which leads to a blank page when
* invoked in jQuery.ready(). Luckily, Whizzywig developers implemented a
* shorthand w() substitute function that we can override to redirect the output
* into the global wysiwygWhizzywig variable.
*
* @see o()
*/
var w = function (string) {
if (string) {
wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField] += string;
}
return wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField];
};
/**
* Override Whizzywig's document.getElementById() function.
*
* Since we redirect the output of w() into a temporary string upon attaching
* an editor, we also have to override the o() shorthand substitute function
* for document.getElementById() to search in the document or our container.
* This override function also inserts the editor instance when Whizzywig
* tries to access its IFRAME, so it has access to the full/regular window
* object.
*
* @see w()
*/
var o = function (id) {
// Upon first access to "whizzy" + id, Whizzywig tries to access its IFRAME,
// so we need to insert the editor into the DOM.
if (id == 'whizzy' + wysiwygWhizzywig.currentField && wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField]) {
jQuery('#' + wysiwygWhizzywig.currentField).after('<div id="' + wysiwygWhizzywig.currentField + '-whizzywig"></div>');
// Iframe's .contentWindow becomes null in Webkit if inserted via .after().
jQuery('#' + wysiwygWhizzywig.currentField + '-whizzywig').html(w());
// Prevent subsequent invocations from inserting the editor multiple times.
wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField] = '';
}
// If id exists in the regular window.document, return it.
if (jQuery('#' + id).size()) {
return jQuery('#' + id).get(0);
}
// Otherwise return id from our container.
return jQuery('#' + id, w()).get(0);
};
(function($) {
/**
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) {
// Previous versions used per-button images found in this location,
// now it is only used for custom buttons.
if (settings.buttonPath) {
window.buttonPath = settings.buttonPath;
}
// Assign the toolbar image path used for native buttons, if available.
if (settings.toolbarImagePath) {
btn._f = settings.toolbarImagePath;
}
// Fall back to text labels for all buttons.
else {
window.buttonPath = 'textbuttons';
}
// Create Whizzywig container.
wysiwygWhizzywig.currentField = params.field;
wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField] = '';
// Whizzywig needs to have the width set 'inline'.
$field = $('#' + params.field);
var originalValues = Drupal.wysiwyg.instances[params.field];
originalValues.originalStyle = $field.attr('style');
$field.css('width', $field.width() + 'px');
// Attach editor.
makeWhizzyWig(params.field, (settings.buttons ? settings.buttons : 'all'));
// Whizzywig fails to detect and set initial textarea contents.
var instance = $('#whizzy' + params.field).get(0);
if (instance) {
instance.contentWindow.document.body.innerHTML = tidyD($field.val());
}
};
/**
* Detach a single or all editors.
*/
Drupal.wysiwyg.editor.detach.whizzywig = function(context, params) {
var detach = function (index) {
var id = whizzies[index];
var instance = $('#whizzy' + id).get(0);
if (!instance) {
return;
}
var editingArea = instance.contentWindow.document;
var $field = $('#' + id);
// Whizzywig shows the original textarea in source mode.
if ($field.css('display') == 'block') {
editingArea.body.innerHTML = $field.val();
}
// Save contents of editor back into textarea.
$field.val(tidyH(editingArea));
// Remove editor instance.
$('#' + id + '-whizzywig').remove();
whizzies.splice(index, 1);
// Restore original textarea styling.
var originalValues = Drupal.wysiwyg.instances[id];
$field.removeAttr('style');
$field.attr('style', originalValues.originalStyle);
};
if (typeof params != 'undefined') {
for (var i = 0; i < whizzies.length; i++) {
if (whizzies[i] == params.field) {
detach(i);
break;
}
}
}
else {
while (whizzies.length > 0) {
detach(0);
}
}
};
})(jQuery);

View File

@@ -0,0 +1,85 @@
var buttonPath = null;
(function($) {
/**
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) {
// Previous versions used per-button images found in this location,
// now it is only used for custom buttons.
if (settings.buttonPath) {
window.buttonPath = settings.buttonPath;
}
// Assign the toolbar image path used for native buttons, if available.
if (settings.toolbarImagePath) {
btn._f = settings.toolbarImagePath;
}
// Fall back to text labels for all buttons.
else {
window.buttonPath = 'textbuttons';
}
// Whizzywig needs to have the width set 'inline'.
$field = $('#' + params.field);
var originalValues = Drupal.wysiwyg.instances[params.field];
originalValues.originalStyle = $field.attr('style');
$field.css('width', $field.width() + 'px');
// Attach editor.
makeWhizzyWig(params.field, (settings.buttons ? settings.buttons : 'all'));
// Whizzywig fails to detect and set initial textarea contents.
var instance = $('#whizzy' + params.field).get(0);
if (instance) {
instance.contentWindow.document.body.innerHTML = tidyD($field.val());
}
};
/**
* Detach a single or all editors.
*/
Drupal.wysiwyg.editor.detach.whizzywig = function(context, params) {
var detach = function (index) {
var id = whizzies[index];
var instance = $('#whizzy' + id).get(0);
if (!instance) {
return;
}
var editingArea = instance.contentWindow.document;
var $field = $('#' + id);
// Whizzywig shows the original textarea in source mode.
if ($field.css('display') == 'block') {
editingArea.body.innerHTML = $field.val();
}
// Save contents of editor back into textarea.
$field.val(tidyH(editingArea));
// Move original textarea back to its previous location.
$container = $('#CONTAINER' + id);
$field.insertBefore($container);
// Remove editor instance.
$container.remove();
whizzies.splice(index, 1);
// Restore original textarea styling.
var originalValues = Drupal.wysiwyg.instances[id];
$field.removeAttr('style');
$field.attr('style', originalValues.originalStyle);
}
if (typeof params != 'undefined') {
for (var i = 0; i < whizzies.length; i++) {
if (whizzies[i] == params.field) {
detach(i);
break;
}
}
}
else {
while (whizzies.length > 0) {
detach(0);
}
}
};
})(jQuery);

View File

@@ -0,0 +1,126 @@
var wysiwygWhizzywig = { currentField: null, fields: {} };
var buttonPath = null;
/**
* Override Whizzywig's document.write() function.
*
* Whizzywig uses document.write() by default, which leads to a blank page when
* invoked in jQuery.ready(). Luckily, Whizzywig developers implemented a
* shorthand w() substitute function that we can override to redirect the output
* into the global wysiwygWhizzywig variable.
*
* @see o()
*/
var w = function (string) {
if (string) {
wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField] += string;
}
return wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField];
};
/**
* Override Whizzywig's document.getElementById() function.
*
* Since we redirect the output of w() into a temporary string upon attaching
* an editor, we also have to override the o() shorthand substitute function
* for document.getElementById() to search in the document or our container.
* This override function also inserts the editor instance when Whizzywig
* tries to access its IFRAME, so it has access to the full/regular window
* object.
*
* @see w()
*/
var o = function (id) {
// Upon first access to "whizzy" + id, Whizzywig tries to access its IFRAME,
// so we need to insert the editor into the DOM.
if (id == 'whizzy' + wysiwygWhizzywig.currentField && wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField]) {
jQuery('#' + wysiwygWhizzywig.currentField).after('<div id="' + wysiwygWhizzywig.currentField + '-whizzywig"></div>');
// Iframe's .contentWindow becomes null in Webkit if inserted via .after().
jQuery('#' + wysiwygWhizzywig.currentField + '-whizzywig').html(w());
// Prevent subsequent invocations from inserting the editor multiple times.
wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField] = '';
}
// If id exists in the regular window.document, return it.
if (jQuery('#' + id).size()) {
return jQuery('#' + id).get(0);
}
// Otherwise return id from our container.
return jQuery('#' + id, w()).get(0);
};
(function($) {
/**
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) {
// Assign button images path, if available.
if (settings.buttonPath) {
window.buttonPath = settings.buttonPath;
}
// Create Whizzywig container.
wysiwygWhizzywig.currentField = params.field;
wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField] = '';
// Whizzywig needs to have the width set 'inline'.
$field = $('#' + params.field);
var originalValues = Drupal.wysiwyg.instances[params.field];
originalValues.originalStyle = $field.attr('style');
$field.css('width', $field.width() + 'px');
// Attach editor.
makeWhizzyWig(params.field, (settings.buttons ? settings.buttons : 'all'));
// Whizzywig fails to detect and set initial textarea contents.
var instance = $('#whizzy' + params.field).get(0);
if (instance) {
instance.contentWindow.document.body.innerHTML = tidyD($field.val());
}
};
/**
* Detach a single or all editors.
*/
Drupal.wysiwyg.editor.detach.whizzywig = function(context, params) {
var detach = function (index) {
var id = whizzies[index];
var instance = $('#whizzy' + id).get(0);
if (!instance) {
return;
}
var body = instance.contentWindow.document.body;
var $field = $('#' + id);
// Whizzywig shows the original textarea in source mode.
if ($field.css('display') == 'block') {
body.innerHTML = $field.val();
}
body.innerHTML = tidyH(body.innerHTML);
// Save contents of editor back into textarea.
$field.val(window.get_xhtml ? get_xhtml(body) : body.innerHTML);
$field.val($field.val().replace(location.href + '#', '#'));
// Remove editor instance.
$('#' + id + '-whizzywig').remove();
whizzies.splice(index, 1);
// Restore original textarea styling.
var originalValues = Drupal.wysiwyg.instances[id];
$field.removeAttr('style');
$field.attr('style', originalValues.originalStyle);
};
if (typeof params != 'undefined') {
for (var i = 0; i < whizzies.length; i++) {
if (whizzies[i] == params.field) {
detach(i);
break;
}
}
}
else {
while (whizzies.length > 0) {
detach(0);
}
}
};
})(jQuery);

View File

@@ -0,0 +1,56 @@
(function($) {
/**
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.wymeditor = function (context, params, settings) {
// Prepend basePath to wymPath.
settings.wymPath = settings.basePath + settings.wymPath;
// Update activeId on focus.
settings.postInit = function (instance) {
$(instance._doc).focus(function () {
Drupal.wysiwyg.activeId = params.field;
});
};
// Attach editor.
$('#' + params.field).wymeditor(settings);
};
/**
* Detach a single or all editors.
*/
Drupal.wysiwyg.editor.detach.wymeditor = function (context, params) {
if (typeof params != 'undefined') {
var $field = $('#' + params.field);
var index = $field.data(WYMeditor.WYM_INDEX);
if (typeof index != 'undefined') {
var instance = WYMeditor.INSTANCES[index];
instance.update();
$(instance._box).remove();
$(instance._element).show();
delete instance;
}
$field.show();
}
else {
jQuery.each(WYMeditor.INSTANCES, function () {
this.update();
$(this._box).remove();
$(this._element).show();
delete this;
});
}
};
Drupal.wysiwyg.editor.instance.wymeditor = {
insert: function (content) {
var $field = $('#' + this.field);
var index = $field.data(WYMeditor.WYM_INDEX);
if (typeof index != 'undefined') {
var instance = WYMeditor.INSTANCES[index];
instance.insert(content);
}
}
};
})(jQuery);

View File

@@ -0,0 +1,35 @@
(function($) {
/**
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.yui = function(context, params, settings) {
// Apply theme.
$('#' + params.field).parent().addClass('yui-skin-' + settings.theme);
// Attach editor.
var editor = new YAHOO.widget.Editor(params.field, settings);
editor.render();
};
/**
* Detach a single or all editors.
*
* See Drupal.wysiwyg.editor.detach.none() for a full desciption of this hook.
*/
Drupal.wysiwyg.editor.detach.yui = function(context, params) {
if (typeof params != 'undefined') {
var instance = YAHOO.widget.EditorInfo.getEditorById(params.field);
if (instance) {
instance.destroy();
}
}
else {
for (var e in YAHOO.widget.EditorInfo._instances) {
// Save contents of all editors back into textareas.
var instance = YAHOO.widget.EditorInfo._instances[e];
instance.destroy();
}
}
};
})(jQuery);

View File

@@ -0,0 +1,62 @@
<?php
/**
* @file
* Editor integration functions for jWYSIWYG.
*/
/**
* Plugin implementation of hook_editor().
*/
function wysiwyg_jwysiwyg_editor() {
$editor['jwysiwyg'] = array(
'title' => 'jWYSIWYG',
'vendor url' => 'http://code.google.com/p/jwysiwyg/',
'download url' => 'http://code.google.com/p/jwysiwyg/downloads/list',
'libraries' => array(
'' => array(
'title' => 'Source',
'files' => array('jquery.wysiwyg.js'),
),
'pack' => array(
'title' => 'Packed',
'files' => array('jquery.wysiwyg.pack.js'),
),
),
'version callback' => 'wysiwyg_jwysiwyg_version',
// @todo Wrong property; add separate properties for editor requisites.
'css path' => wysiwyg_get_path('jwysiwyg'),
'versions' => array(
'0.5' => array(
'js files' => array('jwysiwyg.js'),
'css files' => array('jquery.wysiwyg.css'),
),
),
);
return $editor;
}
/**
* Detect editor version.
*
* @param $editor
* An array containing editor properties as returned from hook_editor().
*
* @return
* The installed editor version.
*/
function wysiwyg_jwysiwyg_version($editor) {
$script = $editor['library path'] . '/jquery.wysiwyg.js';
if (!file_exists($script)) {
return;
}
$script = fopen($script, 'r');
fgets($script);
$line = fgets($script);
if (preg_match('@([0-9\.]+)$@', $line, $version)) {
fclose($script);
return $version[1];
}
fclose($script);
}

View File

@@ -0,0 +1,189 @@
<?php
/**
* @file
* Editor integration functions for markItUp.
*/
/**
* Plugin implementation of hook_editor().
*/
function wysiwyg_markitup_editor() {
$editor['markitup'] = array(
'title' => 'markItUp',
'vendor url' => 'http://markitup.jaysalvat.com',
'download url' => 'http://markitup.jaysalvat.com/downloads',
'library path' => wysiwyg_get_path('markitup'),
'libraries' => array(
'' => array(
'title' => 'Source',
'files' => array('markitup/jquery.markitup.js'),
),
'pack' => array(
'title' => 'Packed',
'files' => array('markitup/jquery.markitup.pack.js'),
),
),
'version callback' => 'wysiwyg_markitup_version',
'themes callback' => 'wysiwyg_markitup_themes',
'settings callback' => 'wysiwyg_markitup_settings',
'plugin callback' => 'wysiwyg_markitup_plugins',
'versions' => array(
'1.1.5' => array(
'js files' => array('markitup.js'),
),
),
);
return $editor;
}
/**
* Detect editor version.
*
* @param $editor
* An array containing editor properties as returned from hook_editor().
*
* @return
* The installed editor version.
*/
function wysiwyg_markitup_version($editor) {
// Changelog was in markitup/markitup/readme.txt <= 1.1.5.
$changelog = $editor['library path'] . '/markitup/readme.txt';
if (!file_exists($changelog)) {
// Changelog was moved up to markitup/CHANGELOG.md after 1.1.5.
$changelog = $editor['library path'] . '/CHANGELOG.md';
if (!file_exists($changelog)) {
return;
}
}
$changelog = fopen($changelog, 'r');
$line = fgets($changelog);
if (preg_match('@([0-9\.]+)@', $line, $version)) {
fclose($changelog);
return $version[1];
}
fclose($changelog);
}
/**
* Determine available editor themes or check/reset a given one.
*
* @param $editor
* A processed hook_editor() array of editor properties.
* @param $profile
* A wysiwyg editor profile.
*
* @return
* An array of theme names. The first returned name should be the default
* theme name.
*/
function wysiwyg_markitup_themes($editor, $profile) {
return array('simple', 'markitup');
}
/**
* 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_markitup_settings($editor, $config, $theme) {
drupal_add_css($editor['library path'] . '/markitup/skins/' . $theme . '/style.css', array(
// Specify an alternate basename; otherwise, style.css would override a
// commonly used style.css file of the theme.
'basename' => 'markitup.' . $theme . '.style.css',
'group' => CSS_THEME,
));
$settings = array(
'root' => base_path() . $editor['library path'] . '/markitup/',
'nameSpace' => $theme,
'markupSet' => array(),
);
// Add configured buttons or all available.
$default_buttons = array(
'bold' => array(
'name' => t('Bold'),
'className' => 'markitup-bold',
'key' => 'B',
'openWith' => '(!(<strong>|!|<b>)!)',
'closeWith' => '(!(</strong>|!|</b>)!)',
),
'italic' => array(
'name' => t('Italic'),
'className' => 'markitup-italic',
'key' => 'I',
'openWith' => '(!(<em>|!|<i>)!)',
'closeWith' => '(!(</em>|!|</i>)!)',
),
'stroke' => array(
'name' => t('Strike-through'),
'className' => 'markitup-stroke',
'key' => 'S',
'openWith' => '<del>',
'closeWith' => '</del>',
),
'image' => array(
'name' => t('Image'),
'className' => 'markitup-image',
'key' => 'P',
'replaceWith' => '<img src="[![Source:!:http://]!]" alt="[![Alternative text]!]" />',
),
'link' => array(
'name' => t('Link'),
'className' => 'markitup-link',
'key' => 'K',
'openWith' => '<a href="[![Link:!:http://]!]"(!( title="[![Title]!]")!)>',
'closeWith' => '</a>',
'placeHolder' => 'Your text to link...',
),
// @todo
// 'cleanup' => array('name' => t('Clean-up'), 'className' => 'markitup-cleanup', 'replaceWith' => 'function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") }'),
'preview' => array(
'name' => t('Preview'),
'className' => 'markitup-preview',
'call' => 'preview',
),
);
$settings['markupSet'] = array();
if (!empty($config['buttons'])) {
foreach ($config['buttons'] as $plugin) {
foreach ($plugin as $button => $enabled) {
if (isset($default_buttons[$button])) {
$settings['markupSet'][$button] = $default_buttons[$button];
}
}
}
}
return $settings;
}
/**
* Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
*/
function wysiwyg_markitup_plugins($editor) {
return array(
'default' => array(
'buttons' => array(
'bold' => t('Bold'), 'italic' => t('Italic'),
'stroke' => t('Strike-through'),
'link' => t('Link'),
'image' => t('Image'),
// 'cleanup' => t('Clean-up'),
'preview' => t('Preview'),
),
'internal' => TRUE,
),
);
}

View File

@@ -0,0 +1,119 @@
<?php
/**
* @file
* Editor integration functions for NicEdit.
*/
/**
* Plugin implementation of hook_editor().
*/
function wysiwyg_nicedit_editor() {
$editor['nicedit'] = array(
'title' => 'NicEdit',
'vendor url' => 'http://nicedit.com',
'download url' => 'http://nicedit.com/download.php',
'libraries' => array(
'' => array(
'title' => 'Source',
'files' => array('nicEdit.js'),
),
),
'version callback' => 'wysiwyg_nicedit_version',
'settings callback' => 'wysiwyg_nicedit_settings',
'plugin callback' => 'wysiwyg_nicedit_plugins',
'versions' => array(
'0.9' => array(
'js files' => array('nicedit.js'),
),
),
);
return $editor;
}
/**
* Detect editor version.
*
* @param $editor
* An array containing editor properties as returned from hook_editor().
*
* @return
* The installed editor version.
*/
function wysiwyg_nicedit_version($editor) {
// @see http://nicedit.com/forums/viewtopic.php?t=425
return '0.9';
}
/**
* 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_nicedit_settings($editor, $config, $theme) {
$settings = array(
'iconsPath' => base_path() . $editor['library path'] . '/nicEditorIcons.gif',
);
// Add configured buttons or all available.
$settings['buttonList'] = array();
if (!empty($config['buttons'])) {
$buttons = array();
foreach ($config['buttons'] as $plugin) {
$buttons = array_merge($buttons, $plugin);
}
$settings['buttonList'] = array_keys($buttons);
}
// Add editor content stylesheet.
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
$css = path_to_theme() . '/style.css';
if (file_exists($css)) {
$settings['externalCSS'] = base_path() . $css;
}
}
else if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['externalCSS'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
}
}
return $settings;
}
/**
* Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
*/
function wysiwyg_nicedit_plugins($editor) {
return array(
'default' => array(
'buttons' => array(
'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
'strikethrough' => t('Strike-through'),
'left' => t('Align left'), 'center' => t('Align center'), 'right' => t('Align right'),
'ul' => t('Bullet list'), 'ol' => t('Numbered list'),
'outdent' => t('Outdent'), 'indent' => t('Indent'),
'image' => t('Image'),
'forecolor' => t('Forecolor'), 'bgcolor' => t('Backcolor'),
'superscript' => t('Superscript'), 'subscript' => t('Subscript'),
'hr' => t('Horizontal rule'),
// @todo New challenge: Optional internal plugins packaged into editor
// library.
'link' => t('Link'), 'unlink' => t('Unlink'),
'fontFormat' => t('HTML block format'), 'fontFamily' => t('Font'), 'fontSize' => t('Font size'),
'xhtml' => t('Source code'),
),
'internal' => TRUE,
),
);
}

View File

@@ -0,0 +1,173 @@
<?php
/**
* @file
* Editor integration functions for openWYSIWYG.
*/
/**
* Plugin implementation of hook_editor().
*/
function wysiwyg_openwysiwyg_editor() {
$editor['openwysiwyg'] = array(
'title' => 'openWYSIWYG',
'vendor url' => 'http://www.openwebware.com',
'download url' => 'http://www.openwebware.com/download.shtml',
'library path' => wysiwyg_get_path('openwysiwyg') . '/scripts',
'libraries' => array(
'src' => array(
'title' => 'Source',
'files' => array('wysiwyg.js'),
),
),
'version callback' => 'wysiwyg_openwysiwyg_version',
'themes callback' => 'wysiwyg_openwysiwyg_themes',
'settings callback' => 'wysiwyg_openwysiwyg_settings',
'plugin callback' => 'wysiwyg_openwysiwyg_plugins',
'versions' => array(
'1.4.7' => array(
'js files' => array('openwysiwyg.js'),
'css files' => array('openwysiwyg.css'),
),
),
);
return $editor;
}
/**
* Detect editor version.
*
* @param $editor
* An array containing editor properties as returned from hook_editor().
*
* @return
* The installed editor version.
*/
function wysiwyg_openwysiwyg_version($editor) {
// 'library path' has '/scripts' appended already.
$changelog = $editor['editor path'] . '/changelog';
if (!file_exists($changelog)) {
return;
}
$changelog = fopen($changelog, 'r');
$line = fgets($changelog, 20);
if (preg_match('@v([\d\.]+)@', $line, $version)) {
fclose($changelog);
return $version[1];
}
fclose($changelog);
}
/**
* Determine available editor themes or check/reset a given one.
*
* @param $editor
* A processed hook_editor() array of editor properties.
* @param $profile
* A wysiwyg editor profile.
*
* @return
* An array of theme names. The first returned name should be the default
* theme name.
*/
function wysiwyg_openwysiwyg_themes($editor, $profile) {
return array('default');
}
/**
* 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_openwysiwyg_settings($editor, $config, $theme) {
$settings = array(
'path' => base_path() . $editor['editor path'] . '/',
'Width' => '100%',
);
if (isset($config['path_loc']) && $config['path_loc'] == 'none') {
$settings['StatusBarEnabled'] = FALSE;
}
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
$settings['CSSFile'] = reset(wysiwyg_get_css());
}
else if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['CSSFile'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
}
}
$settings['Toolbar'] = array();
if (!empty($config['buttons'])) {
$plugins = wysiwyg_get_plugins($editor['name']);
foreach ($config['buttons'] as $plugin => $buttons) {
foreach ($buttons as $button => $enabled) {
foreach (array('buttons', 'extensions') as $type) {
// Skip unavailable plugins.
if (!isset($plugins[$plugin][$type][$button])) {
continue;
}
// Add buttons.
if ($type == 'buttons') {
$settings['Toolbar'][0][] = $button;
}
}
}
}
}
// @todo
// if (isset($config['block_formats'])) {
// $settings['DropDowns']['headings']['elements'] = explode(',', $config['block_formats']);
// }
return $settings;
}
/**
* Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
*/
function wysiwyg_openwysiwyg_plugins($editor) {
$plugins = array(
'default' => array(
'buttons' => array(
'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
'strikethrough' => t('Strike-through'),
'justifyleft' => t('Align left'), 'justifycenter' => t('Align center'), 'justifyright' => t('Align right'), 'justifyfull' => t('Justify'),
'unorderedlist' => t('Bullet list'), 'orderedlist' => t('Numbered list'),
'outdent' => t('Outdent'), 'indent' => t('Indent'),
'undo' => t('Undo'), 'redo' => t('Redo'),
'createlink' => t('Link'),
'insertimage' => t('Image'),
'cleanup' => t('Clean-up'),
'forecolor' => t('Forecolor'), 'backcolor' => t('Backcolor'),
'superscript' => t('Sup'), 'subscript' => t('Sub'),
'blockquote' => t('Blockquote'), 'viewSource' => t('Source code'),
'hr' => t('Horizontal rule'),
'cut' => t('Cut'), 'copy' => t('Copy'), 'paste' => t('Paste'),
'visualaid' => t('Visual aid'),
'removeformat' => t('Remove format'),
'charmap' => t('Character map'),
'headings' => t('HTML block format'), 'font' => t('Font'), 'fontsize' => t('Font size'),
'maximize' => t('Fullscreen'),
'preview' => t('Preview'),
'print' => t('Print'),
'inserttable' => t('Table'),
'help' => t('Help'),
),
'internal' => TRUE,
),
);
return $plugins;
}

View File

@@ -0,0 +1,608 @@
<?php
/**
* @file
* Editor integration functions for TinyMCE.
*/
/**
* Plugin implementation of hook_editor().
*
* @todo wysiwyg_<editor>_alter() to add/inject optional libraries like gzip.
*/
function wysiwyg_tinymce_editor() {
$editor['tinymce'] = array(
'title' => 'TinyMCE',
'vendor url' => 'http://tinymce.moxiecode.com',
'download url' => 'http://tinymce.moxiecode.com/download.php',
'library path' => wysiwyg_get_path('tinymce') . '/jscripts/tiny_mce',
'libraries' => array(
'' => array(
'title' => 'Minified',
'files' => array('tiny_mce.js'),
),
'src' => array(
'title' => 'Source',
'files' => array('tiny_mce_src.js'),
),
),
'version callback' => 'wysiwyg_tinymce_version',
'themes callback' => 'wysiwyg_tinymce_themes',
'settings callback' => 'wysiwyg_tinymce_settings',
'plugin callback' => 'wysiwyg_tinymce_plugins',
'plugin settings callback' => 'wysiwyg_tinymce_plugin_settings',
'proxy plugin' => array(
'drupal' => array(
'load' => TRUE,
'proxy' => TRUE,
),
),
'proxy plugin settings callback' => 'wysiwyg_tinymce_proxy_plugin_settings',
'versions' => array(
'2.1' => array(
'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',
),
// @todo Starting from 3.3, tiny_mce.js may support JS aggregation.
'3.1' => array(
'js files' => array('tinymce-3.js'),
'css files' => array('tinymce-3.css'),
'libraries' => array(
'' => array(
'title' => 'Minified',
'files' => array(
'tiny_mce.js' => array('preprocess' => FALSE),
),
),
'jquery' => array(
'title' => 'jQuery',
'files' => array('tiny_mce_jquery.js'),
),
'src' => array(
'title' => 'Source',
'files' => array('tiny_mce_src.js'),
),
),
),
),
);
return $editor;
}
/**
* Detect editor version.
*
* @param $editor
* An array containing editor properties as returned from hook_editor().
*
* @return
* The installed editor version.
*/
function wysiwyg_tinymce_version($editor) {
$script = $editor['library path'] . '/tiny_mce.js';
if (!file_exists($script)) {
return;
}
$script = fopen($script, 'r');
// Version is contained in the first 200 chars.
$line = fgets($script, 200);
fclose($script);
// 2.x: this.majorVersion="2";this.minorVersion="1.3"
// 3.x: majorVersion:'3',minorVersion:'2.0.1'
if (preg_match('@majorVersion[=:]["\'](\d).+?minorVersion[=:]["\']([\d\.]+)@', $line, $version)) {
return $version[1] . '.' . $version[2];
}
}
/**
* Determine available editor themes or check/reset a given one.
*
* @param $editor
* A processed hook_editor() array of editor properties.
* @param $profile
* A wysiwyg editor profile.
*
* @return
* An array of theme names. The first returned name should be the default
* theme name.
*/
function wysiwyg_tinymce_themes($editor, $profile) {
/*
$themes = array();
$dir = $editor['library path'] . '/themes/';
if (is_dir($dir) && $dh = opendir($dir)) {
while (($file = readdir($dh)) !== FALSE) {
if (!in_array($file, array('.', '..', 'CVS', '.svn')) && is_dir($dir . $file)) {
$themes[$file] = $file;
}
}
closedir($dh);
asort($themes);
}
return $themes;
*/
return array('advanced', 'simple');
}
/**
* 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_tinymce_settings($editor, $config, $theme) {
$settings = array(
'button_tile_map' => TRUE, // @todo Add a setting for this.
'document_base_url' => base_path(),
'mode' => 'none',
'plugins' => array(),
'theme' => $theme,
'width' => '100%',
// Strict loading mode must be enabled; otherwise TinyMCE would use
// document.write() in IE and Chrome.
'strict_loading_mode' => TRUE,
// TinyMCE's URL conversion magic breaks Drupal modules that use a special
// syntax for paths. This makes 'relative_urls' obsolete.
'convert_urls' => FALSE,
// The default entity_encoding ('named') converts too many characters in
// languages (like Greek). Since Drupal supports Unicode, we only convert
// HTML control characters and invisible characters. TinyMCE always converts
// XML default characters '&', '<', '>'.
'entities' => '160,nbsp,173,shy,8194,ensp,8195,emsp,8201,thinsp,8204,zwnj,8205,zwj,8206,lrm,8207,rlm',
);
if (isset($config['apply_source_formatting'])) {
$settings['apply_source_formatting'] = $config['apply_source_formatting'];
}
if (isset($config['convert_fonts_to_spans'])) {
$settings['convert_fonts_to_spans'] = $config['convert_fonts_to_spans'];
}
if (isset($config['language'])) {
$settings['language'] = $config['language'];
}
if (isset($config['paste_auto_cleanup_on_paste'])) {
$settings['paste_auto_cleanup_on_paste'] = $config['paste_auto_cleanup_on_paste'];
}
if (isset($config['preformatted'])) {
$settings['preformatted'] = $config['preformatted'];
}
if (isset($config['remove_linebreaks'])) {
$settings['remove_linebreaks'] = $config['remove_linebreaks'];
}
if (isset($config['verify_html'])) {
$settings['verify_html'] = (bool) $config['verify_html'];
}
if (!empty($config['css_classes'])) {
$settings['theme_advanced_styles'] = implode(';', array_filter(explode("\n", str_replace("\r", '', $config['css_classes']))));
}
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
$settings['content_css'] = implode(',', 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()));
}
}
// Find the enabled buttons and the button row they belong on.
// Also map the plugin metadata for each button.
// @todo What follows is a pain; needs a rewrite.
// $settings['buttons'] are stacked into $settings['theme_advanced_buttons1']
// later.
$settings['buttons'] = array();
if (!empty($config['buttons']) && is_array($config['buttons'])) {
// Only array keys in $settings['extensions'] matter; added to
// $settings['plugins'] later.
$settings['extensions'] = array();
// $settings['extended_valid_elements'] are just stacked, unique'd later,
// and transformed into a comma-separated string in
// wysiwyg_add_editor_settings().
// @todo Needs a complete plugin API redesign using arrays for
// tag => attributes definitions and array_merge_recursive().
$settings['extended_valid_elements'] = array();
$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 buttons.
if ($type == 'buttons') {
$settings['buttons'][] = $button;
}
// Add external Drupal plugins to the list of extensions.
if ($type == 'buttons' && !empty($plugins[$plugin]['proxy'])) {
$settings['extensions'][_wysiwyg_tinymce_plugin_name('add', $button)] = 1;
}
// Add external plugins to the list of extensions.
else if ($type == 'buttons' && empty($plugins[$plugin]['internal'])) {
$settings['extensions'][_wysiwyg_tinymce_plugin_name('add', $plugin)] = 1;
}
// Add internal buttons that also need to be loaded as extension.
else if ($type == 'buttons' && !empty($plugins[$plugin]['load'])) {
$settings['extensions'][$plugin] = 1;
}
// Add plain extensions.
else if ($type == 'extensions' && !empty($plugins[$plugin]['load'])) {
$settings['extensions'][$plugin] = 1;
}
// Allow plugins to add valid HTML elements.
if (!empty($plugins[$plugin]['extended_valid_elements'])) {
$settings['extended_valid_elements'] = array_merge($settings['extended_valid_elements'], $plugins[$plugin]['extended_valid_elements']);
}
// Allow plugins to add or override global configuration settings.
if (!empty($plugins[$plugin]['options'])) {
$settings = array_merge($settings, $plugins[$plugin]['options']);
}
}
}
}
// Clean-up.
$settings['extended_valid_elements'] = array_unique($settings['extended_valid_elements']);
if ($settings['extensions']) {
$settings['plugins'] = array_keys($settings['extensions']);
}
unset($settings['extensions']);
}
// Add theme-specific settings.
switch ($theme) {
case 'advanced':
$settings += array(
'theme_advanced_resize_horizontal' => FALSE,
'theme_advanced_resizing_use_cookie' => FALSE,
'theme_advanced_path_location' => isset($config['path_loc']) ? $config['path_loc'] : 'bottom',
'theme_advanced_resizing' => isset($config['resizing']) ? $config['resizing'] : 1,
'theme_advanced_toolbar_location' => isset($config['toolbar_loc']) ? $config['toolbar_loc'] : 'top',
'theme_advanced_toolbar_align' => isset($config['toolbar_align']) ? $config['toolbar_align'] : 'left',
);
if (isset($config['block_formats'])) {
$settings['theme_advanced_blockformats'] = $config['block_formats'];
}
if (isset($settings['buttons'])) {
// These rows explicitly need to be set to be empty, otherwise TinyMCE
// loads its default buttons of the advanced theme for each row.
$settings += array(
'theme_advanced_buttons1' => array(),
'theme_advanced_buttons2' => array(),
'theme_advanced_buttons3' => array(),
);
// @todo Allow to sort/arrange editor buttons.
for ($i = 0; $i < count($settings['buttons']); $i++) {
$settings['theme_advanced_buttons1'][] = $settings['buttons'][$i];
}
}
break;
}
unset($settings['buttons']);
// Convert the config values into the form expected by TinyMCE.
$csv_settings = array('plugins', 'extended_valid_elements', 'theme_advanced_buttons1', 'theme_advanced_buttons2', 'theme_advanced_buttons3');
foreach ($csv_settings as $key) {
if (isset($settings[$key]) && is_array($settings[$key])) {
$settings[$key] = implode(',', $settings[$key]);
}
}
return $settings;
}
/**
* 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) upon initializing the editor.
*/
function wysiwyg_tinymce_plugin_settings($editor, $profile, $plugins) {
$settings = array();
foreach ($plugins as $name => $plugin) {
if (!empty($plugin['load'])) {
// Add path for native external plugins; internal ones are loaded
// automatically.
if (empty($plugin['internal']) && isset($plugin['filename'])) {
$settings[$name] = base_path() . $plugin['path'] . '/' . $plugin['filename'];
}
}
}
return $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) {
// 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'],
);
if (isset($plugin['css file'])) {
$settings[$name]['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
* its own plugin repository are prefixed with a hiven in the name.
*
* @param string $op
* Operation to perform, 'add' or 'remove' (hiven).
* @param string $name
* A plugin name.
*/
function _wysiwyg_tinymce_plugin_name($op, $name) {
if ($op == 'add') {
if (strpos($name, '-') !== 0) {
return '-' . $name;
}
return $name;
}
else if ($op == 'remove') {
if (strpos($name, '-') === 0) {
return substr($name, 1);
}
return $name;
}
}
/**
* Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
*/
function wysiwyg_tinymce_plugins($editor) {
$plugins = array(
'default' => array(
'path' => $editor['library path'] . '/themes/advanced',
'buttons' => array(
'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
'strikethrough' => t('Strike-through'),
'justifyleft' => t('Align left'), 'justifycenter' => t('Align center'), 'justifyright' => t('Align right'), 'justifyfull' => t('Justify'),
'bullist' => t('Bullet list'), 'numlist' => t('Numbered list'),
'outdent' => t('Outdent'), 'indent' => t('Indent'),
'undo' => t('Undo'), 'redo' => t('Redo'),
'link' => t('Link'), 'unlink' => t('Unlink'), 'anchor' => t('Anchor'),
'image' => t('Image'),
'cleanup' => t('Clean-up'),
'forecolor' => t('Forecolor'), 'backcolor' => t('Backcolor'),
'sup' => t('Superscript'), 'sub' => t('Subscript'),
'blockquote' => t('Blockquote'), 'code' => t('Source code'),
'hr' => t('Horizontal rule'),
'cut' => t('Cut'), 'copy' => t('Copy'), 'paste' => t('Paste'),
'visualaid' => t('Visual aid'),
'removeformat' => t('Remove format'),
'charmap' => t('Character map'),
'help' => t('Help'),
),
'internal' => TRUE,
),
'advhr' => array(
'path' => $editor['library path'] . '/plugins/advhr',
'buttons' => array('advhr' => t('Advanced horizontal rule')),
'extended_valid_elements' => array('hr[class|width|size|noshade]'),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advhr',
'internal' => TRUE,
'load' => TRUE,
),
'advimage' => array(
'path' => $editor['library path'] . '/plugins/advimage',
'extensions' => array('advimage' => t('Advanced image')),
'extended_valid_elements' => array('img[src|alt|title|align|width|height|usemap|hspace|vspace|border|style|class|onmouseover|onmouseout|id|name]'),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advimage',
'internal' => TRUE,
'load' => TRUE,
),
'advlink' => array(
'path' => $editor['library path'] . '/plugins/advlink',
'extensions' => array('advlink' => t('Advanced link')),
'extended_valid_elements' => array('a[name|href|target|title|class|onfocus|onblur|onclick|ondlbclick|onmousedown|onmouseup|onmouseover|onmouseout|onkeypress|onkeydown|onkeyup|id|style|rel]'),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advlink',
'internal' => TRUE,
'load' => TRUE,
),
'autosave' => array(
'path' => $editor['library path'] . '/plugins/autosave',
'extensions' => array('autosave' => t('Auto save')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/autosave',
'internal' => TRUE,
'load' => TRUE,
),
'contextmenu' => array(
'path' => $editor['library path'] . '/plugins/contextmenu',
'extensions' => array('contextmenu' => t('Context menu')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu',
'internal' => TRUE,
'load' => TRUE,
),
'directionality' => array(
'path' => $editor['library path'] . '/plugins/directionality',
'buttons' => array('ltr' => t('Left-to-right'), 'rtl' => t('Right-to-left')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/directionality',
'internal' => TRUE,
'load' => TRUE,
),
'emotions' => array(
'path' => $editor['library path'] . '/plugins/emotions',
'buttons' => array('emotions' => t('Emotions')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/emotions',
'internal' => TRUE,
'load' => TRUE,
),
'font' => array(
'path' => $editor['library path'] . '/plugins/font',
'buttons' => array('formatselect' => t('HTML block format'), 'fontselect' => t('Font'), 'fontsizeselect' => t('Font size'), 'styleselect' => t('Font style')),
'extended_valid_elements' => array('font[face|size|color|style],span[class|align|style]'),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/font',
'internal' => TRUE,
),
'fullscreen' => array(
'path' => $editor['library path'] . '/plugins/fullscreen',
'buttons' => array('fullscreen' => t('Fullscreen')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullscreen',
'internal' => TRUE,
'load' => TRUE,
),
'inlinepopups' => array(
'path' => $editor['library path'] . '/plugins/inlinepopups',
'extensions' => array('inlinepopups' => t('Inline popups')),
'options' => array(
'dialog_type' => array('modal'),
),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/inlinepopups',
'internal' => TRUE,
'load' => TRUE,
),
'insertdatetime' => array(
'path' => $editor['library path'] . '/plugins/insertdatetime',
'buttons' => array('insertdate' => t('Insert date'), 'inserttime' => t('Insert time')),
'options' => array(
'plugin_insertdate_dateFormat' => '%Y-%m-%d',
'plugin_insertdate_timeFormat' => '%H:%M:%S',
),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/insertdatetime',
'internal' => TRUE,
'load' => TRUE,
),
'layer' => array(
'path' => $editor['library path'] . '/plugins/layer',
'buttons' => array('insertlayer' => t('Insert layer'), 'moveforward' => t('Move forward'), 'movebackward' => t('Move backward'), 'absolute' => t('Absolute')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/layer',
'internal' => TRUE,
'load' => TRUE,
),
'paste' => array(
'path' => $editor['library path'] . '/plugins/paste',
'buttons' => array('pastetext' => t('Paste text'), 'pasteword' => t('Paste from Word'), 'selectall' => t('Select all')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/paste',
'internal' => TRUE,
'load' => TRUE,
),
'preview' => array(
'path' => $editor['library path'] . '/plugins/preview',
'buttons' => array('preview' => t('Preview')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/preview',
'internal' => TRUE,
'load' => TRUE,
),
'print' => array(
'path' => $editor['library path'] . '/plugins/print',
'buttons' => array('print' => t('Print')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/print',
'internal' => TRUE,
'load' => TRUE,
),
'searchreplace' => array(
'path' => $editor['library path'] . '/plugins/searchreplace',
'buttons' => array('search' => t('Search'), 'replace' => t('Replace')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/searchreplace',
'internal' => TRUE,
'load' => TRUE,
),
'style' => array(
'path' => $editor['library path'] . '/plugins/style',
'buttons' => array('styleprops' => t('Style properties')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/style',
'internal' => TRUE,
'load' => TRUE,
),
'table' => array(
'path' => $editor['library path'] . '/plugins/table',
'buttons' => array('tablecontrols' => t('Table')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/table',
'internal' => TRUE,
'load' => TRUE,
),
);
if (version_compare($editor['installed version'], '3', '<')) {
$plugins['flash'] = array(
'path' => $editor['library path'] . '/plugins/flash',
'buttons' => array('flash' => t('Flash')),
'extended_valid_elements' => array('img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|obj|param|embed]'),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/flash',
'internal' => TRUE,
'load' => TRUE,
);
}
if (version_compare($editor['installed version'], '2.0.6', '>')) {
$plugins['media'] = array(
'path' => $editor['library path'] . '/plugins/media',
'buttons' => array('media' => t('Media')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/media',
'internal' => TRUE,
'load' => TRUE,
);
$plugins['xhtmlxtras'] = array(
'path' => $editor['library path'] . '/plugins/xhtmlxtras',
'buttons' => array('cite' => t('Citation'), 'del' => t('Deleted'), 'abbr' => t('Abbreviation'), 'acronym' => t('Acronym'), 'ins' => t('Inserted'), 'attribs' => t('HTML attributes')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/xhtmlxtras',
'internal' => TRUE,
'load' => TRUE,
);
}
if (version_compare($editor['installed version'], '3', '>')) {
$plugins['bbcode'] = array(
'path' => $editor['library path'] . '/plugins/bbcode',
'extensions' => array('bbcode' => t('BBCode')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
'internal' => TRUE,
'load' => TRUE,
);
if (version_compare($editor['installed version'], '3.3', '<')) {
$plugins['safari'] = array(
'path' => $editor['library path'] . '/plugins/safari',
'extensions' => array('safari' => t('Safari compatibility')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/safari',
'internal' => TRUE,
'load' => TRUE,
);
}
}
if (version_compare($editor['installed version'], '3.2.5', '>=')) {
$plugins['autoresize'] = array(
'path' => $editor['library path'] . '/plugins/autoresize',
'extensions' => array('autoresize' => t('Auto resize')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/autoresize',
'internal' => TRUE,
'load' => TRUE,
);
}
if (version_compare($editor['installed version'], '3.3', '>=')) {
$plugins['advlist'] = array(
'path' => $editor['library path'] . '/plugins/advlist',
'extensions' => array('advlist' => t('Advanced list')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advlist',
'internal' => TRUE,
'load' => TRUE,
);
}
if (version_compare($editor['installed version'], '3.2.6', '>=')) {
$plugins['wordcount'] = array(
'path' => $editor['library path'] . '/plugins/wordcount',
'extensions' => array('wordcount' => t('Word count')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/wordcount',
'internal' => TRUE,
'load' => TRUE,
);
}
return $plugins;
}

View File

@@ -0,0 +1,147 @@
<?php
/**
* @file
* Editor integration functions for Whizzywig.
*/
/**
* Plugin implementation of hook_editor().
*/
function wysiwyg_whizzywig_editor() {
$editor['whizzywig'] = array(
'title' => 'Whizzywig',
'vendor url' => 'http://www.unverse.net',
'download url' => 'http://www.unverse.net/whizzywig-download.html',
'libraries' => array(
'' => array(
'title' => 'Default',
'files' => array('whizzywig.js', 'xhtml.js'),
),
),
'version callback' => 'wysiwyg_whizzywig_version',
'settings callback' => 'wysiwyg_whizzywig_settings',
'plugin callback' => 'wysiwyg_whizzywig_plugins',
'versions' => array(
'55' => array(
'js files' => array('whizzywig.js'),
),
'56' => array(
'js files' => array('whizzywig-56.js'),
),
'60' => array(
'js files' => array('whizzywig-60.js'),
),
),
);
return $editor;
}
/**
* Detect editor version.
*
* @param $editor
* An array containing editor properties as returned from hook_editor().
*
* @return
* The installed editor version.
*/
function wysiwyg_whizzywig_version($editor) {
$script = $editor['library path'] . '/whizzywig.js';
if (!file_exists($script)) {
return;
}
$script = fopen($script, 'r');
$line = fgets($script, 43);
// 55: Whizzywig v55i
// 60: Whizzywig 60
if (preg_match('@Whizzywig v?([0-9]+)@', $line, $version)) {
fclose($script);
return $version[1];
}
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_whizzywig_settings($editor, $config, $theme) {
$settings = array();
// Add path to button images, if available.
if (is_dir($editor['library path'] . '/btn')) {
$settings['buttonPath'] = base_path() . $editor['library path'] . '/btn/';
}
if (file_exists($editor['library path'] . '/WhizzywigToolbar.png')) {
$settings['toolbarImagePath'] = base_path() . $editor['library path'] . '/WhizzywigToolbar.png';
}
// Filename changed in version 60.
elseif (file_exists($editor['library path'] . '/icons.png')) {
$settings['toolbarImagePath'] = base_path() . $editor['library path'] . '/icons.png';
}
// Add configured buttons or all available.
$settings['buttons'] = array();
if (!empty($config['buttons'])) {
$buttons = array();
foreach ($config['buttons'] as $plugin) {
$buttons = array_merge($buttons, $plugin);
}
$settings['buttons'] = implode(' ', array_keys($buttons));
}
// Add editor content stylesheet.
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
$css = path_to_theme() . '/style.css';
if (file_exists($css)) {
$settings['externalCSS'] = base_path() . $css;
}
}
else if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['externalCSS'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
}
}
return $settings;
}
/**
* Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
*/
function wysiwyg_whizzywig_plugins($editor) {
return array(
'default' => array(
'buttons' => array(
'formatblock' => t('HTML block format'), 'fontname' => t('Font'), 'fontsize' => t('Font size'),
'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
'left' => t('Align left'), 'center' => t('Align center'), 'right' => t('Align right'),
'bullet' => t('Bullet list'), 'number' => t('Numbered list'),
'outdent' => t('Outdent'), 'indent' => t('Indent'),
'undo' => t('Undo'), 'redo' => t('Redo'),
'image' => t('Image'),
'color' => t('Forecolor'), 'hilite' => t('Backcolor'),
'rule' => t('Horizontal rule'),
'link' => t('Link'),
'image' => t('Image'),
'table' => t('Table'),
'clean' => t('Clean-up'),
'html' => t('Source code'),
'spellcheck' => t('Spell check'),
),
'internal' => TRUE,
),
);
}

View File

@@ -0,0 +1,233 @@
<?php
/**
* @file
* Editor integration functions for WYMeditor.
*/
/**
* Plugin implementation of hook_editor().
*/
function wysiwyg_wymeditor_editor() {
$editor['wymeditor'] = array(
'title' => 'WYMeditor',
'vendor url' => 'http://www.wymeditor.org/',
'download url' => 'http://www.wymeditor.org/download/',
'library path' => wysiwyg_get_path('wymeditor') . '/wymeditor',
'libraries' => array(
'min' => array(
'title' => 'Minified',
'files' => array('jquery.wymeditor.min.js'),
),
'pack' => array(
'title' => 'Packed',
'files' => array('jquery.wymeditor.pack.js'),
),
'src' => array(
'title' => 'Source',
'files' => array('jquery.wymeditor.js'),
),
),
'version callback' => 'wysiwyg_wymeditor_version',
'themes callback' => 'wysiwyg_wymeditor_themes',
'settings callback' => 'wysiwyg_wymeditor_settings',
'plugin callback' => 'wysiwyg_wymeditor_plugins',
'versions' => array(
'0.5-rc1' => array(
'js files' => array('wymeditor.js'),
),
),
);
return $editor;
}
/**
* Detect editor version.
*
* @param $editor
* An array containing editor properties as returned from hook_editor().
*
* @return
* The installed editor version.
*/
function wysiwyg_wymeditor_version($editor) {
$script = $editor['library path'] . '/jquery.wymeditor.js';
if (!file_exists($script)) {
return;
}
$script = fopen($script, 'r');
fgets($script);
$line = fgets($script);
if (preg_match('@version\s+([0-9a-z\.-]+)@', $line, $version)) {
fclose($script);
return $version[1];
}
fclose($script);
}
/**
* Determine available editor themes or check/reset a given one.
*
* @param $editor
* A processed hook_editor() array of editor properties.
* @param $profile
* A wysiwyg editor profile.
*
* @return
* An array of theme names. The first returned name should be the default
* theme name.
*/
function wysiwyg_wymeditor_themes($editor, $profile) {
return array('compact', 'default', 'minimal', 'silver', 'twopanels');
}
/**
* 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_wymeditor_settings($editor, $config, $theme) {
// @todo Setup $library in wysiwyg_load_editor() already.
$library = (isset($editor['library']) ? $editor['library'] : key($editor['libraries']));
$settings = array(
'basePath' => base_path() . $editor['library path'] . '/',
'wymPath' => $editor['libraries'][$library]['files'][0],
// @todo Does not work in Drupal; jQuery can live anywhere.
'jQueryPath' => base_path() . 'misc/jquery.js',
'updateSelector' => '.form-submit',
'skin' => $theme,
);
if (isset($config['language'])) {
$settings['lang'] = $config['language'];
}
// Add configured buttons.
$settings['toolsItems'] = array();
if (!empty($config['buttons'])) {
$buttoninfo = _wysiwyg_wymeditor_button_info();
$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 buttons.
if ($type == 'buttons') {
// Merge meta-data for internal default buttons.
if (isset($buttoninfo[$button])) {
$buttoninfo[$button] += array('name' => $button);
$settings['toolsItems'][] = $buttoninfo[$button];
}
// For custom buttons, try to provide a valid button definition.
else {
$settings['toolsItems'][] = array(
'name' => $button,
'title' => $plugins[$plugin][$type][$button],
'css' => 'wym_tools_' . $button,
);
}
}
}
}
}
}
if (!empty($config['block_formats'])) {
$containers = array(
'p' => 'Paragraph',
'h1' => 'Heading_1',
'h2' => 'Heading_2',
'h3' => 'Heading_3',
'h4' => 'Heading_4',
'h5' => 'Heading_5',
'h6' => 'Heading_6',
'pre' => 'Preformatted',
'blockquote' => 'Blockquote',
'th' => 'Table_Header',
);
foreach (explode(',', $config['block_formats']) as $tag) {
if (isset($containers[$tag])) {
$settings['containersItems'][] = array(
'name' => strtoupper($tag),
'title' => $containers[$tag],
'css' => 'wym_containers_' . $tag,
);
}
}
}
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
// WYMeditor only supports one CSS file currently.
$settings['stylesheet'] = reset(wysiwyg_get_css());
}
else if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['stylesheet'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
}
}
return $settings;
}
/**
* Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
*/
function wysiwyg_wymeditor_plugins($editor) {
$plugins = array(
'default' => array(
'buttons' => array(
'Bold' => t('Bold'), 'Italic' => t('Italic'),
'InsertOrderedList' => t('Bullet list'), 'InsertUnorderedList' => t('Numbered list'),
'Outdent' => t('Outdent'), 'Indent' => t('Indent'),
'Undo' => t('Undo'), 'Redo' => t('Redo'),
'CreateLink' => t('Link'), 'Unlink' => t('Unlink'),
'InsertImage' => t('Image'),
'Superscript' => t('Superscript'), 'Subscript' => t('Subscript'),
'ToggleHtml' => t('Source code'),
'Paste' => t('Paste'),
'InsertTable' => t('Table'),
'Preview' => t('Preview'),
),
'internal' => TRUE,
),
);
return $plugins;
}
/**
* Helper function to provide additional meta-data for internal default buttons.
*/
function _wysiwyg_wymeditor_button_info() {
return array(
'Bold' => array('title'=> 'Strong', 'css'=> 'wym_tools_strong'),
'Italic' => array('title'=> 'Emphasis', 'css'=> 'wym_tools_emphasis'),
'Superscript' => array('title'=> 'Superscript', 'css'=> 'wym_tools_superscript'),
'Subscript' => array('title'=> 'Subscript', 'css'=> 'wym_tools_subscript'),
'InsertOrderedList' => array('title'=> 'Ordered_List', 'css'=> 'wym_tools_ordered_list'),
'InsertUnorderedList' => array('title'=> 'Unordered_List', 'css'=> 'wym_tools_unordered_list'),
'Indent' => array('title'=> 'Indent', 'css'=> 'wym_tools_indent'),
'Outdent' => array('title'=> 'Outdent', 'css'=> 'wym_tools_outdent'),
'Undo' => array('title'=> 'Undo', 'css'=> 'wym_tools_undo'),
'Redo' => array('title'=> 'Redo', 'css'=> 'wym_tools_redo'),
'CreateLink' => array('title'=> 'Link', 'css'=> 'wym_tools_link'),
'Unlink' => array('title'=> 'Unlink', 'css'=> 'wym_tools_unlink'),
'InsertImage' => array('title'=> 'Image', 'css'=> 'wym_tools_image'),
'InsertTable' => array('title'=> 'Table', 'css'=> 'wym_tools_table'),
'Paste' => array('title'=> 'Paste_From_Word', 'css'=> 'wym_tools_paste'),
'ToggleHtml' => array('title'=> 'HTML', 'css'=> 'wym_tools_html'),
'Preview' => array('title'=> 'Preview', 'css'=> 'wym_tools_preview'),
);
}

View File

@@ -0,0 +1,297 @@
<?php
/**
* @file
* Editor integration functions for YUI editor.
*/
/**
* Plugin implementation of hook_editor().
*/
function wysiwyg_yui_editor() {
$editor['yui'] = array(
'title' => 'YUI editor',
'vendor url' => 'http://developer.yahoo.com/yui/editor/',
'download url' => 'http://developer.yahoo.com/yui/download/',
'library path' => wysiwyg_get_path('yui') . '/build',
'libraries' => array(
'min' => array(
'title' => 'Minified',
'files' => array(
'yahoo-dom-event/yahoo-dom-event.js',
'animation/animation-min.js',
'element/element-min.js',
'container/container-min.js',
'menu/menu-min.js',
'button/button-min.js',
'editor/editor-min.js',
),
),
'src' => array(
'title' => 'Source',
'files' => array(
'yahoo-dom-event/yahoo-dom-event.js',
'animation/animation.js',
'element/element.js',
'container/container.js',
'menu/menu.js',
'button/button.js',
'editor/editor.js',
),
),
),
'version callback' => 'wysiwyg_yui_version',
'themes callback' => 'wysiwyg_yui_themes',
'load callback' => 'wysiwyg_yui_load',
'settings callback' => 'wysiwyg_yui_settings',
'plugin callback' => 'wysiwyg_yui_plugins',
'versions' => array(
'2.7.0' => array(
'js files' => array('yui.js'),
),
),
);
return $editor;
}
/**
* Detect editor version.
*
* @param $editor
* An array containing editor properties as returned from hook_editor().
*
* @return
* The installed editor version.
*/
function wysiwyg_yui_version($editor) {
$library = $editor['library path'] . '/editor/editor.js';
if (!file_exists($library)) {
return;
}
$library = fopen($library, 'r');
$max_lines = 10;
while ($max_lines && $line = fgets($library, 60)) {
if (preg_match('@version:\s([0-9\.]+)@', $line, $version)) {
fclose($library);
return $version[1];
}
$max_lines--;
}
fclose($library);
}
/**
* Determine available editor themes or check/reset a given one.
*
* @param $editor
* A processed hook_editor() array of editor properties.
* @param $profile
* A wysiwyg editor profile.
*
* @return
* An array of theme names. The first returned name should be the default
* theme name.
*/
function wysiwyg_yui_themes($editor, $profile) {
return array('sam');
}
/**
* Perform additional actions upon loading this editor.
*
* @param $editor
* A processed hook_editor() array of editor properties.
* @param $library
* The internal library name (array key) to use.
*/
function wysiwyg_yui_load($editor, $library) {
drupal_add_css($editor['library path'] . '/menu/assets/skins/sam/menu.css');
drupal_add_css($editor['library path'] . '/button/assets/skins/sam/button.css');
drupal_add_css($editor['library path'] . '/fonts/fonts-min.css');
drupal_add_css($editor['library path'] . '/container/assets/skins/sam/container.css');
drupal_add_css($editor['library path'] . '/editor/assets/skins/sam/editor.css');
}
/**
* 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_yui_settings($editor, $config, $theme) {
$settings = array(
'theme' => $theme,
'animate' => TRUE,
'handleSubmit' => TRUE,
'markup' => 'xhtml',
'ptags' => TRUE,
);
if (isset($config['path_loc']) && $config['path_loc'] != 'none') {
$settings['dompath'] = $config['path_loc'];
}
// Enable auto-height feature when editor should be resizable.
if (!empty($config['resizing'])) {
$settings['autoHeight'] = TRUE;
}
$settings += array(
'toolbar' => array(
'collapse' => FALSE,
'draggable' => TRUE,
'buttonType' => 'advanced',
'buttons' => array(),
),
);
if (!empty($config['buttons'])) {
$buttons = array();
foreach ($config['buttons'] as $plugin => $enabled_buttons) {
foreach ($enabled_buttons as $button => $enabled) {
$extra = array();
if ($button == 'heading') {
$extra = array('menu' => array(
array('text' => 'Normal', 'value' => 'none', 'checked' => TRUE),
));
if (!empty($config['block_formats'])) {
$headings = array(
'p' => array('text' => 'Paragraph', 'value' => 'p'),
'h1' => array('text' => 'Heading 1', 'value' => 'h1'),
'h2' => array('text' => 'Heading 2', 'value' => 'h2'),
'h3' => array('text' => 'Heading 3', 'value' => 'h3'),
'h4' => array('text' => 'Heading 4', 'value' => 'h4'),
'h5' => array('text' => 'Heading 5', 'value' => 'h5'),
'h6' => array('text' => 'Heading 6', 'value' => 'h6'),
);
foreach (explode(',', $config['block_formats']) as $tag) {
if (isset($headings[$tag])) {
$extra['menu'][] = $headings[$tag];
}
}
}
}
else if ($button == 'fontname') {
$extra = array('menu' => array(
array('text' => 'Arial', 'checked' => TRUE),
array('text' => 'Arial Black'),
array('text' => 'Comic Sans MS'),
array('text' => 'Courier New'),
array('text' => 'Lucida Console'),
array('text' => 'Tahoma'),
array('text' => 'Times New Roman'),
array('text' => 'Trebuchet MS'),
array('text' => 'Verdana'),
));
}
$buttons[] = wysiwyg_yui_button_setting($editor, $plugin, $button, $extra);
}
}
// Group buttons in a dummy group.
$buttons = array('group' => 'default', 'label' => '', 'buttons' => $buttons);
$settings['toolbar']['buttons'] = array($buttons);
}
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
$settings['extracss'] = wysiwyg_get_css();
}
else if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['extracss'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
$settings['extracss'] = explode(',', $settings['extracss']);
}
// YUI only supports inline CSS, so we need to use @import directives.
// Syntax: '@import "/base/path/to/theme/style.css"; '
if (!empty($settings['extracss'])) {
$settings['extracss'] = '@import "' . implode('"; @import "', $settings['extracss']) . '";';
}
}
return $settings;
}
/**
* Create the JavaScript structure for a YUI button.
*
* @param $editor
* A processed hook_editor() array of editor properties.
* @param $plugin
* The internal name of a plugin.
* @param $button
* The internal name of a button, defined by $plugin.
* @param $extra
* (optional) An array containing arbitrary other elements to add to the
* resulting button.
*/
function wysiwyg_yui_button_setting($editor, $plugin, $button, $extra = array()) {
static $plugins;
if (!isset($plugins)) {
// @todo Invoke all enabled plugins, not just internals.
$plugins = wysiwyg_yui_plugins($editor);
}
// Return a simple separator.
if ($button === 'separator') {
return array('type' => 'separator');
}
// Setup defaults.
$type = 'push';
$label = $plugins[$plugin]['buttons'][$button];
// Special handling for certain buttons.
if (in_array($button, array('heading', 'fontname'))) {
$type = 'select';
$label = $extra['menu'][0]['text'];
}
elseif (in_array($button, array('fontsize'))) {
$type = 'spin';
}
elseif (in_array($button, array('forecolor', 'backcolor'))) {
$type = 'color';
}
$button = array(
'type' => $type,
'label' => $label,
'value' => $button,
);
// Add arbitrary other elements, if defined.
if (!empty($extra)) {
$button = array_merge($button, $extra);
}
return $button;
}
/**
* Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
*/
function wysiwyg_yui_plugins($editor) {
return array(
'default' => array(
'buttons' => array(
'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
'strikethrough' => t('Strike-through'),
'justifyleft' => t('Align left'), 'justifycenter' => t('Align center'), 'justifyright' => t('Align right'), 'justifyfull' => t('Justify'),
'insertunorderedlist' => t('Bullet list'), 'insertorderedlist' => t('Numbered list'),
'outdent' => t('Outdent'), 'indent' => t('Indent'),
'undo' => t('Undo'), 'redo' => t('Redo'),
'createlink' => t('Link'),
'insertimage' => t('Image'),
'forecolor' => t('Font Color'), 'backcolor' => t('Background Color'),
'superscript' => t('Sup'), 'subscript' => t('Sub'),
'hiddenelements' => t('Show/hide hidden elements'),
'removeformat' => t('Remove format'),
'heading' => t('HTML block format'), 'fontname' => t('Font'), 'fontsize' => t('Font size'),
),
'internal' => TRUE,
),
);
}