@@ -75,7 +75,9 @@ function Accordion ($module, config) {
75
75
this . sectionContentClass = 'govuk-accordion__section-content'
76
76
}
77
77
78
- // Initialize component
78
+ /**
79
+ * Initialise component
80
+ */
79
81
Accordion . prototype . init = function ( ) {
80
82
// Check for module
81
83
if ( ! this . $module ) {
@@ -90,7 +92,9 @@ Accordion.prototype.init = function () {
90
92
this . updateShowAllButton ( areAllSectionsOpen )
91
93
}
92
94
93
- // Initialise controls and set attributes
95
+ /**
96
+ * Initialise controls and set attributes
97
+ */
94
98
Accordion . prototype . initControls = function ( ) {
95
99
// Create "Show all" button and set attributes
96
100
this . $showAllButton = document . createElement ( 'button' )
@@ -123,7 +127,9 @@ Accordion.prototype.initControls = function () {
123
127
}
124
128
}
125
129
126
- // Initialise section headers
130
+ /**
131
+ * Initialise section headers
132
+ */
127
133
Accordion . prototype . initSectionHeaders = function ( ) {
128
134
// Loop through section headers
129
135
nodeListForEach ( this . $sections , function ( $section , i ) {
@@ -141,6 +147,12 @@ Accordion.prototype.initSectionHeaders = function () {
141
147
} . bind ( this ) )
142
148
}
143
149
150
+ /**
151
+ * Construct section header
152
+ *
153
+ * @param {HTMLDivElement } $headerWrapper - Section header wrapper
154
+ * @param {number } index - Section index
155
+ */
144
156
Accordion . prototype . constructHeaderMarkup = function ( $headerWrapper , index ) {
145
157
var $span = $headerWrapper . querySelector ( '.' + this . sectionButtonClass )
146
158
var $heading = $headerWrapper . querySelector ( '.' + this . sectionHeadingClass )
@@ -237,15 +249,23 @@ Accordion.prototype.constructHeaderMarkup = function ($headerWrapper, index) {
237
249
$heading . appendChild ( $button )
238
250
}
239
251
240
- // When a section is opened by the user agent via the 'beforematch' event
252
+ /**
253
+ * When a section is opened by the user agent via the 'beforematch' event
254
+ *
255
+ * @param {Event } event - Generic event
256
+ */
241
257
Accordion . prototype . onBeforeMatch = function ( event ) {
242
258
var $section = event . target . closest ( '.' + this . sectionClass )
243
259
if ( $section ) {
244
260
this . setExpanded ( true , $section )
245
261
}
246
262
}
247
263
248
- // When section toggled, set and store state
264
+ /**
265
+ * When section toggled, set and store state
266
+ *
267
+ * @param {HTMLElement } $section - Section element
268
+ */
249
269
Accordion . prototype . onSectionToggle = function ( $section ) {
250
270
var expanded = this . isExpanded ( $section )
251
271
this . setExpanded ( ! expanded , $section )
@@ -254,7 +274,9 @@ Accordion.prototype.onSectionToggle = function ($section) {
254
274
this . storeState ( $section )
255
275
}
256
276
257
- // When Open/Close All toggled, set and store state
277
+ /**
278
+ * When Open/Close All toggled, set and store state
279
+ */
258
280
Accordion . prototype . onShowOrHideAllToggle = function ( ) {
259
281
var $module = this
260
282
var $sections = this . $sections
@@ -269,7 +291,12 @@ Accordion.prototype.onShowOrHideAllToggle = function () {
269
291
$module . updateShowAllButton ( nowExpanded )
270
292
}
271
293
272
- // Set section attributes when opened/closed
294
+ /**
295
+ * Set section attributes when opened/closed
296
+ *
297
+ * @param {boolean } expanded - Section expanded
298
+ * @param {HTMLElement } $section - Section element
299
+ */
273
300
Accordion . prototype . setExpanded = function ( expanded , $section ) {
274
301
var $icon = $section . querySelector ( '.' + this . upChevronIconClass )
275
302
var $showHideText = $section . querySelector ( '.' + this . sectionShowHideTextClass )
@@ -320,12 +347,21 @@ Accordion.prototype.setExpanded = function (expanded, $section) {
320
347
this . updateShowAllButton ( areAllSectionsOpen )
321
348
}
322
349
323
- // Get state of section
350
+ /**
351
+ * Get state of section
352
+ *
353
+ * @param {HTMLElement } $section - Section element
354
+ * @returns {boolean } True if expanded
355
+ */
324
356
Accordion . prototype . isExpanded = function ( $section ) {
325
357
return $section . classList . contains ( this . sectionExpandedClass )
326
358
}
327
359
328
- // Check if all sections are open
360
+ /**
361
+ * Check if all sections are open
362
+ *
363
+ * @returns {boolean } True if all sections are open
364
+ */
329
365
Accordion . prototype . checkIfAllSectionsOpen = function ( ) {
330
366
// Get a count of all the Accordion sections
331
367
var sectionsCount = this . $sections . length
@@ -336,7 +372,11 @@ Accordion.prototype.checkIfAllSectionsOpen = function () {
336
372
return areAllSectionsOpen
337
373
}
338
374
339
- // Update "Show all sections" button
375
+ /**
376
+ * Update "Show all sections" button
377
+ *
378
+ * @param {boolean } expanded - Section expanded
379
+ */
340
380
Accordion . prototype . updateShowAllButton = function ( expanded ) {
341
381
var $showAllIcon = this . $showAllButton . querySelector ( '.' + this . upChevronIconClass )
342
382
var $showAllText = this . $showAllButton . querySelector ( '.' + this . showAllTextClass )
@@ -354,8 +394,12 @@ Accordion.prototype.updateShowAllButton = function (expanded) {
354
394
}
355
395
}
356
396
357
- // Check for `window.sessionStorage`, and that it actually works.
358
397
var helper = {
398
+ /**
399
+ * Check for `window.sessionStorage`, and that it actually works.
400
+ *
401
+ * @returns {boolean } True if session storage is available
402
+ */
359
403
checkForSessionStorage : function ( ) {
360
404
var testString = 'this is the test string'
361
405
var result
@@ -370,7 +414,11 @@ var helper = {
370
414
}
371
415
}
372
416
373
- // Set the state of the accordions in sessionStorage
417
+ /**
418
+ * Set the state of the accordions in sessionStorage
419
+ *
420
+ * @param {HTMLElement } $section - Section element
421
+ */
374
422
Accordion . prototype . storeState = function ( $section ) {
375
423
if ( this . browserSupportsSessionStorage ) {
376
424
// We need a unique way of identifying each content in the Accordion. Since
@@ -390,7 +438,11 @@ Accordion.prototype.storeState = function ($section) {
390
438
}
391
439
}
392
440
393
- // Read the state of the accordions from sessionStorage
441
+ /**
442
+ * Read the state of the accordions from sessionStorage
443
+ *
444
+ * @param {HTMLElement } $section - Section element
445
+ */
394
446
Accordion . prototype . setInitialState = function ( $section ) {
395
447
if ( this . browserSupportsSessionStorage ) {
396
448
var $button = $section . querySelector ( '.' + this . sectionButtonClass )
@@ -409,11 +461,11 @@ Accordion.prototype.setInitialState = function ($section) {
409
461
/**
410
462
* Create an element to improve semantics of the section button with punctuation
411
463
*
412
- * @returns {HTMLSpanElement } DOM element
413
- *
414
464
* Adding punctuation to the button can also improve its general semantics by dividing its contents
415
465
* into thematic chunks.
416
466
* See https://github.com/alphagov/govuk-frontend/issues/2327#issuecomment-922957442
467
+ *
468
+ * @returns {HTMLElement } DOM element
417
469
*/
418
470
Accordion . prototype . getButtonPunctuationEl = function ( ) {
419
471
var $punctuationEl = document . createElement ( 'span' )
0 commit comments