1-
21const PREFIX = "test-" ;
32const SHOWLINK_SUFFIX = "-showlink" ;
43const HIDELINK_SUFFIX = "-hidelink" ;
@@ -10,12 +9,16 @@ function showFailureSummary(summaryId, query) {
109 document . getElementById ( summaryId + SHOWLINK_SUFFIX ) . style . display = "none" ;
1110 document . getElementById ( summaryId + HIDELINK_SUFFIX ) . style . display = "" ;
1211
13- if ( typeof query !== 'undefined' ) {
12+ if ( typeof query !== 'undefined' && element . innerHTML . trim ( ) === 'Loading...' ) {
1413 let rqo = new XMLHttpRequest ( ) ;
1514 rqo . open ( 'GET' , query , true ) ;
16- rqo . onreadystatechange = function ( ) { element . innerHTML = rqo . responseText ; }
15+ rqo . onreadystatechange = function ( ) {
16+ element . innerHTML = rqo . responseText ;
17+ initializeShowHideLinks ( element ) ;
18+ }
1719 rqo . send ( null ) ;
1820 }
21+
1922}
2023
2124function hideFailureSummary ( summaryId ) {
@@ -24,24 +27,28 @@ function hideFailureSummary(summaryId) {
2427 document . getElementById ( summaryId + HIDELINK_SUFFIX ) . style . display = "none" ;
2528}
2629
30+ function initializeShowHideLinks ( container ) {
31+ container = container || document ;
2732
28- document . addEventListener ( 'DOMContentLoaded' , ( ) => {
29- const testShowlinks = document . querySelectorAll ( "a[id*=test-][id*=-showlink]" ) ;
30- testShowlinks . forEach ( ( element ) => {
31- element . addEventListener ( 'click' , ( event ) => {
32- const id = element . id . replace ( PREFIX , '' ) . replace ( SHOWLINK_SUFFIX , '' ) ;
33- const summaryId = PREFIX + id ;
34- showFailureSummary ( summaryId , document . URL + id + "summary" ) ;
35- } )
33+ container . querySelectorAll ( 'a[id$="-showlink"], a[id$="-hidelink"]' ) . forEach ( link => {
34+ link . addEventListener ( 'click' , handleShowHideClick ) ;
35+ link . style . cursor = 'pointer' ;
3636 } ) ;
37+ }
3738
38- // add the onclick behavior for all the "hidelinks"
39- const testHidelinks = document . querySelectorAll ( "a[id*=test-][id*=-hidelink]" ) ;
40- testHidelinks . forEach ( ( element ) => {
41- element . addEventListener ( 'click' , ( event ) => {
42- const id = element . id . replace ( PREFIX , '' ) . replace ( HIDELINK_SUFFIX , '' ) ;
43- const summaryId = PREFIX + id ;
44- hideFailureSummary ( summaryId ) ;
45- } )
46- } ) ;
39+ function handleShowHideClick ( event ) {
40+ event . preventDefault ( ) ;
41+
42+ let link = event . target . closest ( 'a[id$="-showlink"], a[id$="-hidelink"]' ) ;
43+ const id = link . id . replace ( / - s h o w l i n k $ / , '' ) . replace ( / - h i d e l i n k $ / , '' ) ;
44+
45+ if ( link . id . endsWith ( '-showlink' ) ) {
46+ showFailureSummary ( id , document . URL + id . replace ( PREFIX , '' ) + "summary" ) ;
47+ } else {
48+ hideFailureSummary ( id ) ;
49+ }
50+ }
51+
52+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
53+ initializeShowHideLinks ( ) ;
4754} ) ;
0 commit comments