Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions dist/less-1.1.4.js
Original file line number Diff line number Diff line change
Expand Up @@ -2571,22 +2571,21 @@ function extractId(href) {
}

function createCSS(styles, sheet, lastModified) {
var css;

// Strip the query-string
var href = sheet.href ? sheet.href.replace(/\?.*$/, '') : '';

// If there is no title set, use the filename, minus the extension
var id = 'less:' + (sheet.title || extractId(href));

// 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 = sheet.media || 'screen';
css.id = id;
document.getElementsByTagName('head')[0].appendChild(css);
}
// If this has already been inserted into the DOM, we may need to replace it
var oldCss = document.getElementById(id);
var keepOldCss = false;

// Create a new stylesheet node for insertion or (if necessary) replacement
var css = document.createElement('style');
css.setAttribute('type', 'text/css');
css.setAttribute('media', sheet.media || 'screen');
css.id = id;

if (css.styleSheet) { // IE
try {
Expand All @@ -2595,15 +2594,22 @@ function createCSS(styles, sheet, lastModified) {
throw new(Error)("Couldn't reassign styleSheet.cssText.");
}
} else {
(function (node) {
if (css.childNodes.length > 0) {
if (css.firstChild.nodeValue !== node.nodeValue) {
css.replaceChild(node, css.firstChild);
}
} else {
css.appendChild(node);
}
})(document.createTextNode(styles));
css.appendChild(document.createTextNode(styles));

// If new contents match contents of oldCss, don't replace oldCss
keepOldCss = (oldCss !== null && oldCss.childNodes.length > 0 && css.childNodes.length > 0 &&
oldCss.firstChild.nodeValue === css.firstChild.nodeValue);
}

var head = document.getElementsByTagName('head')[0];

// If there is no oldCss, just append; otherwise, only append if we need
// to replace oldCss with an updated stylesheet
if (oldCss === null) {
head.appendChild(css);
} else if (keepOldCss === false) {
head.appendChild(css);
head.removeChild(oldCss);
}

// Don't update the local store if the file wasn't modified
Expand All @@ -2626,7 +2632,7 @@ function xhr(url, type, callback, errback) {
xhr.send(null);

if (isFileProtocol) {
if (xhr.status === 0) {
if (xhr.status === 0 || (xhr.status >= 200 && xhr.status < 300)) {
callback(xhr.responseText);
} else {
errback(xhr.status, url);
Expand Down
Loading