summaryrefslogtreecommitdiffstats
path: root/theme/javascript/utils/url.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-01-20 11:29:26 +0100
committerSamy Pessé <samypesse@gmail.com>2015-01-20 11:29:26 +0100
commit238cd9f7f09f11ecdb1717a5d07fc33642d29043 (patch)
tree72eac94839bda4f32cb41441b2b88532eed52603 /theme/javascript/utils/url.js
parentbac25cdf297a7fa54f21977aa17d455e439cdf51 (diff)
downloadgitbook-238cd9f7f09f11ecdb1717a5d07fc33642d29043.zip
gitbook-238cd9f7f09f11ecdb1717a5d07fc33642d29043.tar.gz
gitbook-238cd9f7f09f11ecdb1717a5d07fc33642d29043.tar.bz2
Add back theme
Diffstat (limited to 'theme/javascript/utils/url.js')
-rw-r--r--theme/javascript/utils/url.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/theme/javascript/utils/url.js b/theme/javascript/utils/url.js
new file mode 100644
index 0000000..0254299
--- /dev/null
+++ b/theme/javascript/utils/url.js
@@ -0,0 +1,33 @@
+define([
+ "URIjs/URI"
+], function(URI) {
+ // Joins path segments. Preserves initial "/" and resolves ".." and "."
+ // Does not support using ".." to go above/outside the root.
+ // This means that join("foo", "../../bar") will not resolve to "../bar"
+ function join(baseUrl, url) {
+ var theUrl = new URI(url);
+ if (theUrl.is("relative")) {
+ theUrl = theUrl.absoluteTo(baseUrl);
+ }
+ return theUrl.toString();
+ }
+
+ // A simple function to get the dirname of a path
+ // Trailing slashes are ignored. Leading slash is preserved.
+ function dirname(path) {
+ return join(path, "..");
+ }
+
+ // test if a path or url is absolute
+ function isAbsolute(path) {
+ if (!path) return false;
+
+ return (path[0] == "/" || path.indexOf("http://") == 0 || path.indexOf("https://") == 0);
+ }
+
+ return {
+ dirname: dirname,
+ join: join,
+ isAbsolute: isAbsolute
+ };
+}) \ No newline at end of file