diff --git a/lib/less-browser/index.js b/lib/less-browser/index.js index 0553155a..8d847b1a 100644 --- a/lib/less-browser/index.js +++ b/lib/less-browser/index.js @@ -4,6 +4,7 @@ /*global window, document, location */ var less; +var addDataAttr = require("./utils").addDataAttr; /* TODO - options is now hidden - we should expose it on the less object, but not have it "as" the less object @@ -14,6 +15,13 @@ var less; var isFileProtocol = /^(file|chrome(-extension)?|resource|qrc|app):/.test(window.location.protocol), options = window.less || {}; +// use options from the current script tag data attribues +var script = document.currentScript || (function() { + var scripts = document.getElementsByTagName("script"); + return scripts[scripts.length - 1]; +})(); +options = addDataAttr(options, script); + // shim Promise if required require('promise/polyfill.js'); @@ -123,7 +131,7 @@ function loadStyles(modifyVars) { function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) { - var instanceOptions = clone(options); + var instanceOptions = addDataAttr(clone(options), sheet); instanceOptions.mime = sheet.type; if (modifyVars) { diff --git a/lib/less-browser/utils.js b/lib/less-browser/utils.js index 8d6644fc..5a771088 100644 --- a/lib/less-browser/utils.js +++ b/lib/less-browser/utils.js @@ -5,5 +5,15 @@ module.exports = { .replace(/\.[a-zA-Z]+$/, '' ) // Remove simple extension .replace(/[^\.\w-]+/g, '-') // Replace illegal characters .replace(/\./g, ':'); // Replace dots with colons(for valid id) + }, + addDataAttr: function(options, tag) { + for (var opt in tag.dataset) + if (tag.dataset.hasOwnProperty(opt)) { + if (opt === "env" || opt === "dumpLineNumbers" || opt === "rootpath" || opt === "errorReporting") + options[opt] = tag.dataset[opt]; + else + options[opt] = JSON.parse(tag.dataset[opt]); + } + return options; } };