summaryrefslogtreecommitdiff
path: root/bin/lib/less/tree/url.js
diff options
context:
space:
mode:
Diffstat (limited to 'bin/lib/less/tree/url.js')
-rw-r--r--bin/lib/less/tree/url.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/bin/lib/less/tree/url.js b/bin/lib/less/tree/url.js
new file mode 100644
index 00000000..0caec345
--- /dev/null
+++ b/bin/lib/less/tree/url.js
@@ -0,0 +1,25 @@
+(function (tree) {
+
+tree.URL = function (val, paths) {
+ if (val.data) {
+ this.attrs = val;
+ } else {
+ // Add the base path if the URL is relative and we are in the browser
+ if (typeof(window) !== 'undefined' && !/^(?:https?:\/\/|file:\/\/|data:|\/)/.test(val.value) && paths.length > 0) {
+ val.value = paths[0] + (val.value.charAt(0) === '/' ? val.value.slice(1) : val.value);
+ }
+ this.value = val;
+ this.paths = paths;
+ }
+};
+tree.URL.prototype = {
+ toCSS: function () {
+ return "url(" + (this.attrs ? 'data:' + this.attrs.mime + this.attrs.charset + this.attrs.base64 + this.attrs.data
+ : this.value.toCSS()) + ")";
+ },
+ eval: function (ctx) {
+ return this.attrs ? this : new(tree.URL)(this.value.eval(ctx), this.paths);
+ }
+};
+
+})(require('../tree'));