summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsun2010-03-20 14:54:29 (GMT)
committer sun2010-03-20 14:54:29 (GMT)
commitfe2b726fe9f1a11a65a9c667666a022dd5b3fd68 (patch)
tree96961f2d76eb00e94e0d93767fdd6391e1cc2a9e
parentd1a1511bcaeeae0627004f87ef4073ca99e96bfc (diff)
#739558 by sun, TwoD: Updated for new #type text_format.
-rw-r--r--CHANGELOG.txt1
-rw-r--r--editors/js/none.js11
-rw-r--r--wysiwyg.module176
3 files changed, 90 insertions, 98 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index b8f47e5..8769aba 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -6,6 +6,7 @@ Wysiwyg x.x-x.x, xxxx-xx-xx
Wysiwyg 7.x-3.x, xxxx-xx-xx
---------------------------
+#739558 by sun, TwoD: Updated for new #type text_format.
#612954 by TwoD: Fixed broken editor settings.
#585932 by sun: Ported to Drupal 7.
diff --git a/editors/js/none.js b/editors/js/none.js
index 003ca8d..874e37a 100644
--- a/editors/js/none.js
+++ b/editors/js/none.js
@@ -16,8 +16,8 @@
*/
Drupal.wysiwyg.editor.attach.none = function(context, params, settings) {
if (params.resizable) {
- $('#' + params.field).addClass('resizable');
- $('#' + params.field).css({display: ''});
+ var $wrapper = $('#' + params.field).parents('.form-textarea-wrapper:first');
+ $wrapper.addClass('resizable');
if (Drupal.behaviors.textarea.attach) {
Drupal.behaviors.textarea.attach();
}
@@ -37,10 +37,9 @@ Drupal.wysiwyg.editor.attach.none = function(context, params, settings) {
*/
Drupal.wysiwyg.editor.detach.none = function(context, params) {
if (typeof params != 'undefined') {
- var $textarea = $('#' + params.field, context).removeOnce('textarea');
- var $div = $textarea.parents('div.resizable-textarea');
- $div.before($textarea);
- $div.remove();
+ var $wrapper = $('#' + params.field).parents('.form-textarea-wrapper:first');
+ $wrapper.removeOnce('textarea').removeClass('.resizable-textarea')
+ .find('.grippie').remove();
}
};
diff --git a/wysiwyg.module b/wysiwyg.module
index 572e036..25dd013 100644
--- a/wysiwyg.module
+++ b/wysiwyg.module
@@ -88,17 +88,8 @@ function wysiwyg_help($path, $arg) {
/**
* Implementation of hook_form_alter().
- *
- * Before Drupal 7, there is no way to easily identify form fields that are
- * input format enabled. As a workaround, we assign a form #after_build
- * processing callback that is executed on all forms after they have been
- * completely built, so form elements are in their effective order
- * and position already.
- *
- * @see wysiwyg_process_form()
*/
function wysiwyg_form_alter(&$form, &$form_state) {
- $form['#after_build'][] = 'wysiwyg_process_form';
// Teaser splitter is unconditionally removed and NOT supported.
if (isset($form['body_field'])) {
unset($form['body_field']['teaser_js']);
@@ -106,97 +97,98 @@ function wysiwyg_form_alter(&$form, &$form_state) {
}
/**
- * Process a form to attach wysiwyg editors.
- *
- * Recurse into the form and if an text format-enabled element is found, use its
- * #id for attaching client-side editors.
+ * Implements hook_element_info_alter().
+ */
+function wysiwyg_element_info_alter(&$types) {
+ $types['text_format']['#pre_render'][] = 'wysiwyg_pre_render_text_format';
+}
+
+/**
+ * Process a text format widget to load and attach editors.
*
- * @see form_process_text_format()
+ * The element's #id is used as reference to attach client-side editors.
*/
-function wysiwyg_process_form(&$form) {
- foreach (element_children($form) as $item) {
- // filter_form() always uses the key 'format'.
- if (isset($form[$item]['#text_format'])) {
- $element = &$form[$item]['format'];
- $field = &$form[$item]['value'];
- $settings = array(
- 'field' => $field['#id'],
- );
+function wysiwyg_pre_render_text_format($element) {
+ // filter_process_format() copies properties to the expanded 'value' child
+ // element.
+ if (!isset($element['format'])) {
+ return $element;
+ }
- // If this textarea is #resizable and we will load at least one
- // editor, then only load the behavior and let the 'none' editor
- // attach/detach it to avoid hi-jacking the UI. Due to our CSS class
- // parsing, we can add arbitrary parameters for each input format.
- // The #resizable property will be removed below, if at least one
- // profile has been loaded.
- $resizable = 0;
- if (!empty($field['#resizable'])) {
- $resizable = 1;
- drupal_add_js('misc/textarea.js');
- }
- // Determine the available input formats.
- foreach ($element['format']['#options'] as $format_id => $format_name) {
- $format = 'format' . $format_id;
- // Initialize default settings, defaulting to 'none' editor.
- $settings[$format]['editor'] = 'none';
- $settings[$format]['status'] = 1;
- $settings[$format]['toggle'] = 1;
- $settings[$format]['resizable'] = $resizable;
- // Fetch the profile associated to this text format.
- $profile = wysiwyg_get_profile($format_id);
- if ($profile) {
- $loaded = TRUE;
- $settings[$format]['editor'] = $profile->editor;
- $settings[$format]['status'] = (int) wysiwyg_user_get_status($profile);
- if (isset($profile->settings['show_toggle'])) {
- $settings[$format]['toggle'] = (int) $profile->settings['show_toggle'];
- }
- // Check editor theme (and reset it if not/no longer available).
- $theme = wysiwyg_get_editor_themes($profile, (isset($profile->settings['theme']) ? $profile->settings['theme'] : ''));
-
- // Add plugin settings (first) for this text format.
- wysiwyg_add_plugin_settings($profile);
- // Add profile settings for this text format.
- wysiwyg_add_editor_settings($profile, $theme);
-
- }
- }
- // Use a prefix/suffix for a single text format, or attach to text
- // format selector radio buttons.
- if (!$element['format']['#access']) {
- $element['format_guidelines']['format'] = array(
- '#type' => 'hidden',
- '#name' => $element['format']['#name'],
- '#id' => $element['format']['#id'],
- '#value' => $format_id,
- '#attributes' => array('class' => array('wysiwyg')),
- );
- $element['format_guidelines']['#attached']['js'][] = array(
- 'data' => array('wysiwyg' => array('triggers' => array($element['format']['#id'] => $settings))),
- 'type' => 'setting',
- );
- }
- else {
- $element['format']['#attributes']['class'][] = 'wysiwyg';
- $element['format']['#attached']['js'][] = array(
- 'data' => array('wysiwyg' => array('triggers' => array($element['format']['#id'] => $settings))),
- 'type' => 'setting',
- );
- }
+ $format_field = &$element['format'];
+ $field = &$element['value'];
+ $settings = array(
+ 'field' => $field['#id'],
+ );
- // If we loaded at least one editor, then the 'none' editor will
- // handle resizable textareas instead of core.
- if (isset($loaded) && $resizable) {
- $field['#resizable'] = FALSE;
+ // If this textarea is #resizable and we will load at least one
+ // editor, then only load the behavior and let the 'none' editor
+ // attach/detach it to avoid hi-jacking the UI. Due to our CSS class
+ // parsing, we can add arbitrary parameters for each input format.
+ // The #resizable property will be removed below, if at least one
+ // profile has been loaded.
+ $resizable = 0;
+ if (!empty($field['#resizable'])) {
+ $resizable = 1;
+ drupal_add_js('misc/textarea.js');
+ }
+ // Determine the available text formats.
+ foreach ($format_field['format']['#options'] as $format_id => $format_name) {
+ $format = 'format' . $format_id;
+ // Initialize default settings, defaulting to 'none' editor.
+ $settings[$format]['editor'] = 'none';
+ $settings[$format]['status'] = 1;
+ $settings[$format]['toggle'] = 1;
+ $settings[$format]['resizable'] = $resizable;
+
+ // Fetch the profile associated to this text format.
+ $profile = wysiwyg_get_profile($format_id);
+ if ($profile) {
+ $loaded = TRUE;
+ $settings[$format]['editor'] = $profile->editor;
+ $settings[$format]['status'] = (int) wysiwyg_user_get_status($profile);
+ if (isset($profile->settings['show_toggle'])) {
+ $settings[$format]['toggle'] = (int) $profile->settings['show_toggle'];
}
+ // Check editor theme (and reset it if not/no longer available).
+ $theme = wysiwyg_get_editor_themes($profile, (isset($profile->settings['theme']) ? $profile->settings['theme'] : ''));
- // If this element has '#text_format', do not recurse further.
- continue;
+ // Add plugin settings (first) for this text format.
+ wysiwyg_add_plugin_settings($profile);
+ // Add profile settings for this text format.
+ wysiwyg_add_editor_settings($profile, $theme);
}
- // Recurse into children.
- wysiwyg_process_form($form[$item]);
}
- return $form;
+ // Use a hidden element for a single text format.
+ if (!$format_field['format']['#access']) {
+ $format_field['guidelines']['format'] = array(
+ '#type' => 'hidden',
+ '#name' => $format_field['format']['#name'],
+ '#id' => $format_field['format']['#id'],
+ '#value' => $format_id,
+ '#attributes' => array('class' => array('wysiwyg')),
+ );
+ $format_field['guidelines']['format']['#attached']['js'][] = array(
+ 'data' => array('wysiwyg' => array('triggers' => array($format_field['format']['#id'] => $settings))),
+ 'type' => 'setting',
+ );
+ }
+ // Otherwise, attach to text format selector.
+ else {
+ $format_field['format']['#attributes']['class'][] = 'wysiwyg';
+ $format_field['format']['#attached']['js'][] = array(
+ 'data' => array('wysiwyg' => array('triggers' => array($format_field['format']['#id'] => $settings))),
+ 'type' => 'setting',
+ );
+ }
+
+ // If we loaded at least one editor, then the 'none' editor will
+ // handle resizable textareas instead of core.
+ if (isset($loaded) && $resizable) {
+ $field['#resizable'] = FALSE;
+ }
+
+ return $element;
}
/**