| 1 |
/** |
| 2 |
* JavaScript code for the "Options" screen, without the CodeMirror handling. |
| 3 |
* |
| 4 |
* @package TablePress |
| 5 |
* @subpackage Views JavaScript |
| 6 |
* @author Tobias Bäthge |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
/* globals confirm */ |
| 11 |
|
| 12 |
/** |
| 13 |
* WordPress dependencies. |
| 14 |
*/ |
| 15 |
import { __ } from '@wordpress/i18n'; |
| 16 |
|
| 17 |
/** |
| 18 |
* Internal dependencies. |
| 19 |
*/ |
| 20 |
import { $ } from './common/functions'; |
| 21 |
import { register_save_changes_keyboard_shortcut } from './common/keyboard-shortcut'; |
| 22 |
|
| 23 |
/** |
| 24 |
* Enable/disable the regular textarea according to state of "Load Custom CSS" checkbox. |
| 25 |
* |
| 26 |
* @since 1.0.0 |
| 27 |
*/ |
| 28 |
const $cb_use_custom_css = $( '#option-use-custom-css' ); |
| 29 |
if ( $cb_use_custom_css ) { // The checkbox field only exists for admins! |
| 30 |
$cb_use_custom_css.addEventListener( 'change', function () { |
| 31 |
$( '#option-custom-css' ).disabled = ! this.checked; |
| 32 |
} ); |
| 33 |
$cb_use_custom_css.dispatchEvent( new Event( 'change' ) ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* On form submit: Enable disabled fields, so that they are sent in the HTTP POST request. |
| 38 |
* |
| 39 |
* @since 1.0.0 |
| 40 |
*/ |
| 41 |
$( '#tablepress-page-form' ).addEventListener( 'submit', function () { |
| 42 |
this.querySelectorAll( ':scope input, :scope select, :scope textarea' ).forEach( ( field ) => ( field.disabled = false ) ); |
| 43 |
} ); |
| 44 |
|
| 45 |
register_save_changes_keyboard_shortcut( $( '#tablepress-options-save-changes' ) ); |
| 46 |
|
| 47 |
/** |
| 48 |
* Require double confirmation when wanting to uninstall TablePress. |
| 49 |
* |
| 50 |
* @since 1.0.0 |
| 51 |
*/ |
| 52 |
$( '#uninstall-tablepress' ).addEventListener( 'click', ( event ) => { |
| 53 |
if ( |
| 54 |
! confirm( __( 'Do you really want to uninstall TablePress and delete ALL data?', 'tablepress' ) ) || |
| 55 |
! confirm( __( 'Are you really sure?', 'tablepress' ) ) |
| 56 |
) { |
| 57 |
event.preventDefault(); |
| 58 |
} |
| 59 |
} ); |
| 60 |
|