-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy path_multiple-backgrounds.scss
116 lines (98 loc) · 3.4 KB
/
_multiple-backgrounds.scss
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
///
/// A function for prefixing gradients.
///
/// @todo define old webkit mode
///
/// @param {String} $mode - Either `webkit-old`, `webkit` or `''`
/// @param {Arglist} $gradient
///
/// @returns {String} `-<mode>-linear-gradient(<gradient>)`
///
@function prefixed-gradient ($mode, $gradient) {
$prefix: '-' + $mode + '-';
// Get angles
$angles: helper-gradient-angle('' + nth($gradient, 2));
$angle: nth($angles, 1);
// If unprefixed
@if ($mode == '') {
$prefix: '';
$angle: nth($gradient, 2);
}
// @TODO define old webkit mode
@if ($mode == 'webkit-old') {
$prefix: '-webkit-';
$angle: nth($angles, 2);
}
$prefixed: $prefix + 'linear-gradient(' + $angle;
@for $i from 1 through length($gradient) {
@if ($i > 2) {
$prefixed: append(unquote($prefixed), nth($gradient, $i), comma);
}
}
$prefixed: $prefixed + ')';
@return unquote($prefixed);
}
///
/// This mixin generates multiple backgrounds.
///
/// @author drublic
///
/// @link http://caniuse.com/css-gradients caniuse
/// @link http://www.w3.org/TR/2011/WD-css3-images-20110217/#linear-gradients spec
///
///
/// @param {Arglist} $backgrounds
///
/// @example
/// .selector {
/// @include x-multiple-backgrounds(
/// rgba(0, 0, 0, 0.3),
/// url('../img/html5_logo.png') top right no-repeat,
/// (linear-gradient, to bottom, #aaa, #ddd)
/// );
/// }
///
@mixin x-multiple-backgrounds ($backgrounds...) {
$combined-background-webkit-old: ();
$combined-background-webkit: ();
$combined-background: ();
$end: '';
// Iterate through all backgrounds passed
@each $background in $backgrounds {
// Prefix gradients
@if (type-of($background) == list) {
@if (nth($background, 1) == 'linear-gradient') {
$combined-background-webkit-old: append($combined-background-webkit-old, prefixed-gradient('webkit-old', $background), comma);
$combined-background-webkit: append($combined-background-webkit, prefixed-gradient('webkit', $background), comma);
$combined-background: append($combined-background, prefixed-gradient('', $background), comma);
// Nothing to do for non-gradients
} @else {
$combined-background-webkit-old: append($combined-background-webkit-old, $background, comma);
$combined-background-webkit: append($combined-background-webkit, $background, comma);
$combined-background: append($combined-background, $background, comma);
}
// Put colors at end of combined background
} @else if (type-of($background) == color) {
$end: $background;
$background: null;
} @else if (type-of($background) == string) {
$combined-background-webkit-old: append($combined-background-webkit-old, $background, space);
$combined-background-webkit: append($combined-background-webkit, $background, comma);
$combined-background: append($combined-background, $background, comma);
}
}
// Append color if there is one
@if $end != '' {
$combined-background-webkit-old: append($combined-background-webkit-old, $end, space);
$combined-background-webkit: append($combined-background-webkit, $end, comma);
$combined-background: append($combined-background, $end, comma);
}
// Only print all prefixed versions if necessary
@if ($combined-background != $combined-background-webkit) {
background: unquote($combined-background-webkit-old);
background: unquote($combined-background-webkit);
background: unquote($combined-background);
} @else {
background: unquote($combined-background);
}
}