2017-01-10 18:02:20 -05: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 00:26:26 -05:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
var Breakpoints = (function() {
|
|
|
|
var BreakpointInstance, instance;
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
function Breakpoints() {}
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
instance = null;
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
BreakpointInstance = (function() {
|
|
|
|
var BREAKPOINTS;
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
BREAKPOINTS = ["xs", "sm", "md", "lg"];
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
function BreakpointInstance() {
|
|
|
|
this.setup();
|
|
|
|
}
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
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(''));
|
|
|
|
};
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
BreakpointInstance.prototype.visibleDevice = function() {
|
|
|
|
var allDeviceSelector;
|
|
|
|
allDeviceSelector = BREAKPOINTS.map(function(breakpoint) {
|
|
|
|
return ".device-" + breakpoint;
|
|
|
|
});
|
|
|
|
return $(allDeviceSelector.join(",")).filter(":visible");
|
|
|
|
};
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
BreakpointInstance.prototype.getBreakpointSize = function() {
|
|
|
|
var $visibleDevice;
|
|
|
|
$visibleDevice = this.visibleDevice;
|
|
|
|
// TODO: Consider refactoring in light of turbolinks removal.
|
|
|
|
// the page refreshed via turbolinks
|
|
|
|
if (!$visibleDevice().length) {
|
|
|
|
this.setup();
|
|
|
|
}
|
|
|
|
$visibleDevice = this.visibleDevice();
|
|
|
|
return $visibleDevice.attr("class").split("visible-")[1];
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
return BreakpointInstance;
|
2016-07-24 16:45:11 -04:00
|
|
|
})();
|
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
Breakpoints.get = function() {
|
|
|
|
return instance != null ? instance : instance = new BreakpointInstance;
|
|
|
|
};
|
|
|
|
|
|
|
|
return Breakpoints;
|
|
|
|
})();
|
|
|
|
|
|
|
|
$(() => { window.bp = Breakpoints.get(); });
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
window.Breakpoints = Breakpoints;
|