dom.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. define("dojox/data/dom", ["dojo/_base/kernel", "dojo/_base/lang", "dojox/xml/parser"],
  2. function(kernel, lang, xmlParser) {
  3. //DOM type to int value for reference.
  4. //Ints make for more compact code than full constant names.
  5. //ELEMENT_NODE = 1;
  6. //ATTRIBUTE_NODE = 2;
  7. //TEXT_NODE = 3;
  8. //CDATA_SECTION_NODE = 4;
  9. //ENTITY_REFERENCE_NODE = 5;
  10. //ENTITY_NODE = 6;
  11. //PROCESSING_INSTRUCTION_NODE = 7;
  12. //COMMENT_NODE = 8;
  13. //DOCUMENT_NODE = 9;
  14. //DOCUMENT_TYPE_NODE = 10;
  15. //DOCUMENT_FRAGMENT_NODE = 11;
  16. //NOTATION_NODE = 12;
  17. //This file contains internal/helper APIs as holders for people who used them. They have been migrated to
  18. //a better project, dojox.xml and experimental has been removed there. Please update usage to the new package.
  19. dojo.deprecated("dojox.data.dom", "Use dojox.xml.parser instead.", "2.0");
  20. var dataDom = lang.getObject("dojox.data.dom",true);
  21. dataDom.createDocument = function(/*string?*/ str, /*string?*/ mimetype){
  22. // summary:
  23. // cross-browser implementation of creating an XML document object.
  24. //
  25. // str:
  26. // Optional text to create the document from. If not provided, an empty XML document will be created.
  27. // If str is empty string "", then a new empty document will be created.
  28. // mimetype:
  29. // Optional mimetype of the text. Typically, this is text/xml. Will be defaulted to text/xml if not provided.
  30. dojo.deprecated("dojox.data.dom.createDocument()", "Use dojox.xml.parser.parse() instead.", "2.0");
  31. try{
  32. return xmlParser.parse(str,mimetype); //DOMDocument.
  33. }catch(e){
  34. /*Squeltch errors like the old parser did.*/
  35. return null;
  36. }
  37. };
  38. dataDom.textContent = function(/*Node*/node, /*string?*/text){
  39. // summary:
  40. // Implementation of the DOM Level 3 attribute; scan node for text
  41. // description:
  42. // Implementation of the DOM Level 3 attribute; scan node for text
  43. // This function can also update the text of a node by replacing all child
  44. // content of the node.
  45. // node:
  46. // The node to get the text off of or set the text on.
  47. // text:
  48. // Optional argument of the text to apply to the node.
  49. dojo.deprecated("dojox.data.dom.textContent()", "Use dojox.xml.parser.textContent() instead.", "2.0");
  50. if(arguments.length> 1){
  51. return xmlParser.textContent(node, text); //string
  52. }else{
  53. return xmlParser.textContent(node); //string
  54. }
  55. };
  56. dataDom.replaceChildren = function(/*Element*/node, /*Node || array*/ newChildren){
  57. // summary:
  58. // Removes all children of node and appends newChild. All the existing
  59. // children will be destroyed.
  60. // description:
  61. // Removes all children of node and appends newChild. All the existing
  62. // children will be destroyed.
  63. // node:
  64. // The node to modify the children on
  65. // newChildren:
  66. // The children to add to the node. It can either be a single Node or an
  67. // array of Nodes.
  68. dojo.deprecated("dojox.data.dom.replaceChildren()", "Use dojox.xml.parser.replaceChildren() instead.", "2.0");
  69. xmlParser.replaceChildren(node, newChildren);
  70. };
  71. dataDom.removeChildren = function(/*Element*/node){
  72. // summary:
  73. // removes all children from node and returns the count of children removed.
  74. // The children nodes are not destroyed. Be sure to call dojo._destroyElement on them
  75. // after they are not used anymore.
  76. // node:
  77. // The node to remove all the children from.
  78. dojo.deprecated("dojox.data.dom.removeChildren()", "Use dojox.xml.parser.removeChildren() instead.", "2.0");
  79. return dojox.xml.parser.removeChildren(node); //int
  80. };
  81. dataDom.innerXML = function(/*Node*/node){
  82. // summary:
  83. // Implementation of MS's innerXML function.
  84. // node:
  85. // The node from which to generate the XML text representation.
  86. dojo.deprecated("dojox.data.dom.innerXML()", "Use dojox.xml.parser.innerXML() instead.", "2.0");
  87. return xmlParser.innerXML(node); //string||null
  88. };
  89. return dataDom;
  90. });