Example #1
0
 /**
  * Consolidates background styles into a single background style
  *
  * @param array $styles Consolidates the provided array of background styles
  * @return array Consolidated optimised background styles
  */
 public static function consolidate(array $styles)
 {
     if (count($styles) < 1) {
         return $styles;
     }
     $color = $image = $repeat = $attachment = $position = null;
     foreach ($styles as $style) {
         switch ($style->get_name()) {
             case 'background-color':
                 $color = css_style_color::shrink_value($style->get_value());
                 break;
             case 'background-image':
                 $image = $style->get_value();
                 break;
             case 'background-repeat':
                 $repeat = $style->get_value();
                 break;
             case 'background-attachment':
                 $attachment = $style->get_value();
                 break;
             case 'background-position':
                 $position = $style->get_value();
                 break;
         }
     }
     if ((is_null($image) || is_null($position) || is_null($repeat)) && ($image != null || $position != null || $repeat != null)) {
         return $styles;
     }
     $value = array();
     if (!is_null($color)) {
         $value[] .= $color;
     }
     if (!is_null($image)) {
         $value[] .= $image;
     }
     if (!is_null($repeat)) {
         $value[] .= $repeat;
     }
     if (!is_null($attachment)) {
         $value[] .= $attachment;
     }
     if (!is_null($position)) {
         $value[] .= $position;
     }
     return array(new css_style_background('background', join(' ', $value)));
 }
Example #2
0
 /**
  * Returns true if the value for this style is valid
  * @return bool
  */
 public function is_valid()
 {
     return $this->is_special_empty_value() || parent::is_valid();
 }