| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 }, | 78 }, |
| 79 | 79 |
| 80 set selected(x) | 80 set selected(x) |
| 81 { | 81 { |
| 82 if (x) | 82 if (x) |
| 83 this.select(); | 83 this.select(); |
| 84 else | 84 else |
| 85 this.deselect(); | 85 this.deselect(); |
| 86 }, | 86 }, |
| 87 | 87 |
| 88 /** | |
| 89 * @return {!WebInspector.PlacardGroup|undefined} | |
| 90 */ | |
| 91 group: function() | |
| 92 { | |
| 93 return this._group; | |
| 94 }, | |
| 95 | |
| 96 /** | |
| 97 * @param {!WebInspector.PlacardGroup} group | |
| 98 */ | |
| 99 setGroup: function(group) | |
| 100 { | |
| 101 this._group = group; | |
| 102 }, | |
| 103 | |
| 104 select: function() | 88 select: function() |
| 105 { | 89 { |
| 106 if (this._selected) | 90 if (this._selected) |
| 107 return; | 91 return; |
| 108 if (this._group) | |
| 109 this._group.setExpanded(true); | |
| 110 this._selected = true; | 92 this._selected = true; |
| 111 this.element.addStyleClass("selected"); | 93 this.element.addStyleClass("selected"); |
| 112 }, | 94 }, |
| 113 | 95 |
| 114 deselect: function() | 96 deselect: function() |
| 115 { | 97 { |
| 116 if (!this._selected) | 98 if (!this._selected) |
| 117 return; | 99 return; |
| 118 this._selected = false; | 100 this._selected = false; |
| 119 this.element.removeStyleClass("selected"); | 101 this.element.removeStyleClass("selected"); |
| 120 }, | 102 }, |
| 121 | 103 |
| 122 toggleSelected: function() | 104 toggleSelected: function() |
| 123 { | 105 { |
| 124 this.selected = !this.selected; | 106 this.selected = !this.selected; |
| 125 }, | 107 }, |
| 126 | 108 |
| 127 discard: function() | 109 discard: function() |
| 128 { | 110 { |
| 129 } | 111 } |
| 130 } | 112 } |
| 131 | |
| 132 /** | |
| 133 * @constructor | |
| 134 * @param {string} title | |
| 135 * @param {!Array.<!WebInspector.Placard>} placards | |
| 136 */ | |
| 137 WebInspector.PlacardGroup = function(title, placards) | |
| 138 { | |
| 139 this.element = document.createElementWithClass("div", "placard placard-group
"); | |
| 140 this.element.addEventListener("click", this._toggleExpanded.bind(this), fals
e); | |
| 141 this.placards = placards; | |
| 142 this._expanded = false; | |
| 143 this.setTitle(title); | |
| 144 | |
| 145 for (var i = 0; i < placards.length; ++i) | |
| 146 placards[i].setGroup(this); | |
| 147 } | |
| 148 | |
| 149 WebInspector.PlacardGroup.prototype = { | |
| 150 /** | |
| 151 * @return {string} | |
| 152 */ | |
| 153 title: function() | |
| 154 { | |
| 155 return this._title; | |
| 156 }, | |
| 157 | |
| 158 /** | |
| 159 * @param {string} title | |
| 160 */ | |
| 161 setTitle: function(title) | |
| 162 { | |
| 163 this._title = title; | |
| 164 this.element.textContent = title; | |
| 165 }, | |
| 166 | |
| 167 /** | |
| 168 * @return {boolean} | |
| 169 */ | |
| 170 expanded: function() | |
| 171 { | |
| 172 return this._expanded; | |
| 173 }, | |
| 174 | |
| 175 /** | |
| 176 * @param {boolean} x | |
| 177 */ | |
| 178 setExpanded: function(x) | |
| 179 { | |
| 180 if (this._expanded === x) | |
| 181 return; | |
| 182 if (x) { | |
| 183 var parent = this.element.parentElement; | |
| 184 if (!parent) | |
| 185 return; | |
| 186 var sibling = this.element.nextSibling; | |
| 187 for (var i = 0; i < this.placards.length; ++i) { | |
| 188 var placard = this.placards[i]; | |
| 189 placard.element.addStyleClass("grouped"); | |
| 190 parent.insertBefore(placard.element, sibling); | |
| 191 } | |
| 192 } else { | |
| 193 if (this.selected()) | |
| 194 return; | |
| 195 for (var i = 0; i < this.placards.length; ++i) { | |
| 196 var placard = this.placards[i]; | |
| 197 placard.element.removeStyleClass("grouped"); | |
| 198 placard.element.remove(); | |
| 199 } | |
| 200 } | |
| 201 this._expanded = x; | |
| 202 }, | |
| 203 | |
| 204 /** | |
| 205 * @return {boolean} | |
| 206 */ | |
| 207 selected: function() | |
| 208 { | |
| 209 for (var i = 0; i < this.placards.length; ++i) { | |
| 210 if (this.placards[i].selected) | |
| 211 return true; | |
| 212 } | |
| 213 return false; | |
| 214 }, | |
| 215 | |
| 216 _toggleExpanded: function() | |
| 217 { | |
| 218 this.setExpanded(!this._expanded); | |
| 219 this.element.enableStyleClass("expanded", this._expanded); | |
| 220 } | |
| 221 } | |
| OLD | NEW |