From 1291303c5a312fad9f01fbaf22cc21e3b9b3675d Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Sun, 2 Mar 2014 22:30:24 +0100 Subject: Replace OC.Router.generate() with OC.generateUrl() --- core/js/js.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'core/js/js.js') diff --git a/core/js/js.js b/core/js/js.js index 21ccee0f1d5..80d83dc07f9 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -194,6 +194,27 @@ var OC={ linkToRemoteBase:function(service) { return OC.webroot + '/remote.php/' + service; }, + + generateUrl: function(url, params) { + var _build = function (text, vars) { + return text.replace(/{([^{}]*)}/g, + function (a, b) { + var r = vars[b]; + return typeof r === 'string' || typeof r === 'number' ? r : a; + } + ); + }; + if (url.charAt(0) !== '/') { + url = '/' + url; + + } + return OC.webroot + '/index.php' + _build(url, params); + }, + + linkToRoute:function(route) { + return OC.webroot + '/index.php/' + route; + }, + /** * @brief Creates an absolute url for remote use * @param string $service id @@ -791,12 +812,10 @@ function initCore() { if (interval < 60) { interval = 60; } - OC.Router.registerLoadedCallback(function(){ - var url = OC.Router.generate('heartbeat'); - setInterval(function(){ - $.post(url); - }, interval * 1000); - }); + var url = OC.linkToRoute('heartbeat'); + setInterval(function(){ + $.post(url); + }, interval * 1000); } // session heartbeat (defaults to enabled) -- cgit v1.2.3 From e1030c6b5f8775ad4aac13659757cd6cc3cd441b Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Sun, 2 Mar 2014 23:15:37 +0100 Subject: adding JSDoc + remove unused function --- core/js/js.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'core/js/js.js') diff --git a/core/js/js.js b/core/js/js.js index 80d83dc07f9..77aadd23e03 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -195,6 +195,13 @@ var OC={ return OC.webroot + '/remote.php/' + service; }, + /** + * Generates the absolute url for the given relative url, which can contain parameters. + * + * @returns {string} + * @param {string} url + * @param params + */ generateUrl: function(url, params) { var _build = function (text, vars) { return text.replace(/{([^{}]*)}/g, @@ -211,10 +218,6 @@ var OC={ return OC.webroot + '/index.php' + _build(url, params); }, - linkToRoute:function(route) { - return OC.webroot + '/index.php/' + route; - }, - /** * @brief Creates an absolute url for remote use * @param string $service id @@ -812,7 +815,7 @@ function initCore() { if (interval < 60) { interval = 60; } - var url = OC.linkToRoute('heartbeat'); + var url = OC.generateUrl('/heartbeat'); setInterval(function(){ $.post(url); }, interval * 1000); -- cgit v1.2.3 From 8e667d1934d6bd9b4344ac624fdd2846c89abb0a Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 6 Mar 2014 00:17:48 +0100 Subject: adding new javascript function OC.generateUrl(url, params) --- core/js/js.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'core/js/js.js') diff --git a/core/js/js.js b/core/js/js.js index 21ccee0f1d5..89797ed2a3c 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -175,6 +175,30 @@ var OC={ appswebroots:(typeof oc_appswebroots !== 'undefined') ? oc_appswebroots:false, currentUser:(typeof oc_current_user!=='undefined')?oc_current_user:false, coreApps:['', 'admin','log','search','settings','core','3rdparty'], + + /** + * Generates the absolute url for the given relative url, which can contain parameters. + * + * @returns {string} + * @param {string} url + * @param params + */ + generateUrl: function(url, params) { + var _build = function (text, vars) { + return text.replace(/{([^{}]*)}/g, + function (a, b) { + var r = vars[b]; + return typeof r === 'string' || typeof r === 'number' ? r : a; + } + ); + }; + if (url.charAt(0) !== '/') { + url = '/' + url; + + } + return OC.webroot + '/index.php' + _build(url, params); + }, + /** * get an absolute url to a file in an appen * @param app the id of the app the file belongs to -- cgit v1.2.3 From 256dca935bbd683515912f555cee90f8cc43b341 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 6 Mar 2014 15:10:32 +0100 Subject: Revert "adding new javascript function OC.generateUrl(url, params)" This reverts commit 8e667d1934d6bd9b4344ac624fdd2846c89abb0a. --- core/js/js.js | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'core/js/js.js') diff --git a/core/js/js.js b/core/js/js.js index 279a5390a88..77aadd23e03 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -175,30 +175,6 @@ var OC={ appswebroots:(typeof oc_appswebroots !== 'undefined') ? oc_appswebroots:false, currentUser:(typeof oc_current_user!=='undefined')?oc_current_user:false, coreApps:['', 'admin','log','search','settings','core','3rdparty'], - - /** - * Generates the absolute url for the given relative url, which can contain parameters. - * - * @returns {string} - * @param {string} url - * @param params - */ - generateUrl: function(url, params) { - var _build = function (text, vars) { - return text.replace(/{([^{}]*)}/g, - function (a, b) { - var r = vars[b]; - return typeof r === 'string' || typeof r === 'number' ? r : a; - } - ); - }; - if (url.charAt(0) !== '/') { - url = '/' + url; - - } - return OC.webroot + '/index.php' + _build(url, params); - }, - /** * get an absolute url to a file in an appen * @param app the id of the app the file belongs to -- cgit v1.2.3 From 01bcdf5b53d44510176ca1487116c171379def06 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Mon, 10 Mar 2014 16:22:52 +0100 Subject: Add function remove() to OC.localeStorage --- core/js/js.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'core/js/js.js') diff --git a/core/js/js.js b/core/js/js.js index 77aadd23e03..78eeceb2b0c 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -662,6 +662,9 @@ if(typeof localStorage !=='undefined' && localStorage !== null){ setItem:function(name,item){ return localStorage.setItem(OC.localStorage.namespace+name,JSON.stringify(item)); }, + removeItem:function(name,item){ + return localStorage.removeItem(OC.localStorage.namespace+name,JSON.stringify(item)); + }, getItem:function(name){ var item = localStorage.getItem(OC.localStorage.namespace+name); if(item===null) { -- cgit v1.2.3 From 5e6f0dcc6d83ce319ea2685cedbc9b23c7f33c27 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Mon, 10 Mar 2014 16:26:07 +0100 Subject: Fix copy/paste error --- core/js/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/js/js.js') diff --git a/core/js/js.js b/core/js/js.js index 78eeceb2b0c..841f3a769f1 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -663,7 +663,7 @@ if(typeof localStorage !=='undefined' && localStorage !== null){ return localStorage.setItem(OC.localStorage.namespace+name,JSON.stringify(item)); }, removeItem:function(name,item){ - return localStorage.removeItem(OC.localStorage.namespace+name,JSON.stringify(item)); + return localStorage.removeItem(OC.localStorage.namespace+name); }, getItem:function(name){ var item = localStorage.getItem(OC.localStorage.namespace+name); -- cgit v1.2.3 From b37aae9925a1d5516a24f1f9db31a156c2d3bc72 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Fri, 14 Mar 2014 10:33:19 +0100 Subject: mobile: menu togglable for mobile, use code by @PVince81 --- core/css/mobile.css | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ core/js/js.js | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) (limited to 'core/js/js.js') diff --git a/core/css/mobile.css b/core/css/mobile.css index 665ad0daae9..5a465b35fb9 100644 --- a/core/css/mobile.css +++ b/core/css/mobile.css @@ -18,6 +18,71 @@ display: none; } +/* toggle navigation */ +#content-wrapper { + padding-left: 0; +} + +#navigation { + top: 45px; + bottom: initial; + width: 90%; + max-width: 320px; + max-height: 90%; + margin-top: 0; + top: 45px; + background-color: rgba(36, 40, 47, .97); + overflow-x: initial; + border-bottom-right-radius: 7px; + border-bottom: 1px #333 solid; + border-right: 1px #333 solid; + box-shadow: 0 0 7px rgba(29,45,68,.97); + display: none; +} +#navigation, #navigation * { + box-sizing:border-box; -moz-box-sizing:border-box; +} +#navigation li { + display: inline-block; +} +#navigation a { + width: 70px; + height: 80px; + display: inline-block; + text-align: center; + padding: 20px 0; +} +#navigation a span { + display: inline-block; + font-size: 13px; + padding-bottom: 0; + padding-left: 0; + width: initial; +} +#navigation .icon { + margin: 0 auto; + padding: 0; +} +#navigation li:first-child .icon { + padding-top: 0; +} +/* Apps management as sticky footer */ +#navigation .wrapper { + min-height: initial; + margin: 0; +} +#apps-management, #navigation .push { + height: initial; +} + + + +/* shift to account for missing navigation */ +#body-user #controls, +#body-settings #controls { + padding-left: 0; +} + /* don’t require a minimum width for controls bar */ #controls { min-width: initial !important; diff --git a/core/js/js.js b/core/js/js.js index 841f3a769f1..2b3a9f04770 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -482,6 +482,29 @@ var OC={ }).show(); }, 'html'); } + }, + + // for menu toggling + registerMenu: function($toggle, $menuEl) { + $menuEl.addClass('menu'); + $toggle.addClass('menutoggle'); + $toggle.on('click', function(event) { + if ($menuEl.is(OC._currentMenu)) { + $menuEl.hide(); + OC._currentMenu = null; + OC._currentMenuToggle = null; + return false; + } + // another menu was open? + else if (OC._currentMenu) { + // close it + OC._currentMenu.hide(); + } + $menuEl.show(); + OC._currentMenu = $menuEl; + OC._currentMenuToggle = $toggle; + return false + }); } }; OC.search.customResults={}; @@ -940,6 +963,23 @@ function initCore() { $('a.action').tipsy({gravity:'s', fade:true, live:true}); $('td .modified').tipsy({gravity:'s', fade:true, live:true}); $('input').tipsy({gravity:'w', fade:true}); + + // toggle for menus + $(document).on('mouseup.closemenus', function(event) { + var $el = $(event.target); + if ($el.closest('.menu').length || $el.closest('.menutoggle').length) { + // don't close when clicking on the menu directly or a menu toggle + return false; + } + if (OC._currentMenu) { + OC._currentMenu.hide(); + } + OC._currentMenu = null; + OC._currentMenuToggle = null; + }); + + // toggle the navigation on mobile + OC.registerMenu($('#header #owncloud'), $('#navigation')); } $(document).ready(initCore); -- cgit v1.2.3 From 4fc96ebb7b51333497a126658989cb85669aa6dd Mon Sep 17 00:00:00 2001 From: jamesryanbell Date: Mon, 17 Mar 2014 16:11:49 +0000 Subject: SVG support detection The SVGSupport checkMimeType method was failing on my setup as the headers are all returned in lowercase. I have lowercase all the indexes and modified the if statement so that it doesn't matter what case the headers are returned in --- core/js/js.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/js/js.js') diff --git a/core/js/js.js b/core/js/js.js index 841f3a769f1..9ca0730fa6f 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -712,11 +712,11 @@ SVGSupport.checkMimeType=function(){ if(value[0]==='"'){ value=value.substr(1,value.length-2); } - headers[parts[0]]=value; + headers[parts[0].toLowerCase()]=value; } } }); - if(headers["Content-Type"]!=='image/svg+xml'){ + if(headers["content-type"]!=='image/svg+xml'){ replaceSVG(); SVGSupport.checkMimeType.correct=false; } -- cgit v1.2.3 From 413afab4240dedcb271def0d30480f4f5d6522ef Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Mon, 17 Mar 2014 19:39:19 +0100 Subject: Replace console.time/timeEnd --- core/js/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/js/js.js') diff --git a/core/js/js.js b/core/js/js.js index 841f3a769f1..3d3185f12c1 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -27,7 +27,7 @@ if (oc_debug !== true || typeof console === "undefined" || typeof console.log == if (!window.console) { window.console = {}; } - var methods = ['log', 'debug', 'warn', 'info', 'error', 'assert']; + var methods = ['log', 'debug', 'warn', 'info', 'error', 'assert', 'time', 'timeEnd']; for (var i = 0; i < methods.length; i++) { console[methods[i]] = function () { }; } -- cgit v1.2.3 From 872006da035b92b17b0a0d5da781844080861531 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 17 Mar 2014 20:40:22 +0100 Subject: Only enable toggle for sidebar in mobile mode --- core/js/js.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'core/js/js.js') diff --git a/core/js/js.js b/core/js/js.js index 2b3a9f04770..23d16b69234 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -979,7 +979,12 @@ function initCore() { }); // toggle the navigation on mobile - OC.registerMenu($('#header #owncloud'), $('#navigation')); + if (window.matchMedia) { + var mq = window.matchMedia('(max-width: 600px)'); + if (mq && mq.matches) { + OC.registerMenu($('#header #owncloud'), $('#navigation')); + } + } } $(document).ready(initCore); -- cgit v1.2.3 From fe04106e0f6a88b5e3cf490773f2cb625465e98a Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 18 Mar 2014 13:09:25 +0100 Subject: Add/remove main menu action when switching between desktop/mobile mode --- core/js/js.js | 59 ++++++++++++++++++++--- core/js/tests/specs/coreSpec.js | 101 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 6 deletions(-) (limited to 'core/js/js.js') 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); diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index 069546387c7..7fa0b8e9e62 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -279,5 +279,106 @@ describe('Core base tests', function() { expect(OC.generateUrl('apps/files/download{file}', {file: '/Welcome.txt'})).toEqual(OC.webroot + '/index.php/apps/files/download/Welcome.txt'); }); }); + describe('Main menu mobile toggle', function() { + var oldMatchMedia; + var $toggle; + var $navigation; + + beforeEach(function() { + oldMatchMedia = window.matchMedia; + window.matchMedia = sinon.stub(); + $('#testArea').append('' + + ''); + $toggle = $('#owncloud'); + $navigation = $('#navigation'); + }); + + afterEach(function() { + window.matchMedia = oldMatchMedia; + }); + it('Sets up menu toggle in mobile mode', function() { + window.matchMedia.returns({matches: true}); + window.initCore(); + expect($toggle.hasClass('menutoggle')).toEqual(true); + expect($navigation.hasClass('menu')).toEqual(true); + }); + it('Does not set up menu toggle in desktop mode', function() { + window.matchMedia.returns({matches: false}); + window.initCore(); + expect($toggle.hasClass('menutoggle')).toEqual(false); + expect($navigation.hasClass('menu')).toEqual(false); + }); + it('Switches on menu toggle when mobile mode changes', function() { + var mq = {matches: false}; + window.matchMedia.returns(mq); + window.initCore(); + expect($toggle.hasClass('menutoggle')).toEqual(false); + mq.matches = true; + $(window).trigger('resize'); + expect($toggle.hasClass('menutoggle')).toEqual(true); + }); + it('Switches off menu toggle when mobile mode changes', function() { + var mq = {matches: true}; + window.matchMedia.returns(mq); + window.initCore(); + expect($toggle.hasClass('menutoggle')).toEqual(true); + mq.matches = false; + $(window).trigger('resize'); + expect($toggle.hasClass('menutoggle')).toEqual(false); + }); + it('Clicking menu toggle toggles navigation in mobile mode', function() { + window.matchMedia.returns({matches: true}); + window.initCore(); + $navigation.hide(); // normally done through media query triggered CSS + expect($navigation.is(':visible')).toEqual(false); + $toggle.click(); + expect($navigation.is(':visible')).toEqual(true); + $toggle.click(); + expect($navigation.is(':visible')).toEqual(false); + }); + it('Clicking menu toggle does not toggle navigation in desktop mode', function() { + window.matchMedia.returns({matches: false}); + window.initCore(); + expect($navigation.is(':visible')).toEqual(true); + $toggle.click(); + expect($navigation.is(':visible')).toEqual(true); + }); + it('Switching to mobile mode hides navigation', function() { + var mq = {matches: false}; + window.matchMedia.returns(mq); + window.initCore(); + expect($navigation.is(':visible')).toEqual(true); + mq.matches = true; + $(window).trigger('resize'); + expect($navigation.is(':visible')).toEqual(false); + }); + it('Switching to desktop mode shows navigation', function() { + var mq = {matches: true}; + window.matchMedia.returns(mq); + window.initCore(); + expect($navigation.is(':visible')).toEqual(false); + mq.matches = false; + $(window).trigger('resize'); + expect($navigation.is(':visible')).toEqual(true); + }); + it('Switch to desktop with opened menu then back to mobile resets toggle', function() { + var mq = {matches: true}; + window.matchMedia.returns(mq); + window.initCore(); + expect($navigation.is(':visible')).toEqual(false); + $toggle.click(); + expect($navigation.is(':visible')).toEqual(true); + mq.matches = false; + $(window).trigger('resize'); + expect($navigation.is(':visible')).toEqual(true); + mq.matches = true; + $(window).trigger('resize'); + expect($navigation.is(':visible')).toEqual(false); + $toggle.click(); + expect($navigation.is(':visible')).toEqual(true); + }); + }); }); -- cgit v1.2.3 From cc6c1529848022765b9be6be808cf4dfb5b2d029 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 18 Mar 2014 15:52:06 +0100 Subject: 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 --- core/js/js.js | 67 +++++++++++++++++++++++------------------ core/js/tests/specs/coreSpec.js | 27 +++++++++-------- 2 files changed, 52 insertions(+), 42 deletions(-) (limited to 'core/js/js.js') 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); diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index 7fa0b8e9e62..57ea5be8be0 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -285,8 +285,11 @@ describe('Core base tests', function() { var $navigation; beforeEach(function() { - oldMatchMedia = window.matchMedia; - window.matchMedia = sinon.stub(); + oldMatchMedia = OC._matchMedia; + // a separate method was needed because window.matchMedia + // cannot be stubbed due to a bug in PhantomJS: + // https://github.com/ariya/phantomjs/issues/12069 + OC._matchMedia = sinon.stub(); $('#testArea').append('' + @@ -296,23 +299,23 @@ describe('Core base tests', function() { }); afterEach(function() { - window.matchMedia = oldMatchMedia; + OC._matchMedia = oldMatchMedia; }); it('Sets up menu toggle in mobile mode', function() { - window.matchMedia.returns({matches: true}); + OC._matchMedia.returns({matches: true}); window.initCore(); expect($toggle.hasClass('menutoggle')).toEqual(true); expect($navigation.hasClass('menu')).toEqual(true); }); it('Does not set up menu toggle in desktop mode', function() { - window.matchMedia.returns({matches: false}); + OC._matchMedia.returns({matches: false}); window.initCore(); expect($toggle.hasClass('menutoggle')).toEqual(false); expect($navigation.hasClass('menu')).toEqual(false); }); it('Switches on menu toggle when mobile mode changes', function() { var mq = {matches: false}; - window.matchMedia.returns(mq); + OC._matchMedia.returns(mq); window.initCore(); expect($toggle.hasClass('menutoggle')).toEqual(false); mq.matches = true; @@ -321,7 +324,7 @@ describe('Core base tests', function() { }); it('Switches off menu toggle when mobile mode changes', function() { var mq = {matches: true}; - window.matchMedia.returns(mq); + OC._matchMedia.returns(mq); window.initCore(); expect($toggle.hasClass('menutoggle')).toEqual(true); mq.matches = false; @@ -329,7 +332,7 @@ describe('Core base tests', function() { expect($toggle.hasClass('menutoggle')).toEqual(false); }); it('Clicking menu toggle toggles navigation in mobile mode', function() { - window.matchMedia.returns({matches: true}); + OC._matchMedia.returns({matches: true}); window.initCore(); $navigation.hide(); // normally done through media query triggered CSS expect($navigation.is(':visible')).toEqual(false); @@ -339,7 +342,7 @@ describe('Core base tests', function() { expect($navigation.is(':visible')).toEqual(false); }); it('Clicking menu toggle does not toggle navigation in desktop mode', function() { - window.matchMedia.returns({matches: false}); + OC._matchMedia.returns({matches: false}); window.initCore(); expect($navigation.is(':visible')).toEqual(true); $toggle.click(); @@ -347,7 +350,7 @@ describe('Core base tests', function() { }); it('Switching to mobile mode hides navigation', function() { var mq = {matches: false}; - window.matchMedia.returns(mq); + OC._matchMedia.returns(mq); window.initCore(); expect($navigation.is(':visible')).toEqual(true); mq.matches = true; @@ -356,7 +359,7 @@ describe('Core base tests', function() { }); it('Switching to desktop mode shows navigation', function() { var mq = {matches: true}; - window.matchMedia.returns(mq); + OC._matchMedia.returns(mq); window.initCore(); expect($navigation.is(':visible')).toEqual(false); mq.matches = false; @@ -365,7 +368,7 @@ describe('Core base tests', function() { }); it('Switch to desktop with opened menu then back to mobile resets toggle', function() { var mq = {matches: true}; - window.matchMedia.returns(mq); + OC._matchMedia.returns(mq); window.initCore(); expect($navigation.is(':visible')).toEqual(false); $toggle.click(); -- cgit v1.2.3 From 67b8cfedf9f500eb25871265a05c874acc4809ff Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 18 Mar 2014 16:02:13 +0100 Subject: Define _matchMedia wrapper earlier The unit test stub didn't work because the _matchMedia wrapper was defined too late. This fix defines it earlier. --- core/js/js.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'core/js/js.js') diff --git a/core/js/js.js b/core/js/js.js index 87b2d59f160..121a4062d37 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -516,6 +516,19 @@ var OC={ } $toggle.off('click.menu').removeClass('menutoggle'); $menuEl.removeClass('menu'); + }, + + /** + * Wrapper for matchMedia + * + * This is makes it possible for unit tests to + * stub matchMedia (which doesn't work in PhantomJS) + */ + _matchMedia: function(media) { + if (window.matchMedia) { + return window.matchMedia(media); + } + return false; } }; OC.search.customResults={}; @@ -1033,10 +1046,6 @@ function initCore() { } if (window.matchMedia) { - // wrapper needed for unit tests due to PhantomJS bugs - OC._matchMedia = function(media) { - return window.matchMedia(media); - } setupMainMenu(); } } -- cgit v1.2.3 From 89ee5511580b7e9f5619961b12cd96b984b6b6e9 Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Fri, 21 Mar 2014 16:43:04 +0100 Subject: mobile: adjust breakpoint in JS as well --- core/js/js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/js/js.js') diff --git a/core/js/js.js b/core/js/js.js index 121a4062d37..3c169cfb21f 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1013,7 +1013,7 @@ function initCore() { if (!OC._matchMedia) { return; } - var mq = OC._matchMedia('(max-width: 600px)'); + var mq = OC._matchMedia('(max-width: 768px)'); var lastMatch = mq.matches; var $toggle = $('#header #owncloud'); var $navigation = $('#navigation'); -- cgit v1.2.3