mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
Fix Entity widget not rendering its content without a refresh (#4776)
* Expose TEXT_NODE and ELEMENT_NODE constants * Add failing test for initial rendering of entity widget * Compute attributes when rendering
This commit is contained in:
parent
b32eb49d50
commit
222821804e
@ -21,14 +21,32 @@ var bumpSequenceNumber = function(object) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var TW_Node = function (){
|
||||||
|
throw TypeError("Illegal constructor");
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.defineProperty(TW_Node.prototype, 'ELEMENT_NODE', {
|
||||||
|
get: function() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(TW_Node.prototype, 'TEXT_NODE', {
|
||||||
|
get: function() {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var TW_TextNode = function(text) {
|
var TW_TextNode = function(text) {
|
||||||
bumpSequenceNumber(this);
|
bumpSequenceNumber(this);
|
||||||
this.textContent = text + "";
|
this.textContent = text + "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TW_TextNode.prototype = Object.create(TW_Node.prototype);
|
||||||
|
|
||||||
Object.defineProperty(TW_TextNode.prototype, "nodeType", {
|
Object.defineProperty(TW_TextNode.prototype, "nodeType", {
|
||||||
get: function() {
|
get: function() {
|
||||||
return 3;
|
return this.TEXT_NODE;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -49,6 +67,8 @@ var TW_Element = function(tag,namespace) {
|
|||||||
this.namespaceURI = namespace || "http://www.w3.org/1999/xhtml";
|
this.namespaceURI = namespace || "http://www.w3.org/1999/xhtml";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TW_Element.prototype = Object.create(TW_Node.prototype);
|
||||||
|
|
||||||
Object.defineProperty(TW_Element.prototype, "style", {
|
Object.defineProperty(TW_Element.prototype, "style", {
|
||||||
get: function() {
|
get: function() {
|
||||||
return this._style;
|
return this._style;
|
||||||
@ -69,7 +89,7 @@ Object.defineProperty(TW_Element.prototype, "style", {
|
|||||||
|
|
||||||
Object.defineProperty(TW_Element.prototype, "nodeType", {
|
Object.defineProperty(TW_Element.prototype, "nodeType", {
|
||||||
get: function() {
|
get: function() {
|
||||||
return 1;
|
return this.ELEMENT_NODE;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ Render this widget into the DOM
|
|||||||
*/
|
*/
|
||||||
EntityWidget.prototype.render = function(parent,nextSibling) {
|
EntityWidget.prototype.render = function(parent,nextSibling) {
|
||||||
this.parentDomNode = parent;
|
this.parentDomNode = parent;
|
||||||
|
this.computeAttributes();
|
||||||
this.execute();
|
this.execute();
|
||||||
var entityString = this.getAttribute("entity",this.parseTreeNode.entity || ""),
|
var entityString = this.getAttribute("entity",this.parseTreeNode.entity || ""),
|
||||||
textNode = this.document.createTextNode($tw.utils.entityDecode(entityString));
|
textNode = this.document.createTextNode($tw.utils.entityDecode(entityString));
|
||||||
|
@ -273,6 +273,24 @@ describe("Widget module", function() {
|
|||||||
expect(wrapper.innerHTML).toBe("<p><a href=\"data:text/vnd.tiddlywiki,Jolly%20Old%20World\">My linky link</a></p>");
|
expect(wrapper.innerHTML).toBe("<p><a href=\"data:text/vnd.tiddlywiki,Jolly%20Old%20World\">My linky link</a></p>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* This test reproduces issue #4693. */
|
||||||
|
it("should render the entity widget", function() {
|
||||||
|
var wiki = new $tw.Wiki();
|
||||||
|
// Construct the widget node
|
||||||
|
var text = "\n\n<$entity entity=' ' />\n\n<$entity entity='✓' />\n";
|
||||||
|
var widgetNode = createWidgetNode(parseText(text,wiki),wiki);
|
||||||
|
// Render the widget node to the DOM
|
||||||
|
var wrapper = renderWidgetNode(widgetNode);
|
||||||
|
// Test the rendering
|
||||||
|
expect(wrapper.innerHTML).toBe(" ✓");
|
||||||
|
// Test the sequence numbers in the DOM
|
||||||
|
expect(wrapper.sequenceNumber).toBe(0);
|
||||||
|
expect(wrapper.children[0].sequenceNumber).toBe(1);
|
||||||
|
expect(wrapper.children[0].nodeType).toBe(wrapper.children[0].TEXT_NODE);
|
||||||
|
expect(wrapper.children[1].sequenceNumber).toBe(2);
|
||||||
|
expect(wrapper.children[1].nodeType).toBe(wrapper.children[1].TEXT_NODE);
|
||||||
|
});
|
||||||
|
|
||||||
it("should deal with the list widget", function() {
|
it("should deal with the list widget", function() {
|
||||||
var wiki = new $tw.Wiki();
|
var wiki = new $tw.Wiki();
|
||||||
// Add some tiddlers
|
// Add some tiddlers
|
||||||
|
Loading…
Reference in New Issue
Block a user