Compresses shorthand values. Example: margin:1px 1px 1px 1px -> margin:1px

@access public

@version 1.0

Parameters

string $value:

Return value

string

2 calls to csstidy_optimise::shorthand()
csstidy_optimise::merge_4value_shorthands in advagg_css_compress/csstidy/class.csstidy_optimise.inc
Merges Shorthand properties again, the opposite of dissolve_4value_shorthands()
csstidy_optimise::value in advagg_css_compress/csstidy/class.csstidy_optimise.inc
Optimises values @access public @version 1.0

File

advagg_css_compress/csstidy/class.csstidy_optimise.inc, line 220

Class

csstidy_optimise
CSS Optimising Class

Code

function shorthand($value) {
    $important = '';
    if (csstidy::is_important($value)) {
        $values = csstidy::gvw_important($value);
        $important = '!important';
    }
    else {
        $values = $value;
    }
    $values = explode(' ', $values);
    switch (count($values)) {
        case 4:
            if ($values[0] == $values[1] && $values[0] == $values[2] && $values[0] == $values[3]) {
                return $values[0] . $important;
            }
            elseif ($values[1] == $values[3] && $values[0] == $values[2]) {
                return $values[0] . ' ' . $values[1] . $important;
            }
            elseif ($values[1] == $values[3]) {
                return $values[0] . ' ' . $values[1] . ' ' . $values[2] . $important;
            }
            break;
        case 3:
            if ($values[0] == $values[1] && $values[0] == $values[2]) {
                return $values[0] . $important;
            }
            elseif ($values[0] == $values[2]) {
                return $values[0] . ' ' . $values[1] . $important;
            }
            break;
        case 2:
            if ($values[0] == $values[1]) {
                return $values[0] . $important;
            }
            break;
    }
    return $value;
}