You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XMLAttribute.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Generated by CoffeeScript 2.4.1
  2. (function() {
  3. var NodeType, XMLAttribute, XMLNode;
  4. NodeType = require('./NodeType');
  5. XMLNode = require('./XMLNode');
  6. // Represents an attribute
  7. module.exports = XMLAttribute = (function() {
  8. class XMLAttribute {
  9. // Initializes a new instance of `XMLAttribute`
  10. // `parent` the parent node
  11. // `name` attribute target
  12. // `value` attribute value
  13. constructor(parent, name, value) {
  14. this.parent = parent;
  15. if (this.parent) {
  16. this.options = this.parent.options;
  17. this.stringify = this.parent.stringify;
  18. }
  19. if (name == null) {
  20. throw new Error("Missing attribute name. " + this.debugInfo(name));
  21. }
  22. this.name = this.stringify.name(name);
  23. this.value = this.stringify.attValue(value);
  24. this.type = NodeType.Attribute;
  25. // DOM level 3
  26. this.isId = false;
  27. this.schemaTypeInfo = null;
  28. }
  29. // Creates and returns a deep clone of `this`
  30. clone() {
  31. return Object.create(this);
  32. }
  33. // Converts the XML fragment to string
  34. // `options.pretty` pretty prints the result
  35. // `options.indent` indentation for pretty print
  36. // `options.offset` how many indentations to add to every line for pretty print
  37. // `options.newline` newline sequence for pretty print
  38. toString(options) {
  39. return this.options.writer.attribute(this, this.options.writer.filterOptions(options));
  40. }
  41. // Returns debug string for this node
  42. debugInfo(name) {
  43. name = name || this.name;
  44. if (name == null) {
  45. return "parent: <" + this.parent.name + ">";
  46. } else {
  47. return "attribute: {" + name + "}, parent: <" + this.parent.name + ">";
  48. }
  49. }
  50. isEqualNode(node) {
  51. if (node.namespaceURI !== this.namespaceURI) {
  52. return false;
  53. }
  54. if (node.prefix !== this.prefix) {
  55. return false;
  56. }
  57. if (node.localName !== this.localName) {
  58. return false;
  59. }
  60. if (node.value !== this.value) {
  61. return false;
  62. }
  63. return true;
  64. }
  65. };
  66. // DOM level 1
  67. Object.defineProperty(XMLAttribute.prototype, 'nodeType', {
  68. get: function() {
  69. return this.type;
  70. }
  71. });
  72. Object.defineProperty(XMLAttribute.prototype, 'ownerElement', {
  73. get: function() {
  74. return this.parent;
  75. }
  76. });
  77. // DOM level 3
  78. Object.defineProperty(XMLAttribute.prototype, 'textContent', {
  79. get: function() {
  80. return this.value;
  81. },
  82. set: function(value) {
  83. return this.value = value || '';
  84. }
  85. });
  86. // DOM level 4
  87. Object.defineProperty(XMLAttribute.prototype, 'namespaceURI', {
  88. get: function() {
  89. return '';
  90. }
  91. });
  92. Object.defineProperty(XMLAttribute.prototype, 'prefix', {
  93. get: function() {
  94. return '';
  95. }
  96. });
  97. Object.defineProperty(XMLAttribute.prototype, 'localName', {
  98. get: function() {
  99. return this.name;
  100. }
  101. });
  102. Object.defineProperty(XMLAttribute.prototype, 'specified', {
  103. get: function() {
  104. return true;
  105. }
  106. });
  107. return XMLAttribute;
  108. }).call(this);
  109. }).call(this);