Merge branch 'insert-function' into 3.1.0

This commit is contained in:
Mike Bostock 2013-03-05 20:54:58 -08:00
Родитель d80cc86287 873db8d893
Коммит aad4969807
4 изменённых файлов: 22 добавлений и 14 удалений

9
d3.js поставляемый
Просмотреть файл

@ -1695,11 +1695,12 @@ d3 = function() {
}; };
d3_selectionPrototype.insert = function(name, before) { d3_selectionPrototype.insert = function(name, before) {
name = d3.ns.qualify(name); name = d3.ns.qualify(name);
function insert() { if (typeof before !== "function") before = d3_selection_selector(before);
return this.insertBefore(d3_document.createElementNS(this.namespaceURI, name), d3_select(before, this)); function insert(d, i) {
return this.insertBefore(d3_document.createElementNS(this.namespaceURI, name), before.call(this, d, i));
} }
function insertNS() { function insertNS(d, i) {
return this.insertBefore(d3_document.createElementNS(name.space, name.local), d3_select(before, this)); return this.insertBefore(d3_document.createElementNS(name.space, name.local), before.call(this, d, i));
} }
return this.select(name.local ? insertNS : insert); return this.select(name.local ? insertNS : insert);
}; };

6
d3.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -1,19 +1,18 @@
// TODO insert(node, function)?
// TODO insert(function, string)?
// TODO insert(function, function)?
d3_selectionPrototype.insert = function(name, before) { d3_selectionPrototype.insert = function(name, before) {
name = d3.ns.qualify(name); name = d3.ns.qualify(name);
function insert() { if (typeof before !== "function") before = d3_selection_selector(before);
function insert(d, i) {
return this.insertBefore( return this.insertBefore(
d3_document.createElementNS(this.namespaceURI, name), d3_document.createElementNS(this.namespaceURI, name),
d3_select(before, this)); before.call(this, d, i));
} }
function insertNS() { function insertNS(d, i) {
return this.insertBefore( return this.insertBefore(
d3_document.createElementNS(name.space, name.local), d3_document.createElementNS(name.space, name.local),
d3_select(before, this)); before.call(this, d, i));
} }
return this.select(name.local ? insertNS : insert); return this.select(name.local ? insertNS : insert);

Просмотреть файл

@ -18,6 +18,14 @@ suite.addBatch({
assert.domEqual(div[0][0], document.body.firstChild); assert.domEqual(div[0][0], document.body.firstChild);
assert.domEqual(div[0][0].nextSibling, span[0][0]); assert.domEqual(div[0][0].nextSibling, span[0][0]);
}, },
"inserts before the specified node": function(body) {
var span = body.html("").append("span");
var div = body.insert("div", function() { return span.node(); });
assert.equal(div[0][0].tagName, "DIV");
assert.isNull(div[0][0].namespaceURI);
assert.domEqual(div[0][0], document.body.firstChild);
assert.domEqual(div[0][0].nextSibling, span[0][0]);
},
"appends an HTML element": function(body) { "appends an HTML element": function(body) {
var div = body.insert("div"); var div = body.insert("div");
assert.equal(div[0][0].tagName, "DIV"); assert.equal(div[0][0].tagName, "DIV");