You are here

function _jquery_ui_filter_process_replacer in jQuery UI filter 7

Same name and namespace in other branches
  1. 6 jquery_ui_filter.module \_jquery_ui_filter_process_replacer()

Jquery UI filter process replacer: Inserts jQuery UI widget classes into text.

2 calls to _jquery_ui_filter_process_replacer()
_jquery_ui_filter_accordion_process_replacer in accordion/jquery_ui_filter_accordion.module
Jquery UI filter accordion process replacer.
_jquery_ui_filter_tabs_process_replacer in tabs/jquery_ui_filter_tabs.module
Jquery UI filter tabs process replacer.

File

./jquery_ui_filter.module, line 97
Converts static HTML to a jQuery UI accordian or tabs widget.

Code

function _jquery_ui_filter_process_replacer($type, $html, $collapsed = FALSE) {

  // Add jquery ui filter classes and wrap content in a container <div>.
  $header_tag = variable_get("jquery_ui_filter_{$type}_header_tag", 'h3');
  if (preg_match_all("#(<{$header_tag}[^>]*>)(.*?)(</{$header_tag}>)(.*?)(?=<{$header_tag}|\$)#s", $html, $matches)) {
    foreach ($matches[0] as $index => $match) {
      $header_open_tag = $matches[1][$index];
      $header_attributes = _jquery_ui_filter_parse_tag_attributes($header_open_tag);
      $header_text = $matches[2][$index];
      $header_close_tag = $matches[3][$index];
      $content = $matches[4][$index];
      $header_attributes['class'] .= "jquery-ui-filter-header jquery-ui-filter-{$type}-header";
      $replace_with = '<' . $header_tag . drupal_attributes($header_attributes) . '>' . $header_text . $header_close_tag . '<div class="jquery-ui-filter-container jquery-ui-filter-' . $type . '-container">' . $content . '</div>';
      $html = str_replace($matches[0][$index], $replace_with, $html);
    }
  }

  // Build jquery ui filter widget wrapper.
  $classes = array(
    'jquery-ui-filter',
    'jquery-ui-filter-' . $type,
  );
  if ($collapsed) {
    $classes[] = 'jquery-ui-filter-' . $type . '-collapsed';
  }
  $attributes = array(
    'id' => drupal_html_id('jquery-ui-filter'),
    'class' => implode(' ', $classes),
  );
  return '<div' . drupal_attributes($attributes) . '>' . $html . '</div>';
}