You are here

function csstidy_optimise::dissolve_4value_shorthands in Advanced CSS/JS Aggregation 6

Same name and namespace in other branches
  1. 7 advagg_css_compress/csstidy/class.csstidy_optimise.inc \csstidy_optimise::dissolve_4value_shorthands()

Dissolves properties like padding:10px 10px 10px to padding-top:10px;padding-bottom:10px;...

@version 1.0

Parameters

string $property:

string $value:

Return value

array

See also

merge_4value_shorthands()

1 call to csstidy_optimise::dissolve_4value_shorthands()
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 532

Class

csstidy_optimise
CSS Optimising Class

Code

function dissolve_4value_shorthands($property, $value) {
  $shorthands =& $GLOBALS['csstidy']['shorthands'];
  if (!is_array($shorthands[$property])) {
    $return[$property] = $value;
    return $return;
  }
  $important = '';
  if (csstidy::is_important($value)) {
    $value = csstidy::gvw_important($value);
    $important = '!important';
  }
  $values = explode(' ', $value);
  $return = array();
  if (count($values) == 4) {
    for ($i = 0; $i < 4; $i++) {
      $return[$shorthands[$property][$i]] = $values[$i] . $important;
    }
  }
  elseif (count($values) == 3) {
    $return[$shorthands[$property][0]] = $values[0] . $important;
    $return[$shorthands[$property][1]] = $values[1] . $important;
    $return[$shorthands[$property][3]] = $values[1] . $important;
    $return[$shorthands[$property][2]] = $values[2] . $important;
  }
  elseif (count($values) == 2) {
    for ($i = 0; $i < 4; $i++) {
      $return[$shorthands[$property][$i]] = $i % 2 != 0 ? $values[1] . $important : $values[0] . $important;
    }
  }
  else {
    for ($i = 0; $i < 4; $i++) {
      $return[$shorthands[$property][$i]] = $values[0] . $important;
    }
  }
  return $return;
}