summaryrefslogtreecommitdiffstats
path: root/core/js/js.js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-03-18 15:52:06 +0100
committerVincent Petry <pvince81@owncloud.com>2014-03-18 15:52:06 +0100
commitcc6c1529848022765b9be6be808cf4dfb5b2d029 (patch)
treeaa3b96f618ff629a2d9e8cb10ed2a0b836c4a7ad /core/js/js.js
parentfe04106e0f6a88b5e3cf490773f2cb625465e98a (diff)
downloadnextcloud-server-cc6c1529848022765b9be6be808cf4dfb5b2d029.tar.gz
nextcloud-server-cc6c1529848022765b9be6be808cf4dfb5b2d029.zip
Fixed matchMedia usage to make unit tests work in PhantomJS
PhantomJS has a bug that makes it impossible to properly stub window.matchMedia. This fix adds a wrapper as OC._matchMedia that is used for unit tests
Diffstat (limited to 'core/js/js.js')
-rw-r--r--core/js/js.js67
1 files changed, 37 insertions, 30 deletions
diff --git a/core/js/js.js b/core/js/js.js
index aefca235093..87b2d59f160 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -997,41 +997,48 @@ function initCore() {
*/
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();
- }
+ if (!OC._matchMedia) {
+ return;
+ }
+ var mq = OC._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();
+ updateMainMenu();
- // TODO: debounce this
- $(window).resize(function() {
- if (lastMatch !== mq.matches) {
- lastMatch = mq.matches;
- updateMainMenu();
- }
- });
- }
+ // TODO: debounce this
+ $(window).resize(function() {
+ if (lastMatch !== mq.matches) {
+ lastMatch = mq.matches;
+ updateMainMenu();
+ }
+ });
}
- setupMainMenu();
+ if (window.matchMedia) {
+ // wrapper needed for unit tests due to PhantomJS bugs
+ OC._matchMedia = function(media) {
+ return window.matchMedia(media);
+ }
+ setupMainMenu();
+ }
}
$(document).ready(initCore);