You are here

public function QueryPath::css in QueryPath 7.2

Same name and namespace in other branches
  1. 6 QueryPath/QueryPath.php \QueryPath::css()
  2. 7.3 QueryPath/QueryPath.php \QueryPath::css()

File

QueryPath/QueryPath.php, line 368

Class

QueryPath

Code

public function css($name = NULL, $value = '') {
  if (empty($name)) {
    return $this
      ->attr('style');
  }
  $css = array();
  foreach ($this->matches as $match) {
    $style = $match
      ->getAttribute('style');
    if (!empty($style)) {
      $style_array = explode(';', $style);
      foreach ($style_array as $item) {
        $item = trim($item);
        if (strlen($item) == 0) {
          continue;
        }
        list($css_att, $css_val) = explode(':', $item, 2);
        $css[$css_att] = trim($css_val);
      }
    }
  }
  if (is_array($name)) {
    $css = array_merge($css, $name);
  }
  else {
    $css[$name] = $value;
  }
  $format = '%s: %s;';
  $css_string = '';
  foreach ($css as $n => $v) {
    $css_string .= sprintf($format, $n, trim($v));
  }
  $this
    ->attr('style', $css_string);
  return $this;
}