#304330 follow-up by sun: Clean-up of text format widget patch.

merge-requests/26/head
Angie Byron 2009-03-30 03:15:41 +00:00
parent 2feffc2d61
commit 28aaa036e4
7 changed files with 114 additions and 74 deletions

View File

@ -3717,6 +3717,9 @@ function drupal_common_theme() {
'form_element' => array(
'arguments' => array('element' => NULL),
),
'text_format_wrapper' => array(
'arguments' => array('element' => NULL),
),
);
}

View File

@ -1927,19 +1927,45 @@ function form_process_text_format($element) {
// We need to break references, otherwise form_builder recurses infinitely.
$element['value'] = (array)$element;
$element['value']['#weight'] = 0;
unset($element['value']['#description']);
$element['#type'] = 'markup';
$element['#theme'] = NULL;
$element['#theme_wrapper'] = NULL;
$element['#theme_wrapper'] = 'text_format_wrapper';
$element['format'] = filter_form($element['#text_format'], 1, $element_parents);
// We need to clear the #text_format from the new child otherwise we
// would get into an infinite loop.
unset($element['value']['#text_format']);
$element['value']['#weight'] = 0;
}
return $element;
}
/**
* Return a themed text format form element.
*
* @param element
* An associative array containing the properties of the element.
* Properties used: children, description
* @return
* A string representing the form element.
*
* @ingroup themeable
*/
function theme_text_format_wrapper($element) {
$output = '<div class="text-format-wrapper">' . "\n";
$output .= $element['#children'] . "\n";
if (!empty($element['#description'])) {
$output .= '<div class="description">' . $element['#description'] . "</div>\n";
}
$output .= "</div>\n";
return $output;
}
/**
* Add AHAH information about a form element to the page to communicate with
* javascript. If #ahah[path] is set on an element, this additional javascript is

View File

@ -14,18 +14,18 @@ Drupal.behaviors.multiselectSelector = {
/**
* Automatically displays the guidelines of the selected text format.
* Automatically display the guidelines of the selected text format.
*/
Drupal.behaviors.filterGuidelines = {
attach: function(context) {
$('.filter-guidelines:not(.filterGuidelines-processed)', context)
.addClass('filterGuidelines-processed')
$('.filter-guidelines:not(.filter-guidelines-processed)', context)
.addClass('filter-guidelines-processed')
.find('label').hide()
.parents('.filter-wrapper').find('select.filter-list')
.bind('change', function() {
.bind('change', function () {
$(this).parents('.filter-wrapper')
.find('.filter-guidelines-item').hide()
.siblings('#filter-guidelines-' + this.value).show();
.find('.filter-guidelines-item').hide()
.siblings('#filter-guidelines-' + this.value).show();
})
.change();
}

37
modules/filter/filter.css Normal file
View File

@ -0,0 +1,37 @@
/* $Id$ */
.text-format-wrapper .form-item {
margin-bottom: 0;
}
.filter-wrapper {
border-top: 0;
width: 95%;
margin: 0;
padding: 1.5em 0 1.5em;
}
.filter-wrapper .form-item {
float: left;
margin: 0;
padding: 0 0 0.5em 1.5em;
}
.filter-wrapper .form-item label {
display: inline;
}
.filter-help {
float: right;
padding: 0 1.5em 0.5em;
}
.filter-help p {
margin: 0;
}
.filter-help a {
background: transparent url(../../misc/help.png) right center no-repeat;
padding-right: 20px;
}
.filter-guidelines {
clear: left;
padding: 0 1.5em;
}
.text-format-wrapper .description {
margin-top: 0.5em;
}

View File

@ -484,40 +484,44 @@ 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();
$form = array(
'#type' => 'fieldset',
'#weight' => $weight,
'#attributes' => array('class' => 'filter-wrapper'),
);
drupal_add_js('misc/form.js');
drupal_add_css(drupal_get_path('module', 'filter') . '/filter.css');
$element_id = form_clean_id('edit-' . implode('-', $parents));
if (count($formats) > 1) {
foreach ($formats as $format) {
$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'),
$form = array(
'#type' => 'fieldset',
'#weight' => $weight,
'#attributes' => array('class' => 'filter-wrapper'),
);
$form['format_guidelines'] = array(
'#prefix' => '<div id="' . $element_id . '-guidelines" class="filter-guidelines">',
'#suffix' => '</div>',
'#weight' => 2,
);
foreach ($formats as $format) {
$options[$format->format] = $format->name;
$form['format_guidelines'][$format->format] = array(
'#markup' => theme('filter_guidelines', $format),
);
}
else {
// 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);
}
$form['format_help'] = array('#markup' => '<div id="' . $element_id . '-help" class="filter-help">' . theme('filter_tips_more_info') . '</div>');
$form['format_guidelines'] = array_merge($guidelines, array('#prefix' => '<div id="' . $element_id . '-guidelines" class="filter-guidelines">', '#suffix' => '</div>'));
$form['format'] = array(
'#type' => 'select',
'#title' => t('Text format'),
'#options' => $options,
'#default_value' => $value,
'#parents' => $parents,
'#access' => count($formats) > 1,
'#id' => $element_id,
'#attributes' => array('class' => 'filter-list'),
);
$form['format_help'] = array(
'#prefix' => '<div id="' . $element_id . '-help" class="filter-help">',
'#markup' => theme('filter_tips_more_info'),
'#suffix' => '</div>',
'#weight' => 1,
);
return $form;
}
@ -583,7 +587,7 @@ function theme_filter_tips_more_info() {
* @ingroup themeable
*/
function theme_filter_guidelines($format) {
$name = isset($format->name) ? '<label>' . $format->name . ':</label>' : NULL;
$name = isset($format->name) ? '<label>' . $format->name . ':</label>' : '';
return '<div id="filter-guidelines-' . $format->format . '" class="filter-guidelines-item">' . $name . theme('filter_tips', _filter_tips($format->format, FALSE)) . '</div>';
}

View File

@ -42,38 +42,4 @@ td.revision-current {
.terms-inline {
display: inline;
}
.filter-label {
font-weight: bold;
}
.filter-wrapper {
border-top: 0;
width: 95%;
padding: 0;
margin-top: -1em;
float: left; /* Required by IE6 to respect negative margins */
}
.filter-guidelines {
clear: left;
margin: 1.5em;
}
.filter-wrapper .form-item {
float: left;
line-height: 3em;
margin: 0 0 0 1.5em;
}
.filter-wrapper .form-item label {
display: inline;
}
.filter-help {
float: right;
margin-right: 1em;
}
.filter-help a {
background: url(../../misc/help.png) right center no-repeat;
padding-right: 20px;
}
html.js fieldset.collapsible {
clear: left; /* Test fix for Safari issues caused by IE6 fix above, need to test impact elsewhere and move to appropriate CSS file */
}

View File

@ -822,6 +822,10 @@ fieldset {
background-position: 0 .75em;
background-color: transparent;
}
*:first-child+html .text-format-wrapper .filter-wrapper {
padding: 1.5em 0 1.5em;
background-position: 0 0;
}
*:first-child+html fieldset > .description, *:first-child+html fieldset .fieldset-wrapper .description {
padding-top: 1em;