PluginProbe
Embed Privacy / 1.11.2
Embed Privacy v1.11.2
1.14.0 1.13.0 trunk 0.1 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.10.0 1.10.1 1.10.10 1.10.2 1.10.3 1.10.4 1.10.5 1.10.6 1.10.7 1.10.8 1.10.9 1.11.0 1.11.1 1.11.2 All 68 releases
embed-privacy / assets / js / admin / clipboard.js

clipboard.js in Embed Privacy 1.11.2, at assets/js/admin/clipboard.js

54 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global embedPrivacyAdminSettings */
2 document.addEventListener( 'DOMContentLoaded', () => {
3 const actionElements = document.querySelectorAll( '.embed-privacy__support-data--copy-to-clipboard' );
4
5 for ( const actionElement of actionElements ) {
6 actionElement.addEventListener( 'click', ( event ) => clipboardAction( event.currentTarget ) );
7 }
8
9 /**
10 * Clipboard action.
11 *
12 * @param {HTMLElement} element Element the action has been started from
13 */
14 function clipboardAction( element ) {
15 const copyElement = document.querySelector( '.' + element.getAttribute( 'data-copy' ) );
16 const statusElement = document.querySelector( '.' + element.getAttribute( 'data-status' ) );
17
18 if ( ! navigator.clipboard ) {
19 statusElement.classList.add( 'is-error' );
20 statusElement.classList.remove( 'is-success' );
21 statusElement.textContent = embedPrivacyAdminSettings.supportDataCopiedToClipboardFailure;
22 removeNotice( statusElement );
23 console.error( 'Copy to clipboard not supported.' );
24
25 return;
26 }
27
28 navigator.clipboard.writeText( copyElement.textContent ).then( () => {
29 statusElement.classList.add( 'is-success' );
30 statusElement.classList.remove( 'is-error' );
31 statusElement.textContent = embedPrivacyAdminSettings.supportDataCopiedToClipboardSuccess;
32 removeNotice( statusElement );
33 } ).catch( ( error ) => {
34 statusElement.classList.add( 'is-error' );
35 statusElement.classList.remove( 'is-success' );
36 statusElement.textContent = embedPrivacyAdminSettings.supportDataCopiedToClipboardFailure;
37 removeNotice( statusElement );
38 console.error( error );
39 } );
40 }
41
42 /**
43 * Remove notice visually.
44 *
45 * @param {HTMLElement} element Notice element
46 */
47 function removeNotice( element ) {
48 setTimeout( () => {
49 element.classList.remove( 'is-error', 'is-success' );
50 element.textContent = '';
51 }, 10000 );
52 }
53 } );
54