From f9a6d7cc38d1eb3c27f74dc3c0b427d2b1df99c0 Mon Sep 17 00:00:00 2001
From: M Parker <mparker17@536298.no-reply.drupal.org>
Date: Fri, 20 Jun 2014 16:17:26 -0400
Subject: [PATCH] 2290031-3

---
 facetapi.module    |  4 +++
 facetapi.theme.inc | 95 +++++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 69 insertions(+), 30 deletions(-)

diff --git a/facetapi.module b/facetapi.module
index 58bb566..9a3a7aa 100644
--- a/facetapi.module
+++ b/facetapi.module
@@ -274,6 +274,10 @@ function facetapi_theme() {
       'arguments' => array('text' => NULL),
       'file' => 'facetapi.theme.inc',
     ),
+    'facetapi_activate_widget' => array(
+      'arguments' => array('text' => NULL),
+      'file' => 'facetapi.theme.inc',
+    ),
     'facetapi_accessible_markup' => array(
       'arguments' => array('text' => NULL, 'active' => NULL),
       'file' => 'facetapi.theme.inc',
diff --git a/facetapi.theme.inc b/facetapi.theme.inc
index d392dcb..93af426 100644
--- a/facetapi.theme.inc
+++ b/facetapi.theme.inc
@@ -43,6 +43,16 @@ function theme_facetapi_title($variables) {
  * @ingroup themeable
  */
 function theme_facetapi_link_inactive($variables) {
+  $count = '';
+
+  // Sanitizes the link text if necessary.
+  $sanitize = empty($variables['options']['html']);
+  $variables['text'] = ($sanitize) ? check_plain($variables['text']) : $variables['text'];
+
+  // Wrap the actual term in a span so it wraps correctly (or, rather, so it
+  // doesn't wrap).
+  $term = '<span class="term" aria-hidden="true">' . $variables['text'] . '</span>';
+
   // Builds accessible markup.
   // @see http://drupal.org/node/1316580
   $accessible_vars = array(
@@ -51,18 +61,60 @@ function theme_facetapi_link_inactive($variables) {
   );
   $accessible_markup = theme('facetapi_accessible_markup', $accessible_vars);
 
+  // Adds count to link if one was passed.
+  if (isset($variables['count'])) {
+    $count = theme('facetapi_count', $variables);
+  }
+
+  // Activate widget.
+  $widget = theme('facetapi_activate_widget', $variables);
+
+  // Ensure the spans aren't escaped and render the link.
+  $variables['text'] = $term . $accessible_markup . $count . $widget;
+  $variables['options']['html'] = TRUE;
+  return theme_link($variables);
+}
+
+/**
+ * Returns HTML for an inactive facet item.
+ *
+ * @param $variables
+ *   An associative array containing the keys 'text', 'path', and 'options'. See
+ *   the l() function for information about these variables.
+ *
+ * @see l()
+ *
+ * @ingroup themeable
+ */
+function theme_facetapi_link_active($variables) {
+  $count = '';
+
   // Sanitizes the link text if necessary.
   $sanitize = empty($variables['options']['html']);
   $variables['text'] = ($sanitize) ? check_plain($variables['text']) : $variables['text'];
 
+  // Wrap the actual term in a span so it wraps correctly (or, rather, so it
+  // doesn't wrap).
+  $term = '<span class="term" aria-hidden="true">' . $variables['text'] . '</span>';
+
+  // Builds accessible markup.
+  // @see http://drupal.org/node/1316580
+  $accessible_vars = array(
+    'text' => $variables['text'],
+    'active' => TRUE,
+  );
+  $accessible_markup = theme('facetapi_accessible_markup', $accessible_vars);
+
   // Adds count to link if one was passed.
   if (isset($variables['count'])) {
-    $variables['text'] .= ' ' . theme('facetapi_count', $variables);
+    $count = theme('facetapi_count', $variables);
   }
 
-  // Resets link text, sets to options to HTML since we already sanitized the
-  // link text and are providing additional markup for accessibility.
-  $variables['text'] .= $accessible_markup;
+  // Adds deactivate widget.
+  $widget = theme('facetapi_deactivate_widget', $variables);
+
+  // Ensure the spans aren't escaped and render the link.
+  $variables['text'] = $term . $accessible_markup . $count . $widget;
   $variables['options']['html'] = TRUE;
   return theme_link($variables);
 }
@@ -77,42 +129,24 @@ function theme_facetapi_link_inactive($variables) {
  * @ingroup themeable
  */
 function theme_facetapi_count($variables) {
-  return '(' . (int) $variables['count'] . ')';
+  return '<span class="filter-result-number">(' . (int) $variables['count'] . ')</span>';
 }
 
 /**
- * Returns HTML for an inactive facet item.
+ * Returns HTML for the activation widget.
  *
  * @param $variables
  *   An associative array containing the keys 'text', 'path', and 'options'. See
  *   the l() function for information about these variables.
  *
  * @see l()
+ * @see theme_facetapi_link_inactive()
+ * @see theme_facetapi_deactivate_widget()
  *
- * @ingroup themeable
+ * @ingroup themable
  */
-function theme_facetapi_link_active($variables) {
-
-  // Sanitizes the link text if necessary.
-  $sanitize = empty($variables['options']['html']);
-  $link_text = ($sanitize) ? check_plain($variables['text']) : $variables['text'];
-
-  // Theme function variables fro accessible markup.
-  // @see http://drupal.org/node/1316580
-  $accessible_vars = array(
-    'text' => $variables['text'],
-    'active' => TRUE,
-  );
-
-  // Builds link, passes through t() which gives us the ability to change the
-  // position of the widget on a per-language basis.
-  $replacements = array(
-    '!facetapi_deactivate_widget' => theme('facetapi_deactivate_widget', $variables),
-    '!facetapi_accessible_markup' => theme('facetapi_accessible_markup', $accessible_vars),
-  );
-  $variables['text'] = t('!facetapi_deactivate_widget !facetapi_accessible_markup', $replacements);
-  $variables['options']['html'] = TRUE;
-  return theme_link($variables) . $link_text;
+function theme_facetapi_activate_widget($variables) {
+  return '<span class="filter-cion" aria-hidden="true"></span>';
 }
 
 /**
@@ -124,11 +158,12 @@ function theme_facetapi_link_active($variables) {
  *
  * @see l()
  * @see theme_facetapi_link_active()
+ * @see theme_facetapi_activate_widget()
  *
  * @ingroup themable
  */
 function theme_facetapi_deactivate_widget($variables) {
-  return '(-)';
+  return '<span class="filter-cion" aria-hidden="true">(-)</span>';
 }
 
 /**
-- 
2.0.0

