@@ -118,23 +118,10 @@ function _appendIssue(issue, node, listEl, issueGroups) {
118118 } ) ;
119119
120120 if ( ! isNodeContainedInGroup ) {
121- issueGroup . nodes . push ( node ) ;
122-
123- if ( issueGroup . view ) {
124- // Remove occurrences element in order to update occurrences only.
125- issueGroup . view . querySelector ( ".occurrences" ) . remove ( ) ;
126- } else {
127- // Append new view for this issue.
128- const view = _renderIssue ( issueGroup ) ;
129- listEl . appendChild ( view ) ;
130- issueGroup . view = view ;
131- }
132-
133- issueGroup . view . append ( _renderOccurrences ( issueGroup . nodes ) ) ;
121+ _appendOccurrence ( issueGroup , node , listEl ) ;
134122 }
135123}
136124
137-
138125function _renderNoIssue ( listEl ) {
139126 const noIssueEl = document . createElement ( "li" ) ;
140127 noIssueEl . textContent = "No issues" ;
@@ -152,38 +139,53 @@ function _renderIssue(issue) {
152139 return issueEl ;
153140}
154141
155- function _renderOccurrences ( nodes ) {
156- const occurrencesEl = document . createElement ( "section" ) ;
157- occurrencesEl . classList . add ( "occurrences" ) ;
158-
159- const nodelistEl = document . createElement ( "ul" ) ;
160- for ( const { id, className, nodeName } of nodes ) {
161- const nodeEl = document . createElement ( "li" ) ;
162- nodeEl . append ( _renderTerm ( nodeName . toLowerCase ( ) , [ "node-name" ] ) ) ;
163-
164- if ( id ) {
165- nodeEl . append ( _renderTerm ( `#${ id } ` , [ "node-id" ] ) ) ;
166- } else if ( className . length ) {
167- nodeEl . append ( _renderTerm ( `.${ className . replace ( / \s + / g, "." ) } ` , [ "node-class" ] ) ) ;
142+ function _appendOccurrence ( issueGroup , occurrencedNode , issueListEl ) {
143+ issueGroup . nodes . push ( occurrencedNode ) ;
144+
145+ if ( issueGroup . nodes . length === 1 ) {
146+ // Append new view for this issue.
147+ const issueGroupEl = _renderIssue ( issueGroup ) ;
148+ issueListEl . appendChild ( issueGroupEl ) ;
149+
150+ // Prepare the element to show the occurrences.
151+ const sectionEl = document . createElement ( "section" ) ;
152+ sectionEl . classList . add ( "occurrences" ) ;
153+ const occurrencesEl = document . createElement ( "ul" ) ;
154+ issueGroupEl . append ( sectionEl ) ;
155+ sectionEl . append ( occurrencesEl ) ;
156+ issueGroup . view = sectionEl ;
157+ } else {
158+ if ( issueGroup . nodes . length === 2 ) {
159+ // As found multiple occurrences, change to the collapsable element.
160+ const listEl = issueGroup . view . querySelector ( "ul" ) ;
161+ const summaryEl = document . createElement ( "summary" ) ;
162+ const detailsEl = document . createElement ( "details" ) ;
163+ detailsEl . append ( summaryEl , listEl ) ;
164+ issueGroup . view . append ( detailsEl ) ;
168165 }
169166
170- nodeEl . addEventListener ( "click" , _onClickNodeSelector ) ;
171- nodelistEl . append ( nodeEl ) ;
167+ const summaryEl = issueGroup . view . querySelector ( "summary" ) ;
168+ summaryEl . textContent = ` ${ issueGroup . nodes . length } occurrences` ;
172169 }
173170
174- if ( nodes . length !== 1 ) {
175- const summaryEl = document . createElement ( "summary" ) ;
176- summaryEl . textContent = ` ${ nodes . length } occurrences` ;
171+ const listEl = issueGroup . view . querySelector ( "ul" ) ;
172+ listEl . append ( _renderOccurrence ( occurrencedNode ) ) ;
173+ }
177174
178- const detailsEl = document . createElement ( "details" ) ;
179- detailsEl . append ( summaryEl , nodelistEl ) ;
175+ function _renderOccurrence ( { id, className, nodeName} ) {
176+ const occurrenceEl = document . createElement ( "li" ) ;
177+ occurrenceEl . append ( _renderTerm ( nodeName . toLowerCase ( ) , [ "node-name" ] ) ) ;
180178
181- occurrencesEl . append ( detailsEl ) ;
182- } else {
183- occurrencesEl . append ( nodelistEl ) ;
179+ if ( id ) {
180+ occurrenceEl . append ( _renderTerm ( `#${ id } ` , [ "node-id" ] ) ) ;
181+ } else if ( className . length ) {
182+ occurrenceEl . append (
183+ _renderTerm ( `.${ className . replace ( / \s + / g, "." ) } ` , [ "node-class" ] ) ) ;
184184 }
185185
186- return occurrencesEl ;
186+ occurrenceEl . addEventListener ( "click" , _onClickNodeSelector ) ;
187+
188+ return occurrenceEl ;
187189}
188190
189191function _renderSubject ( issue ) {
0 commit comments