Requires

Provides

Document.js

Provides a virtual root to all the widgets. DOM-Compatible for Slick traversals.

License:
Public domain (http://unlicense.org).
Authors:
Yaroslaff Fedin

Document is a big disguise proxy class that contains the tree of widgets and a link to document element.

It is DOM-compatible (to some degree), so tools that crawl DOM tree (we use Slick) can work with the widget tree like it usually does with the real DOM so we get selector engine for free.

The class contains a few hacks that allows Slick to initialize.

  1. 38
  2. 39
  3. 40
  4. 41
  5. 42
  6. 43
  7. 44
  8. 45
  9. 46
  10. 47
  11. 48
  12. 49
  13. 50
  14. 51
  15. 52
  16. 53
  17. 54
  18. 55
  19. 56
  20. 57
  21. 58
  22. 59
  23. 60
  24. 61
  25. 62
  26. 63
  27. 64
  28. 65
  29. 66
  30. 67
  31. 68
  32. 69
  33. 70
  34. 71
  35. 72
  36. 73
  37. 74
  38. 75
  39. 76
  40. 77
  41. 78
  42. 79
  43. 80
  44. 81
  45. 82
  46. 83
  47. 84
  48. 85
  49. 86
  50. 87
  51. 88
  52. 89
  53. 90
  54. 91
  55. 92
  56. 93
  57. 94
  58. 95
  59. 96
  60. 97
  61. 98
  62. 99
  63. 100
  64. 101
  65. 102
  66. 103
  67. 104
  68. 105
  69. 106
  70. 107
  71. 108
  72. 109
  73. 110
  74. 111
  75. 112
  76. 113
  77. 114
  78. 115
  79. 116
  80. 117
  81. 118
  82. 119
  83. 120
  84. 121
  85. 122
  86. 123
  87. 124
  88. 125
  89. 126
  90. 127
  91. 128
  92. 129
  93. 130
LSD.Document = new Class({ Includes: [ LSD.Node, LSD.Module.Attributes, LSD.Module.DOM, LSD.Module.Events, LSD.Module.Layout ], options: { tag: '#document', root: false, // topmost widget's parentNode is the document if set to true layout: { method: 'augment' }, nodeType: 9 }, initialize: function(element, options) { if (!LSD.document.body) LSD.document = Object.append(this, LSD.document); this.parent.apply(this, [element, options]); this.body = this.element; this.document = this.documentElement = this; if (this.nodeType != 9) this.ownerDocument = this; this.xml = true; this.navigator = {}; this.attributes = {}; this.slickFeatures = { brokenStarGEBTN: false, starSelectsClosedQSA: false, idGetsName: false, brokenMixedCaseQSA: false, brokenGEBCN: false, brokenCheckedQSA: false, brokenEmptyAttributeQSA: false, isHTMLDocument: false, nativeMatchesSelector: false, hasAttribute: function(node, attribute) { return (attribute in node.attributes) || ((attribute in node.options.states) && (attribute in node.pseudos)) }, getAttribute: function(node, attribute) { return node.attributes[attribute] || ((attribute in node.options.states) || node.pseudos[attribute]); }, compareDocumentPosition: function(self, node) { var context = node.localName ? (self.localName ? self : self.toElement()) : self; if (node) do { if (node === context) return true; } while ((node = node.parentNode)); return false; }, documentSorter: function(a, b) { return features.compareDocumentPosition(a, b) & 4 ? -1 : a === b ? 0 : 1; } } this.events = this.options.events; this.dominjected = true; this.build(); }, setParent: function(widget) { if (this.options.root) this.parent.apply(this, arguments); }, id: function(item) { if (item.render) return item; }, addStylesheet: function(sheet) { if (!this.stylesheets) this.stylesheets = []; this.stylesheets.include(sheet); sheet.attach(this); }, removeStylesheet: function(sheet) { if (!this.stylesheets) return; this.stylesheets.erase(sheet); sheet.detach(this); }, createFragment: function(content) { var fragment = document.createFragment(content) this.fireEvent('DOMNodeInserted', fragment); return fragment; } }); LSD.Document.prototype.addState('built'); LSD.Document.prototype.addEvents({ initialize: function() { if (this.watch) {

Attach behaviour expectations

  1. 132
LSD.Module.Expectations.attach(this);

Attach action expectations

  1. 134
  2. 135
LSD.Module.Actions.attach(this); }

Attach stylesheets, if there are stylesheets loaded

  1. 137
  2. 138
  3. 139
if (LSD.Sheet && LSD.Sheet.stylesheets) for (var i = 0, sheet; sheet = LSD.Sheet.stylesheets[i++];) this.addStylesheet(sheet); } });

Properties set here will be picked up by first document

  1. 142
LSD.document = {};