Fixes for IE7 compatibility

This commit is contained in:
James Foster
2010-05-19 08:28:24 +08:00
committed by Alexis Sellier
parent 61c2b5877a
commit e501f2e47c
3 changed files with 29 additions and 23 deletions

View File

@@ -1,8 +1,11 @@
//
// Select all links with the 'rel' attribute set to "less"
//
var sheets = (document.querySelectorAll ? document.querySelectorAll
: jQuery).call(document, 'link[rel="stylesheet/less"]');
var sheets = [];
if(!document.querySelectorAll && typeof(jQuery) === "undefined")
log("No selector method found");
else
sheets = (document.querySelectorAll || jQuery).call(document, 'link[rel="stylesheet/less"]');
less.env = location.hostname == '127.0.0.1' ||
location.hostname == '0.0.0.0' ||
@@ -12,7 +15,7 @@ less.env = location.hostname == '127.0.0.1' ||
for (var i = 0; i < sheets.length; i++) {
(function (sheet) { // Because the functions here are async, we need to create a closure
var css = localStorage && localStorage.getItem(sheet.href);
var css = typeof(localStorage) !== "undefined" && localStorage.getItem(sheet.href);
var styles = css && JSON.parse(css);
xhr(sheet.href, function (data, lastModified) {
@@ -37,13 +40,13 @@ function createCSS(styles, sheet, lastModified) {
var css = document.createElement('style');
css.type = 'text/css';
css.media = 'screen';
css.title = 'lessheet';
css.title = 'less-sheet';
if (sheet) {
css.title = sheet.title || sheet.href.match(/\/([-\w]+)\.[a-z]+$/i)[1];
css.title = sheet.title || sheet.href.match(/(^|\/)([-\w]+)\.[a-z]+$/i)[1];
// Don't update the local store if the file wasn't modified
if (lastModified && localStorage) {
if (lastModified && typeof(localStorage) !== "undefined") {
localStorage.setItem(sheet.href, JSON.stringify({ timestamp: lastModified, css: styles }));
}
}
@@ -84,7 +87,7 @@ function xhr(url, callback, errback) {
}
function log(str) {
if (less.env == 'development') { console.log(str) }
if (less.env == 'development' && typeof(console) !== "undefined") { console.log(str) }
}
function error(e, href) {
@@ -100,7 +103,6 @@ function error(e, href) {
'<p><a href="' + href + '">' + href + "</a> " +
'on line ' + e.line + ', column ' + e.column + ':</p>' +
template.replace(/\[(-?\d)\]/g, function (_, i) {
console.log(i)
return e.line + parseInt(i);
}).replace(/\{(\d)\}/g, function (_, i) {
return e.extract[parseInt(i)];