From 87e209ed8a739ecdf94f1fd15a8667e5e8fb184d Mon Sep 17 00:00:00 2001 From: cloudhead Date: Thu, 1 Apr 2010 22:37:59 -0400 Subject: [PATCH] less.js now works in firefox, safari and chrome --- lib/less/browser.js | 10 ++++++++-- lib/less/tree.js | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/less/browser.js b/lib/less/browser.js index c5d16805..807890a3 100644 --- a/lib/less/browser.js +++ b/lib/less/browser.js @@ -7,11 +7,17 @@ for (var i = 0; i < sheets.length; i++) { (function (sheet) { // Because the functions here are async, we need to create a closure xhr(sheet.href, function (data) { new(less.Parser)({ optimization: 3 }).parse(data, function (e, root) { - var css = document.createElement('style'); + var css = document.createElement('style'), styles; css.type = 'text/css'; css.media = 'screen'; css.title = sheet.title || sheet.href.match(/\/([-\w]+)\.[a-z]+$/i)[1]; - css.innerHTML = root.toCSS(); + styles = root.toCSS(); + + if (css.styleSheet) { + css.styleSheet.cssText = styles; + } else { + css.appendChild(document.createTextNode(styles)); + } document.getElementsByTagName('head')[0].appendChild(css); }); }); diff --git a/lib/less/tree.js b/lib/less/tree.js index c5572880..a1d4878c 100644 --- a/lib/less/tree.js +++ b/lib/less/tree.js @@ -1,4 +1,4 @@ -var tree = exports; +if (typeof(require) !== 'undefined') { var tree = exports } tree.find = function (obj, fun) { for (var i = 0, r; i < obj.length; i++) {