public function QueryPath::css in QueryPath 7.3
Same name and namespace in other branches
- 6 QueryPath/QueryPath.php \QueryPath::css()
- 7.2 QueryPath/QueryPath.php \QueryPath::css()
File
- QueryPath/
QueryPath.php, line 368
Class
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;
}