11/*!
22 * @license MIT (https://github.com/geotrev/undernet/blob/master/LICENSE)
3- * Undernet v4.3 .0 (https://undernet.io)
3+ * Undernet v4.4 .0 (https://undernet.io)
44 * Copyright 2017-2019 George Treviranus
55 */
66const KeyCodes = {
@@ -21,6 +21,9 @@ const Events = {
2121 CLICK : "click" ,
2222} ;
2323
24+ /**
25+ * Simple DOM manipulator methods. NOTE: These aren't chainable.
26+ */
2427const dom = {
2528 attr : ( element , attr , newValue ) => {
2629 if ( newValue === false ) {
@@ -57,6 +60,9 @@ const dom = {
5760 } ,
5861} ;
5962
63+ /**
64+ * Return an array literal of elements matching focusable elements within a given container.
65+ */
6066const getFocusableElements = container => {
6167 const focusables = Selectors . FOCUSABLE_TAGS . map (
6268 element => `${ container } ${ element } ${ Selectors . NOT_VISUALLY_HIDDEN_CLASS } `
@@ -65,8 +71,15 @@ const getFocusableElements = container => {
6571 return dom . findAll ( focusables )
6672} ;
6773
74+ /**
75+ * Check if the current browser session is within an Apple device.
76+ */
6877const iOSMobile = / ( i p h o n e | i p o d | i p a d ) / i. test ( navigator . userAgent ) ;
6978
79+ /**
80+ * Utility class to help with focus trapping and keyboard outline management.
81+ * Components extend from this method.
82+ */
7083class Utils {
7184 constructor ( ) {
7285 // events
@@ -284,41 +297,40 @@ class Accordion extends Utils {
284297 // private
285298
286299 _setup ( instance ) {
287- const buttonId = dom . attr ( instance , Selectors$1 . DATA_TARGET ) ;
300+ const buttonTargetId = dom . attr ( instance , Selectors$1 . DATA_TARGET ) ;
288301 const accordionId = dom . attr ( instance , Selectors$1 . DATA_PARENT ) ;
289- const buttonContent = dom . find ( `#${ buttonId } ` ) ;
302+ const buttonContent = dom . find ( `#${ buttonTargetId } ` ) ;
290303
291304 if ( ! accordionId ) {
292- throw new Error ( Messages . NO_ACCORDION_ID_ERROR ( buttonId ) )
305+ throw new Error ( Messages . NO_ACCORDION_ID_ERROR ( buttonTargetId ) )
293306 }
294307
295308 if ( ! buttonContent ) {
296- throw new Error ( Messages . NO_CONTENT_ERROR ( buttonId ) )
309+ throw new Error ( Messages . NO_CONTENT_ERROR ( buttonTargetId ) )
297310 }
298311
299- const accordionRowAttr = this . _getAccordionRowAttr ( buttonId ) ;
312+ const accordionRowAttr = this . _getAccordionRowAttr ( buttonTargetId ) ;
300313 const accordionRow = dom . find ( accordionRowAttr ) ;
301314
302315 if ( ! accordionRow ) {
303- throw new Error ( Messages . NO_ROW_ERROR ( buttonId ) )
316+ throw new Error ( Messages . NO_ROW_ERROR ( buttonTargetId ) )
304317 }
305318
306- const buttonHeaderSelector = this . _headers . join ( ", " ) ;
307- const buttonHeader = dom . find ( buttonHeaderSelector , accordionRow ) ;
319+ const buttonId = instance . id ;
308320
309- if ( ! buttonHeader . id ) {
321+ if ( ! buttonId ) {
310322 throw new Error ( Messages . NO_HEADER_ID_ERROR ( accordionRowAttr ) )
311323 }
312324
313325 const buttonContentChildren = getFocusableElements ( `#${ buttonContent . id } ` ) ;
314326
315- dom . attr ( instance , Selectors$1 . ARIA_CONTROLS , buttonId ) ;
316- dom . attr ( buttonContent , Selectors$1 . ARIA_LABELLEDBY , buttonHeader . id ) ;
327+ dom . attr ( instance , Selectors$1 . ARIA_CONTROLS , buttonTargetId ) ;
328+ dom . attr ( buttonContent , Selectors$1 . ARIA_LABELLEDBY , buttonId ) ;
317329
318330 const contentShouldExpand = dom . attr ( accordionRow , Selectors$1 . DATA_VISIBLE ) ;
319331
320332 if ( ! contentShouldExpand ) {
321- throw new Error ( Messages . NO_VISIBLE_ERROR ( buttonId ) )
333+ throw new Error ( Messages . NO_VISIBLE_ERROR ( buttonTargetId ) )
322334 }
323335
324336 if ( contentShouldExpand === "true" ) {
0 commit comments