| 1 |
/* global ClipboardJS */ |
| 2 |
|
| 3 |
/* |
| 4 |
* Classic-editor Inspect panel: copy-to-clipboard confirmation + "Remove all |
| 5 |
* BeyondWords data" toggle. |
| 6 |
*/ |
| 7 |
( function () { |
| 8 |
'use strict'; |
| 9 |
|
| 10 |
function init() { |
| 11 |
const copyButton = document.getElementById( |
| 12 |
'beyondwords__inspect--copy' |
| 13 |
); |
| 14 |
|
| 15 |
if ( copyButton && typeof ClipboardJS !== 'undefined' ) { |
| 16 |
const clipboard = new ClipboardJS( '#beyondwords__inspect--copy' ); |
| 17 |
|
| 18 |
clipboard.on( 'success', function () { |
| 19 |
const confirm = document.getElementById( |
| 20 |
'beyondwords__inspect--copy-confirm' |
| 21 |
); |
| 22 |
if ( confirm ) { |
| 23 |
confirm.style.display = ''; |
| 24 |
} |
| 25 |
} ); |
| 26 |
} |
| 27 |
|
| 28 |
document.addEventListener( 'click', function ( event ) { |
| 29 |
if ( ! event.target.closest( '#beyondwords__inspect--remove' ) ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
/* eslint-disable-next-line no-alert */ |
| 34 |
const confirmed = window.confirm( |
| 35 |
wp.i18n.__( |
| 36 |
'Remove all BeyondWords data when the post is saved?', |
| 37 |
'speechkit' |
| 38 |
) |
| 39 |
); |
| 40 |
|
| 41 |
if ( ! confirmed ) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
const deleteInput = document.getElementById( |
| 46 |
'beyondwords_delete_content' |
| 47 |
); |
| 48 |
if ( deleteInput ) { |
| 49 |
deleteInput.removeAttribute( 'disabled' ); |
| 50 |
} |
| 51 |
|
| 52 |
document |
| 53 |
.querySelectorAll( '[data-beyondwords-metavalue]' ) |
| 54 |
.forEach( ( el ) => { |
| 55 |
el.value = ''; |
| 56 |
} ); |
| 57 |
} ); |
| 58 |
} |
| 59 |
|
| 60 |
if ( document.readyState !== 'loading' ) { |
| 61 |
init(); |
| 62 |
} else { |
| 63 |
document.addEventListener( 'DOMContentLoaded', init ); |
| 64 |
} |
| 65 |
} )(); |
| 66 |
|