Commit f2446499 authored by sun's avatar sun

#329657 by svendecabooter, sun: Added Whizzywig support.

parent 216b2cfb
tinymce*
fckeditor*
jwysiwyg*
\ No newline at end of file
jwysiwyg*
nicedit*
whizzywig*
......@@ -6,6 +6,7 @@ Wysiwyg x.x-x.x, xxxx-xx-xx
Wysiwyg 6.x-x.x, xxxx-xx-xx
---------------------------
#329657 by svendecabooter, sun: Added Whizzywig support.
#333521 by sun: Fixed TinyMCE version detection docs.
#327100 by sun: Changed access permission for settings page to 'administer
filters' to prevent incomplete updates.
......
// $Id$
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]) {
$('#' + wysiwygWhizzywig.currentField).after('<div id="' + wysiwygWhizzywig.currentField + '-whizzywig">' + w() + '</div>');
// Prevent subsequent invocations from inserting the editor multiple times.
wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField] = '';
}
// If id exists in the regular window.document, return it.
if ($('#' + id).size()) {
return $('#' + id).get(0);
}
// Otherwise return id from our container.
return $('#' + id, w()).get(0);
};
/**
* Attach this editor to a target element.
*/
Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, editorSettings) {
// Attach editor control if default is on.
if (Drupal.settings.wysiwyg.status) {
// Assign button images path, if available.
if (editorSettings[params.theme].buttonPath) {
window.buttonPath = editorSettings[params.theme].buttonPath;
}
// Create Whizzywig container.
wysiwygWhizzywig.currentField = params.field;
wysiwygWhizzywig.fields[wysiwygWhizzywig.currentField] = '';
// Attach editor.
makeWhizzyWig(params.field, (editorSettings[params.theme].buttons ? editorSettings[params.theme].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 = $('#' + params.field).val();
}
}
};
/**
* Detach a single or all editors.
*/
Drupal.wysiwyg.editor.detach.whizzywig = function(context, params) {
var detach = function (id) {
var instance = $('#whizzy' + whizzies[id]).get(0);
if (!instance) {
return;
}
var body = instance.contentWindow.document.body;
var $field = $('#' + whizzies[id]);
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.
$('#' + whizzies[id] + '-whizzywig').remove();
whizzies.splice(id, 1);
}
if (typeof params != 'undefined') {
for (var id in whizzies) {
if (whizzies[id] == params.field) {
detach(id);
}
}
}
else {
for (var id in whizzies) {
detach(id);
}
}
};
<?php
// $Id$
/**
* Plugin implementation of hook_editor().
*/
function wysiwyg_whizzywig_editor() {
$editor = array();
$editor['whizzywig'] = array(
'title' => 'Whizzywig',
'vendor url' => 'http://www.unverse.net',
'download url' => 'http://www.unverse.net/whizzywig-download.html',
'library path' => wysiwyg_get_path('whizzywig'),
'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'),
),
),
);
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 = wysiwyg_get_path('whizzywig') . '/whizzywig.js';
$script = fopen($script, 'r');
$line = fgets($script, 43);
if (preg_match('@Whizzywig v([0-9]+)@', $line, $version)) {
fclose($script);
return $version[1];
}
}
/**
* 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(wysiwyg_get_path('whizzywig') . '/btn')) {
$settings['buttonPath'] = wysiwyg_get_path('whizzywig', TRUE) . '/btn/';
}
// Add configured buttons or all available.
if (!empty($config['buttons'])) {
$buttons = array();
foreach ($config['buttons'] as $plugin) {
$buttons = array_merge($buttons, $plugin);
}
$settings['buttons'] = implode(' ', array_keys($buttons));
}
else {
$settings['buttons'] = 'all';
}
// 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 Whizzywig; 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,
),
);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment