#522 closed enhancement (wontfix)
additional dojo.dom utility methods/patch
Reported by: | Owned by: | anonymous | |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | General | Version: | 0.2 |
Keywords: | Cc: | [email protected]… | |
Blocked By: | Blocking: |
Description
Attaching a patch...oh...trac doesn't allow file attachments...that's awkward..ok..well here's the patch inlined then...If approved, would go into dojo.dom, just after the dojo.dom.textContent function:
/
- Capable of taking an incoming detached pure xml dom node, or
- document body node and grabbing the textual content it contains
- in a form suitable for doing node.innerHTML = dojo.dom.getContentAsString(),
- if you have a need to do something like this. */
dojo.dom.getContentAsString = function(node) {
if (!node) return "";
if (typeof node.xml != "undefined")
return dojo.dom.getContentAsStringIE(node);
else if (typeof XMLSerializer != "undefined" )
return dojo.dom.getContentAsStringMozilla(node);
else
return dojo.dom.getContentAsStringGeneric(node);
}
do not use directly, internal only dojo.dom.getContentAsStringIE = function(node) {
var contentStr = "";
for (var i = 0; i < node.childNodes.length; i++)
contentStr += node.childNodes[i].xml;
return contentStr;
}
do not use directly, internal only dojo.dom.getContentAsStringMozilla = function(node) {
var xmlSerializer = new XMLSerializer();
var contentStr = ""; for (var i = 0; i < node.childNodes.length; i++) {
contentStr += xmlSerializer.serializeToString(node.childNodes[i]); if (contentStr == "undefined") {
return dojo.dom.getContentAsStringGeneric(parentNode);
}
}
return contentStr;
}
do not use directly, internal only dojo.dom.getContentAsStringGeneric = function(node) {
var _result = ""; if (node == null) { return _result; } for (var i = 0; i < node.childNodes.length; i++) {
var thisNode = node.childNodes[i]; switch (thisNode.nodeType) {
case 1: ELEMENT_NODE case 5: ENTITY_REFERENCE_NODE
_result += dojo.dom.getElementAsStringGeneric(thisNode); break;
case 3: TEXT_NODE case 2: ATTRIBUTE_NODE case 4: CDATA_SECTION_NODE
_result += thisNode.nodeValue; break;
default:
break;
}
} return _result;
}
do not use directly, internal only dojo.dom.getElementAsStringGeneric = function(node) {
var result = ""; if (node == null) { return _result; } start tag result += '<' + node.nodeName; add attributes if (node.attributes && node.attributes.length>0) {
for (var i = 0; i < node.attributes.length; i++) {
result += " " + node.attributes[i].name
+ "="" + node.attributes[i].value + """;
}
} close start tag result += '>'; content of tag result += dojo.dom.getContentAsStringGeneric(node); end tag result += '</' + node.nodeName + '>'; return result;
}
Attachments (2)
Change History (8)
Changed 15 years ago by
Attachment: | dojo-dom-patch.txt added |
---|
comment:2 Changed 15 years ago by
Uggh..You're going to hate me, but the dojo.dom.getContentAsStringMozilla has a bug in it, the parentNode reference should be to just "node" instead. I'll upload a new patch though in case you haven't applied anything already.
comment:3 Changed 15 years ago by
Neither patch version meets the style guide. Can you fix and resubmit?
comment:4 Changed 15 years ago by
Sounds good. I will work on that this weekend along with the other things.
comment:5 Changed 15 years ago by
Milestone: | → 0.4 |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
Functionality is now questionable considering discussions about core library size. This can stay in tacos.
patch