From cfab9bc488b48f785e265199b5ca527988958f1b Mon Sep 17 00:00:00 2001 From: Dries Date: Sun, 29 Jan 2012 16:47:33 -0500 Subject: [PATCH] - Patch #1229442 by bleen18, amateescu, chrispomeroy, jessebeach: convert poll tpls and markup to HTML5. --- core/includes/common.inc | 3 + core/includes/theme.inc | 43 +++++++++++++ core/modules/poll/poll-bar--block.tpl.php | 26 -------- core/modules/poll/poll-bar.tpl.php | 26 -------- core/modules/poll/poll-results--block.tpl.php | 28 --------- core/modules/poll/poll-results.tpl.php | 10 ++- core/modules/poll/poll-rtl.css | 2 +- core/modules/poll/poll-vote.tpl.php | 16 ++--- core/modules/poll/poll.css | 6 +- core/modules/poll/poll.module | 62 +++++-------------- core/modules/poll/poll.test | 4 +- core/themes/bartik/css/style.css | 4 +- 12 files changed, 85 insertions(+), 145 deletions(-) delete mode 100644 core/modules/poll/poll-bar--block.tpl.php delete mode 100644 core/modules/poll/poll-bar.tpl.php delete mode 100644 core/modules/poll/poll-results--block.tpl.php diff --git a/core/includes/common.inc b/core/includes/common.inc index e2c8784e7d9..a4c445f5e77 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 40c4f35c4a9..de695a46ba1 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 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 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 = ''; + $output .= '
'; + $output .= "\n"; + + if (!empty($variables['display_value'])) { + $output .= '
' . $variables['display_value'] . '
'; + } + + 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 3b91afc3a05..00000000000 --- a/core/modules/poll/poll-bar--block.tpl.php +++ /dev/null @@ -1,26 +0,0 @@ - - -
-
-
-
-
- % -
diff --git a/core/modules/poll/poll-bar.tpl.php b/core/modules/poll/poll-bar.tpl.php deleted file mode 100644 index 9426ff59f2a..00000000000 --- a/core/modules/poll/poll-bar.tpl.php +++ /dev/null @@ -1,26 +0,0 @@ - - -
-
-
-
-
- % () -
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 f8387f5657c..00000000000 --- a/core/modules/poll/poll-results--block.tpl.php +++ /dev/null @@ -1,28 +0,0 @@ - - -
-
- -
- $votes)); ?> -
-
- diff --git a/core/modules/poll/poll-results.tpl.php b/core/modules/poll/poll-results.tpl.php index 5e14dec21e4..bb4cee38292 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() */ ?> -
+
+ +

+
$votes)); ?> @@ -25,4 +28,7 @@ -
+
+ + + diff --git a/core/modules/poll/poll-rtl.css b/core/modules/poll/poll-rtl.css index 14d42e691a7..1d215d7d629 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 068ff7c0535..a749f918366 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() */ ?> -
+
-
- -
- - -
+ + +

+ + +
-
+ diff --git a/core/modules/poll/poll.css b/core/modules/poll/poll.css index 8b04e380911..6abcaf5a1e8 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 40a481a5825..886230860e1 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' => '
' . check_plain($choice['chtext']) . '
', + '#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 3fad677feba..78af995c56c 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 cafd744579f..25a29edbd0e 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; }