From 91375c6aab1e6a698520c22e5c6a21e667e4d7e5 Mon Sep 17 00:00:00 2001 From: surunzi Date: Wed, 20 Sep 2017 13:17:18 +0800 Subject: [PATCH] Fix: Css custom properties #33 --- package.json | 21 ++++++++++++++------- src/Elements/Elements.es6 | 3 +++ test/manual.html | 8 ++++++++ test/util.js | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 test/util.js diff --git a/package.json b/package.json index a69d73e..3051a63 100644 --- a/package.json +++ b/package.json @@ -14,13 +14,20 @@ "utilDoc": "eustia doc src/lib/util.js -f md -o doc/UTIL_API.md -t \"Eruda Util Documentation\"" }, "eustia": { - "files": "src/**/*.es6", - "ignore": "**/Info/defInfo.es6", - "output": "src/lib/util.js", - "exclude": [ - "createCfg" - ], - "format": "commonjs" + "eruda": { + "files": "src/**/*.es6", + "ignore": "**/Info/defInfo.es6", + "output": "src/lib/util.js", + "exclude": [ + "createCfg" + ], + "format": "commonjs" + }, + "test": { + "files": ["test/**/*.js", "test/**/*.html"], + "output": "test/util.js", + "format": "global" + } }, "repository": { "type": "git", diff --git a/src/Elements/Elements.es6 b/src/Elements/Elements.es6 index 0b0d3d9..bf4887c 100644 --- a/src/Elements/Elements.es6 +++ b/src/Elements/Elements.es6 @@ -355,6 +355,9 @@ let regColor = /rgba?\((.*?)\)/g, function processStyleRule(val) { + // For css custom properties, val is unable to retrieved. + val = util.toStr(val); + return val.replace(regColor, '$&') .replace(regCssUrl, (match, url) => `url("${wrapLink(url)}")`); } diff --git a/test/manual.html b/test/manual.html index 85219fb..40b9858 100644 --- a/test/manual.html +++ b/test/manual.html @@ -7,6 +7,7 @@ +
Manual Test
@@ -24,6 +25,9 @@
  • #31
  • +
  • + #33 +
  • diff --git a/test/util.js b/test/util.js new file mode 100644 index 0000000..dd79400 --- /dev/null +++ b/test/util.js @@ -0,0 +1,35 @@ +// Built by eustia. +window._ = (function() +{ + var _ = {}; + + if (typeof window === 'object' && window._) _ = window._; + + /* ------------------------------ evalCss ------------------------------ */ + + _.evalCss = (function () + { + var mark = []; + + function exports(css) + { + for (var i = 0, len = mark.length; i < len; i++) + { + if (mark[i] === css) return; + } + mark.push(css); + + var container = exports.container || document.head, + style = document.createElement('style'); + + style.type = 'text/css'; + style.textContent = css; + + container.appendChild(style); + } + + return exports; + })(); + + return _; +})(); \ No newline at end of file