@@ -152,23 +152,10 @@ function _appendIssue(issue, node, listEl, issueGroups) {
152152 } ) ;
153153
154154 if ( ! isNodeContainedInGroup ) {
155- issueGroup . nodes . push ( node ) ;
156-
157- if ( issueGroup . view ) {
158- // Remove occurrences element in order to update occurrences only.
159- issueGroup . view . querySelector ( ".occurrences" ) . remove ( ) ;
160- } else {
161- // Append new view for this issue.
162- const view = _renderIssue ( issueGroup ) ;
163- listEl . appendChild ( view ) ;
164- issueGroup . view = view ;
165- }
166-
167- issueGroup . view . append ( _renderOccurrences ( issueGroup . nodes ) ) ;
155+ _appendOccurrence ( issueGroup , node , listEl ) ;
168156 }
169157}
170158
171-
172159function _renderNoIssue ( listEl ) {
173160 const noIssueEl = document . createElement ( "li" ) ;
174161 noIssueEl . textContent = "No issues" ;
@@ -186,38 +173,53 @@ function _renderIssue(issue) {
186173 return issueEl ;
187174}
188175
189- function _renderOccurrences ( nodes ) {
190- const occurrencesEl = document . createElement ( "section" ) ;
191- occurrencesEl . classList . add ( "occurrences" ) ;
192-
193- const nodelistEl = document . createElement ( "ul" ) ;
194- for ( const { id, className, nodeName } of nodes ) {
195- const nodeEl = document . createElement ( "li" ) ;
196- nodeEl . append ( _renderTerm ( nodeName . toLowerCase ( ) , [ "node-name" ] ) ) ;
197-
198- if ( id ) {
199- nodeEl . append ( _renderTerm ( `#${ id } ` , [ "node-id" ] ) ) ;
200- } else if ( className . length ) {
201- nodeEl . append ( _renderTerm ( `.${ className . replace ( / \s + / g, "." ) } ` , [ "node-class" ] ) ) ;
176+ function _appendOccurrence ( issueGroup , occurrencedNode , issueListEl ) {
177+ issueGroup . nodes . push ( occurrencedNode ) ;
178+
179+ if ( issueGroup . nodes . length === 1 ) {
180+ // Append new view for this issue.
181+ const issueGroupEl = _renderIssue ( issueGroup ) ;
182+ issueListEl . appendChild ( issueGroupEl ) ;
183+
184+ // Prepare the element to show the occurrences.
185+ const sectionEl = document . createElement ( "section" ) ;
186+ sectionEl . classList . add ( "occurrences" ) ;
187+ const occurrencesEl = document . createElement ( "ul" ) ;
188+ issueGroupEl . append ( sectionEl ) ;
189+ sectionEl . append ( occurrencesEl ) ;
190+ issueGroup . view = sectionEl ;
191+ } else {
192+ if ( issueGroup . nodes . length === 2 ) {
193+ // As found multiple occurrences, change to the collapsable element.
194+ const listEl = issueGroup . view . querySelector ( "ul" ) ;
195+ const summaryEl = document . createElement ( "summary" ) ;
196+ const detailsEl = document . createElement ( "details" ) ;
197+ detailsEl . append ( summaryEl , listEl ) ;
198+ issueGroup . view . append ( detailsEl ) ;
202199 }
203200
204- nodeEl . addEventListener ( "click" , _onClickNodeSelector ) ;
205- nodelistEl . append ( nodeEl ) ;
201+ const summaryEl = issueGroup . view . querySelector ( "summary" ) ;
202+ summaryEl . textContent = ` ${ issueGroup . nodes . length } occurrences` ;
206203 }
207204
208- if ( nodes . length !== 1 ) {
209- const summaryEl = document . createElement ( "summary" ) ;
210- summaryEl . textContent = ` ${ nodes . length } occurrences` ;
205+ const listEl = issueGroup . view . querySelector ( "ul" ) ;
206+ listEl . append ( _renderOccurrence ( occurrencedNode ) ) ;
207+ }
211208
212- const detailsEl = document . createElement ( "details" ) ;
213- detailsEl . append ( summaryEl , nodelistEl ) ;
209+ function _renderOccurrence ( { id, className, nodeName} ) {
210+ const occurrenceEl = document . createElement ( "li" ) ;
211+ occurrenceEl . append ( _renderTerm ( nodeName . toLowerCase ( ) , [ "node-name" ] ) ) ;
214212
215- occurrencesEl . append ( detailsEl ) ;
216- } else {
217- occurrencesEl . append ( nodelistEl ) ;
213+ if ( id ) {
214+ occurrenceEl . append ( _renderTerm ( `#${ id } ` , [ "node-id" ] ) ) ;
215+ } else if ( className . length ) {
216+ occurrenceEl . append (
217+ _renderTerm ( `.${ className . replace ( / \s + / g, "." ) } ` , [ "node-class" ] ) ) ;
218218 }
219219
220- return occurrencesEl ;
220+ occurrenceEl . addEventListener ( "click" , _onClickNodeSelector ) ;
221+
222+ return occurrenceEl ;
221223}
222224
223225function _renderSubject ( issue ) {
0 commit comments