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.js151
1 files changed, 142 insertions, 9 deletions
diff --git a/core/js/js.js b/core/js/js.js
index 21ccee0f1d5..302b6b4d9fa 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 () { };
}
@@ -194,6 +194,30 @@ var OC={
linkToRemoteBase:function(service) {
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,
+ 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);
+ },
+
/**
* @brief Creates an absolute url for remote use
* @param string $service id
@@ -458,6 +482,53 @@ var OC={
}).show();
}, 'html');
}
+ },
+
+ // for menu toggling
+ registerMenu: function($toggle, $menuEl) {
+ $menuEl.addClass('menu');
+ $toggle.addClass('menutoggle');
+ $toggle.on('click.menu', 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
+ });
+ },
+
+ 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');
+ },
+
+ /**
+ * 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={};
@@ -638,6 +709,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);
+ },
getItem:function(name){
var item = localStorage.getItem(OC.localStorage.namespace+name);
if(item===null) {
@@ -685,11 +759,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;
}
@@ -791,12 +865,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.generateUrl('/heartbeat');
+ setInterval(function(){
+ $.post(url);
+ }, interval * 1000);
}
// session heartbeat (defaults to enabled)
@@ -915,6 +987,67 @@ 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;
+ });
+
+
+ /**
+ * 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 (!OC._matchMedia) {
+ return;
+ }
+ var mq = OC._matchMedia('(max-width: 768px)');
+ 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();
+ }
+ });
+ }
+
+ if (window.matchMedia) {
+ setupMainMenu();
+ }
}
$(document).ready(initCore);