mirror of
https://github.com/Jermolene/TiddlyWiki5.git
synced 2026-01-24 13:30:55 -08:00
Add namespace support to the element renderer
This allows us to create SVG elements with the correct namespace, which allows us to have inline SVG images (coming up next)
This commit is contained in:
parent
dd2a7199f6
commit
0a3389c277
1 changed files with 17 additions and 2 deletions
|
|
@ -49,6 +49,17 @@ var ElementRenderer = function(renderTree,parentRenderer,parseTreeNode) {
|
|||
if(!this.widgetClasses) {
|
||||
ElementRenderer.prototype.widgetClasses = $tw.modules.applyMethods("widget");
|
||||
}
|
||||
// Select the namespace for the tag
|
||||
var tagNameSpaces = {
|
||||
svg: "http://www.w3.org/2000/svg"
|
||||
};
|
||||
this.namespace = tagNameSpaces[this.parseTreeNode.tag];
|
||||
if(this.namespace) {
|
||||
this.context = this.context || {};
|
||||
this.context.namespace = this.namespace;
|
||||
} else {
|
||||
this.namespace = this.renderTree.getContextVariable(this.parentRenderer,"namespace","http://www.w3.org/1999/xhtml");
|
||||
}
|
||||
// Get the context tiddler title
|
||||
this.tiddlerTitle = this.renderTree.getContextVariable(this.parentRenderer,"tiddlerTitle");
|
||||
// Compute our dependencies
|
||||
|
|
@ -161,7 +172,7 @@ ElementRenderer.prototype.renderInDom = function() {
|
|||
// Check if our widget is providing an element
|
||||
if(this.widget.tag) {
|
||||
// Create the element
|
||||
this.domNode = document.createElement(this.widget.tag);
|
||||
this.domNode = document.createElementNS(this.namespace,this.widget.tag);
|
||||
// Assign any specified event handlers
|
||||
$tw.utils.addEventListeners(this.domNode,this.widget.events);
|
||||
// Assign the attributes
|
||||
|
|
@ -196,7 +207,11 @@ ElementRenderer.prototype.assignAttributes = function() {
|
|||
self.domNode.style[$tw.utils.unHyphenateCss(p)] = v[p];
|
||||
}
|
||||
} else {
|
||||
self.domNode.setAttribute(a,v);
|
||||
// Setting certain attributes can cause a DOM error (eg xmlns on the svg element)
|
||||
try {
|
||||
self.domNode.setAttributeNS(null,a,v);
|
||||
} catch(e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue