2017-01-10 23:02:20 +00:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, wrap-iife, one-var, no-var, one-var-declaration-per-line, quotes, no-shadow, prefer-arrow-callback, prefer-template, consistent-return, no-return-assign, new-parens, no-param-reassign, max-len */
|
2016-12-14 05:26:26 +00:00
|
|
|
|
2016-07-24 20:45:11 +00:00
|
|
|
(function() {
|
2016-12-14 05:26:26 +00:00
|
|
|
var Breakpoints = (function() {
|
2016-07-24 20:45:11 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-07-27 03:32:10 +00:00
|
|
|
// Create all the elements
|
2016-07-24 20:45:11 +00:00
|
|
|
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;
|
2017-01-13 21:54:16 +00:00
|
|
|
// TODO: Consider refactoring in light of turbolinks removal.
|
2016-07-27 03:32:10 +00:00
|
|
|
// the page refreshed via turbolinks
|
2016-07-24 20:45:11 +00:00
|
|
|
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));
|
|
|
|
|
2016-12-14 05:26:26 +00:00
|
|
|
window.Breakpoints = Breakpoints;
|
2017-02-10 06:50:50 +00:00
|
|
|
}).call(window);
|