Skip to content
This repository
Phil LaPier March 20, 2014
file 56 lines (44 sloc) 1.758 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
//************************************************************************//
// Background property for adding multiple backgrounds using shorthand
// notation.
//************************************************************************//

@mixin background($backgrounds...) {
  $webkit-backgrounds: ();
  $spec-backgrounds: ();

  @each $background in $backgrounds {
    $webkit-background: ();
    $spec-background: ();
    $background-type: type-of($background);

    @if $background-type == string or list {
      $background-str: if($background-type == list, nth($background, 1), $background);

      $url-str: str-slice($background-str, 0, 3);
      $gradient-type: str-slice($background-str, 0, 6);

      @if $url-str == "url" {
        $webkit-background: $background;
          $spec-background: $background;
      }

      @else if $gradient-type == "linear" {
        $gradients: _linear-gradient-parser("#{$background}");
        $webkit-background: map-get($gradients, webkit-image);
        $spec-background: map-get($gradients, spec-image);
      }

      @else if $gradient-type == "radial" {
        $gradients: _radial-gradient-parser("#{$background}");
        $webkit-background: map-get($gradients, webkit-image);
        $spec-background: map-get($gradients, spec-image);
      }

      @else {
        $webkit-background: $background;
          $spec-background: $background;
      }
    }

    @else {
      $webkit-background: $background;
        $spec-background: $background;
    }

    $webkit-backgrounds: append($webkit-backgrounds, $webkit-background, comma);
    $spec-backgrounds: append($spec-backgrounds, $spec-background, comma);
  }

  background: $webkit-backgrounds;
  background: $spec-backgrounds;
}
Something went wrong with that request. Please try again.