summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-03-06 17:26:17 +0100
committerVincent Petry <pvince81@owncloud.com>2014-03-06 17:26:17 +0100
commitc358373dfa1e6c011a9ab7e1ce8aa48e8d15615f (patch)
treeca3ab0328a3d1a480c052ce5f62bc3df577e359d /core
parent95ddadd146c75db21a76ba4c7b0c4aeb34d360a5 (diff)
parent91392c5a8707a73427f7afa86e5e5871a4dbd4e7 (diff)
downloadnextcloud-server-c358373dfa1e6c011a9ab7e1ce8aa48e8d15615f.tar.gz
nextcloud-server-c358373dfa1e6c011a9ab7e1ce8aa48e8d15615f.zip
Merge pull request #7578 from owncloud/introduce-generateUrl-stable6
adding new javascript function OC.generateUrl(url, params)
Diffstat (limited to 'core')
-rw-r--r--core/js/js.js24
-rw-r--r--core/js/router.js4
2 files changed, 28 insertions, 0 deletions
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
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