diff --git a/index.js b/index.js index f254f12..facf6d8 100644 --- a/index.js +++ b/index.js @@ -59,7 +59,8 @@ module.exports = function (h, opts) { if (typeof parts[i][2] === 'object' && !key) { for (copyKey in parts[i][2]) { if (parts[i][2].hasOwnProperty(copyKey) && !cur[1][copyKey]) { - cur[1][copyKey] = parts[i][2][copyKey] + if (/data-/.test(copyKey)) data(cur[1], copyKey, parts[i][2][copyKey]) + else cur[1][copyKey] = parts[i][2][copyKey] } } } else { @@ -71,11 +72,13 @@ module.exports = function (h, opts) { var j = i for (; i < parts.length; i++) { if (parts[i][0] === ATTR_VALUE || parts[i][0] === ATTR_KEY) { - if (!cur[1][key]) cur[1][key] = strfn(parts[i][1]) + if (/data-/.test(key)) data(cur[1], key, parts[i][1]) + else if (!cur[1][key]) cur[1][key] = strfn(parts[i][1]) else cur[1][key] = concat(cur[1][key], parts[i][1]) } else if (parts[i][0] === VAR && (parts[i][1] === ATTR_VALUE || parts[i][1] === ATTR_KEY)) { - if (!cur[1][key]) cur[1][key] = strfn(parts[i][2]) + if (/data-/.test(key)) data(cur[1], key, parts[i][2]) + else if (!cur[1][key]) cur[1][key] = strfn(parts[i][2]) else cur[1][key] = concat(cur[1][key], parts[i][2]) } else { if (key.length && !cur[1][key] && i === j @@ -229,6 +232,11 @@ module.exports = function (h, opts) { } } + function data(cur, key, value) { + if (!cur.attributes) cur.attributes = {} + cur.attributes[key] = strfn(value) + } + function strfn (x) { if (typeof x === 'function') return x else if (typeof x === 'string') return x diff --git a/test/key.js b/test/key.js index 774c269..47c7199 100644 --- a/test/key.js +++ b/test/key.js @@ -50,8 +50,8 @@ test('multiple keys', function (t) { } var key = 'data-' var value = 'bar' - var tree = hx`` - t.equal(vdom.create(tree).toString(), '') + var tree = hx`` + t.equal(vdom.create(tree).toString(), '') t.end() })