Elements can be created with namespace #4

pull/8/head
paldepind 10 years ago
parent def68db88b
commit f1ee781962

3
.gitignore vendored

@ -25,3 +25,6 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
# Vim
*.swp

@ -1,4 +1,5 @@
// jshint newcap: false
/* global require, module, document, Element */
'use strict';
var VNode = require('./vnode');
@ -45,11 +46,11 @@ function init(modules) {
}
function createElm(vnode) {
var i;
if (!isUndef(i = vnode.data) && !isUndef(i = i.hook) && !isUndef(i = i.init)) {
i(vnode);
var i, data = vnode.data;
if (!isUndef(data)) {
if (!isUndef(i = data.hook) && !isUndef(i = i.init)) i(vnode);
if (!isUndef(i = data.vnode)) vnode = i;
}
if (!isUndef(i = vnode.data) && !isUndef(i = i.vnode)) vnode = i;
var elm, children = vnode.children, sel = vnode.sel;
if (!isUndef(sel)) {
// Parse selector
@ -58,7 +59,8 @@ function init(modules) {
var hash = hashIdx > 0 ? hashIdx : sel.length;
var dot = dotIdx > 0 ? dotIdx : sel.length;
var tag = hashIdx !== -1 || dotIdx !== -1 ? sel.slice(0, Math.min(hash, dot)) : sel;
elm = vnode.elm = document.createElement(tag);
elm = vnode.elm = !isUndef(data) && !isUndef(i = data.ns) ? document.createElementNS(i, tag)
: document.createElement(tag);
if (hash < dot) elm.id = sel.slice(hash + 1, dot);
if (dotIdx > 0) elm.className = sel.slice(dot+1).replace(/\./g, ' ');
if (is.array(children)) {

@ -64,6 +64,10 @@ describe('snabbdom', function() {
patch(vnode0, h('div', [h('div#unique')]));
assert.equal(elm.firstChild.id, 'unique');
});
it('has correct namespace', function() {
patch(vnode0, h('div', [h('div', {ns: 'http://www.w3.org/2000/svg'})]));
assert.equal(elm.firstChild.namespaceURI, 'http://www.w3.org/2000/svg');
});
it('is recieves classes in selector', function() {
patch(vnode0, h('div', [h('i.am.a.class')]));
assert(elm.firstChild.classList.contains('am'));

Loading…
Cancel
Save