-
Notifications
You must be signed in to change notification settings - Fork 250
/
_functions.scss
89 lines (72 loc) · 2.25 KB
/
_functions.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
// List functions courtesy of Team Sass.
// Get percentage from a given ratio.
@function _get-span($ratio: 1) {
@return $ratio * 100;
}
// Work out the column widths based on the ratio and gutter sizes.
@function _get-column($ratios: 1, $gutter: map-get($jeet, 'gutter')) {
$ratios: if(not map-get($jeet, 'parent-first'), _reverse($ratios), $ratios);
$width: 100;
@each $ratio in $ratios {
$gutter: $gutter / $width * 100;
$width: 100 * $ratio - $gutter + $ratio * $gutter;
}
@return $width $gutter;
}
// Get the set layout direction for the project.
@function _get-layout-direction() {
$direction: if(map-get($jeet, 'layout-direction') == 'RTL', right, left);
@return $direction;
}
// Replace a specified list value with a new value (uses built in set-nth() if available)
@function _replace-nth($list, $index, $value) {
// Fallback for Sass 3.2
@if function-exists('set-nth') != true {
$result: ();
$index: if($index < 0, length($list) + $index + 1, $index);
@for $i from 1 through length($list) {
$result: append($result, if($i == $index, $value, nth($list, $i)));
}
@return $result;
}
// Sass 3.3
$result: set-nth($list, $index, $value);
@return $result;
}
// Reverse a list (progressively enhanced for Sass 3.3)
@function _reverse($list) {
// Sass 3.2
@if function-exists('set-nth') != true {
$result: ();
@for $i from length($list) * -1 through -1 {
$result: append($result, nth($list, abs($i)));
}
@return $result;
}
// Sass 3.3
@for $i from 1 through floor(length($list) / 2) + 1 {
$tmp: nth($list, $i);
$list: set-nth($list, $i, nth($list, -$i));
$list: set-nth($list, -$i, $tmp);
}
@return $list;
}
// Get the opposite direction to a given value.
@function _opposite-direction($direction) {
@if $direction == 'left' {
@return right;
} @else if $direction == 'right' {
@return left;
} @else if $direction == 'top' {
@return bottom;
} @else if $direction == 'bottom' {
@return top;
} @else if index('ltr' 'LTR', $direction) {
@return rtl;
} @else if index('rtl' 'RTL', $direction) {
@return ltr;
} @else {
@warn '`#{$direction}` is not a direction; please make sure your direction is all lowercase.';
@return false;
}
}