This commit is contained in:
Mike Bostock 2011-12-30 11:56:59 -08:00
Родитель 6c80963884 adb57e2aa8
Коммит 22cdb642cd
6 изменённых файлов: 47 добавлений и 24 удалений

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

@ -1575,16 +1575,18 @@ d3_selectionPrototype.property = function(name, value) {
? propertyFunction : propertyConstant));
};
d3_selectionPrototype.text = function(value) {
return arguments.length < 1 ? this.node().textContent
: (this.each(typeof value === "function"
? function() { this.textContent = value.apply(this, arguments); }
: function() { this.textContent = value; }));
return arguments.length < 1
? this.node().textContent : this.each(typeof value === "function"
? function() { var v = value.apply(this, arguments); this.textContent = v == null ? "" : v; } : value == null
? function() { this.textContent = ""; }
: function() { this.textContent = value; });
};
d3_selectionPrototype.html = function(value) {
return arguments.length < 1 ? this.node().innerHTML
: (this.each(typeof value === "function"
? function() { this.innerHTML = value.apply(this, arguments); }
: function() { this.innerHTML = value; }));
return arguments.length < 1
? this.node().innerHTML : this.each(typeof value === "function"
? function() { var v = value.apply(this, arguments); this.innerHTML = v == null ? "" : v; } : value == null
? function() { this.innerHTML = ""; }
: function() { this.innerHTML = value; });
};
// TODO append(node)?
// TODO append(function)?

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

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

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

@ -1,6 +1,7 @@
d3_selectionPrototype.html = function(value) {
return arguments.length < 1 ? this.node().innerHTML
: (this.each(typeof value === "function"
? function() { this.innerHTML = value.apply(this, arguments); }
: function() { this.innerHTML = value; }));
return arguments.length < 1
? this.node().innerHTML : this.each(typeof value === "function"
? function() { var v = value.apply(this, arguments); this.innerHTML = v == null ? "" : v; } : value == null
? function() { this.innerHTML = ""; }
: function() { this.innerHTML = value; });
};

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

@ -1,6 +1,7 @@
d3_selectionPrototype.text = function(value) {
return arguments.length < 1 ? this.node().textContent
: (this.each(typeof value === "function"
? function() { this.textContent = value.apply(this, arguments); }
: function() { this.textContent = value; }));
return arguments.length < 1
? this.node().textContent : this.each(typeof value === "function"
? function() { var v = value.apply(this, arguments); this.textContent = v == null ? "" : v; } : value == null
? function() { this.textContent = ""; }
: function() { this.textContent = value; });
};

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

@ -28,24 +28,36 @@ suite.addBatch({
assert.equal(document.body.lastChild.tagName, "I");
assert.equal(document.body.lastChild.textContent, "0");
},
/*
https://github.com/tmpvar/jsdom/issues/276
"clears the inner HTML as null": function(body) {
body.html(null);
assert.equal(document.body.innerHTML, "");
assert.isNull(document.body.firstChild);
},
*/
"clears the inner HTML as undefined": function(body) {
body.html(undefined);
assert.equal(document.body.innerHTML, "");
assert.isNull(document.body.firstChild);
},
"clears the inner HTML as the empty string": function(body) {
body.html("");
assert.equal(document.body.innerHTML, "");
assert.isNull(document.body.firstChild);
},
"clears the inner HTML as a function": function(body) {
"clears the inner HTML as a function returning the empty string": function(body) {
body.text(function() { return ""; });
assert.equal(document.body.innerHTML, "");
assert.isNull(document.body.firstChild);
},
"clears the inner HTML as a function returning null": function(body) {
body.text(function() { return null; });
assert.equal(document.body.innerHTML, "");
assert.isNull(document.body.firstChild);
},
"clears the inner HTML as a function returning undefined": function(body) {
body.text(function() { return undefined; });
assert.equal(document.body.innerHTML, "");
assert.isNull(document.body.firstChild);
},
"ignores null nodes": function() {
var body = d3.select("body");
body[0][0] = null;

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

@ -28,16 +28,23 @@ suite.addBatch({
assert.equal(document.body.textContent, "<h1>Hello, world!</h1>");
assert.equal(document.body.firstChild.nodeType, document.TEXT_NODE);
},
/*
https://github.com/tmpvar/jsdom/issues/276
/* <https://github.com/tmpvar/jsdom/issues/276>
"clears the text content as null": function(body) {
body.text(null);
assert.equal(document.body.textContent, "");
},
"clears the text content as a function": function(body) {
"clears the text content as undefined": function(body) {
body.text(undefined);
assert.equal(document.body.textContent, "");
},
"clears the text content as a function returning null": function(body) {
body.text(function() { return null; });
assert.equal(document.body.textContent, "");
},
"clears the text content as a function returning undefined": function(body) {
body.text(function() { return undefined; });
assert.equal(document.body.textContent, "");
},
*/
"ignores null nodes": function() {
var body = d3.select("body");