responder 0.0.3 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +65 -7
- data/lib/responder/version.rb +1 -1
- data/scss/responder/_respond-to.scss +39 -22
- data/scss/responder/functions.scss +31 -26
- data/scss/responder.scss +2 -0
- data/test/css/style-old-ie.css +82 -0
- data/test/index.html +28 -0
- data/test/scss/style-old-ie.scss +13 -0
- data/test/scss/style.scss +6 -0
- metadata +8 -5
data/README.md
CHANGED
@@ -45,11 +45,11 @@ Responder will do the math for you and convert your breakpoint values into ems.
|
|
45
45
|
**Prefer pixel breakpoints?** Easy:
|
46
46
|
|
47
47
|
$responder-use-ems: false; // Defaults to true
|
48
|
-
|
49
|
-
**Change the default media type **
|
50
48
|
|
51
|
-
|
52
|
-
|
49
|
+
**Change the default media type**
|
50
|
+
|
51
|
+
$responder-media-type: tv; // Defaults to screen
|
52
|
+
|
53
53
|
### 2. Using the respond-to mixin
|
54
54
|
|
55
55
|
Yep, that was it. Your mixin is ready to use.
|
@@ -106,11 +106,69 @@ Given the example breakpoint list above, `respond-to(mobile-only)` will output t
|
|
106
106
|
|
107
107
|
min-width value is the first breakpoint of the group and max-width is the last one. You can create as many breakpoints as you need for each group. It's that simple.
|
108
108
|
|
109
|
-
### 3.
|
109
|
+
### 3. Mobile first & Old IE
|
110
|
+
|
111
|
+
If you're designing your site "mobile first" and prefer to serve a separate CSS to browsers that don't support media queries (IE8 and below), Responder gets you covered!
|
112
|
+
|
113
|
+
_(NOTE: This step is completely optional)_
|
114
|
+
|
115
|
+
#### Old IE only stylesheet
|
116
|
+
|
117
|
+
Just create a new SASS stylesheet and add the following lines:
|
118
|
+
|
119
|
+
old-ie.scss:
|
120
|
+
|
121
|
+
// Enable support for old IE
|
122
|
+
$old-ie-support: true;
|
123
|
+
|
124
|
+
// Set the breakpoint for old IE
|
125
|
+
$old-ie-breakpoint: desktop;
|
126
|
+
|
127
|
+
// Import the main stylesheet
|
128
|
+
@import "style";
|
129
|
+
|
130
|
+
|
131
|
+
`$old-ie-support` Enables support for old-IE, the main styles and old-IE-specific styles will be compiled to your new old-IE-only stylesheet.
|
110
132
|
|
111
|
-
|
133
|
+
`$old-ie-breakpoint` Styles from this breakpoint will be compiled (without media queries) into the IE-only stylesheet.
|
112
134
|
|
135
|
+
That's it. Three lines of code and you get a new stylesheet for browsers that don't support media queries.
|
136
|
+
|
137
|
+
#### respond-to(ie)
|
138
|
+
|
139
|
+
Whenever you need to add old-IE specific rules, simply use the respond-to() mixin as you would with your media queries in your main stylesheet.
|
140
|
+
|
141
|
+
An example on style.scss:
|
142
|
+
|
143
|
+
.block {
|
144
|
+
padding: 10px;
|
145
|
+
|
146
|
+
// Only gets compiled on you main stylesheet (style.css)
|
147
|
+
@include respon-to(tablet-only) {
|
148
|
+
background: blue;
|
149
|
+
}
|
150
|
+
|
151
|
+
// Gets compiled on you main stylesheet (style.css)
|
152
|
+
// AND on ie-only.css (without the media query)
|
153
|
+
@include respond-to(desktop-and-up) {
|
154
|
+
background-color: yellow;
|
155
|
+
}
|
156
|
+
|
157
|
+
// Only gets compiled on ie-only.css
|
158
|
+
@include respond-to(ie) {
|
159
|
+
border: solid 1px red;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
The resulting old-ie.css is:
|
164
|
+
|
165
|
+
.block {
|
166
|
+
padding: 10px;
|
167
|
+
background-color: yellow;
|
168
|
+
border: solid 1px red;
|
169
|
+
}
|
113
170
|
|
114
171
|
## What's next?
|
115
172
|
|
116
|
-
- Support for more media features (height, device-dimensions, orientation, retina displays, …)
|
173
|
+
- Support for more media features (height, device-dimensions, orientation, retina displays, …)
|
174
|
+
- Combined media queries? _e.g. respond-to(mobile-only && retina)_
|
data/lib/responder/version.rb
CHANGED
@@ -6,9 +6,19 @@
|
|
6
6
|
|
7
7
|
$breakpoint-info: getBreakpointInfo($breakpoint);
|
8
8
|
|
9
|
+
// Breakpoint info error
|
9
10
|
@if $breakpoint-info == 'error' {
|
10
11
|
@warn '[ERROR] Invalid breakpoint parameter';
|
12
|
+
|
13
|
+
// Respond to IE
|
14
|
+
} @else if $breakpoint-info == 'ie' {
|
15
|
+
// Only print content if support is true
|
16
|
+
@if $old-ie-support == true {
|
17
|
+
@content;
|
18
|
+
}
|
19
|
+
|
11
20
|
} @else {
|
21
|
+
|
12
22
|
$breakpoint-name: nth($breakpoint-info, 1);
|
13
23
|
$breakpoint-extend: nth($breakpoint-info, 2);
|
14
24
|
$breakpoint-group: nth($breakpoint-info, 3);
|
@@ -17,33 +27,40 @@
|
|
17
27
|
$min-width: 0;
|
18
28
|
$max-width: 0;
|
19
29
|
|
20
|
-
|
21
|
-
|
22
|
-
|
30
|
+
@if $old-ie-support == true {
|
31
|
+
@if $breakpoint-name == $old-ie-breakpoint or $breakpoint-name == $old-ie-breakpoint {
|
32
|
+
@content;
|
33
|
+
}
|
34
|
+
} @else {
|
23
35
|
|
24
|
-
//
|
25
|
-
@if
|
26
|
-
$
|
27
|
-
|
28
|
-
|
29
|
-
|
36
|
+
// If it's a regular breakpoint
|
37
|
+
@if $breakpoint-group == false {
|
38
|
+
$min-width: nth($breakpoint-values, index($breakpoint-names, $breakpoint-name));
|
39
|
+
|
40
|
+
// Only set a max-width if it's not the last breakpoint
|
41
|
+
@if (index($breakpoint-names, $breakpoint-name) + 1) <= length($breakpoint-values) {
|
42
|
+
$max-width: nth($breakpoint-values, (index($breakpoint-names, $breakpoint-name) + 1));
|
30
43
|
} @else {
|
31
|
-
$breakpoint-extend
|
44
|
+
@if $breakpoint-extend == and-below {
|
45
|
+
$max-width: nth($breakpoint-values, (index($breakpoint-names, $breakpoint-name)));
|
46
|
+
} @else {
|
47
|
+
$breakpoint-extend: and-up;
|
48
|
+
}
|
32
49
|
}
|
33
|
-
}
|
34
50
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
51
|
+
// If it's a breakpoint group
|
52
|
+
} @else {
|
53
|
+
$min-width: nth( nth($breakpoint-groups, $breakpoint-group-id), 2);
|
54
|
+
$max-width: nth( nth($breakpoint-groups, $breakpoint-group-id), 3);
|
55
|
+
}
|
40
56
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
57
|
+
@if $breakpoint-extend == only {
|
58
|
+
@media #{$responder-media-type} and (min-width: getSize($min-width)) and (max-width: getSize($max-width - 1)) { @content; }
|
59
|
+
} @else if $breakpoint-extend == and-up {
|
60
|
+
@media #{$responder-media-type} and (min-width: getSize($min-width)) { @content; }
|
61
|
+
} @else if $breakpoint-extend == and-below {
|
62
|
+
@media #{$responder-media-type} and (max-width: getSize($max-width - 1)) { @content; }
|
63
|
+
}
|
47
64
|
}
|
48
65
|
}
|
49
66
|
}
|
@@ -102,39 +102,44 @@
|
|
102
102
|
|
103
103
|
@function getBreakpointInfo($breakpoint) {
|
104
104
|
|
105
|
-
|
106
|
-
|
105
|
+
@if $breakpoint == ie {
|
106
|
+
@return ie;
|
107
|
+
} @else {
|
107
108
|
|
108
|
-
|
109
|
-
|
109
|
+
// capture the extension (only, and-up or and-below)
|
110
|
+
$extension: regex($breakpoint, '((and-)?[a-z]+)$');
|
110
111
|
|
111
|
-
|
112
|
-
|
112
|
+
// capture the breakpoint name
|
113
|
+
$root: regex($breakpoint, '(.*?)-'+ $extension + '$');
|
113
114
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
$
|
118
|
-
|
119
|
-
|
120
|
-
|
115
|
+
// Check if it's a normal breakpoint
|
116
|
+
@for $i from 1 through length($breakpoint-names) {
|
117
|
+
|
118
|
+
@if $root == nth($breakpoint-names, $i) {
|
119
|
+
$group: false;
|
120
|
+
$groupid: false;
|
121
|
+
$br: join($root, $extension, space);
|
122
|
+
$br: join($br, $group, space);
|
123
|
+
$br: join($br, $groupid, space);
|
124
|
+
@return $br;
|
125
|
+
}
|
121
126
|
}
|
122
|
-
}
|
123
127
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
128
|
+
// Check if it's a group
|
129
|
+
@for $i from 1 through length($breakpoint-groups) {
|
130
|
+
@if $root == nth(nth($breakpoint-groups, $i),1) {
|
131
|
+
$group: true;
|
132
|
+
$groupid: $i;
|
133
|
+
$br: join($root, $extension, space);
|
134
|
+
$br: join($br, $group, space);
|
135
|
+
$br: join($br, $groupid, space);
|
136
|
+
@return $br;
|
137
|
+
}
|
133
138
|
}
|
134
|
-
}
|
135
139
|
|
136
|
-
|
137
|
-
|
140
|
+
@warn '[ERROR] "' + $breakpoint + '"" is not a valid parameter. Please, check the breakpoint name and also make sure you used -only, -and-up, or -and-below]';
|
141
|
+
@return 'error';
|
142
|
+
}
|
138
143
|
}
|
139
144
|
|
140
145
|
// =============================================================================
|
data/scss/responder.scss
CHANGED
@@ -31,6 +31,8 @@ $breakpoint-groups: ();
|
|
31
31
|
$responder-use-ems: true !default;
|
32
32
|
$responder-ems-context: $base-font-size !default;
|
33
33
|
$responder-media-type: screen !default;
|
34
|
+
$old-ie-support: false !default;
|
35
|
+
$old-ie-breakpoint: false !default;
|
34
36
|
|
35
37
|
// =============================================================================
|
36
38
|
// 2. Initialization
|
@@ -0,0 +1,82 @@
|
|
1
|
+
/* line 17, ../scss/style.scss */
|
2
|
+
body {
|
3
|
+
font: 16px/21px "Helvetica Neue", Arial, sans-serif;
|
4
|
+
}
|
5
|
+
|
6
|
+
/* line 24, ../scss/style.scss */
|
7
|
+
.wrapper {
|
8
|
+
margin: 0 auto;
|
9
|
+
padding: 0 1em;
|
10
|
+
max-width: 1000px;
|
11
|
+
}
|
12
|
+
|
13
|
+
/* line 30, ../scss/style.scss */
|
14
|
+
tr > td:first-child {
|
15
|
+
width: 80%;
|
16
|
+
}
|
17
|
+
|
18
|
+
/* line 45, ../scss/style.scss */
|
19
|
+
.mq-mixins-test {
|
20
|
+
width: 100%;
|
21
|
+
}
|
22
|
+
/* line 51, ../scss/style.scss */
|
23
|
+
.mq-mixins-test tbody .response-example {
|
24
|
+
text-align: center;
|
25
|
+
color: #ccc;
|
26
|
+
}
|
27
|
+
/* line 54, ../scss/style.scss */
|
28
|
+
.mq-mixins-test tbody .response-example .isResponding {
|
29
|
+
display: none;
|
30
|
+
}
|
31
|
+
/* line 63, ../scss/style.scss */
|
32
|
+
.mq-mixins-test tbody .respond-to-desktop-only {
|
33
|
+
background: #a7e040;
|
34
|
+
color: white;
|
35
|
+
}
|
36
|
+
/* line 41, ../scss/style.scss */
|
37
|
+
.mq-mixins-test tbody .respond-to-desktop-only .isResponding {
|
38
|
+
display: inline;
|
39
|
+
}
|
40
|
+
/* line 42, ../scss/style.scss */
|
41
|
+
.mq-mixins-test tbody .respond-to-desktop-only .isInactive {
|
42
|
+
display: none;
|
43
|
+
}
|
44
|
+
/* line 63, ../scss/style.scss */
|
45
|
+
.mq-mixins-test tbody .respond-to-desktop-and-up {
|
46
|
+
background: #a7e040;
|
47
|
+
color: white;
|
48
|
+
}
|
49
|
+
/* line 41, ../scss/style.scss */
|
50
|
+
.mq-mixins-test tbody .respond-to-desktop-and-up .isResponding {
|
51
|
+
display: inline;
|
52
|
+
}
|
53
|
+
/* line 42, ../scss/style.scss */
|
54
|
+
.mq-mixins-test tbody .respond-to-desktop-and-up .isInactive {
|
55
|
+
display: none;
|
56
|
+
}
|
57
|
+
/* line 63, ../scss/style.scss */
|
58
|
+
.mq-mixins-test tbody .respond-to-desktop-and-below {
|
59
|
+
background: #a7e040;
|
60
|
+
color: white;
|
61
|
+
}
|
62
|
+
/* line 41, ../scss/style.scss */
|
63
|
+
.mq-mixins-test tbody .respond-to-desktop-and-below .isResponding {
|
64
|
+
display: inline;
|
65
|
+
}
|
66
|
+
/* line 42, ../scss/style.scss */
|
67
|
+
.mq-mixins-test tbody .respond-to-desktop-and-below .isInactive {
|
68
|
+
display: none;
|
69
|
+
}
|
70
|
+
/* line 71, ../scss/style.scss */
|
71
|
+
.mq-mixins-test tbody .respond-to-ie {
|
72
|
+
background: #a7e040;
|
73
|
+
color: white;
|
74
|
+
}
|
75
|
+
/* line 41, ../scss/style.scss */
|
76
|
+
.mq-mixins-test tbody .respond-to-ie .isResponding {
|
77
|
+
display: inline;
|
78
|
+
}
|
79
|
+
/* line 42, ../scss/style.scss */
|
80
|
+
.mq-mixins-test tbody .respond-to-ie .isInactive {
|
81
|
+
display: none;
|
82
|
+
}
|
data/test/index.html
CHANGED
@@ -4,7 +4,12 @@
|
|
4
4
|
<meta charset="UTF-8">
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
6
6
|
<title>Responder testing</title>
|
7
|
+
<!--[if lte IE 8]>
|
8
|
+
<link href="/css/style-old-ie.css" rel="stylesheet">
|
9
|
+
<![endif]-->
|
10
|
+
<!--[if gt IE 8]><!-->
|
7
11
|
<link href="/css/style.css" rel="stylesheet">
|
12
|
+
<!--<![endif]-->
|
8
13
|
</head>
|
9
14
|
<body>
|
10
15
|
<div class="wrapper">
|
@@ -22,6 +27,9 @@
|
|
22
27
|
<li>desktop 992px</li>
|
23
28
|
</ul>
|
24
29
|
|
30
|
+
<h2>Support for old-IE</h2>
|
31
|
+
<pre><code>$old-ie-breakpoint: desktop</code></pre>
|
32
|
+
|
25
33
|
<h2>Respond-to mixin</h2>
|
26
34
|
<p>Resize your browser!</p>
|
27
35
|
|
@@ -148,6 +156,26 @@
|
|
148
156
|
</tr>
|
149
157
|
</tbody>
|
150
158
|
</table>
|
159
|
+
|
160
|
+
<hr>
|
161
|
+
|
162
|
+
<h3>Old IE</h3>
|
163
|
+
|
164
|
+
<table class="mq-mixins-test">
|
165
|
+
<thead>
|
166
|
+
<tr>
|
167
|
+
<th>Mixin</th>
|
168
|
+
<th>Response</th>
|
169
|
+
</tr>
|
170
|
+
</thead>
|
171
|
+
<tbody>
|
172
|
+
<tr>
|
173
|
+
<td><code class="language-css">respond-to(ie)</code></td>
|
174
|
+
<td class="response-example respond-to-ie"><span class="isInactive">inactive</span> <span class="isResponding">responding</span></td>
|
175
|
+
</tr>
|
176
|
+
</tbody>
|
177
|
+
</table>
|
178
|
+
|
151
179
|
</div> <!-- /wrapper -->
|
152
180
|
|
153
181
|
</body>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// Respond-to IE Test Bed
|
3
|
+
//
|
4
|
+
// =============================================================================
|
5
|
+
|
6
|
+
// Enable support for old IE
|
7
|
+
$old-ie-support: true;
|
8
|
+
|
9
|
+
// Set the breakpoint for old IE
|
10
|
+
$old-ie-breakpoint: desktop;
|
11
|
+
|
12
|
+
// Import the main stylesheet
|
13
|
+
@import "style";
|
data/test/scss/style.scss
CHANGED
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: responder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.0.3
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Daniel Guillan
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2012-10-
|
17
|
+
date: 2012-10-24 00:00:00 Z
|
19
18
|
dependencies:
|
20
19
|
- !ruby/object:Gem::Dependency
|
21
20
|
name: sass
|
@@ -85,8 +84,10 @@ files:
|
|
85
84
|
- scss/responder/_respond-to.scss
|
86
85
|
- scss/responder/functions.scss
|
87
86
|
- test/config.rb
|
87
|
+
- test/css/style-old-ie.css
|
88
88
|
- test/css/style.css
|
89
89
|
- test/index.html
|
90
|
+
- test/scss/style-old-ie.scss
|
90
91
|
- test/scss/style.scss
|
91
92
|
homepage: http://github.com/danielguillan/responder
|
92
93
|
licenses: []
|
@@ -123,6 +124,8 @@ specification_version: 3
|
|
123
124
|
summary: Magic media queries for your Compass project
|
124
125
|
test_files:
|
125
126
|
- test/config.rb
|
127
|
+
- test/css/style-old-ie.css
|
126
128
|
- test/css/style.css
|
127
129
|
- test/index.html
|
130
|
+
- test/scss/style-old-ie.scss
|
128
131
|
- test/scss/style.scss
|