SidebarTreeElement.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * Copyright (C) 2008 Apple Inc. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. /**
  26. * @constructor
  27. * @extends {TreeElement}
  28. */
  29. WebInspector.SidebarSectionTreeElement = function(title, representedObject, hasChildren)
  30. {
  31. TreeElement.call(this, title.escapeHTML(), representedObject || {}, hasChildren);
  32. this.expand();
  33. }
  34. WebInspector.SidebarSectionTreeElement.prototype = {
  35. selectable: false,
  36. collapse: function()
  37. {
  38. // Should not collapse as it is not selectable.
  39. },
  40. get smallChildren()
  41. {
  42. return this._smallChildren;
  43. },
  44. set smallChildren(x)
  45. {
  46. if (this._smallChildren === x)
  47. return;
  48. this._smallChildren = x;
  49. if (this._smallChildren)
  50. this._childrenListNode.addStyleClass("small");
  51. else
  52. this._childrenListNode.removeStyleClass("small");
  53. },
  54. onattach: function()
  55. {
  56. this._listItemNode.addStyleClass("sidebar-tree-section");
  57. },
  58. onreveal: function()
  59. {
  60. if (this.listItemElement)
  61. this.listItemElement.scrollIntoViewIfNeeded(false);
  62. },
  63. __proto__: TreeElement.prototype
  64. }
  65. /**
  66. * @constructor
  67. * @extends {TreeElement}
  68. * @param {string=} subtitle
  69. * @param {Object=} representedObject
  70. * @param {boolean=} hasChildren
  71. */
  72. WebInspector.SidebarTreeElement = function(className, title, subtitle, representedObject, hasChildren)
  73. {
  74. TreeElement.call(this, "", representedObject, hasChildren);
  75. if (hasChildren) {
  76. this.disclosureButton = document.createElement("button");
  77. this.disclosureButton.className = "disclosure-button";
  78. }
  79. if (!this.iconElement) {
  80. this.iconElement = document.createElement("img");
  81. this.iconElement.className = "icon";
  82. }
  83. this.statusElement = document.createElement("div");
  84. this.statusElement.className = "status";
  85. this.titlesElement = document.createElement("div");
  86. this.titlesElement.className = "titles";
  87. this.titleElement = document.createElement("span");
  88. this.titleElement.className = "title";
  89. this.titlesElement.appendChild(this.titleElement);
  90. this.subtitleElement = document.createElement("span");
  91. this.subtitleElement.className = "subtitle";
  92. this.titlesElement.appendChild(this.subtitleElement);
  93. this.className = className;
  94. this.mainTitle = title;
  95. this.subtitle = subtitle;
  96. }
  97. WebInspector.SidebarTreeElement.prototype = {
  98. get small()
  99. {
  100. return this._small;
  101. },
  102. set small(x)
  103. {
  104. this._small = x;
  105. if (this._listItemNode) {
  106. if (this._small)
  107. this._listItemNode.addStyleClass("small");
  108. else
  109. this._listItemNode.removeStyleClass("small");
  110. }
  111. },
  112. get mainTitle()
  113. {
  114. return this._mainTitle;
  115. },
  116. set mainTitle(x)
  117. {
  118. this._mainTitle = x;
  119. this.refreshTitles();
  120. },
  121. get subtitle()
  122. {
  123. return this._subtitle;
  124. },
  125. set subtitle(x)
  126. {
  127. this._subtitle = x;
  128. this.refreshTitles();
  129. },
  130. get bubbleText()
  131. {
  132. return this._bubbleText;
  133. },
  134. set bubbleText(x)
  135. {
  136. if (!this.bubbleElement) {
  137. this.bubbleElement = document.createElement("div");
  138. this.bubbleElement.className = "bubble";
  139. this.statusElement.appendChild(this.bubbleElement);
  140. }
  141. this._bubbleText = x;
  142. this.bubbleElement.textContent = x;
  143. },
  144. set wait(x)
  145. {
  146. if (x)
  147. this._listItemNode.addStyleClass("wait");
  148. else
  149. this._listItemNode.removeStyleClass("wait");
  150. },
  151. refreshTitles: function()
  152. {
  153. var mainTitle = this.mainTitle;
  154. if (this.titleElement.textContent !== mainTitle)
  155. this.titleElement.textContent = mainTitle;
  156. var subtitle = this.subtitle;
  157. if (subtitle) {
  158. if (this.subtitleElement.textContent !== subtitle)
  159. this.subtitleElement.textContent = subtitle;
  160. this.titlesElement.removeStyleClass("no-subtitle");
  161. } else {
  162. this.subtitleElement.textContent = "";
  163. this.titlesElement.addStyleClass("no-subtitle");
  164. }
  165. },
  166. isEventWithinDisclosureTriangle: function(event)
  167. {
  168. return event.target === this.disclosureButton;
  169. },
  170. onattach: function()
  171. {
  172. this._listItemNode.addStyleClass("sidebar-tree-item");
  173. if (this.className)
  174. this._listItemNode.addStyleClass(this.className);
  175. if (this.small)
  176. this._listItemNode.addStyleClass("small");
  177. if (this.hasChildren && this.disclosureButton)
  178. this._listItemNode.appendChild(this.disclosureButton);
  179. this._listItemNode.appendChild(this.iconElement);
  180. this._listItemNode.appendChild(this.statusElement);
  181. this._listItemNode.appendChild(this.titlesElement);
  182. },
  183. onreveal: function()
  184. {
  185. if (this._listItemNode)
  186. this._listItemNode.scrollIntoViewIfNeeded(false);
  187. },
  188. __proto__: TreeElement.prototype
  189. }