mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
JSHint lib/* and test runners.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// browser.js - client-side engine
|
||||
//
|
||||
/*global less */
|
||||
|
||||
var isFileProtocol = /^(file|chrome(-extension)?|resource|qrc|app):/.test(location.protocol);
|
||||
|
||||
@@ -43,7 +44,7 @@ less.watch = function () {
|
||||
less.env = 'development';
|
||||
initRunningMode();
|
||||
}
|
||||
return this.watchMode = true
|
||||
return this.watchMode = true;
|
||||
};
|
||||
|
||||
less.unwatch = function () {clearInterval(less.watchTimer); return this.watchMode = false; };
|
||||
@@ -105,12 +106,12 @@ less.modifyVars = function(record) {
|
||||
newVars += ((name.slice(0,1) === '@')? '' : '@') + name +': '+
|
||||
((record[name].slice(-1) === ';')? record[name] : record[name] +';');
|
||||
}
|
||||
less.refresh(false, newVars)
|
||||
less.refresh(false, newVars);
|
||||
};
|
||||
|
||||
less.refresh = function (reload, newVars) {
|
||||
var startTime, endTime;
|
||||
startTime = endTime = new(Date);
|
||||
startTime = endTime = new Date();
|
||||
|
||||
loadStyleSheets(function (e, root, _, sheet, env) {
|
||||
if (e) {
|
||||
@@ -122,9 +123,9 @@ less.refresh = function (reload, newVars) {
|
||||
log("parsed " + sheet.href + " successfully.");
|
||||
createCSS(root.toCSS(less), sheet, env.lastModified);
|
||||
}
|
||||
log("css for " + sheet.href + " generated in " + (new(Date) - endTime) + 'ms');
|
||||
(env.remaining === 0) && log("css generated in " + (new(Date) - startTime) + 'ms');
|
||||
endTime = new(Date);
|
||||
log("css for " + sheet.href + " generated in " + (new Date() - endTime) + 'ms');
|
||||
(env.remaining === 0) && log("css generated in " + (new Date() - startTime) + 'ms');
|
||||
endTime = new Date();
|
||||
}, reload, newVars);
|
||||
|
||||
loadStyles(newVars);
|
||||
@@ -145,6 +146,7 @@ function loadStyles(newVars) {
|
||||
lessText += "\n" + newVars;
|
||||
}
|
||||
|
||||
/*jshint loopfunc:true */
|
||||
// use closure to store current value of i
|
||||
var callback = (function(style) {
|
||||
return function (e, cssAST) {
|
||||
@@ -158,7 +160,7 @@ function loadStyles(newVars) {
|
||||
} else {
|
||||
style.innerHTML = css;
|
||||
}
|
||||
}
|
||||
};
|
||||
})(style);
|
||||
new(less.Parser)(env).parse(lessText, callback);
|
||||
}
|
||||
@@ -337,20 +339,20 @@ function loadFile(originalHref, currentFileInfo, callback, env, newVars) {
|
||||
if (newVars) {
|
||||
lessText += "\n" + newVars;
|
||||
}
|
||||
callback(null, lessText, href, newFileInfo, { lastModified: new Date() })
|
||||
callback(null, lessText, href, newFileInfo, { lastModified: new Date() });
|
||||
} catch (e) {
|
||||
callback(e, null, href);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
xhr(href, env.mime, function (data, lastModified) {
|
||||
doXHR(href, env.mime, function (data, lastModified) {
|
||||
// per file cache
|
||||
fileCache[href] = data;
|
||||
|
||||
// Use remote copy (re-parse)
|
||||
try {
|
||||
callback(null, data, href, newFileInfo, { lastModified: lastModified })
|
||||
callback(null, data, href, newFileInfo, { lastModified: lastModified });
|
||||
} catch (e) {
|
||||
callback(e, null, href);
|
||||
}
|
||||
@@ -406,7 +408,7 @@ function createCSS(styles, sheet, lastModified) {
|
||||
|
||||
// If there is no oldCss, just append; otherwise, only append if we need
|
||||
// to replace oldCss with an updated stylesheet
|
||||
if (oldCss == null || keepOldCss === false) {
|
||||
if (oldCss === null || keepOldCss === false) {
|
||||
var nextEl = sheet && sheet.nextSibling || null;
|
||||
(nextEl || document.getElementsByTagName('head')[0]).parentNode.insertBefore(css, nextEl);
|
||||
}
|
||||
@@ -427,7 +429,7 @@ function createCSS(styles, sheet, lastModified) {
|
||||
}
|
||||
}
|
||||
|
||||
function xhr(url, type, callback, errback) {
|
||||
function doXHR(url, type, callback, errback) {
|
||||
var xhr = getXMLHttpRequest();
|
||||
var async = isFileProtocol ? less.fileAsync : less.async;
|
||||
|
||||
@@ -467,10 +469,11 @@ function xhr(url, type, callback, errback) {
|
||||
|
||||
function getXMLHttpRequest() {
|
||||
if (window.XMLHttpRequest) {
|
||||
return new(XMLHttpRequest);
|
||||
return new XMLHttpRequest();
|
||||
} else {
|
||||
try {
|
||||
return new(ActiveXObject)("MSXML2.XMLHTTP.3.0");
|
||||
/*global ActiveXObject */
|
||||
return new ActiveXObject("MSXML2.XMLHTTP.3.0");
|
||||
} catch (e) {
|
||||
log("browser doesn't support AJAX.");
|
||||
return null;
|
||||
@@ -483,13 +486,13 @@ function removeNode(node) {
|
||||
}
|
||||
|
||||
function log(str) {
|
||||
if (less.env == 'development' && typeof(console) !== "undefined") { console.log('less: ' + str) }
|
||||
if (less.env == 'development' && typeof(console) !== "undefined") { console.log('less: ' + str); }
|
||||
}
|
||||
|
||||
function error(e, rootHref) {
|
||||
var id = 'less-error-message:' + extractId(rootHref || "");
|
||||
var template = '<li><label>{line}</label><pre class="{class}">{content}</pre></li>';
|
||||
var elem = document.createElement('div'), timer, content, error = [];
|
||||
var elem = document.createElement('div'), timer, content, errors = [];
|
||||
var filename = e.filename || rootHref;
|
||||
var filenameNoPath = filename.match(/([^\/]+(\?.*)?)$/)[1];
|
||||
|
||||
@@ -500,8 +503,8 @@ function error(e, rootHref) {
|
||||
'</h3>' + '<p>in <a href="' + filename + '">' + filenameNoPath + "</a> ";
|
||||
|
||||
var errorline = function (e, i, classname) {
|
||||
if (e.extract[i] != undefined) {
|
||||
error.push(template.replace(/\{line\}/, (parseInt(e.line) || 0) + (i - 1))
|
||||
if (e.extract[i] !== undefined) {
|
||||
errors.push(template.replace(/\{line\}/, (parseInt(e.line, 10) || 0) + (i - 1))
|
||||
.replace(/\{class\}/, classname)
|
||||
.replace(/\{content\}/, e.extract[i]));
|
||||
}
|
||||
@@ -512,7 +515,7 @@ function error(e, rootHref) {
|
||||
errorline(e, 1, 'line');
|
||||
errorline(e, 2, '');
|
||||
content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':</p>' +
|
||||
'<ul>' + error.join('') + '</ul>';
|
||||
'<ul>' + errors.join('') + '</ul>';
|
||||
} else if (e.stack) {
|
||||
content += '<br/>' + e.stack.split('\n').slice(1).join('<br/>');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user