| @@ -16,9 +16,10 @@ | ||
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * Internal dependencies. |
| 19 | 19 | */ |
| 20 | -import { $ } from './_common-functions'; | |
| 20 | +import { $ } from './common/functions'; | |
| 21 | +import { registerSaveChangesKeyboardShortcut } from './common/keyboard-shortcut'; | |
| 21 | 22 | |
| 22 | 23 | /** |
| 23 | 24 | * Enable/disable the regular textarea according to state of "Load Custom CSS" checkbox. |
| 24 | 25 | * |
| @@ -36,21 +37,26 @@ | ||
| 36 | 37 | * On form submit: Enable disabled fields, so that they are sent in the HTTP POST request. |
| 37 | 38 | * |
| 38 | 39 | * @since 1.0.0 |
| 39 | 40 | */ |
| 40 | -document.querySelector( '#tablepress-page form' ).addEventListener( 'submit', function () { | |
| 41 | - this.querySelectorAll( 'input, select, textarea' ).forEach( ( field ) => ( field.disabled = false ) ); | |
| 41 | +$( '#tablepress-page-form' ).addEventListener( 'submit', function () { | |
| 42 | + this.querySelectorAll( ':scope input, :scope select, :scope textarea' ).forEach( ( field ) => ( field.disabled = false ) ); | |
| 42 | 43 | } ); |
| 43 | 44 | |
| 45 | +registerSaveChangesKeyboardShortcut( $( '#tablepress-options-save-changes' ) ); | |
| 46 | + | |
| 44 | 47 | /** |
| 45 | 48 | * Require double confirmation when wanting to uninstall TablePress. |
| 46 | 49 | * |
| 47 | 50 | * @since 1.0.0 |
| 48 | 51 | */ |
| 49 | -$( '#uninstall-tablepress' ).addEventListener( 'click', ( event ) => { | |
| 50 | - if ( | |
| 51 | - ! confirm( __( 'Do you really want to uninstall TablePress and delete ALL data?', 'tablepress' ) ) || | |
| 52 | - ! confirm( __( 'Are you really sure?', 'tablepress' ) ) ) | |
| 53 | - { | |
| 54 | - event.preventDefault(); | |
| 55 | - } | |
| 56 | -} ); | |
| 52 | +const $button_uninstall = $( '#uninstall-tablepress' ); | |
| 53 | +if ( $button_uninstall ) { // The button only exists for admins! | |
| 54 | + $button_uninstall.addEventListener( 'click', ( event ) => { | |
| 55 | + if ( | |
| 56 | + ! confirm( __( 'Do you really want to uninstall TablePress and delete ALL data?', 'tablepress' ) ) || | |
| 57 | + ! confirm( __( 'Are you really sure?', 'tablepress' ) ) | |
| 58 | + ) { | |
| 59 | + event.preventDefault(); | |
| 60 | + } | |
| 61 | + } ); | |
| 62 | +} | |