Skip to content

Instantly share code, notes, and snippets.

@soychicka
Created June 26, 2011 00:55
Show Gist options
  • Save soychicka/1047106 to your computer and use it in GitHub Desktop.
Save soychicka/1047106 to your computer and use it in GitHub Desktop.
Slight improvement on LessCSS's handling of string interpolation in URLs
// less-1.1.3.js
// starting around line 2268
// modify the regex to handle the condition of an interpolated string
// /^(?:https?:\/\/|file:\/\/|data:\/\/|@{)?/
// /^(?:https?:\/|file:\/|data:\/)?\//
tree.URL = function (val, paths) {
if (val.data) {
this.attrs = val;
} else {
// Add the base path if the URL is relative and does not start with an interpolated string and we are in the browser
if (!/^(?:https?:\/\/|file:\/\/|data:\/\/|@{)?/.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;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment