|
1 | 1 | /** |
2 | 2 | * @output wp-includes/js/wp-embed-template.js |
3 | 3 | */ |
| 4 | + |
| 5 | +/** |
| 6 | + * IIFE setup function. |
| 7 | + * |
| 8 | + * @param {Window} window Global window object. |
| 9 | + * @param {Document} document Global document object. |
| 10 | + */ |
4 | 11 | (function ( window, document ) { |
5 | 12 | 'use strict'; |
6 | 13 |
|
|
25 | 32 | sendEmbedMessage( 'height', Math.ceil( document.body.getBoundingClientRect().height ) ); |
26 | 33 | } |
27 | 34 |
|
| 35 | + /** |
| 36 | + * Runs on DomContentLoaded and load event. |
| 37 | + * |
| 38 | + * Exits early on the load event if the earlier event has |
| 39 | + * successfully fired. |
| 40 | + */ |
28 | 41 | function onLoad() { |
29 | 42 | if ( loaded ) { |
30 | 43 | return; |
|
47 | 60 | } |
48 | 61 | } |
49 | 62 |
|
| 63 | + /** |
| 64 | + * Open share dialog within embed iframe. |
| 65 | + */ |
50 | 66 | function openSharingDialog() { |
51 | 67 | share_dialog.className = share_dialog.className.replace( 'hidden', '' ); |
52 | 68 | // Initial focus should go on the currently selected tab in the dialog. |
53 | 69 | document.querySelector( '.wp-embed-share-tab-button [aria-selected="true"]' ).focus(); |
54 | 70 | } |
55 | 71 |
|
| 72 | + /** |
| 73 | + * Close share dialog within embed iframe. |
| 74 | + */ |
56 | 75 | function closeSharingDialog() { |
57 | 76 | share_dialog.className += ' hidden'; |
58 | 77 | document.querySelector( '.wp-embed-share-dialog-open' ).focus(); |
|
70 | 89 | } ); |
71 | 90 | } |
72 | 91 |
|
| 92 | + /** |
| 93 | + * Click event handler for share button. |
| 94 | + * |
| 95 | + * @param {MouseEvent} event Event handler. |
| 96 | + */ |
73 | 97 | function shareClickHandler( event ) { |
74 | 98 | var currentTab = document.querySelector( '.wp-embed-share-tab-button [aria-selected="true"]' ); |
75 | 99 | currentTab.setAttribute( 'aria-selected', 'false' ); |
|
79 | 103 | document.querySelector( '#' + event.target.getAttribute( 'aria-controls' ) ).setAttribute( 'aria-hidden', 'false' ); |
80 | 104 | } |
81 | 105 |
|
| 106 | + /** |
| 107 | + * Keyboard event handler for share button. |
| 108 | + * |
| 109 | + * @param {KeyboardEvent} event Event handler. |
| 110 | + * @return {boolean|void} Returns false if default action is to be prevented. |
| 111 | + */ |
82 | 112 | function shareKeyHandler( event ) { |
83 | 113 | var target = event.target, |
84 | 114 | previousSibling = target.parentElement.previousElementSibling, |
|
127 | 157 | } |
128 | 158 | }, false ); |
129 | 159 |
|
| 160 | + /** |
| 161 | + * Constrain tabbing to share dialog when open. |
| 162 | + * |
| 163 | + * @param {KeyboardEvent} event Event object. |
| 164 | + */ |
130 | 165 | function constrainTabbing( event ) { |
131 | 166 | // Need to re-get the selected tab each time. |
132 | 167 | var firstFocusable = document.querySelector( '.wp-embed-share-tab-button [aria-selected="true"]' ); |
|
0 commit comments