Merge branch 'insert-function' into 3.1.0
This commit is contained in:
Коммит
aad4969807
|
@ -1695,11 +1695,12 @@ d3 = function() {
|
|||
};
|
||||
d3_selectionPrototype.insert = function(name, before) {
|
||||
name = d3.ns.qualify(name);
|
||||
function insert() {
|
||||
return this.insertBefore(d3_document.createElementNS(this.namespaceURI, name), d3_select(before, this));
|
||||
if (typeof before !== "function") before = d3_selection_selector(before);
|
||||
function insert(d, i) {
|
||||
return this.insertBefore(d3_document.createElementNS(this.namespaceURI, name), before.call(this, d, i));
|
||||
}
|
||||
function insertNS() {
|
||||
return this.insertBefore(d3_document.createElementNS(name.space, name.local), d3_select(before, this));
|
||||
function insertNS(d, i) {
|
||||
return this.insertBefore(d3_document.createElementNS(name.space, name.local), before.call(this, d, i));
|
||||
}
|
||||
return this.select(name.local ? insertNS : insert);
|
||||
};
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -1,19 +1,18 @@
|
|||
// TODO insert(node, function)?
|
||||
// TODO insert(function, string)?
|
||||
// TODO insert(function, function)?
|
||||
d3_selectionPrototype.insert = function(name, before) {
|
||||
name = d3.ns.qualify(name);
|
||||
|
||||
function insert() {
|
||||
if (typeof before !== "function") before = d3_selection_selector(before);
|
||||
|
||||
function insert(d, i) {
|
||||
return this.insertBefore(
|
||||
d3_document.createElementNS(this.namespaceURI, name),
|
||||
d3_select(before, this));
|
||||
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));
|
||||
before.call(this, d, i));
|
||||
}
|
||||
|
||||
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].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) {
|
||||
var div = body.insert("div");
|
||||
assert.equal(div[0][0].tagName, "DIV");
|
||||
|
|
Загрузка…
Ссылка в новой задаче