|
// Our respond-to mixin, with the new hotness? |
|
// A little more complicated than previous respond-to mixins, but not runs off of a variable. Truthfully, a little sloppy, but can't think of a better way to do it in just Sass ATM. This is also Rev 1 so if someone can help me make it better, I'm all ears. |
|
|
|
@mixin respond-to($context) { |
|
// Special case for Breakpoint Length equal to 2, 3, or 4 |
|
@if length($breakpoints) >= 2 and length($breakpoints) <= 4 { |
|
// Check to see if the 2nd item is a number. If it is, we've got a single query |
|
@if type-of(nth($breakpoints, 2)) == 'number' { |
|
// Check to see if the context matches the breakpoint namespace |
|
@if $context == nth($breakpoints, 1) { |
|
// Call Media Query Generator |
|
@include media-query-gen($breakpoints) { |
|
@content; |
|
} |
|
} |
|
} |
|
// Else, loop over all of them |
|
@else { |
|
// Loop over each breakpoint and check context |
|
@each $bkpt in $breakpoints { |
|
// If context is correct… |
|
@if $context == nth($bkpt, 1) { |
|
// Call the generator! |
|
@include media-query-gen($bkpt) { |
|
@content; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
// Else, loop over all of them |
|
@else { |
|
// Loop over each breakpoint and check context |
|
@each $bkpt in $breakpoints { |
|
// If context is correct… |
|
@if $context == nth($bkpt, 1) { |
|
// Call the generator! |
|
@include media-query-gen($bkpt) { |
|
@content; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
// This functionality gets used three times so I turned it into its own function. |
|
|
|
@mixin media-query-gen($bpt) { |
|
// Get length of breakpoint variable, minus the namespace |
|
$length: length($bpt); |
|
// Go through all of the breakpoint items, starting at the second, and add them to a variable to be passed into the media query mixin |
|
$mq: false !default; |
|
@for $i from 2 through $length { |
|
// If it's the first item, override $mq |
|
@if $i == 2 { |
|
$mq: nth($bpt, $i); |
|
} |
|
// Else, join $mq |
|
@else { |
|
$mq: join($mq, nth($bpt, $i)); |
|
} |
|
} |
|
// Call Media Query mixin |
|
@include media-query($mq) { |
|
@content; |
|
} |
|
} |
|
|
|
// Slightly modified version of my Media Query Mixin (https://gist.github.com/2490750) from earlier, modified to accommodate list input |
|
@mixin media-query($value, $operator: 'min-width', $query: 'screen') { |
|
// If a list is passed in for value, break it into value, operator, and query |
|
@if type-of($value) == 'list' { |
|
$mq: $value; |
|
|
|
@for $i from 1 through length($mq) { |
|
@if $i == 1 { |
|
$value: nth($mq, 1); |
|
} |
|
@else if $i == 2 { |
|
$operator: nth($mq, 2); |
|
} |
|
@else if $i == 3 { |
|
$query: nth($mq, 3); |
|
} |
|
} |
|
} |
|
|
|
@media #{$query} and (#{$operator}: #{$value}) { |
|
@content; |
|
} |
|
} |