- Patch #1229442 by bleen18, amateescu, chrispomeroy, jessebeach: convert poll tpls and markup to HTML5.

8.0.x
Dries 2012-01-29 16:47:33 -05:00
parent 64e79ac197
commit cfab9bc488
12 changed files with 85 additions and 145 deletions

View File

@ -6753,6 +6753,9 @@ function drupal_common_theme() {
'table' => array(
'variables' => array('header' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => TRUE, 'empty' => ''),
),
'meter' => array(
'variables' => array('display_value' => NULL, 'form' => NULL, 'high' => NULL, 'low' => NULL, 'max' => NULL, 'min' => NULL, 'optimum' => NULL, 'value' => NULL, 'percentage' => NULL, 'attributes' => array()),
),
'tablesort_indicator' => array(
'variables' => array('style' => NULL),
),

View File

@ -2142,6 +2142,49 @@ function theme_progress_bar($variables) {
return $output;
}
/**
* Returns HTML for a meter.
*
* @param $variables
* An associative array containing:
* - display_value: The textual representation of the meter bar.
* - form: A string specifying one or more forms to which the <meter> element
* belongs separated by spaces.
* - high: A number specifying the range that is considered to be a high
* value.
* - low: A number specifying the range that is considered to be a low value.
* - max: A number specifying the maximum value of the range.
* - min: A number specifying the minimum value of the range.
* - optimum: A number specifying what value is the optimal value for the
* gauge.
* - value: A number specifying the current value of the gauge.
* - percentage: A number specifying the current percentage of the gauge.
* - attributes: Associative array of attributes to be placed in the meter
* tag.
*/
function theme_meter($variables) {
$attributes = $variables['attributes'];
foreach (array('form', 'high', 'low', 'max', 'min', 'optimum', 'value') as $attribute) {
if (!empty($variables[$attribute])) {
// This function was initially designed for the <meter> tag, but due to
// the lack of browser and styling support for it, we're currently using
// it's attributes as HTML5 data attributes.
$attributes['data-' . $attribute] = $variables[$attribute];
}
}
$output = '<div' . drupal_attributes($attributes) . '>';
$output .= ' <div style="width: '. $variables['percentage'] .'%;" class="foreground"></div>';
$output .= "</div>\n";
if (!empty($variables['display_value'])) {
$output .= '<div class="percent">' . $variables['display_value'] . '</div>';
}
return $output;
}
/**
* Returns HTML for an indentation div; used for drag and drop tables.
*

View File

@ -1,26 +0,0 @@
<?php
/**
* @file
* Default theme implementation to display the bar for a single choice in a
* poll.
*
* Variables available:
* - $title: The title of the poll.
* - $votes: The number of votes for this choice
* - $total_votes: The number of votes for this choice
* - $percentage: The percentage of votes for this choice.
* - $vote: The choice number of the current user's vote.
* - $voted: Set to TRUE if the user voted for this choice.
*
* @see template_preprocess_poll_bar()
*/
?>
<div class="text"><?php print $title; ?></div>
<div class="bar">
<div style="width: <?php print $percentage; ?>%;" class="foreground"></div>
</div>
<div class="percent">
<?php print $percentage; ?>%
</div>

View File

@ -1,26 +0,0 @@
<?php
/**
* @file
* Default theme implementation to display the bar for a single choice in a
* poll.
*
* Variables available:
* - $title: The title of the poll.
* - $votes: The number of votes for this choice
* - $total_votes: The number of votes for this choice
* - $percentage: The percentage of votes for this choice.
* - $vote: The choice number of the current user's vote.
* - $voted: Set to TRUE if the user voted for this choice.
*
* @see template_preprocess_poll_bar()
*/
?>
<div class="text"><?php print $title; ?></div>
<div class="bar">
<div style="width: <?php print $percentage; ?>%;" class="foreground"></div>
</div>
<div class="percent">
<?php print $percentage; ?>% (<?php print format_plural($votes, '1 vote', '@count votes'); ?>)
</div>

View File

@ -1,28 +0,0 @@
<?php
/**
* @file
* Default theme implementation to display the poll results in a block.
*
* Variables available:
* - $title: The title of the poll.
* - $results: The results of the poll.
* - $votes: The total results in the poll.
* - $links: Links in the poll.
* - $nid: The nid of the poll
* - $cancel_form: A form to cancel the user's vote, if allowed.
* - $raw_links: The raw array of links. Should be run through theme('links')
* if used.
* - $vote: The choice number of the current user's vote.
*
* @see template_preprocess_poll_results()
*/
?>
<div class="poll">
<div class="title"><?php print $title ?></div>
<?php print $results ?>
<div class="total">
<?php print t('Total votes: @votes', array('@votes' => $votes)); ?>
</div>
</div>
<div class="links"><?php print $links; ?></div>

View File

@ -17,7 +17,10 @@
* @see template_preprocess_poll_results()
*/
?>
<div class="poll">
<article class="poll">
<?php if ($block): ?>
<h3 class="poll-title"><?php print $title; ?></h3>
<?php endif; ?>
<?php print $results; ?>
<div class="total">
<?php print t('Total votes: @votes', array('@votes' => $votes)); ?>
@ -25,4 +28,7 @@
<?php if (!empty($cancel_form)): ?>
<?php print $cancel_form; ?>
<?php endif; ?>
</div>
</article>
<?php if ($block): ?>
<div class="links"><?php print $links; ?></div>
<?php endif; ?>

View File

@ -5,6 +5,6 @@
.poll .percent {
text-align: left;
}
.poll .vote-form .choices {
.poll .vote-form {
text-align: right;
}

View File

@ -14,16 +14,16 @@
* @see template_preprocess_poll_vote()
*/
?>
<div class="poll">
<article class="poll">
<div class="vote-form">
<div class="choices">
<?php if ($block): ?>
<div class="title"><?php print $title; ?></div>
<?php endif; ?>
<?php print $choice; ?>
</div>
<?php if ($block): ?>
<h3 class="poll-title"><?php print $title; ?></h3>
<?php endif; ?>
<?php print $choice; ?>
<?php print $vote; ?>
</div>
<?php // This is the 'rest' of the form, in case items have been added. ?>
<?php print $rest ?>
</div>
</article>

View File

@ -24,12 +24,10 @@
.poll .vote-form {
text-align: center;
}
.poll .vote-form .choices {
.poll .vote-form {
text-align: left; /* LTR */
margin: 0 auto;
display: table;
}
.poll .vote-form .choices .title {
.poll .vote-form .poll-title {
font-weight: bold;
}
.node-form #edit-poll-more {

View File

@ -42,25 +42,8 @@ function poll_theme() {
'template' => 'poll-results',
'variables' => array('raw_title' => NULL, 'results' => NULL, 'votes' => NULL, 'raw_links' => NULL, 'block' => NULL, 'nid' => NULL, 'vote' => NULL),
),
'poll_bar' => array(
'template' => 'poll-bar',
'variables' => array('title' => NULL, 'votes' => NULL, 'total_votes' => NULL, 'vote' => NULL, 'block' => NULL),
),
);
// The theme system automatically discovers the theme's functions and
// templates that implement more targeted "suggestions" of generic theme
// hooks. But suggestions implemented by a module must be explicitly
// registered.
$theme_hooks += array(
'poll_results__block' => array(
'template' => 'poll-results--block',
'variables' => $theme_hooks['poll_results']['variables'],
),
'poll_bar__block' => array(
'template' => 'poll-bar--block',
'variables' => $theme_hooks['poll_bar']['variables'],
),
);
return $theme_hooks;
}
@ -832,15 +815,25 @@ function poll_view_results($node, $view_mode, $block = FALSE) {
}
}
$poll_results = '';
$poll_results = array();
foreach ($node->choice as $i => $choice) {
if (!empty($choice['chtext'])) {
$chvotes = isset($choice['chvotes']) ? $choice['chvotes'] : NULL;
$poll_results .= theme('poll_bar', array('title' => $choice['chtext'], 'votes' => $chvotes, 'total_votes' => $total_votes, 'vote' => isset($node->vote) && $node->vote == $i, 'block' => $block));
}
$chvotes = isset($choice['chvotes']) ? $choice['chvotes'] : NULL;
$percentage = round($chvotes * 100 / max($total_votes, 1));
$display_votes = !$block ? ' (' . format_plural($chvotes, '1 vote', '@count votes') . ')' : '';
$poll_results[] = array(
'#theme' => 'meter',
'#prefix' => '<div class="choice-title">' . check_plain($choice['chtext']) . '</div>',
'#display_value' => t('!percentage%', array('!percentage' => $percentage)) . $display_votes,
'#min' => 0,
'#max' => $total_votes,
'#value' => $chvotes,
'#percentage' => $percentage,
'#attributes' => array('class' => 'bar'),
);
}
return theme('poll_results', array('raw_title' => $node->title, 'results' => $poll_results, 'votes' => $total_votes, 'raw_links' => isset($node->links) ? $node->links : array(), 'block' => $block, 'nid' => $node->nid, 'vote' => isset($node->vote) ? $node->vote : NULL));
return theme('poll_results', array('raw_title' => $node->title, 'results' => drupal_render($poll_results), 'votes' => $total_votes, 'raw_links' => isset($node->links) ? $node->links : array(), 'block' => $block, 'nid' => $node->nid, 'vote' => isset($node->vote) ? $node->vote : NULL));
}
@ -917,27 +910,6 @@ function template_preprocess_poll_results(&$variables) {
$variables['cancel_form'] = drupal_render($elements);
}
$variables['title'] = check_plain($variables['raw_title']);
if ($variables['block']) {
$variables['theme_hook_suggestions'][] = 'poll_results__block';
}
}
/**
* Preprocess the poll_bar theme hook.
*
* Inputs: $title, $votes, $total_votes, $voted, $block
*
* @see poll-bar.tpl.php
* @see poll-bar--block.tpl.php
* @see theme_poll_bar()
*/
function template_preprocess_poll_bar(&$variables) {
if ($variables['block']) {
$variables['theme_hook_suggestions'][] = 'poll_bar__block';
}
$variables['title'] = check_plain($variables['title']);
$variables['percentage'] = round($variables['votes'] * 100 / max($variables['total_votes'], 1));
}
/**

View File

@ -228,10 +228,10 @@ class PollCreateTestCase extends PollTestCase {
$this->clickLink($title);
$this->assertText($new_option, 'New option found.');
$option = $this->xpath('//div[@id="node-1"]//div[@class="poll"]//div[@class="text"]');
$option = $this->xpath('//div[@id="node-1"]//article[@class="poll"]//div[@class="choice-title"]');
$this->assertEqual(end($option), $new_option, 'Last item is equal to new option.');
$votes = $this->xpath('//div[@id="node-1"]//div[@class="poll"]//div[@class="percent"]');
$votes = $this->xpath('//div[@id="node-1"]//article[@class="poll"]//div[@class="percent"]');
$this->assertTrue(strpos(end($votes), $vote_count) > 0, t("Votes saved."));
}

View File

@ -1584,8 +1584,6 @@ div.admin-panel .description {
}
.poll .vote-form {
text-align: left; /* LTR */
}
.poll .vote-form .choices {
margin: 0;
}
.poll .percent {
@ -1596,7 +1594,7 @@ div.admin-panel .description {
float: right;
text-align: right;
}
.poll .text {
.poll .choice-title {
clear: right;
margin-right: 2.25em;
}