| 1 |
/* global ClipboardJS */ |
| 2 |
|
| 3 |
/** |
| 4 |
* WordPress dependencies. |
| 5 |
*/ |
| 6 |
import domReady from '@wordpress/dom-ready'; |
| 7 |
import { render } from '@wordpress/element'; |
| 8 |
|
| 9 |
/** |
| 10 |
* Internal dependencies. |
| 11 |
*/ |
| 12 |
import { reports } from './config'; |
| 13 |
import Reports from './components/reports'; |
| 14 |
|
| 15 |
/** |
| 16 |
* Status report copy button. |
| 17 |
* |
| 18 |
* @returns {void} |
| 19 |
*/ |
| 20 |
const init = () => { |
| 21 |
const report = document.getElementById('ep-status-reports'); |
| 22 |
const clipboard = new ClipboardJS('#ep-copy-report'); |
| 23 |
|
| 24 |
/** |
| 25 |
* Handle successful copy. |
| 26 |
* |
| 27 |
* @param {Event} event Copy event. |
| 28 |
* @returns {void} |
| 29 |
*/ |
| 30 |
const onSuccess = (event) => { |
| 31 |
event.trigger.nextElementSibling.style.display = 'initial'; |
| 32 |
|
| 33 |
setTimeout(() => { |
| 34 |
event.trigger.nextElementSibling.style.display = 'none'; |
| 35 |
}, 3000); |
| 36 |
|
| 37 |
event.clearSelection(); |
| 38 |
}; |
| 39 |
|
| 40 |
/** |
| 41 |
* Bind copy button events. |
| 42 |
*/ |
| 43 |
clipboard.on('success', onSuccess); |
| 44 |
|
| 45 |
/** |
| 46 |
* Render reports. |
| 47 |
*/ |
| 48 |
render(<Reports reports={reports} />, report); |
| 49 |
}; |
| 50 |
|
| 51 |
domReady(init); |
| 52 |
|