diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-07-13 15:26:01 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-07-13 15:26:01 +0200 |
commit | b56a57e21cdaca3e93e98cabea63b7cf2e0b3b9a (patch) | |
tree | 7fa7b2ac36f9dae6afa8829efce967a0053909b7 /core/js/js.js | |
parent | 1006ec56ceb2c7c5bc14a5401d46767cb4b72e6c (diff) | |
download | nextcloud-server-b56a57e21cdaca3e93e98cabea63b7cf2e0b3b9a.tar.gz nextcloud-server-b56a57e21cdaca3e93e98cabea63b7cf2e0b3b9a.zip |
Add helper functions for host, port and webroot
These should be used in the future instead of location.*.
It will make it possible to stub these methods for writing unit tests
and simulating different URL schemes.
Diffstat (limited to 'core/js/js.js')
-rw-r--r-- | core/js/js.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/core/js/js.js b/core/js/js.js index ff52c8f1f39..1dfcb576c2a 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -68,7 +68,17 @@ var OC={ PERMISSION_ALL:31, TAG_FAVORITE: '_$!<Favorite>!$_', /* jshint camelcase: false */ + /** + * Relative path to ownCloud root. + * For example: "/owncloud" + * + * @type string + * + * @deprecated since 8.2, use OC.getRootPath() instead + * @see OC#getRootPath + */ webroot:oc_webroot, + appswebroots:(typeof oc_appswebroots !== 'undefined') ? oc_appswebroots:false, currentUser:(typeof oc_current_user!=='undefined')?oc_current_user:false, config: window.oc_config, @@ -219,6 +229,41 @@ var OC={ }, /** + * Returns the host name used to access this ownCloud instance + * + * @return {string} host name + * + * @since 8.2 + */ + getHost: function() { + return window.location.host; + }, + + /** + * Returns the port number used to access this ownCloud instance + * + * @return {int} port number + * + * @since 8.2 + */ + getPort: function() { + return window.location.port; + }, + + /** + * Returns the web root path where this ownCloud instance + * is accessible, with a leading slash. + * For example "/owncloud". + * + * @return {string} web root path + * + * @since 8.2 + */ + getRootPath: function() { + return OC.webroot; + }, + + /** * get the absolute path to an image file * if no extension is given for the image, it will automatically decide * between .png and .svg based on what the browser supports |