summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2014-03-06 00:17:48 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2014-03-06 00:17:48 +0100
commit8e667d1934d6bd9b4344ac624fdd2846c89abb0a (patch)
treeb4b6b4a518945879ffe09a7c33d2d93606deb821
parent1785c0c9b9fcdc6e9a8e58f13f45e5b53364882a (diff)
downloadnextcloud-server-8e667d1934d6bd9b4344ac624fdd2846c89abb0a.tar.gz
nextcloud-server-8e667d1934d6bd9b4344ac624fdd2846c89abb0a.zip
adding new javascript function OC.generateUrl(url, params)
-rw-r--r--core/js/js.js24
1 files changed, 24 insertions, 0 deletions
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