private static function SassExtentionsCompassFunctionsColourStops::normalize_stops in Sassy 7
1 call to SassExtentionsCompassFunctionsColourStops::normalize_stops()
- SassExtentionsCompassFunctionsColourStops::grad_colour_stops in phamlp/
sass/ extensions/ compass/ functions/ colourStops.php
File
- phamlp/
sass/ extensions/ compass/ functions/ colourStops.php, line 231
Class
- SassExtentionsCompassFunctionsColourStops
- Compass extension SassScript colour stops functions class. A collection of functions for use in SassSCript. @package PHamlP @subpackage Sass.extensions.compass.functions
Code
private static function normalize_stops($colourList) {
$positions = $colourList->values;
$s = sizeof($positions);
# fill in the start and end positions, if unspecified
if (empty($positions[0]->stop)) {
$positions[0]->stop = new SassNumber(0);
}
if (empty($positions[$s - 1]->stop)) {
$positions[$s - 1]->stop = new SassNumber('100%');
}
# fill in empty values
for ($i = 0; $i < $s; $i++) {
if (is_null($positions[$i]->stop)) {
$num = 2;
for ($j = $i + 1; $j < $s; $j++) {
if (isset($positions[$j]->stop)) {
$positions[$i]->stop = $positions[$i - 1]->stop
->op_plus($positions[$j]->stop
->op_minus($positions[$i - 1]->stop))
->op_div(new SassNumber($num));
break;
}
else {
$num += 1;
}
}
}
}
# normalize unitless numbers
foreach ($positions as &$pos) {
if ($pos->stop
->isUnitless()) {
$pos->stop = $pos->stop->value <= 1 ? $pos->stop
->op_times(new SassNumber('100%')) : $pos->stop
->op_times(new SassNumber('1px'));
}
}
if ($positions[$s - 1]->stop
->op_eq(new SassNumber('0px'))
->toBoolean() || $positions[$s - 1]->stop
->op_eq(new SassNumber('0%'))
->toBoolean()) {
throw new SassScriptFunctionException('Colour stops must be specified in increasing order', array(), SassScriptParser::$context->node);
}
return null;
}