aboutsummaryrefslogtreecommitdiffstats
path: root/core/js/js.js
diff options
context:
space:
mode:
Diffstat (limited to 'core/js/js.js')
-rw-r--r--core/js/js.js59
1 files changed, 53 insertions, 6 deletions
diff --git a/core/js/js.js b/core/js/js.js
index 23d16b69234..aefca235093 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -488,7 +488,7 @@ var OC={
registerMenu: function($toggle, $menuEl) {
$menuEl.addClass('menu');
$toggle.addClass('menutoggle');
- $toggle.on('click', function(event) {
+ $toggle.on('click.menu', function(event) {
if ($menuEl.is(OC._currentMenu)) {
$menuEl.hide();
OC._currentMenu = null;
@@ -505,6 +505,17 @@ var OC={
OC._currentMenuToggle = $toggle;
return false
});
+ },
+
+ unregisterMenu: function($toggle, $menuEl) {
+ // close menu if opened
+ if ($menuEl.is(OC._currentMenu)) {
+ $menuEl.hide();
+ OC._currentMenu = null;
+ OC._currentMenuToggle = null;
+ }
+ $toggle.off('click.menu').removeClass('menutoggle');
+ $menuEl.removeClass('menu');
}
};
OC.search.customResults={};
@@ -978,13 +989,49 @@ function initCore() {
OC._currentMenuToggle = null;
});
- // toggle the navigation on mobile
- if (window.matchMedia) {
- var mq = window.matchMedia('(max-width: 600px)');
- if (mq && mq.matches) {
- OC.registerMenu($('#header #owncloud'), $('#navigation'));
+
+ /**
+ * Set up the main menu toggle to react to media query changes.
+ * If the screen is small enough, the main menu becomes a toggle.
+ * If the screen is bigger, the main menu is not a toggle any more.
+ */
+ function setupMainMenu() {
+ // toggle the navigation on mobile
+ if (window.matchMedia) {
+ var mq = window.matchMedia('(max-width: 600px)');
+ var lastMatch = mq.matches;
+ var $toggle = $('#header #owncloud');
+ var $navigation = $('#navigation');
+
+ function updateMainMenu() {
+ // mobile mode ?
+ if (lastMatch && !$toggle.hasClass('menutoggle')) {
+ // init the menu
+ OC.registerMenu($toggle, $navigation);
+ $toggle.data('oldhref', $toggle.attr('href'));
+ $toggle.attr('href', '#');
+ $navigation.hide();
+ }
+ else {
+ OC.unregisterMenu($toggle, $navigation);
+ $toggle.attr('href', $toggle.data('oldhref'));
+ $navigation.show();
+ }
+ }
+
+ updateMainMenu();
+
+ // TODO: debounce this
+ $(window).resize(function() {
+ if (lastMatch !== mq.matches) {
+ lastMatch = mq.matches;
+ updateMainMenu();
+ }
+ });
}
}
+
+ setupMainMenu();
}
$(document).ready(initCore);