diff --git a/misc/form.js b/misc/form.js index 8631ed68c81b3be762f3085777deb0e99c26d820..fd34cd103340eba0566b72e1c86a5c8c42188998 100644 --- a/misc/form.js +++ b/misc/form.js @@ -12,4 +12,23 @@ Drupal.behaviors.multiselectSelector = { } }; + +/** + * Automatically displays the guidelines of the selected text format. + */ +Drupal.behaviors.filterGuidelines = { + attach: function(context) { + $('.filter-guidelines:not(.filterGuidelines-processed)', context) + .addClass('filterGuidelines-processed') + .find('label').hide() + .parents('.filter-wrapper').find('select.filter-list') + .bind('change', function() { + $(this).parents('.filter-wrapper') + .find('.filter-guidelines-item').hide() + .siblings('#filter-guidelines-' + this.value).show(); + }) + .change(); + } +}; + })(jQuery); diff --git a/modules/filter/filter.module b/modules/filter/filter.module index a98423418bd542a1c686a0eb57597efe2b0aed7e..5c34b29710af3c5d967199074d24dd0df5e5809b 100644 --- a/modules/filter/filter.module +++ b/modules/filter/filter.module @@ -60,6 +60,9 @@ function filter_theme() { 'filter_tips_more_info' => array( 'arguments' => array(), ), + 'filter_guidelines' => array( + 'arguments' => array('format' => NULL), + ), ); } @@ -481,58 +484,43 @@ function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $langcode = '', $c function filter_form($value = FILTER_FORMAT_DEFAULT, $weight = NULL, $parents = array('format')) { $value = filter_resolve_format($value); $formats = filter_formats(); - - $extra = theme('filter_tips_more_info'); - + + $form = array( + '#type' => 'fieldset', + '#weight' => $weight, + '#attributes' => array('class' => 'filter-wrapper'), + ); + + $element_id = form_clean_id('edit-' . implode('-', $parents)); + if (count($formats) > 1) { - $form = array( - '#type' => 'fieldset', - '#title' => t('Text format'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#weight' => $weight, - '#element_validate' => array('filter_form_validate'), - ); - // Multiple formats available: display radio buttons with tips. foreach ($formats as $format) { - // Generate the parents as the autogenerator does, so we will have a - // unique id for each radio button. - $parents_for_id = array_merge($parents, array($format->format)); - $form[$format->format] = array( - '#type' => 'radio', - '#title' => $format->name, - '#default_value' => $value, - '#return_value' => $format->format, - '#parents' => $parents, - '#description' => theme('filter_tips', _filter_tips($format->format, FALSE)), - '#id' => form_clean_id('edit-' . implode('-', $parents_for_id)), - ); + $options[$format->format] = $format->name; + $guidelines[$format->format] = array('#markup' => theme('filter_guidelines', $format)); } + drupal_add_js('misc/form.js'); + $form['format'] = array( + '#type' => 'select', + '#title' => t('Text format'), + '#options' => $options, + '#default_value' => $value, + '#parents' => $parents, + '#id' => $element_id, + '#attributes' => array('class' => 'filter-list'), + ); } else { - // Only one format available: use a hidden form item and only show tips. + // Only one format available: use a form value and only show label. $format = array_shift($formats); + unset($format->name); + $guidelines = array('#markup' => theme('filter_guidelines', $format)); $form[$format->format] = array('#type' => 'value', '#value' => $format->format, '#parents' => $parents); - $tips = _filter_tips(variable_get('filter_default_format', 1), FALSE); - $form['format']['guidelines'] = array( - '#title' => t('Formatting guidelines'), - '#markup' => theme('filter_tips', $tips, FALSE), - ); } - $form[] = array('#markup' => $extra); + $form['format_help'] = array('#markup' => '
' . l(t('More information about formatting options'), 'filter/tips') . '
'; + return '' . l(t('More information about text formats'), 'filter/tips') . '
'; +} + +/** + * Format guidelines for a text format. + * + * @ingroup themeable + */ +function theme_filter_guidelines($format) { + $name = isset($format->name) ? '' : NULL; + return '