From 87d385303fe27074d9915f11ee2c1562bbe30d3b 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') diff --git a/core/js/js.js b/core/js/js.js index c79d5e84eb0..7f45a9b622b 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 91392c5a8707a73427f7afa86e5e5871a4dbd4e7 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 6 Mar 2014 15:17:55 +0100 Subject: add dprecated warning for OC.Router --- core/js/router.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core') diff --git a/core/js/router.js b/core/js/router.js index 44e7c30602e..8cd01bbaa79 100644 --- a/core/js/router.js +++ b/core/js/router.js @@ -1,4 +1,7 @@ OC.router_base_url = OC.webroot + '/index.php'; + +// deprecated Use OC.generateUrl instead +// see http://mailman.owncloud.org/pipermail/user/2014-March/000152.html OC.Router = { // register your ajax requests to load after the loading of the routes // has finished. otherwise you face problems with race conditions @@ -14,6 +17,7 @@ OC.Router = { } }), generate:function(name, opt_params) { + console.warn("This function is deprecated! Use OC.generateUrl instead"); if (!('routes' in this)) { if(this.routes_request.state() != 'resolved') { console.warn('To avoid race conditions, please register a callback');// wait -- cgit v1.2.3