carto/lib/mess/tree/url.js
2011-01-05 14:23:28 -05:00

27 lines
893 B
JavaScript

(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 (!/^(?:https?:\/|file:\/)?\//.test(val.value) && paths.length > 0 && typeof(window) !== 'undefined') {
val.value = paths[0] + (val.value.charAt(0) === '/' ? val.value.slice(1) : val.value);
}
this.value = val;
this.paths = paths;
this.is = 'uri';
}
};
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('mess/tree'));