Opened 14 years ago

Closed 14 years ago

Last modified 12 years ago

#522 closed enhancement (wontfix)

additional dojo.dom utility methods/patch

Reported by: jkuhnert@… Owned by: anonymous
Priority: high Milestone:
Component: General Version: 0.2
Keywords: Cc: jkuhnert@…
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)

dojo-dom-patch.txt (2.9 KB) - added by jkuhnert@… 14 years ago.
patch
dojo-dom-patch.2.txt (2.9 KB) - added by jkuhnert@… 14 years ago.
good patch

Download all attachments as: .zip

Change History (8)

Changed 14 years ago by jkuhnert@…

Attachment: dojo-dom-patch.txt added

patch

comment:1 Changed 14 years ago by jkuhnert@…

Yeah I should have a CLA on file somewhere.

comment:2 Changed 14 years ago by jkuhnert@…

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.

Changed 14 years ago by jkuhnert@…

Attachment: dojo-dom-patch.2.txt added

good patch

comment:3 Changed 14 years ago by alex

Neither patch version meets the style guide. Can you fix and resubmit?

comment:4 Changed 14 years ago by jkuhnert@…

Sounds good. I will work on that this weekend along with the other things.

comment:5 Changed 14 years ago by jkuhnert@…

Milestone: 0.4
Resolution: wontfix
Status: newclosed

Functionality is now questionable considering discussions about core library size. This can stay in tacos.

comment:6 Changed 12 years ago by (none)

Milestone: 0.4

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.