| @@ -6,11 +6,16 @@ | ||
| 6 | 6 | * @author Tobias Bäthge |
| 7 | 7 | * @since 1.0.0 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -/* globals postboxes, pagenow, jQuery */ | |
| 10 | +/* globals confirm, postboxes, pagenow, jQuery */ | |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | + * WordPress dependencies. | |
| 14 | + */ | |
| 15 | +import { _n } from '@wordpress/i18n'; | |
| 16 | + | |
| 17 | +/** | |
| 13 | 18 | * Enable toggle/order functionality for post meta boxes. |
| 14 | 19 | * For TablePress, pagenow has the form "tablepress_{$action}". |
| 15 | 20 | * |
| 16 | 21 | * @since 1.0.0 |
| @@ -24,4 +29,27 @@ | ||
| 24 | 29 | * |
| 25 | 30 | * @since 2.1.0 |
| 26 | 31 | */ |
| 27 | 32 | jQuery( '.postbox .hndle' ).off( 'click.postboxes', postboxes.handle_click ); |
| 33 | + | |
| 34 | +document.getElementById( 'tablepress-page' ).addEventListener( 'click', ( event ) => { | |
| 35 | + if ( ! event.target ) { | |
| 36 | + return; | |
| 37 | + } | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * Show an AYS warning when a "Delete" link is clicked. | |
| 41 | + * | |
| 42 | + * @since 1.0.0 | |
| 43 | + */ | |
| 44 | + if ( event.target.matches( '.delete-link' ) ) { | |
| 45 | + if ( ! confirm( _n( 'Do you really want to delete this table?', 'Do you really want to delete these tables?', 1, 'tablepress' ) ) ) { | |
| 46 | + event.preventDefault(); | |
| 47 | + return; | |
| 48 | + } | |
| 49 | + | |
| 50 | + // Prevent onunload warning, by calling unset method from edit.js (if defined). | |
| 51 | + window?.tp?.helpers?.unsaved_changes?.unset?.(); | |
| 52 | + | |
| 53 | + return; | |
| 54 | + } | |
| 55 | +} ); | |