-
Notifications
You must be signed in to change notification settings - Fork 0
/
_functions.scss
114 lines (84 loc) · 1.99 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
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
/**
* Functions for z-index management
*
* @author paul
* @package z-manager
* @date 25/11/15
*/
/**
* Spin through the z-indexes and get the highest value
*
* @return int
*/
@function z-index-manager-highest(){
$highest: 0;
@each $layer, $z-index in $z-indexes {
@if( $z-index > $highest ){
$highest: $z-index;
}
}
@return $highest;
};
/**
* Spin through the z-indexes and get the lowest value
*
* @return int
*/
@function z-index-manager-lowest(){
$lowest: 999999999;
@each $layer, $z-index in $z-indexes {
@if( $z-index < $lowest ){
$lowest: $z-index;
}
}
@return $lowest;
};
/**
* Get the z-dex of a layer
*
* @param $target {string} layer name
*/
@function z-index-manager-get( $target ){
@return map-get( $z-indexes, $target );
}
/**
* Work out the z-index for an element.
* By default will assume we want to get the value above the layer target.
*
* Example:
* z-index-manager( 'modal' ); // 25
*
* @param $target {string} layer target.
* @param $insert-above {boolean} get the z-index valuer of above or below the layer target. Set to false to insert below.
* @param $layer {string} if specified will store the new layer in our
*
* @return {int}
*/
@function z-index-manager( $target, $insert-above: true, $layer: '' ){
$new-z-index: auto;
$target-z-index: 1;
// Get our target from the map of layers
@if map-has-key( $z-indexes, $target ){
$target-z-index: z-index-manager-get( $target );
@if( $insert-above ){
$new-z-index: $target-z-index + $z-index-buffer;
}
@else {
$new-z-index: $target-z-index - $z-index-buffer;
}
}
// Mapped layer not found test for all layers
@elseif( $target == '*' ){
@if( $insert-above ){
$new-z-index: z-index-manager-highest() + 1;
}
@else {
$new-z-index: z-index-manager-lowest() - 1;
}
}
// Save the layer if layer name is specified.
@if( $layer ){
$z-indexes: map-merge( $z-indexes, ( $layer: $new-z-index ) ) !global;
}
@return $new-z-index;
}