summaryrefslogtreecommitdiff
path: root/app/assets
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2016-03-11 15:11:11 +0000
committerPhil Hughes <me@iamphill.com>2016-03-14 11:39:56 +0000
commitf0f6723fe02bfb1a79c1cbefed156a420dddc352 (patch)
tree493a93b8c22abe55e45791bc6ff2c2e3e6b79c42 /app/assets
parentce9bbce78a258b43181766bcbebad7add90968ff (diff)
downloadgitlab-ce-f0f6723fe02bfb1a79c1cbefed156a420dddc352.tar.gz
Created bootstrap breakpoint class
This class checks the current bootstrap breakpoint
Diffstat (limited to 'app/assets')
-rw-r--r--app/assets/javascripts/application.js.coffee27
-rw-r--r--app/assets/javascripts/breakpoints.coffee24
-rw-r--r--app/assets/javascripts/sidebar.js.coffee7
-rw-r--r--app/assets/stylesheets/framework/header.scss18
-rw-r--r--app/assets/stylesheets/framework/sidebar.scss2
5 files changed, 41 insertions, 37 deletions
diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee
index 1212e89975b..9e114a80c27 100644
--- a/app/assets/javascripts/application.js.coffee
+++ b/app/assets/javascripts/application.js.coffee
@@ -256,35 +256,15 @@ $ ->
$('.right-sidebar')
.hasClass('right-sidebar-collapsed'), { path: '/' })
- bootstrapBreakpoint = undefined;
- checkBootstrapBreakpoints = ->
- if $('.device-xs').is(':visible')
- bootstrapBreakpoint = "xs"
- else if $('.device-sm').is(':visible')
- bootstrapBreakpoint = "sm"
- else if $('.device-md').is(':visible')
- bootstrapBreakpoint = "md"
- else if $('.device-lg').is(':visible')
- bootstrapBreakpoint = "lg"
-
- setBootstrapBreakpoints = ->
- if $('.device-xs').length
- return
-
- $("body")
- .append('<div class="device-xs visible-xs"></div>'+
- '<div class="device-sm visible-sm"></div>'+
- '<div class="device-md visible-md"></div>'+
- '<div class="device-lg visible-lg"></div>')
- checkBootstrapBreakpoints()
-
fitSidebarForSize = ->
oldBootstrapBreakpoint = bootstrapBreakpoint
checkBootstrapBreakpoints()
+ bootstrapBreakpoint = breakpoints.getBreakpointSize()
if bootstrapBreakpoint != oldBootstrapBreakpoint
$(document).trigger('breakpoint:change', [bootstrapBreakpoint])
checkInitialSidebarSize = ->
+ bootstrapBreakpoint = breakpoints.getBreakpointSize()
if bootstrapBreakpoint is "xs" or "sm"
$(document).trigger('breakpoint:change', [bootstrapBreakpoint])
@@ -293,6 +273,7 @@ $ ->
.on "resize", (e) ->
fitSidebarForSize()
- setBootstrapBreakpoints()
checkInitialSidebarSize()
+ breakpoints = new Breakpoints()
+ bootstrapBreakpoint = breakpoints.getBreakpointSize()
new Aside()
diff --git a/app/assets/javascripts/breakpoints.coffee b/app/assets/javascripts/breakpoints.coffee
new file mode 100644
index 00000000000..fd2ee8efa2c
--- /dev/null
+++ b/app/assets/javascripts/breakpoints.coffee
@@ -0,0 +1,24 @@
+class @Breakpoints
+ BREAKPOINTS = ["xs", "sm", "md", "lg"]
+
+ constructor: ->
+ @setup()
+
+ setup: ->
+ allDeviceSelector = BREAKPOINTS.map (breakpoint) ->
+ ".device-#{breakpoint}"
+
+ if $(allDeviceSelector.join(",")).length
+ return
+
+ # Create all the elements
+ $.each BREAKPOINTS, (i, breakpoint) ->
+ $("body").append "<div class='device-#{breakpoint} visible-#{breakpoint}'></div>"
+
+ getBreakpointSize: ->
+ allDeviceSelector = BREAKPOINTS.map (breakpoint) ->
+ ".device-#{breakpoint}"
+
+ $visibleDevice = $(allDeviceSelector.join(",")).filter(":visible")
+
+ return $visibleDevice.attr("class").split("visible-")[1]
diff --git a/app/assets/javascripts/sidebar.js.coffee b/app/assets/javascripts/sidebar.js.coffee
index 1ffb6619ab5..5c68690979d 100644
--- a/app/assets/javascripts/sidebar.js.coffee
+++ b/app/assets/javascripts/sidebar.js.coffee
@@ -1,4 +1,4 @@
-mobileWidth = 768
+mobileWidth = 991
collapsed = 'page-sidebar-collapsed'
expanded = 'page-sidebar-expanded'
@@ -21,6 +21,9 @@ $(document).on("click", '.toggle-nav-collapse', (e) ->
)
$ ->
- if $(window).width() < mobileWidth
+ breakpoints = new Breakpoints()
+ size = breakpoints.getBreakpointSize()
+
+ if size is "xs" or size is "sm"
if $('.page-with-sidebar').hasClass(expanded)
toggleSidebar()
diff --git a/app/assets/stylesheets/framework/header.scss b/app/assets/stylesheets/framework/header.scss
index 9aa97f6ac47..a73643b35ad 100644
--- a/app/assets/stylesheets/framework/header.scss
+++ b/app/assets/stylesheets/framework/header.scss
@@ -141,22 +141,18 @@ header {
margin-left: $sidebar_collapsed_width;
}
-@media (max-width: $screen-sm-min) {
- .header-collapsed {
- margin-left: $sidebar_collapsed_width;
- }
+.header-collapsed {
+ margin-left: $sidebar_collapsed_width;
- .header-expanded {
- margin-left: $sidebar_collapsed_width;
+ @media (min-width: $screen-sm-max) {
+ @include collapsed-header;
}
}
-@media(min-width: $screen-sm-min) {
- .header-collapsed {
- @include collapsed-header;
- }
+.header-expanded {
+ margin-left: $sidebar_collapsed_width;
- .header-expanded {
+ @media (min-width: $screen-sm-max) {
margin-left: $sidebar_width;
}
}
diff --git a/app/assets/stylesheets/framework/sidebar.scss b/app/assets/stylesheets/framework/sidebar.scss
index 0f83bd8b556..24608e6cff2 100644
--- a/app/assets/stylesheets/framework/sidebar.scss
+++ b/app/assets/stylesheets/framework/sidebar.scss
@@ -205,7 +205,7 @@
@mixin expanded-sidebar {
padding-left: $sidebar_collapsed_width;
- @media (min-width: $screen-sm-min) {
+ @media (min-width: $screen-sm-max) {
padding-left: $sidebar_width;
}