Skip to content

Change in css function #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions src/QueryPath/DOMQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,14 @@ public function css($name = NULL, $value = '') {
return $this->attr('style');
}

// Get any existing CSS.
$css = array();
foreach ($this->matches as $match) {

foreach ($this->matches as $match) {
// Get any existing CSS. //+
$css = array(); //The css is restored in every repetition of the loop, so that it doesn't
//homogenize all of the matches to share ALL their css attributes, only
//the ones indicated in the parameters.
$style = $match->getAttribute('style');
//$style =$this->attr('style');
if (!empty($style)) {
// XXX: Is this sufficient?
$style_array = explode(';', $style);
Expand All @@ -604,26 +608,29 @@ public function css($name = NULL, $value = '') {
$css[$css_att] = trim($css_val);
}
}
}
if (is_array($name)) {
// Use array_merge instead of + to preserve order.
$css = array_merge($css, $name);
}
else {
$css[$name] = $value;
}

if (is_array($name)) {
// Use array_merge instead of + to preserve order.
$css = array_merge($css, $name);
}
else {
$css[$name] = $value;
}
// Collapse CSS into a string.
$format = '%s: %s;';
$css_string = '';
foreach ($css as $n => $v) {
$css_string .= sprintf($format, $n, trim($v));
}

// Collapse CSS into a string.
$format = '%s: %s;';
$css_string = '';
foreach ($css as $n => $v) {
$css_string .= sprintf($format, $n, trim($v));
//$this->attr('style', $css_string); //Deprecated: instead of sharing the same style for all the matches,
// the change in the css will be applied finely for
// each match without homogenization
$match->setAttribute('style', $css_string);
}

$this->attr('style', $css_string);
return $this;
}
} //End of css function


/**
* Insert or retrieve a Data URL.
Expand Down