11@import " rwd-variables" ;
2+ @import " strapless/base/scss/functions/map" ;
23
4+ // region //////////////////////////////////////////////// String Functions
5+
6+ // Explodes a string into a SASS list by the given delimiter
7+ // @author Hugo Giraudel (modified from original)
38@function _str-explode ($string , $delimiter : " " ) {
49 $result : ();
510 $length : str-length ($string );
3035 @return append ($result , $remaining );
3136}
3237
38+ // endregion ///////////////////////////////////////////// End String Functions
39+
40+ // region //////////////////////////////////////////////// Breakpoint Functions
41+
42+ // Returns -breakpoint for adding into class selectors.
43+ // For breakpoints with no minimum size, returns null.
44+ @function breakpoint-infix ($bp ) {
45+ @if variable-exists (grid-breakpoints ) == false {
46+ @error ' You must set the $grid-breakpoints map prior to the first usage of the `breakpoint-infix` function.' ;
47+ }
48+ @if map-has-key ($grid-breakpoints , $bp ) {
49+ $min : strip-unit (map-get ($grid-breakpoints , $bp ));
50+ @if $min > 0 {
51+ @return - #{$bp } ;
52+ }
53+ }
54+
55+ @return null;
56+ }
57+
58+ // Returns the max width for the given breakpoint.
59+ @function breakpoint ($breakpoint ) {
60+ @if map-has-key ($grid-breakpoints ,$breakpoint ) {
61+ @return map-get ($grid-breakpoints , $breakpoint );
62+ }
63+
64+ @error " The breakpoint `#{$breakpoint } does not exist in the $grid-breakpoints map." ;
65+ }
66+
67+ // Returns the max container width for the given breakpoint.
68+ @function container ($breakpoint ) {
69+ @if map-has-key ($container-max-widths ,$breakpoint ) {
70+ @return map-get ($container-max-widths , $breakpoint );
71+ }
72+
73+ @error " The breakpoint `#{$breakpoint } does not exist in the $container-max-widths map." ;
74+ }
3375
76+ // Sets the width for a given breakpoint to the given value
77+ // This is a mixin, as SASS functions should not have consequences.
78+ @mixin set-breakpoint ($breakpoint ,$value ) {
79+ @if not (variable-exists (grid-breakpoints )) {
80+ @error " You may not use the `set-breakpoint` mixin without the $grid-breakpoints map. Please include `root-variables` prior to this usage."
81+ } @else {
82+ $grid-breakpoints : set-map-key($grid-breakpoints , $breakpoint , $value ) !global;
83+ }
84+ }
85+
86+ // Sets the container max width for the given breakpoint to
87+ // the given value. This is a mixin, as SASS functions should
88+ // not have consequences.
89+ @mixin set-max-width ($breakpoint ,$value ) {
90+ @if not (variable-exists (container-max-widths )) {
91+ @error " You may not use the `set-max-width` mixin without the $container-max-widths map. Please include `root-variables` prior to this usage."
92+ } @else {
93+ $container-max-widths : set-map-key($container-max-widths , $breakpoint , $value ) !global;
94+ }
95+ }
96+
97+ // endregion ///////////////////////////////////////////// End Breakpoint Functions
98+
99+ // region //////////////////////////////////////////////// Media Expression Functions
100+
101+ // Gets the operator prefixing a value in an expression.
102+ // @author Hugo Giraudel
34103@function get-expression-operator ($expression ) {
35104 @each $operator in (' >=' , ' <=' , ' >' , ' <' , ' ≥' , ' ≤' , ' =' ) {
36105 @if str-index ($expression , $operator ) {
41110 @return ' ' ;
42111}
43112
113+ // Gets the value of an expression given the prefixing operator.
114+ // @author Hugo Giraudel
44115@function get-expression-value ($expression , $operator ) {
45116 $operator-index : str-index ($expression , $operator );
46117 $value : str-slice ($expression , $operator-index + str-length ($operator ));
47118 @return $value ;
48119}
49120
121+ // Returns the proper condition string to use in a CSS media
122+ // query for the given minimum and maximum width.
50123@function get-width-string ($operator , $min : 0 , $max : 0 ) {
51124 @if $operator == ' ≥' { $operator : ' >=' ; }
52125 @if $operator == ' ≤' { $operator : ' <=' ; }
69142 @return ' ' ;
70143}
71144
72- @function get-condition-string ($viewport ,$operator ) {
145+ // Returns the proper condition string to use in a CSS media
146+ // query for the given breakpoint. The $grid-breakpoints
147+ // variable must be accessible for this function.
148+ @function get-breakpoint-string ($viewport ,$operator ) {
73149 @each $class , $min in $grid-breakpoints {
74150 @if ($class == $viewport ) {
75151 $max : map-get-next ($grid-breakpoints ,$class , 0 );
80156 @return ' ' ;
81157}
82158
159+ // Determines if the string given is a CSS media type.
83160@function is-media-type ($string ) {
84161 @if type-of ($string ) == string {
85162 $types : (all , print, screen , speech , tty, tv, projection, handheld, braille, embossed, aural);
94171 @return false;
95172}
96173
97- @function add-condition ($conditions-string , $new-string ) {
98- @if type-of ($conditions-string ) == null {
99- @if not (is-media-type ($new-string )) {
100- $conditions-string : unquote (" all" );
101- }
102- }
103- }
174+ // endregion ///////////////////////////////////////////// End Media Expression Functions
175+
176+ // region //////////////////////////////////////////////// Selector/Media Targeting Functions
104177
178+ // Returns media query for the given conditions.
105179@function _media ($conditions ... ) {
106180 $compiled-list : ();
107181 @for $i from 1 through length ($conditions ) {
115189 $value : get-expression-value ($condition ,$operator );
116190 @if map-has-key ($grid-breakpoints , $value ) {
117191 // Breakpoint Based Conditions
118- $compiled-list : append ($compiled-list , get-condition -string ($value , $operator ), comma );
192+ $compiled-list : append ($compiled-list , get-breakpoint -string ($value , $operator ), comma );
119193 } @else {
120194 // Width Based Condition
121195 $compiled-list : append ($compiled-list , get-width-string ($operator ,$value ,$value ), comma );
148222 @return $conditions-string ;
149223}
150224
225+ // Returns selector for targeting a specific browser based on a user
226+ // agent placed in the HTML tag by xq-detect. As user agents can easily
227+ // be spoofed, this should only be used for minimal 'hacks'.
151228@function _browser-target ($browser , $version : null , $negate : false ) {
152229 $sep : ' ' ;
153230 @if map-has-key ($target-user-agent ,$browser ) {
161238 @return null;
162239}
163240
241+ // Returns selector targeting a specific feature that cannot
242+ // be targeted with media queries. Requires usage of xq-detect
243+ // in the head of the document. Also works with Modernizr.
164244@function _feature-target ($feature , $negate : false ) {
165245 @if map-has-key ($target-feature , $feature ) {
166246 $sel : unquote (map-get ($target-feature , $feature ));
171251 @return null;
172252}
173253
174-
254+ // Returns selector for given targets
175255@function _target ($targets ... ) {
176256 $class : ' ' ;
177257 $ua : ' ' ;
191271 }
192272
193273 @return unquote (' html#{$class }#{$ua } ' );
194- }
274+ }
275+
276+
277+ // endregion ///////////////////////////////////////////// End Selector/Media Targeting Functions
0 commit comments