[Pkg-javascript-commits] [less.js] 221/285: add support to read options from less file link tag data attr

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:56 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v2.0.0
in repository less.js.

commit 815e977b0b39c3b990726d904102064abd3aa0d3
Author: Moez Bouhlel <bmoez.j at gmail.com>
Date:   Wed Oct 22 19:20:20 2014 +0100

    add support to read options from less file link tag data attr
---
 lib/less-browser/index.js |  8 ++++++--
 lib/less-browser/utils.js | 15 +++++----------
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/lib/less-browser/index.js b/lib/less-browser/index.js
index 36cda97..8d847b1 100644
--- a/lib/less-browser/index.js
+++ b/lib/less-browser/index.js
@@ -16,7 +16,11 @@ var isFileProtocol = /^(file|chrome(-extension)?|resource|qrc|app):/.test(window
     options = window.less || {};
 
 // use options from the current script tag data attribues
-options = addDataAttr(options);
+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');
@@ -127,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 5a881c8..5a77108 100644
--- a/lib/less-browser/utils.js
+++ b/lib/less-browser/utils.js
@@ -1,4 +1,3 @@
-/* global document */
 module.exports = {
     extractId: function(href) {
         return href.replace(/^[a-z-]+:\/+?[^\/]+/, '' )  // Remove protocol & domain
@@ -7,17 +6,13 @@ module.exports = {
             .replace(/[^\.\w-]+/g,          '-')  // Replace illegal characters
             .replace(/\./g,                 ':'); // Replace dots with colons(for valid id)
     },
-    addDataAttr: function(options) {
-        var script = document.currentScript || (function() {
-            var scripts = document.getElementsByTagName("script");
-            return scripts[scripts.length - 1];
-        })();
-        for (var opt in script.dataset)
-            if (script.dataset.hasOwnProperty(opt)) {
+    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] = script.dataset[opt];
+                    options[opt] = tag.dataset[opt];
                 else
-                    options[opt] = JSON.parse(script.dataset[opt]);
+                    options[opt] = JSON.parse(tag.dataset[opt]);
             }
         return options;
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list