use 'type' attribute from link tag, when performing a request

This commit is contained in:
cloudhead 2010-11-19 15:18:35 -05:00
parent 4c6087fdf5
commit 01549ab751
2 changed files with 9 additions and 6 deletions

View File

@ -124,7 +124,7 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
href = url.slice(0, url.lastIndexOf('/') + 1) + href;
}
xhr(sheet.href, function (data, lastModified) {
xhr(sheet.href, sheet.type, function (data, lastModified) {
if (!reload && styles &&
(new(Date)(lastModified).valueOf() ===
new(Date)(styles.timestamp).valueOf())) {
@ -136,7 +136,8 @@ function loadStyleSheet(sheet, callback, reload, remaining) {
try {
new(less.Parser)({
optimization: less.optimization,
paths: [href.replace(/[\w\.-]+$/, '')]
paths: [href.replace(/[\w\.-]+$/, '')],
mime: sheet.type
}).parse(data, function (e, root) {
if (e) { return error(e, href) }
try {
@ -208,7 +209,7 @@ function createCSS(styles, sheet, lastModified) {
}
}
function xhr(url, callback, errback) {
function xhr(url, type, callback, errback) {
var xhr = getXMLHttpRequest();
var async = isFileProtocol ? false : less.async;
@ -216,6 +217,7 @@ function xhr(url, callback, errback) {
xhr.overrideMimeType('text/css');
}
xhr.open('GET', url, async);
xhr.setRequestHeader('Accept', type || 'text/x-less, text/css; q=0.9, */*; q=0.5');
xhr.send(null);
if (isFileProtocol) {

View File

@ -62,6 +62,7 @@ less.Parser = function Parser(env) {
paths: env && env.paths || [], // Search paths, when importing
queue: [], // Files which haven't been imported yet
files: {}, // Holds the imported parse trees
mime: env && env.mime, // MIME type of .less files
push: function (path, callback) {
var that = this;
this.queue.push(path);
@ -76,7 +77,7 @@ less.Parser = function Parser(env) {
callback(root);
if (that.queue.length === 0) { finish() } // Call `finish` if we're done importing
});
}, env);
}
};
@ -1054,14 +1055,14 @@ if (typeof(window) !== 'undefined') {
//
// Used by `@import` directives
//
less.Parser.importer = function (path, paths, callback) {
less.Parser.importer = function (path, paths, callback, env) {
if (path.charAt(0) !== '/' && paths.length > 0) {
path = paths[0] + path;
}
// We pass `true` as 3rd argument, to force the reload of the import.
// This is so we can get the syntax tree as opposed to just the CSS output,
// as we need this to evaluate the current stylesheet.
loadStyleSheet({ href: path, title: path }, callback, true);
loadStyleSheet({ href: path, title: path, type: env.mime }, callback, true);
};
}