summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/breakpoints.js
blob: 5d4d23e26c6a4608d35ed551117cf1c90436195a (plain)
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
/* eslint-disable */
(function() {
  this.Breakpoints = (function() {
    var BreakpointInstance, instance;

    function Breakpoints() {}

    instance = null;

    BreakpointInstance = (function() {
      var BREAKPOINTS;

      BREAKPOINTS = ["xs", "sm", "md", "lg"];

      function BreakpointInstance() {
        this.setup();
      }

      BreakpointInstance.prototype.setup = function() {
        var allDeviceSelector, els;
        allDeviceSelector = BREAKPOINTS.map(function(breakpoint) {
          return ".device-" + breakpoint;
        });
        if ($(allDeviceSelector.join(",")).length) {
          return;
        }
        // Create all the elements
        els = $.map(BREAKPOINTS, function(breakpoint) {
          return "<div class='device-" + breakpoint + " visible-" + breakpoint + "'></div>";
        });
        return $("body").append(els.join(''));
      };

      BreakpointInstance.prototype.visibleDevice = function() {
        var allDeviceSelector;
        allDeviceSelector = BREAKPOINTS.map(function(breakpoint) {
          return ".device-" + breakpoint;
        });
        return $(allDeviceSelector.join(",")).filter(":visible");
      };

      BreakpointInstance.prototype.getBreakpointSize = function() {
        var $visibleDevice;
        $visibleDevice = this.visibleDevice;
        // the page refreshed via turbolinks
        if (!$visibleDevice().length) {
          this.setup();
        }
        $visibleDevice = this.visibleDevice();
        return $visibleDevice.attr("class").split("visible-")[1];
      };

      return BreakpointInstance;

    })();

    Breakpoints.get = function() {
      return instance != null ? instance : instance = new BreakpointInstance;
    };

    return Breakpoints;

  })();

  $((function(_this) {
    return function() {
      return _this.bp = Breakpoints.get();
    };
  })(this));

}).call(this);