diff --git a/core/includes/common.inc b/core/includes/common.inc index e2c8784e7d989d7bbeeffb23f81d8c4e744d990b..a4c445f5e77431063b6e451817b228eb845775ec 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -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), ), diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 40c4f35c4a938b45e848ff7e86ab061e7ef1a423..de695a46ba1ddad105e2bcde3e894823bfd9dc2f 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -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. * diff --git a/core/modules/poll/poll-bar--block.tpl.php b/core/modules/poll/poll-bar--block.tpl.php deleted file mode 100644 index 3b91afc3a0523d68410dcde65a22f32d0c27f116..0000000000000000000000000000000000000000 --- a/core/modules/poll/poll-bar--block.tpl.php +++ /dev/null @@ -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> diff --git a/core/modules/poll/poll-bar.tpl.php b/core/modules/poll/poll-bar.tpl.php deleted file mode 100644 index 9426ff59f2a6c34ce32f3aa9c921dcdad1b7f897..0000000000000000000000000000000000000000 --- a/core/modules/poll/poll-bar.tpl.php +++ /dev/null @@ -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> diff --git a/core/modules/poll/poll-results--block.tpl.php b/core/modules/poll/poll-results--block.tpl.php deleted file mode 100644 index f8387f5657c8da38b36a67d77cc6a91f296aaa3a..0000000000000000000000000000000000000000 --- a/core/modules/poll/poll-results--block.tpl.php +++ /dev/null @@ -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> diff --git a/core/modules/poll/poll-results.tpl.php b/core/modules/poll/poll-results.tpl.php index 5e14dec21e420dcb793265cbedbeed8c1f1c05f4..bb4cee38292c66d5dacf08dfec039783d40668f3 100644 --- a/core/modules/poll/poll-results.tpl.php +++ b/core/modules/poll/poll-results.tpl.php @@ -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; ?> diff --git a/core/modules/poll/poll-rtl.css b/core/modules/poll/poll-rtl.css index 14d42e691a76b042041fc34176f2fa5016cc2bf8..1d215d7d62911a996feabd92c02df81b7485868c 100644 --- a/core/modules/poll/poll-rtl.css +++ b/core/modules/poll/poll-rtl.css @@ -5,6 +5,6 @@ .poll .percent { text-align: left; } -.poll .vote-form .choices { +.poll .vote-form { text-align: right; } diff --git a/core/modules/poll/poll-vote.tpl.php b/core/modules/poll/poll-vote.tpl.php index 068ff7c05352210aea674e53d60b96e14f82c151..a749f918366d3e78ff6be71ebe075d22d7b476e9 100644 --- a/core/modules/poll/poll-vote.tpl.php +++ b/core/modules/poll/poll-vote.tpl.php @@ -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> diff --git a/core/modules/poll/poll.css b/core/modules/poll/poll.css index 8b04e380911ebcf33a71adc96b63741bf20cf504..6abcaf5a1e84e64b09ea5a26c93a1df370e5b567 100644 --- a/core/modules/poll/poll.css +++ b/core/modules/poll/poll.css @@ -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 { diff --git a/core/modules/poll/poll.module b/core/modules/poll/poll.module index 40a481a5825ec412f939d50acddc8a456c7bac5d..886230860e154e7aa0c582188c9a96ab7794fc19 100644 --- a/core/modules/poll/poll.module +++ b/core/modules/poll/poll.module @@ -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)); } /** diff --git a/core/modules/poll/poll.test b/core/modules/poll/poll.test index 3fad677feba7b5097698e964e6c56e56fd8a19fb..78af995c56cbf469d763ec5a6911de78ac3ab771 100644 --- a/core/modules/poll/poll.test +++ b/core/modules/poll/poll.test @@ -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.")); } diff --git a/core/themes/bartik/css/style.css b/core/themes/bartik/css/style.css index cafd744579f906e62f64b2452d6b61323dd19849..25a29edbd0eefb979345c99fe84c38b8c349d5b1 100644 --- a/core/themes/bartik/css/style.css +++ b/core/themes/bartik/css/style.css @@ -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; }