File: _context.scss

package info (click to toggle)
compass-breakpoint-plugin 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 648 kB
  • sloc: javascript: 27; makefile: 2; sh: 1
file content (95 lines) | stat: -rw-r--r-- 3,143 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//////////////////////////////
// Private Breakpoint Variables
//////////////////////////////
$private-breakpoint-context-holder: ();
$private-breakpoint-query-count: 0 !default;

//////////////////////////////
// Breakpoint Has Context
// Returns whether or not you are inside a Breakpoint query
//////////////////////////////
@function breakpoint-has-context() {
  @if length($private-breakpoint-query-count) {
    @return true;
  }
  @else {
    @return false;
  }
}

//////////////////////////////
// Breakpoint Get Context
// $feature: Input feature to get it's current MQ context. Returns false if no context
//////////////////////////////
@function breakpoint-get-context($feature) {
  @if map-has-key($private-breakpoint-context-holder, $feature) {
    $get: map-get($private-breakpoint-context-holder, $feature);
    // Special handling of no-query from get side so /false/ prepends aren't returned
    @if $feature == 'no-query' {
      @if type-of($get) == 'list' and length($get) > 1 and nth($get, 1) == false {
        $get: nth($get, length($get));
      }
    }
    @return $get;
  }
  @else {
    @if breakpoint-has-context() and $feature == 'media' {
      @return breakpoint-get('default media');
    }
    @else {
      @return false;
    }
  }
}

//////////////////////////////
// Private function to set context
//////////////////////////////
@function private-breakpoint-set-context($feature, $value) {
  @if $value == 'monochrome' {
    $feature: 'monochrome';
  }

  $current: map-get($private-breakpoint-context-holder, $feature);
  @if $current and length($current) == $private-breakpoint-query-count {
    @warn "You have already queried against `#{$feature}`. Unexpected things may happen if you query against the same feature more than once in the same `and` query. Breakpoint is overwriting the current context with `#{$value}`";
  }

  @if not map-has-key($private-breakpoint-context-holder, $feature) {
    $v-holder: ();
    @for $i from 1 to $private-breakpoint-query-count {
      @if $feature == 'media' {
        $v-holder: append($v-holder, breakpoint-get('default media'));
      }
      @else {
        $v-holder: append($v-holder, false);
      }
    }
    $v-holder: append($v-holder, $value);
    $private-breakpoint-context-holder: map-merge($private-breakpoint-context-holder, ($feature: $v-holder)) !global;
  }
  @else {
    $v-holder: map-get($private-breakpoint-context-holder, $feature);
    $length: length($v-holder);
    @for $i from $length to $private-breakpoint-query-count - 1 {
      @if $feature == 'media' {
        $v-holder: append($v-holder, breakpoint-get('default media'));
      }
      @else {
        $v-holder: append($v-holder, false);
      }
    }
    $v-holder: append($v-holder, $value);
    $private-breakpoint-context-holder: map-merge($private-breakpoint-context-holder, ($feature: $v-holder)) !global;
  }

  @return true;
}

//////////////////////////////
// Private function to reset context
//////////////////////////////
@mixin private-breakpoint-reset-contexts {
  $private-breakpoint-context-holder: () !global;
  $private-breakpoint-query-count: 0 !global;
}