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