diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-07-10 13:01:01 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-07-10 13:02:28 +0200 |
commit | 119e27166e69d70e7fee697fe1a6b7c2f0839ece (patch) | |
tree | 9380700fae62438dcdba02d7723a62cbd8e217b8 /core/js/js.js | |
parent | 87f3500fda04f76d97754185a71f285e9770c66c (diff) | |
download | nextcloud-server-119e27166e69d70e7fee697fe1a6b7c2f0839ece.tar.gz nextcloud-server-119e27166e69d70e7fee697fe1a6b7c2f0839ece.zip |
Add OC.joinPaths for convenient path joining
Diffstat (limited to 'core/js/js.js')
-rw-r--r-- | core/js/js.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/core/js/js.js b/core/js/js.js index e0adc3591ac..ff52c8f1f39 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -326,6 +326,48 @@ var OC={ }, /** + * Join path sections + * + * @param {...String} path sections + * + * @return {String} joined path, any leading or trailing slash + * will be kept + * + * @since 8.2 + */ + joinPaths: function() { + if (arguments.length < 1) { + return ''; + } + var path = ''; + var lastArg = arguments[arguments.length - 1]; + var leadingSlash = arguments[0].charAt(0) === '/'; + var trailingSlash = lastArg.charAt(lastArg.length - 1) === '/'; + var sections = []; + var i; + for (i = 0; i < arguments.length; i++) { + sections = sections.concat(arguments[i].split('/')); + } + var first = !leadingSlash; + for (i = 0; i < sections.length; i++) { + if (sections[i] !== '') { + if (first) { + first = false; + } else { + path += '/'; + } + path += sections[i]; + } + } + + if (trailingSlash) { + // add it back + path += '/'; + } + return path; + }, + + /** * Do a search query and display the results * @param {string} query the search query */ |