forked from drublic/Sass-Mixins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_multiple-backgrounds.scss
133 lines (114 loc) · 4.26 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* @description
* This mixin generates multiple backgrounds
*
* @author drublic
*
* @link caniuse http://caniuse.com/css-gradients
* @link spec http://www.w3.org/TR/2011/WD-css3-images-20110217/#linear-gradients
*/
/*
* A function for prefixing gradients
*
* @param mode {'webkit-old'|'webkit'|'moz'|'o'|''}
* @param gradient
* @returns
* -<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);
}
/*
* Generates multiple backgrounds
*
* @param backgrounds {list}
* @return
* <property>: (<value> * <default-font-size>)px;
* <property>: <value>;
*
* @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-moz: ();
$combined-background-o: ();
$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-moz: append($combined-background-moz, prefixed-gradient('moz', $background), comma);
$combined-background-o: append($combined-background-o, prefixed-gradient('o', $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-moz: append($combined-background-moz, $background, comma);
$combined-background-o: append($combined-background-o, $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-moz: append($combined-background-moz, $background, comma);
$combined-background-o: append($combined-background-o, $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-moz: append($combined-background-moz, $end, comma);
$combined-background-o: append($combined-background-o, $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-moz);
background: unquote($combined-background-o);
background: unquote($combined-background);
} @else {
background: unquote($combined-background);
}
}