Skip to content

Commit 31ebe51

Browse files
author
AMJones
committed
Renames media query function, allows function to work with media-type-only queries.
1 parent 8e32d98 commit 31ebe51

4 files changed

Lines changed: 35 additions & 27 deletions

File tree

scss/_rwd-functions.scss

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
@import "rwd-variables";
22
@import "strapless/base/scss/base";
33

4-
// region //////////////////////////////////////////////// String Functions
5-
6-
7-
8-
// endregion ///////////////////////////////////////////// End String Functions
9-
104
// region //////////////////////////////////////////////// Breakpoint Functions
115

126
// Returns -breakpoint for adding into class selectors.
@@ -146,14 +140,21 @@
146140
// region //////////////////////////////////////////////// Selector/Media Targeting Functions
147141

148142
// Returns media query for the given conditions.
149-
@function _media($conditions...) {
143+
@function media-condition($conditions...) {
150144
$compiled-list: ();
151145
@for $i from 1 through length($conditions) {
152146
$condition: unquote(quote(nth($conditions,$i)));
153-
154147
// Basic String Conditions
155148
@if map-has-key($condition-map, $condition) {
156-
$compiled-list: append( $compiled-list, map-get( $condition-map,$condition ), comma );
149+
$pre: map-get($condition-map,$condition);
150+
@if(type-of($pre) == list) {
151+
@for $ii from 1 through length($pre) {
152+
$part: unquote(quote(nth($pre,$ii)));
153+
$compiled-list: append( $compiled-list, $part, comma );
154+
}
155+
} @else {
156+
$compiled-list: append( $compiled-list, map-get( $condition-map,$condition ), comma );
157+
}
157158
} @else {
158159
$operator: get-expression-operator($condition);
159160
$value: get-expression-value($condition,$operator);
@@ -173,17 +174,8 @@
173174
$last: if($i > 1, nth($compiled-list, $i - 1), null);
174175
$sep: '';
175176

176-
@if $i == 1 and $conditions-string == '' and not(is-media-type($this)) {
177-
$last: all;
178-
$conditions-string: all;
179-
}
180-
181177
@if $conditions-string != '' {
182-
@if is-media-type($last) and not(is-media-type($this)) {
183-
$sep: unquote(" and ");
184-
} @else {
185-
$sep: unquote(", ");
186-
}
178+
$sep: unquote(", ");
187179
}
188180

189181
$conditions-string: $conditions-string + $sep + $this;

scss/_rwd-mixins.scss

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
@import "rwd-variables";
22
@import "rwd-functions";
33

4+
// Inserts a psuedo-element used to detect the current breakpoint.
5+
@mixin responsive-breakpoint($breakpoint) {
6+
body::before { content: "#{$breakpoint}"; display: none !important; }
7+
}
8+
49
// Wraps the given content in the appropriate media
510
// query for the given conditions. If no media type
611
// is included in the conditions, the 'all' media type
712
// is used.
813
@mixin media($conditions...) {
9-
@media #{_media($conditions...)} {
14+
@media #{media-condition($conditions...)} {
1015
@content;
1116
}
1217
}
@@ -15,7 +20,7 @@
1520
// devices without a 'fine' pointing device. On Firefox
1621
// browsers, this may include all touch devices.
1722
@mixin only-touch() {
18-
@media #{_media("screen", "touch")} {
23+
@media #{media-condition("touch")} {
1924
@content;
2025
}
2126
}

scss/_rwd-variables.scss

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
$enable-framework: false;
3+
24
// region //////////////////////////////////////////////// Breakpoints
35

46
$grid-breakpoints: (
@@ -23,11 +25,11 @@ $container-max-widths: (
2325
// Media Query Targets
2426
$condition-map: (
2527
"screen": "screen",
26-
"print" : "print ",
27-
"coarse": "(pointer: fine)",
28-
"touch" : "(pointer: coarse), (-moz-touch-enabled)",
29-
"fine" : "(pointer: fine), not all and (-moz-touch-enabled)",
30-
"hidpi" : "(-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi)"
28+
"print" : "print",
29+
"coarse": "screen and (pointer: coarse)",
30+
"touch" : ("handheld", "screen and (pointer: coarse)", "screen and (-moz-touch-enabled)"),
31+
"fine" : ("screen and (pointer: fine)", "not (-moz-touch-enabled)"),
32+
"hidpi" : ("screen and (-webkit-min-device-pixel-ratio: 1.5)", "screen and (min-resolution: 144dpi)")
3133
);
3234

3335
// Feature-Based Targets (requires d.js)

scss/_rwd.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11

2-
@import "rwd-mixins";
2+
@import "rwd-mixins";
3+
4+
// If not in framework, output responsive breakpoint detection.
5+
@if variable-exists(enable-framework) {
6+
@if not($enable-framework) {
7+
@each $bp, $min in $grid-breakpoints {
8+
@include responsive-breakpoint($bp);
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)