summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/breakpoints.js
diff options
context:
space:
mode:
authorJacob Schatz <jschatz1@gmail.com>2016-07-21 19:16:14 -0400
committerJacob Schatz <jschatz1@gmail.com>2016-07-21 19:16:14 -0400
commit08a2bdc560b949f359008f8c2c8d32a294ac48f8 (patch)
tree2ce8048810eb1e062eae2b27b24fef828a2cac69 /app/assets/javascripts/breakpoints.js
parent95c4825a456a4d1df8dba1def8735203368356c9 (diff)
downloadgitlab-ce-vanilla_js_no4.tar.gz
All files now JS instead of CSvanilla_js_no4
Diffstat (limited to 'app/assets/javascripts/breakpoints.js')
-rw-r--r--app/assets/javascripts/breakpoints.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/app/assets/javascripts/breakpoints.js b/app/assets/javascripts/breakpoints.js
new file mode 100644
index 00000000000..1e0148e5798
--- /dev/null
+++ b/app/assets/javascripts/breakpoints.js
@@ -0,0 +1,68 @@
+(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;
+ }
+ 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;
+ 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);