Commit 89962a3d authored by Eric Rasmussen's avatar Eric Rasmussen
Browse files

[gh-486] Upgrade WYSIWYG module to 7.x-2.2

Includes UNL patch outlined in the README
parent 26746157
Wysiwyg 7.x-2.x, xxxx-xx-xx
---------------------------
#1388224 by ksenzee, sun, TwoD: Fixed editors detaching on form submissions.
#682160 by n_vashenko, TwoD: Fixed lists plugin support for TinyMCE.
#1414354 by Merco: Fixed none.js breaks if textarea.js is not loaded.
#1064600 by TwoD: Fixed maximized editors hidden under Drupal's toolbar.
#1405786 by logaritmisk: Fixed CKEditor being wider than parent elements.
#1531896 by Chi: Fixed strict warning for WYMeditor.
#1442226 by robertom: Fixed inverted list button names for WYMeditor.
#1352426 by TwoD, sun: Added install notes (CKEditor edition clarification).
#1112212 by timdiacon, TwoD: Added language direction buttons for CKEditor.
#1398560 by markwittens: Fixed TinyMCE removing the longdesc attribute.
#970452 by smk-ka, sun, TwoD, drzraf: Fixed outdated TinyMCE plugin info.
#1155678 by james.elliott, Jody Lynn, sun: Add Drupal.detachBehaviors support.
#624018 by smk-ka, quartsize, dagmar, nedjo, rickvug, catch, sun: Added Features support.
#1238766 by Dave Reid: Fixed Missing cells in profile plugins table.
#1073106 by scottrouse: Fixed 'Input Format' should be 'Text Format'.
#1153458 by TwoD: Fixed TinyMCE 'Verify HTML' setting ignored.
#1125582 by TwoD: Fixed TinyMCE fullscreen plugin deletes content.
#1078834 by sun: Fixed coding standards errors.
#1173476 by jim0203, sun: Fixed installation instructions in README.txt.
Wysiwyg 7.x-2.1, 2011-06-19
......
This diff is collapsed.
......@@ -18,7 +18,8 @@ To submit bug reports and feature suggestions, or to track changes:
-- INSTALLATION --
* Install as usual, see http://drupal.org/node/70151 for further information.
* Install as usual, see
http://drupal.org/documentation/install/modules-themes/modules-7
* Go to Administration » Configuration » Content authoring » Wysiwyg,
and follow the displayed installation instructions to download and install one
......
......@@ -27,8 +27,11 @@ function wysiwyg_ckeditor_editor() {
),
),
),
'install note callback' => 'wysiwyg_ckeditor_install_note',
'version callback' => 'wysiwyg_ckeditor_version',
'themes callback' => 'wysiwyg_ckeditor_themes',
'settings form callback' => 'wysiwyg_ckeditor_settings_form',
'init callback' => 'wysiwyg_ckeditor_init',
'settings callback' => 'wysiwyg_ckeditor_settings',
'plugin callback' => 'wysiwyg_ckeditor_plugins',
'plugin settings callback' => 'wysiwyg_ckeditor_plugin_settings',
......@@ -48,6 +51,13 @@ function wysiwyg_ckeditor_editor() {
return $editor;
}
/**
* Return an install note.
*/
function wysiwyg_ckeditor_install_note() {
return '<p class="warning">' . t('Do NOT download the "CKEditor for Drupal" edition.') . '</p>';
}
/**
* Detect editor version.
*
......@@ -111,6 +121,69 @@ function wysiwyg_ckeditor_themes($editor, $profile) {
}
}
/**
* Enhances the editor profile settings form for CKEditor.
*
* Adds support for CKEditor's advanced stylesSets, which are a more advanced
* implementation and combination of block formats and font styles that allow
* to adjust the HTML element, attributes, and CSS styles at once.
*
* @see http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Styles
* @see http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.stylesSet
*/
function wysiwyg_ckeditor_settings_form(&$form, &$form_state) {
if (version_compare($form_state['wysiwyg']['editor']['installed version'], '3.2.1', '>=')) {
// Replace CSS classes element description to explain the advanced syntax.
$form['css']['css_classes']['#description'] = t('Optionally define CSS classes for the "Font style" dropdown list.<br />Enter one class on each line in the format: !format. Example: !example<br />If left blank, CSS classes are automatically imported from loaded stylesheet(s).', array(
'!format' => '<code>[label]=[element].[class]</code>',
'!example' => '<code>Title=h1.title</code>',
));
$form['css']['css_classes']['#element_validate'][] = 'wysiwyg_ckeditor_settings_form_validate_css_classes';
}
else {
// Versions below 3.2.1 do not support Font styles at all.
$form['css']['css_classes']['#access'] = FALSE;
}
}
/**
* #element_validate handler for CSS classes element altered by wysiwyg_ckeditor_settings_form().
*/
function wysiwyg_ckeditor_settings_form_validate_css_classes($element, &$form_state) {
if (wysiwyg_ckeditor_settings_parse_styles($element['#value']) === FALSE) {
form_error($element, t('The specified CSS classes are syntactically incorrect.'));
}
}
/**
* Returns an initialization JavaScript for this editor library.
*
* @param array $editor
* The editor library definition.
* @param string $library
* The library variant key from $editor['libraries'].
* @param object $profile
* The (first) wysiwyg editor profile.
*
* @return string
* A string containing inline JavaScript to execute before the editor library
* script is loaded.
*/
function wysiwyg_ckeditor_init($editor) {
// CKEditor unconditionally searches for its library filename in SCRIPT tags
// on the page upon loading the library in order to determine the base path to
// itself. When JavaScript aggregation is enabled, this search fails and all
// relative constructed paths within CKEditor are broken. The library has a
// CKEditor.basePath property, but it is not publicly documented and thus not
// reliable. The official documentation suggests to solve the issue through
// the global window variable.
// @see http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Specifying_the_Editor_Path
$library_path = base_path() . $editor['library path'] . '/';
return <<<EOL
window.CKEDITOR_BASEPATH = '$library_path';
EOL;
}
/**
* Return runtime editor settings for a given wysiwyg profile.
*
......@@ -127,8 +200,7 @@ function wysiwyg_ckeditor_themes($editor, $profile) {
*/
function wysiwyg_ckeditor_settings($editor, $config, $theme) {
$settings = array(
'baseHref' => $GLOBALS['base_url'] . '/',
'width' => '100%',
'width' => 'auto',
// For better compatibility with smaller textareas.
'resize_minWidth' => 450,
'height' => 420,
......@@ -167,7 +239,7 @@ function wysiwyg_ckeditor_settings($editor, $config, $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()));
$settings['contentsCss'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => drupal_get_path('theme', variable_get('theme_default', NULL))));
}
}
else {
......@@ -175,16 +247,25 @@ function wysiwyg_ckeditor_settings($editor, $config, $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())));
$settings['contentsCss'] = explode(',', strtr($config['css_path'], array('%b' => base_path(), '%t' => drupal_get_path('theme', variable_get('theme_default', NULL)))));
}
}
}
// Parse and define the styles set for the Styles plugin (3.2.1+).
// @todo This should be a plugin setting, but Wysiwyg does not support
// plugin-specific settings yet.
if (!empty($config['buttons']['default']['Styles']) && version_compare($editor['installed version'], '3.2.1', '>=')) {
if ($styles = wysiwyg_ckeditor_settings_parse_styles($config['css_classes'])) {
$settings['stylesSet'] = $styles;
}
}
if (isset($config['language'])) {
$settings['language'] = $config['language'];
}
if (isset($config['resizing'])) {
// CKEditor tests "!== false", so ensure it is a Boolean.
// CKEditor performs a type-agnostic comparison on this particular setting.
$settings['resize_enabled'] = (bool) $config['resizing'];
}
if (isset($config['toolbar_loc'])) {
......@@ -240,6 +321,51 @@ function wysiwyg_ckeditor_settings($editor, $config, $theme) {
return $settings;
}
/**
* Parses CSS classes settings string into a stylesSet JavaScript settings array.
*
* @param string $css_classes
* A string containing CSS class definitions to add to the Style dropdown
* list, separated by newlines.
*
* @return array|false
* An array containing the parsed stylesSet definition, or FALSE on parse
* error.
*
* @see wysiwyg_ckeditor_settings_form()
* @see wysiwyg_ckeditor_settings_form_validate_css_classes()
*
* @todo This should be a plugin setting, but Wysiwyg does not support
* plugin-specific settings yet.
*/
function wysiwyg_ckeditor_settings_parse_styles($css_classes) {
$set = array();
$input = trim($css_classes);
if (empty($input)) {
return $set;
}
// Handle both Unix and Windows line-endings.
foreach (explode("\n", str_replace("\r", '', $input)) as $line) {
$line = trim($line);
// [label]=[element].[class][.[class]][...] pattern expected.
if (!preg_match('@^.+= *[a-zA-Z0-9]+(\.[a-zA-Z0-9_ -]+)*$@', $line)) {
return FALSE;
}
list($label, $selector) = explode('=', $line, 2);
$classes = explode('.', $selector);
$element = array_shift($classes);
$style = array();
$style['name'] = trim($label);
$style['element'] = trim($element);
if (!empty($classes)) {
$style['attributes']['class'] = implode(' ', array_map('trim', $classes));
}
$set[] = $style;
}
return $set;
}
/**
* Build a JS settings array of native external plugins that need to be loaded separately.
*/
......@@ -294,6 +420,7 @@ function wysiwyg_ckeditor_plugins($editor) {
'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'),
'BidiLtr' => t('Left-to-right'), 'BidiRtl' => t('Right-to-left'),
'BulletedList' => t('Bullet list'), 'NumberedList' => t('Numbered list'),
'Outdent' => t('Outdent'), 'Indent' => t('Indent'),
'Undo' => t('Undo'), 'Redo' => t('Redo'),
......@@ -325,6 +452,10 @@ function wysiwyg_ckeditor_plugins($editor) {
if (version_compare($editor['installed version'], '3.1.0.4885', '<')) {
unset($plugins['default']['buttons']['CreateDiv']);
}
if (version_compare($editor['installed version'], '3.4.0.5808', '<')) {
unset($plugins['default']['buttons']['BidiLtr']);
unset($plugins['default']['buttons']['BidiRtl']);
}
if (version_compare($editor['installed version'], '3.5.0.6260', '<')) {
unset($plugins['default']['buttons']['Iframe']);
}
......
<?php
/**
* @file
* Editor integration functions for EpicEditor.
*/
/**
* Plugin implementation of hook_editor().
*/
function wysiwyg_epiceditor_editor() {
$editor['epiceditor'] = array(
'title' => 'EpicEditor',
'vendor url' => 'http://oscargodson.github.com/EpicEditor',
'download url' => 'http://oscargodson.github.com/EpicEditor/docs/downloads/EpicEditor-v0.1.1.zip',
'libraries' => array(
'' => array(
'title' => 'Minified',
'files' => array('js/epiceditor.min.js'),
),
'src' => array(
'title' => 'Source',
'files' => array('js/epiceditor.js'),
),
),
'version callback' => 'wysiwyg_epiceditor_version',
'themes callback' => 'wysiwyg_epiceditor_themes',
'settings callback' => 'wysiwyg_epiceditor_settings',
'versions' => array(
'0.1.1' => array(
'js files' => array('epiceditor.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_epiceditor_version($editor) {
$library = $editor['library path'] . '/js/epiceditor.js';
if (!file_exists($library)) {
return;
}
// @todo Do not load the entire file; use fgets() instead.
$library = file_get_contents($library, 'r');
$version = preg_match('%EpicEditor\.version = \'(.*)\'\;%', $library, $matches);
if (!isset($matches[1])) {
return;
}
return $matches[1];
}
/**
* 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_epiceditor_themes($editor, $profile) {
return array('epic-dark', 'epic-light');
// @todo Use the preview themes somewhere.
//return array('preview-dark', 'github');
}
/**
* 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_epiceditor_settings($editor, $config, $theme) {
$settings = array(
'basePath' => base_path() . $editor['library path'],
'clientSideStorage' => FALSE,
'theme' => $theme,
//'preview_theme' => '',
);
return $settings;
}
......@@ -131,8 +131,8 @@ function wysiwyg_fckeditor_settings($editor, $config, $theme) {
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()));
elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['EditorAreaCSS'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => drupal_get_path('theme', variable_get('theme_default', NULL))));
}
}
......
......@@ -23,6 +23,10 @@ Drupal.wysiwyg.editor.init.ckeditor = function(settings) {
}
}
}
// Register Font styles (versions 3.2.1 and above).
if (Drupal.settings.wysiwyg.configs.ckeditor[format].stylesSet) {
CKEDITOR.stylesSet.add(format, Drupal.settings.wysiwyg.configs.ckeditor[format].stylesSet);
}
}
};
......@@ -34,6 +38,8 @@ Drupal.wysiwyg.editor.attach.ckeditor = function(context, params, settings) {
// Apply editor instance settings.
CKEDITOR.config.customConfig = '';
var $drupalToolbar = $('#toolbar', Drupal.overlayChild ? window.parent.document : document);
settings.on = {
instanceReady: function(ev) {
var editor = ev.editor;
......@@ -125,6 +131,19 @@ Drupal.wysiwyg.editor.attach.ckeditor = function(context, params, settings) {
focus: function(ev) {
Drupal.wysiwyg.activeId = ev.editor.name;
},
afterCommandExec: function(ev) {
// Fix Drupal toolbar obscuring editor toolbar in fullscreen mode.
if (ev.data.name != 'maximize') {
return;
}
if (ev.data.command.state == CKEDITOR.TRISTATE_ON) {
$drupalToolbar.hide();
}
else {
$drupalToolbar.show();
}
}
};
......@@ -139,16 +158,19 @@ Drupal.wysiwyg.editor.attach.ckeditor = function(context, params, settings) {
* 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) {
Drupal.wysiwyg.editor.detach.ckeditor = function (context, params, trigger) {
var method = (trigger == 'serialize') ? 'updateElement' : 'destroy';
if (typeof params != 'undefined') {
var instance = CKEDITOR.instances[params.field];
if (instance) {
instance.destroy();
instance[method]();
}
}
else {
for (var instanceName in CKEDITOR.instances) {
CKEDITOR.instances[instanceName].destroy();
if (CKEDITOR.instances.hasOwnProperty(instanceName)) {
CKEDITOR.instances[instanceName][method]();
}
}
}
};
......@@ -208,9 +230,18 @@ Drupal.wysiwyg.editor.instance.ckeditor = {
// @todo Don't know if we need this yet.
return content;
},
insert: function(content) {
content = this.prepareContent(content);
CKEDITOR.instances[this.field].insertHtml(content);
},
setContent: function (content) {
CKEDITOR.instances[this.field].setData(content);
},
getContent: function () {
return CKEDITOR.instances[this.field].getData();
}
};
......
(function($) {
/**
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.epiceditor = function (context, params, settings) {
var $target = $('#' + params.field);
var containerId = params.field + '-epiceditor';
var defaultContent = $target.val();
$target.hide().after('<div id="' + containerId + '" />');
settings.container = containerId;
settings.file = {
defaultContent: defaultContent
};
settings.theme = {
preview: '/themes/preview/preview-dark.css',
editor: '/themes/editor/' + settings.theme + '.css'
}
var editor = new EpicEditor(settings).load();
$target.data('epiceditor', editor);
};
/**
* Detach a single or all editors.
*/
Drupal.wysiwyg.editor.detach.epiceditor = function (context, params, trigger) {
var $target = $('#' + params.field);
var editor = $target.data('epiceditor');
$target.val(editor.exportFile());
editor.unload(function () {
$target.show();
});
};
})(jQuery);
......@@ -21,7 +21,7 @@ Drupal.wysiwyg.editor.attach.fckeditor = function(context, params, settings) {
/**
* Detach a single or all editors.
*/
Drupal.wysiwyg.editor.detach.fckeditor = function(context, params) {
Drupal.wysiwyg.editor.detach.fckeditor = function (context, params, trigger) {
var instances = [];
if (typeof params != 'undefined' && typeof FCKeditorAPI != 'undefined') {
var instance = FCKeditorAPI.GetInstance(params.field);
......@@ -36,6 +36,11 @@ Drupal.wysiwyg.editor.detach.fckeditor = function(context, params) {
for (var instanceName in instances) {
var instance = instances[instanceName];
instance.UpdateLinkedField();
if (trigger == 'serialize') {
// The editor is not being removed from the DOM, so updating the linked
// field is the only action necessary.
continue;
}
// 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
......@@ -175,6 +180,16 @@ Drupal.wysiwyg.editor.instance.fckeditor = {
var instance = FCKeditorAPI.GetInstance(this.field);
// @see FCK.InsertHtml(), FCK.InsertElement()
instance.InsertHtml(content);
},
getContent: function () {
var instance = FCKeditorAPI.GetInstance(this.field);
return instance.GetData();
},
setContent: function (content) {
var instance = FCKeditorAPI.GetInstance(this.field);
instance.SetHTML(content);
}
};
......
......@@ -40,6 +40,19 @@ for (var setting in wysiwygSettings) {
}
}
// Fix Drupal toolbar obscuring editor toolbar in fullscreen mode.
var oldFitWindowExecute = FCKFitWindow.prototype.Execute;
var $drupalToolbar = window.parent.jQuery('#toolbar', Drupal.overlayChild ? window.parent.window.parent.document : window.parent.document);
FCKFitWindow.prototype.Execute = function() {
oldFitWindowExecute.apply(this, arguments);
if (this.IsMaximized) {
$drupalToolbar.hide();
}
else {
$drupalToolbar.show();
}
}
/**
* Initialize this editor instance.
*/
......
......@@ -11,15 +11,33 @@ Drupal.wysiwyg.editor.attach.jwysiwyg = function(context, params, settings) {
/**
* Detach a single or all editors.
*/
Drupal.wysiwyg.editor.detach.jwysiwyg = function(context, params) {
Drupal.wysiwyg.editor.detach.jwysiwyg = function (context, params, trigger) {
var $field = $('#' + params.field);
var editor = $field.data('wysiwyg');
if (typeof editor != 'undefined') {
editor.saveContent();
editor.element.remove();
if (trigger != 'serialize') {
editor.element.remove();
}
}
$field.removeData('wysiwyg');
$field.show();
if (trigger != 'serialize') {
$field.show();
}
};
Drupal.wysiwyg.editor.instance.jwysiwyg = {
insert: function (content) {
$('#' + this.field).wysiwyg('insertHtml', content);
},
setContent: function (content) {
$('#' + this.field).wysiwyg('setContent', content);
},
getContent: function () {
return $('#' + this.field).wysiwyg('getContent');
}
};
})(jQuery);
......@@ -17,7 +17,10 @@ Drupal.wysiwyg.editor.attach.markitup = function(context, params, settings) {
/**
* Detach a single or all editors.
*/
Drupal.wysiwyg.editor.detach.markitup = function(context, params) {
Drupal.wysiwyg.editor.detach.markitup = function (context, params, trigger) {
if (trigger == 'serialize') {
return;
}
if (typeof params != 'undefined') {
$('#' + params.field, context).markItUpRemove();
}
......@@ -26,4 +29,18 @@ Drupal.wysiwyg.editor.detach.markitup = function(context, params) {
}