mirror of
https://github.com/less/less.js.git
synced 2026-02-04 03:55:10 -05:00
refactored and fixed css node creation, for watch mode
This commit is contained in:
@@ -91,26 +91,39 @@ function loadStyleSheet(sheet, callback) {
|
||||
}
|
||||
|
||||
function createCSS(styles, sheet, lastModified) {
|
||||
var css = document.createElement('style');
|
||||
css.type = 'text/css';
|
||||
css.media = 'screen';
|
||||
css.title = 'less-sheet';
|
||||
var css, title, id;
|
||||
|
||||
if (sheet) {
|
||||
css.title = sheet.title || sheet.href.match(/(?:^|\/)([-\w]+)\.[a-z]+$/i)[1];
|
||||
// If there is no title set, use the filename, minus the extension
|
||||
title = sheet.title || sheet.href.match(/(?:^|\/)([-\w]+)\.[a-z]+$/i)[1];
|
||||
id = '-less-' + title;
|
||||
|
||||
// Don't update the local store if the file wasn't modified
|
||||
if (lastModified && typeof(localStorage) !== "undefined") {
|
||||
localStorage.setItem(sheet.href, JSON.stringify({ timestamp: lastModified, css: styles }));
|
||||
}
|
||||
// If the stylesheet doesn't exist, create a new node
|
||||
if ((css = document.getElementById(id)) === null) {
|
||||
css = document.createElement('style');
|
||||
css.type = 'text/css';
|
||||
css.media = 'screen';
|
||||
css.title = title;
|
||||
css.id = id;
|
||||
document.getElementsByTagName('head')[0].appendChild(css);
|
||||
}
|
||||
|
||||
if (css.styleSheet) {
|
||||
css.styleSheet.cssText = styles;
|
||||
if (css.styleSheet) { // IE
|
||||
try {
|
||||
css.styleSheet.cssText = styles;
|
||||
} catch (e) {
|
||||
throw new(Error)("Couldn't reassign styleSheet.cssText.");
|
||||
}
|
||||
} else {
|
||||
if (css.childNodes.length > 0) {
|
||||
css.removeChild(css.childNodes[0]);
|
||||
}
|
||||
css.appendChild(document.createTextNode(styles));
|
||||
}
|
||||
document.getElementsByTagName('head')[0].appendChild(css);
|
||||
|
||||
// Don't update the local store if the file wasn't modified
|
||||
if (lastModified && typeof(localStorage) !== "undefined") {
|
||||
localStorage.setItem(sheet.href, JSON.stringify({ timestamp: lastModified, css: styles }));
|
||||
}
|
||||
}
|
||||
|
||||
function xhr(url, callback, errback) {
|
||||
@@ -158,6 +171,8 @@ function log(str) {
|
||||
}
|
||||
|
||||
function error(e, href) {
|
||||
if (document.getElementById('less-error-message')) { return }
|
||||
|
||||
var template = ['<div>',
|
||||
'<pre class="ctx"><span>[-1]</span>{0}</pre>',
|
||||
'<pre><span>[0]</span>{current}</pre>',
|
||||
@@ -203,7 +218,7 @@ function error(e, href) {
|
||||
'padding-bottom: 2px;',
|
||||
'border-bottom: 1px dashed red;',
|
||||
'}'
|
||||
].join(''));
|
||||
].join(''), { title: 'error-message' });
|
||||
|
||||
elem.style.cssText = [
|
||||
"font-family: Arial, sans-serif",
|
||||
|
||||
Reference in New Issue
Block a user