breakpoint 1.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -47,7 +47,7 @@ This will install Sass 3.2. If you are compiling with CodeKit, [Chris Coyier has
47
47
  `compass create <my_project> -r breakpoint`
48
48
 
49
49
  #### If adding to existing project, in config.rb
50
- `require 'breakpoint`
50
+ `require 'breakpoint'`
51
51
 
52
52
  #### Import the breakpoint partial at the top of your working file
53
53
  `@import "breakpoint";`
@@ -79,7 +79,7 @@ $breakpoint-medium-width-em: 30em;
79
79
  // set min-width/max-width if both values are numbers
80
80
  $breakpoint-medium-not-wide: 500px 700px;
81
81
  // set min/max of feature if there are two numbers
82
- $breakpoint-medium-height: 300px 700px 'height';
82
+ $breakpoint-medium-height: height 300px 700px;
83
83
  // if one value is a string, assume a feature/value pair
84
84
  $breakpoint-kind-of-wide: min-width 700px;
85
85
  $breakpoint-not-too-wide: max-width 700px;
@@ -314,7 +314,7 @@ Caviats with Media Query context:
314
314
 
315
315
  ## No Query Fallback
316
316
 
317
- Breakpoint provides a way to generate fallback CSS for if you would like the CSS to apply even if media queries aren't available. There are three methidologies we discovered cover most, if not all, of the stylistic options a user could have in a system like this: a wrapping selector within the same stylesheet, a seperate stylesheet with no wrapping selector, and a seperate stylesheet with a wrapping selector. For both of these, bare in mind that Sass cannot create separate stylesheets automatically ([yet](https://github.com/nex3/sass/issues/241)), so you're going to need to do it by hand, but the tools we've provided are very powerful, so we think you'll like.
317
+ Breakpoint provides a way to generate fallback CSS for if you would like the CSS to apply even if media queries aren't available. There are three methidologies we discovered cover most, if not all, of the stylistic options a user could have in a system like this: a wrapping selector within the same stylesheet, a seperate stylesheet with no wrapping selector, and a seperate stylesheet with a wrapping selector. For both of these, bare in mind that Sass cannot create separate stylesheets automatically ([yet](https://github.com/nex3/sass/issues/241)), so you're going to need to do it by hand, but the tools we've provided are very powerful, so we think you'll like it anyway.
318
318
 
319
319
  There are now two new breakpoint flags to set that control no query support, `$breakpoint-no-queries` for specifying that only no query output should be output by Breakpoint and `$breakpoint-no-query-wrappers` for specifying that you want no query wrappers to be printed. Both of the new flags, `$breakpoint-no-queries` and `$breakpoint-no-query-wrappers` default to `false`, toggling them to `true` activates them. For the purposes of clarity in the following code samples, I'm including both flags even though the `false` flags are not explicitly needed. When passing in a wrapper, you must write the whole wrapper and may include a compound wrapper, *i.e.* `'.no-mqs'` or `'#print'` or `'.high-dpi.no-mqs'`. Variables may also be passed in, but they still require the whole wrapper.
320
320
 
data/lib/breakpoint.rb CHANGED
@@ -3,8 +3,8 @@ require 'compass'
3
3
  Compass::Frameworks.register("breakpoint", :path => "#{File.dirname(__FILE__)}/..")
4
4
 
5
5
  module Breakpoint
6
- VERSION = "1.3"
7
- DATE = "2012-08-28"
6
+ VERSION = "2.0.0"
7
+ DATE = "2012-04-05"
8
8
  end
9
9
 
10
10
  module Sass::Script::Functions
@@ -1,401 +1,131 @@
1
1
  //////////////////////////////
2
2
  // Default Variables
3
3
  //////////////////////////////
4
- $breakpoint-default-feature: 'min-width' !default;
5
- $breakpoint-default-media: 'all' !default;
6
- $breakpoint-force-media-all: false !default;
7
- $breakpoint-default-pair: 'width' !default;
8
- $breakpoint-to-ems: false !default;
9
- $breakpoint-prefixes: 'webkit' 'moz' !default;
10
- $breakpoint-prefixed-queries: 'device-pixel-ratio' 'min-device-pixel-ratio' 'max-device-pixel-ratio' !default;
4
+ // Default Features
5
+ $breakpoint-default-media: all !default;
6
+ $breakpoint-default-feature: min-width !default;
7
+ $breakpoint-default-pair: width !default;
11
8
 
12
- $breakpoint-no-queries: false !default;
13
- $breakpoint-no-query-wrappers: false !default;
9
+ // Default Transforms
10
+ $breakpoint-force-media-all: false !default;
11
+ $breakpoint-to-ems: false !default;
12
+ $breakpoint-resolutions: true !default;
14
13
 
15
- $breakpoint-base-font-size: false;
14
+ // Default No Query Options
15
+ $breakpoint-no-queries: false !default;
16
+ $breakpoint-no-query-wrappers: false !default;
17
+
18
+ // Deftault Base Font Size
19
+ $breakpoint-base-font-size: 16px !default;
20
+
21
+ // Legacy Syntax Support
22
+ $breakpoint-legacy-syntax: false !default;
16
23
 
17
24
  //////////////////////////////
18
- // Import Breakpoint Helpers
25
+ // Imports
19
26
  //////////////////////////////
20
- @import 'breakpoint/helpers';
21
27
  @import 'breakpoint/context';
28
+ @import 'breakpoint/helpers';
29
+ @import 'breakpoint/parsers';
30
+ @import 'breakpoint/no-query';
31
+
32
+ @import 'breakpoint/respond-to';
22
33
 
23
34
  //////////////////////////////
24
35
  // Breakpoint Mixin
25
36
  //////////////////////////////
26
- @mixin breakpoint($breakpoint, $media: $breakpoint-default-media, $no-query: false, $base-font-size: $breakpoint-base-font-size) {
27
- // Query and Media String Defaults
28
- $query: false !default;
29
- $query-holder: false !default;
30
- $media-string: false !default;
31
- $do-prefix: false !default;
32
-
33
- $webkit: false !default;
34
- $webkit-first: true !default;
35
- $moz: false !default;
36
- $moz-first: true !default;
37
- $o: false !default;
38
- $o-first: true !default;
39
- $ms: false !default;
40
- $ms-first: true !default;
41
37
 
42
- // Holder for Count
43
- $first: true !default;
38
+ @mixin breakpoint($query) {
39
+ // Internal Variables
40
+ $query-string: '';
44
41
 
45
- // Reset Context
46
- @include TXkgcmVzZXQhIEdvIGF3YXkh;
42
+ // Reset contexts
43
+ @include private-breakpoint-reset-contexts();
47
44
 
48
- // Set Media Context
49
- $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh('media', $media);
45
+ // Test to see if it's a comma-separated list
46
+ $or-list: is-breakpoint-list($query);
47
+ $query-fallback: false;
50
48
 
51
- // Initialize Query String
52
- @if $media != 'all' or $breakpoint-force-media-all {
53
- $media-string: "#{$media} ";
54
- }
55
- @else {
56
- $media-string: "";
57
- }
58
-
59
- // If we have a single query, let's just work with that.
60
- @if is_breakpoint_list($breakpoint) == false {
61
- @each $prefix-query in $breakpoint-prefixed-queries {
62
- @if $do-prefix == false {
63
- $do-prefix: featureExists($prefix-query, $breakpoint);
64
- }
65
- }
66
- @if $do-prefix {
67
- @each $prfx in $breakpoint-prefixes {
68
- @if $prfx == 'webkit' {
69
- $webkit: breakpoint-switch($breakpoint, $media-string, true, $prfx, $base-font-size: $base-font-size);
70
- }
71
49
 
72
- @if $prfx == 'moz' {
73
- $moz: breakpoint-switch($breakpoint, $media-string, true, $prfx, $base-font-size: $base-font-size);
74
- }
50
+ @if ($or-list != false and $breakpoint-legacy-syntax == false) {
51
+ $length: length($query);
75
52
 
76
- @if $prfx == 'o' {
77
- $o: breakpoint-switch($breakpoint, $media-string, true, $prfx, $base-font-size: $base-font-size);
78
- }
53
+ $last: nth($query, $length);
54
+ $query-fallback: breakpoint-no-query($last);
79
55
 
80
- @if $prfx == 'ms' {
81
- $ms: breakpoint-switch($breakpoint, $media-string, true, $prfx, $base-font-size: $base-font-size);
82
- }
83
- }
84
- }
85
- @else {
86
- $query: breakpoint-switch($breakpoint, $media-string, true, $base-font-size: $base-font-size);
87
- }
88
- }
89
- @else {
90
- // See if Prefix Query exists
91
- @each $prefix-query in $breakpoint-prefixed-queries {
92
- @if $do-prefix == false {
93
- $do-prefix: featureExists($prefix-query, $breakpoint);
94
- }
56
+ @if ($query-fallback != false) {
57
+ $length: $length - 1;
95
58
  }
96
59
 
97
- @if $do-prefix {
98
- @each $prfx in $breakpoint-prefixes {
99
- @each $bkpt in $breakpoint {
100
- @if $prfx == 'webkit' {
101
- @if $webkit-first {
102
- $webkit: breakpoint-switch($bkpt, $media-string, true, $prfx, $base-font-size: $base-font-size);
103
- $webkit-first: false;
104
- }
105
- @else {
106
- $webkit: join($webkit, breakpoint-switch($bkpt, $media-string, $prefix: $prfx, $base-font-size: $base-font-size));
107
- }
108
- }
109
60
 
110
- @if $prfx == 'moz' {
111
- @if $moz-first {
112
- $moz: breakpoint-switch($bkpt, $media-string, true, $prfx, $base-font-size: $base-font-size);
113
- $moz-first: false;
114
- }
115
- @else {
116
- $moz: join($moz, breakpoint-switch($bkpt, $media-string, $prefix: $prfx, $base-font-size: $base-font-size));
117
- }
118
- }
119
-
120
- @if $prfx == 'o' {
121
- @if $o-first {
122
- $o: breakpoint-switch($bkpt, $media-string, true, $prfx, $base-font-size: $base-font-size);
123
- $o-first: false;
124
- }
125
- @else {
126
- $o: join($o, breakpoint-switch($bkpt, $media-string, $prefix: $prfx, $base-font-size: $base-font-size));
127
- }
128
- }
129
-
130
- @if $prfx == 'ms' {
131
- @if $ms-first {
132
- $ms: breakpoint-switch($bkpt, $media-string, true, $prfx, $base-font-size: $base-font-size);
133
- $ms-first: false;
134
- }
135
- @else {
136
- $ms: join($ms, breakpoint-switch($bkpt, $media-string, $prefix: $prfx, $base-font-size: $base-font-size));
137
- }
138
- }
139
- }
140
- }
141
- }
142
- @else {
143
- @each $bkpt in $breakpoint {
144
- @if $first == true {
145
- $query: breakpoint-switch($bkpt, $media-string, true, $base-font-size: $base-font-size);
146
- $first: false;
147
- }
148
- @else {
149
- $query: join($query, breakpoint-switch($bkpt, $media-string, $base-font-size: $base-font-size));
150
- }
151
- }
152
- }
153
- }
154
-
155
- @if $breakpoint-no-queries {
156
- @if $no-query {
157
- $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh('no queries', true);
158
- @if $breakpoint-no-query-wrappers and type-of($no-query) == string {
159
- #{$no-query} & {
160
- @content;
161
- $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh('no query wrapper', $no-query);
162
- }
61
+ @for $i from 1 through $length {
62
+ @if $i == 1 {
63
+ $query-string: breakpoint-parse(nth($query, $i));
163
64
  }
164
65
  @else {
165
- @content;
66
+ $query-string: $query-string + ', ' + breakpoint-parse(nth($query, $i));
166
67
  }
167
68
  }
168
69
  }
169
70
  @else {
170
- @if $breakpoint-no-query-wrappers and type-of($no-query) == string {
171
- #{$no-query} & {
172
- @content;
173
- $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh('no query wrapper', $no-query);
174
- }
175
- }
176
- @if $query {
177
- @media #{$query} {
178
- @content;
179
- }
180
- }
181
- @else {
182
- $pf-queries: $webkit, $moz, $o, $ms;
183
- $pf-query: ();
71
+ @if ($breakpoint-legacy-syntax == true) {
72
+ $length: length($query);
184
73
 
185
- @each $pfq in $pf-queries {
186
- @if $pfq {
187
- $pf-query: append($pf-query, $pfq, comma);
188
- }
189
- }
190
- @media #{$pf-query} {
191
- @content;
192
- }
193
- }
194
- }
74
+ $last: nth($query, $length);
75
+ $query-fallback: breakpoint-no-query($last);
195
76
 
196
- @include TXkgcmVzZXQhIEdvIGF3YXkh;
197
- }
198
-
199
- @function breakpoint-switch($breakpoint, $media-string, $first: false, $prefix: false, $base-font-size: $breakpoint-base-font-size) {
200
- // Feature/Value/Length/Query Placehoders:
201
- $feature: false !default;
202
- $min-feature: "min-#{$breakpoint-default-pair}" !default;
203
- $max-feature: "max-#{$breakpoint-default-pair}" !default;
204
- $value: false !default;
205
- $min-value: false !default;
206
- $max-value: false !default;
207
- $length: false !default;
208
- $query: false !default;
209
-
210
- $length: length($breakpoint);
211
- // Check to see if there is only one item.
212
- @if $length == 1 {
213
- $value: $breakpoint;
214
- @if type-of($breakpoint) == 'number' {
215
- $feature: $breakpoint-default-feature;
216
- }
217
-
218
- // If EM Breakpoints are active, do it!
219
- @if $breakpoint-to-ems and type-of($value) == 'number' {
220
- $value: breakpoint-to-base-em($value, $base-font-size);
221
- }
222
- // Build the Query
223
- $query: breakpoint-generate($media-string, $feature, $value, $first);
224
- // Set Context
225
- $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($feature, $value);
226
- }
227
- @else if $length == 2 {
228
- // If both are numbers, we've got a double!
229
- @if type-of(nth($breakpoint, 1)) == 'number' and type-of(nth($breakpoint, 2)) == 'number' {
230
- // See which is larger.
231
- @if nth($breakpoint, 1) > nth($breakpoint, 2) {
232
- $min-value: nth($breakpoint, 2);
233
- $max-value: nth($breakpoint, 1);
234
- }
235
- @else {
236
- $min-value: nth($breakpoint, 1);
237
- $max-value: nth($breakpoint, 2);
77
+ @if ($query-fallback != false) {
78
+ $length: $length - 1;
238
79
  }
239
80
 
240
- // If EM Breakpoints are active, do it!
241
- @if $breakpoint-to-ems and type-of($min-value) == 'number' {
242
- $min-value: breakpoint-to-base-em($min-value, $base-font-size);
243
- }
244
- @if $breakpoint-to-ems and type-of($max-value) == 'number' {
245
- $max-value: breakpoint-to-base-em($max-value, $base-font-size);
246
- }
81
+ $mq: ();
247
82
 
248
- // Min/Max for given
249
- $query: breakpoint-generate($media-string, $min-feature, $min-value, $first);
250
- $query: join($query, breakpoint-generate($media-string, $max-feature, $max-value));
251
- // Set Context
252
- $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($min-feature, $min-value);
253
- $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($max-feature, $max-value);
254
- }
255
- @else if type-of(nth($breakpoint, 1)) == 'string' and type-of(nth($breakpoint, 2)) == 'string' {
256
- @if breakpoint-string-value(nth($breakpoint, 1)) == true {
257
- $feature: nth($breakpoint, 1);
258
- $value: nth($breakpoint, 2);
259
- }
260
- @else {
261
- $feature: nth($breakpoint, 2);
262
- $value: nth($breakpoint, 1);
83
+ @for $i from 1 through $length {
84
+ $mq: append($mq, nth($query, $i), comma);
263
85
  }
264
86
 
265
- // If EM Breakpoints are active, do it!
266
- @if $breakpoint-to-ems and type-of($value) == 'number' {
267
- $value: breakpoint-to-base-em($value, $base-font-size);
268
- }
269
-
270
- // Build the Query
271
- $query: breakpoint-generate($media-string, $feature, $value, $first);
272
- // Set Context
273
- $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($feature, $value);
87
+ $query-string: breakpoint-parse($mq);
274
88
  }
275
89
  @else {
276
- // Because we can have either the first or second option be the feature, we switch on it.
277
- @if type-of(nth($breakpoint, 1)) == string {
278
- $feature: nth($breakpoint, 1);
279
- $value: nth($breakpoint, 2);
280
- }
281
- @else if type-of(nth($breakpoint, 2)) == string {
282
- $feature: nth($breakpoint, 2);
283
- $value: nth($breakpoint, 1);
284
- }
285
-
286
- @if $feature == 'device-pixel-ratio' or $feature == 'min-device-pixel-ratio' or $feature == 'max-device-pixel-ratio' {
287
- $feature: breakpoint-experimental($feature, $prefix);
288
- //$value: 96 * $value * 1dpi;
289
- // @if $feature == 'device-pixel-ratio' {
290
- // $feature: 'resolution';
291
- // }
292
- // @else if $feature == 'min-device-pixel-ratio' {
293
- // $feature: 'min-resolution';
294
- // }
295
- // @else if $feature == 'max-device-pixel-ratio' {
296
- // $feature: 'max-resolution';
297
- // }
298
- }
299
-
300
- // If EM Breakpoints are active, do it!
301
- @if $breakpoint-to-ems and type-of($value) == 'number' {
302
- $value: breakpoint-to-base-em($value, $base-font-size);
303
- }
304
-
305
- // Build the Query
306
- $query: breakpoint-generate($media-string, $feature, $value, $first);
307
- // Set Context
308
- $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($feature, $value);
90
+ $query-string: breakpoint-parse($query);
309
91
  }
310
92
  }
311
- @else if $length == 3 {
312
- @if type-of(nth($breakpoint, 1)) == 'string' {
313
- $feature: nth($breakpoint, 1);
314
- // See which is larger.
315
- @if nth($breakpoint, 2) > nth($breakpoint, 3) {
316
- $min-value: nth($breakpoint, 3);
317
- $max-value: nth($breakpoint, 2);
318
- }
319
- @else {
320
- $min-value: nth($breakpoint, 2);
321
- $max-value: nth($breakpoint, 3);
322
- }
323
- }
324
- @else {
325
- $feature: nth($breakpoint, 3);
326
- // See which is larger.
327
- @if nth($breakpoint, 1) > nth($breakpoint, 2) {
328
- $min-value: nth($breakpoint, 2);
329
- $max-value: nth($breakpoint, 1);
330
- }
331
- @else {
332
- $min-value: nth($breakpoint, 1);
333
- $max-value: nth($breakpoint, 2);
334
- }
335
- }
336
93
 
337
- // If EM Breakpoints are active, do it!
338
- @if $breakpoint-to-ems and type-of($min-value) == 'number' {
339
- $min-value: breakpoint-to-base-em($min-value, $base-font-size);
340
- }
341
- @if $breakpoint-to-ems and type-of($max-value) == 'number' {
342
- $max-value: breakpoint-to-base-em($max-value, $base-font-size);
343
- }
344
94
 
345
- @if breakpoint-min-max($feature) == true {
346
- @if $feature == 'device-pixel-ratio' {
347
- $min-feature: breakpoint-experimental('min-#{$feature}', $prefix);
348
- $max-feature: breakpoint-experimental('max-#{$feature}', $prefix);
349
- }
350
- @else {
351
- $min-feature: 'min-#{$feature}';
352
- $max-feature: 'max-#{$feature}';
353
- }
95
+ // Print Out Query String
354
96
 
355
- // Min/Max for given
356
- $query: breakpoint-generate($media-string, $min-feature, $min-value, $first);
357
- $query: join($query, breakpoint-generate($media-string, $max-feature, $max-value));
358
- // Set Context
359
- $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($min-feature, $min-value);
360
- $context: U2V0IHlvdXIgb3duIGRhbW4gY29udGV4dHMh($max-feature, $max-value);
361
- }
362
- @else {
363
- @warn '#{$feature} cannot have a min/max value!';
97
+ @if not $breakpoint-no-queries {
98
+ @media #{$query-string} {
99
+ @content;
364
100
  }
365
101
  }
366
102
 
367
- @return $query;
368
- }
103
+ @if $breakpoint-no-query-wrappers != false {
369
104
 
370
- @function breakpoint-generate($media, $feature, $value, $first: false) {
371
- // Media Query string to be returned
372
- $new-string: "";
105
+ $type: type-of($breakpoint-no-query-wrappers);
106
+ $print: false;
373
107
 
374
- // If it's the first item, it gets special treatment
375
- @if $first == true {
376
- // And Statement
377
- $and: 'and ';
378
- // If $media is blank (i.e. all), remove and statement
379
- @if $media == '' {
380
- $and: '';
108
+ @if ($type == 'bool') {
109
+ $print: true;
381
110
  }
382
-
383
- @if $feature != false {
384
- $new-string: #{$media}unquote("#{$and}(#{$feature}: #{$value})");
111
+ @else if ($type == 'string') {
112
+ @if $query-fallback == $breakpoint-no-query-wrappers {
113
+ $print: true;
114
+ }
385
115
  }
386
- @else {
387
- $new-string: #{$media}unquote("#{$and}(#{$value})");
116
+ @else if ($type == 'list') {
117
+ @each $wrapper in $breakpoint-no-query-wrappers {
118
+ @if $query-fallback == $wrapper {
119
+ $print: true;
120
+ }
121
+ }
388
122
  }
389
- }
390
123
 
391
- @else {
392
- @if $feature != false {
393
- $new-string: unquote("and (#{$feature}: #{$value})");
394
- }
395
- @else {
396
- $new-string: unquote("and (#{$value})");
124
+ @if ($query-fallback != false) and ($print == true) {
125
+ #{$query-fallback} & {
126
+ @content;
127
+ }
397
128
  }
398
129
  }
399
130
 
400
- @return $new-string;
401
131
  }