|
330 | 330 |
|
331 | 331 | function mc_build_toggles( targetId ) {
|
332 | 332 | if ( targetId ) {
|
333 |
| - const subscribe = $( '#' + targetId + ' .mc-subscribe' ); |
334 |
| - const exports = $( '#' + targetId + ' .mc-download' ); |
335 |
| - if ( subscribe.length > 0 ) { |
| 333 | + const subscribe = document.querySelector( '#' + targetId + ' .mc-subscribe' ); |
| 334 | + const exports = document.querySelector( '#' + targetId + ' .mc-download' ); |
| 335 | + if ( null !== subscribe ) { |
336 | 336 | let controls_id = 'mc_control_' + Math.floor(Math.random() * 1000 ).toString();
|
337 | 337 | const toggle = document.createElement( 'button' );
|
338 | 338 | toggle.setAttribute( 'type', 'button' );
|
339 | 339 | toggle.setAttribute( 'aria-controls', controls_id );
|
340 | 340 | toggle.setAttribute( 'aria-expanded', false );
|
341 | 341 | toggle.innerHTML = my_calendar.subscribe + ' <span class="dashicons dashicons-arrow-right" aria-hidden="true"></span>';
|
342 |
| - subscribe.find( 'ul' ).attr( 'id', controls_id ); |
343 |
| - subscribe.find( 'ul' ).css( { 'display' : 'none' } ); |
344 |
| - subscribe.prepend( toggle ); |
| 342 | + subscribe.querySelector( 'ul' ).setAttribute( 'id', controls_id ); |
| 343 | + subscribe.querySelector( 'ul' ).style.display = 'none'; |
| 344 | + subscribe.insertAdjacentElement( 'afterbegin', toggle ); |
345 | 345 | }
|
346 |
| - if ( exports.length > 0 ) { |
| 346 | + if ( null !== exports ) { |
347 | 347 | let controls_id = 'mc_control_' + Math.floor(Math.random() * 1000 ).toString();
|
348 | 348 | const toggle = document.createElement( 'button' );
|
349 | 349 | toggle.setAttribute( 'type', 'button' );
|
350 | 350 | toggle.setAttribute( 'aria-controls', controls_id );
|
351 | 351 | toggle.setAttribute( 'aria-expanded', false );
|
352 | 352 | toggle.innerHTML = my_calendar.export + ' <span class="dashicons dashicons-arrow-right" aria-hidden="true"></span>';
|
353 |
| - exports.find( 'ul' ).attr( 'id', controls_id ); |
354 |
| - exports.find( 'ul' ).css( { 'display' : 'none' } ); |
355 |
| - exports.prepend( toggle ); |
| 353 | + exports.querySelector( 'ul' ).setAttribute( 'id', controls_id ); |
| 354 | + exports.querySelector( 'ul' ).style.display = 'none'; |
| 355 | + exports.insertAdjacentElement( 'afterbegin', toggle ); |
356 | 356 | }
|
357 |
| - const toggles = $( '#' + targetId + ' .mc-export button' ); |
358 |
| - toggles.each( function() { |
359 |
| - $( this ).on( 'click', function() { |
360 |
| - let controlled = $( this ).attr( 'aria-controls' ); |
361 |
| - let target = $( '#' + controlled ); |
362 |
| - if ( target.is( ':visible' ) ) { |
363 |
| - target.css( { 'display' : 'none' } ); |
364 |
| - $( this ).attr( 'aria-expanded', 'false' ); |
365 |
| - $( this ).find( '.dashicons' ).removeClass( 'dashicons-arrow-down' ).addClass( 'dashicons-arrow-right' ); |
| 357 | + const toggles = document.querySelectorAll( '#' + targetId + ' .mc-export button' ); |
| 358 | + let icon; |
| 359 | + toggles.forEach( (el) => { |
| 360 | + el.addEventListener( 'click', function() { |
| 361 | + let controlled = el.getAttribute( 'aria-controls' ); |
| 362 | + let target = document.getElementById( controlled ); |
| 363 | + if ( target.checkVisibility() ) { |
| 364 | + target.style.display = 'none'; |
| 365 | + el.setAttribute( 'aria-expanded', 'false' ); |
| 366 | + icon = el.querySelector( '.dashicons' ); |
| 367 | + icon.classList.remove( 'dashicons-arrow-down' ); |
| 368 | + icon.classList.add( 'dashicons-arrow-right' ); |
366 | 369 | } else {
|
367 |
| - target.css( { 'display' : 'block' } ); |
368 |
| - $( this ).attr( 'aria-expanded', 'true' ); |
369 |
| - $( this ).find( '.dashicons' ).removeClass( 'dashicons-arrow-right' ).addClass( 'dashicons-arrow-down' ); |
| 370 | + target.style.display = 'block'; |
| 371 | + el.setAttribute( 'aria-expanded', 'true' ); |
| 372 | + icon = el.querySelector( '.dashicons' ); |
| 373 | + icon.classList.remove( 'dashicons-arrow-right' ) |
| 374 | + icon.classList.add( 'dashicons-arrow-down' ); |
370 | 375 | }
|
371 | 376 | });
|
372 | 377 | });
|
|
0 commit comments