| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /** |
| 2 | - * JavaScript code for the "Options" screen, without the CodeMirror handling | |
| 2 | + * JavaScript code for the "Options" screen, without the CodeMirror handling. | |
| 3 | 3 | * |
| 4 | 4 | * @package TablePress |
| 5 | 5 | * @subpackage Views JavaScript |
| 6 | 6 | * @author Tobias Bäthge |
| @@ -6,42 +6,57 @@ | ||
| 6 | 6 | * @author Tobias Bäthge |
| 7 | 7 | * @since 1.0.0 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -/* global confirm, tablepress_strings */ | |
| 10 | +/* globals confirm */ | |
| 11 | 11 | |
| 12 | -jQuery( document ).ready( function( $ ) { | |
| 12 | +/** | |
| 13 | + * WordPress dependencies. | |
| 14 | + */ | |
| 15 | +import { __ } from '@wordpress/i18n'; | |
| 13 | 16 | |
| 14 | - 'use strict'; | |
| 17 | +/** | |
| 18 | + * Internal dependencies. | |
| 19 | + */ | |
| 20 | +import { $ } from './common/functions'; | |
| 21 | +import { registerSaveChangesKeyboardShortcut } from './common/keyboard-shortcut'; | |
| 15 | 22 | |
| 16 | - /** | |
| 17 | - * Enable/disable the regular textarea according to state of "Load Custom CSS" checkbox. | |
| 18 | - * | |
| 19 | - * @since 1.0.0 | |
| 20 | - */ | |
| 21 | - $( '#option-use-custom-css' ).on( 'change', function() { | |
| 22 | - $( '#option-custom-css' ).prop( 'disabled', ! $(this).prop( 'checked' ) ); | |
| 23 | - } ).change(); | |
| 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 | +} | |
| 24 | 35 | |
| 25 | - /** | |
| 26 | - * On form submit: Enable disabled fields, so that they are transmitted in the POST request. | |
| 27 | - * | |
| 28 | - * @since 1.0.0 | |
| 29 | - */ | |
| 30 | - $( '#tablepress-page' ).on( 'submit', 'form', function() { | |
| 31 | - $(this).find( 'input, select, textarea' ).prop( 'disabled', false ); | |
| 32 | - } ); | |
| 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 | +} ); | |
| 33 | 44 | |
| 34 | - /** | |
| 35 | - * Require double confirmation when wanting to uninstall TablePress. | |
| 36 | - * | |
| 37 | - * @since 1.0.0 | |
| 38 | - */ | |
| 39 | - $( '#uninstall-tablepress' ).on( 'click', function() { | |
| 40 | - if ( confirm( tablepress_strings.uninstall_warning_1 ) ) { | |
| 41 | - return confirm( tablepress_strings.uninstall_warning_2 ); | |
| 42 | - } else { | |
| 43 | - return false; | |
| 45 | +registerSaveChangesKeyboardShortcut( $( '#tablepress-options-save-changes' ) ); | |
| 46 | + | |
| 47 | +/** | |
| 48 | + * Require double confirmation when wanting to uninstall TablePress. | |
| 49 | + * | |
| 50 | + * @since 1.0.0 | |
| 51 | + */ | |
| 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(); | |
| 44 | 60 | } |
| 45 | 61 | } ); |
| 46 | - | |
| 47 | -} ); | |
| 62 | +} | |