function csstidy_optimise::dissolve_short_bg in Advanced CSS/JS Aggregation 6
Same name and namespace in other branches
- 7 advagg_css_compress/csstidy/class.csstidy_optimise.inc \csstidy_optimise::dissolve_short_bg()
Dissolve background property
@version 1.0 @todo full CSS 3 compliance
Parameters
string $str_value:
Return value
array
See also
merge_bg()
1 call to csstidy_optimise::dissolve_short_bg()
- csstidy_optimise::shorthands in advagg_css_compress/
csstidy/ class.csstidy_optimise.inc - Optimises shorthands @access public @version 1.0
File
- advagg_css_compress/
csstidy/ class.csstidy_optimise.inc, line 661
Class
- csstidy_optimise
- CSS Optimising Class
Code
function dissolve_short_bg($str_value) {
// don't try to explose background gradient !
if (stripos($str_value, "gradient(") !== FALSE) {
return array(
'background' => $str_value,
);
}
$background_prop_default =& $GLOBALS['csstidy']['background_prop_default'];
$repeat = array(
'repeat',
'repeat-x',
'repeat-y',
'no-repeat',
'space',
);
$attachment = array(
'scroll',
'fixed',
'local',
);
$clip = array(
'border',
'padding',
);
$origin = array(
'border',
'padding',
'content',
);
$pos = array(
'top',
'center',
'bottom',
'left',
'right',
);
$important = '';
$return = array(
'background-image' => null,
'background-size' => null,
'background-repeat' => null,
'background-position' => null,
'background-attachment' => null,
'background-clip' => null,
'background-origin' => null,
'background-color' => null,
);
if (csstidy::is_important($str_value)) {
$important = ' !important';
$str_value = csstidy::gvw_important($str_value);
}
$str_value = csstidy_optimise::explode_ws(',', $str_value);
for ($i = 0; $i < count($str_value); $i++) {
$have['clip'] = false;
$have['pos'] = false;
$have['color'] = false;
$have['bg'] = false;
if (is_array($str_value[$i])) {
$str_value[$i] = $str_value[$i][0];
}
$str_value[$i] = csstidy_optimise::explode_ws(' ', trim($str_value[$i]));
for ($j = 0; $j < count($str_value[$i]); $j++) {
if ($have['bg'] === false && (substr($str_value[$i][$j], 0, 4) === 'url(' || $str_value[$i][$j] === 'none')) {
$return['background-image'] .= $str_value[$i][$j] . ',';
$have['bg'] = true;
}
elseif (in_array($str_value[$i][$j], $repeat, true)) {
$return['background-repeat'] .= $str_value[$i][$j] . ',';
}
elseif (in_array($str_value[$i][$j], $attachment, true)) {
$return['background-attachment'] .= $str_value[$i][$j] . ',';
}
elseif (in_array($str_value[$i][$j], $clip, true) && !$have['clip']) {
$return['background-clip'] .= $str_value[$i][$j] . ',';
$have['clip'] = true;
}
elseif (in_array($str_value[$i][$j], $origin, true)) {
$return['background-origin'] .= $str_value[$i][$j] . ',';
}
elseif ($str_value[$i][$j][0] === '(') {
$return['background-size'] .= substr($str_value[$i][$j], 1, -1) . ',';
}
elseif (in_array($str_value[$i][$j], $pos, true) || is_numeric($str_value[$i][$j][0]) || $str_value[$i][$j][0] === null || $str_value[$i][$j][0] === '-' || $str_value[$i][$j][0] === '.') {
$return['background-position'] .= $str_value[$i][$j];
if (!$have['pos']) {
$return['background-position'] .= ' ';
}
else {
$return['background-position'] .= ',';
}
$have['pos'] = true;
}
elseif (!$have['color']) {
$return['background-color'] .= $str_value[$i][$j] . ',';
$have['color'] = true;
}
}
}
foreach ($background_prop_default as $bg_prop => $default_value) {
if ($return[$bg_prop] !== null) {
$return[$bg_prop] = substr($return[$bg_prop], 0, -1) . $important;
}
else {
$return[$bg_prop] = $default_value . $important;
}
}
return $return;
}