| 1 |
/** |
| 2 |
* JavaScript code for all TablePress admin screens |
| 3 |
* |
| 4 |
* @package TablePress |
| 5 |
* @subpackage Views JavaScript |
| 6 |
* @author Tobias Bäthge |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
/* global confirm, tp, postboxes, pagenow, tp, tablepress_common */ |
| 11 |
|
| 12 |
// Ensure the global `tp` object exists. |
| 13 |
window.tp = window.tp || {}; |
| 14 |
|
| 15 |
jQuery( function( $ ) { |
| 16 |
|
| 17 |
'use strict'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Enable toggle/order functionality for post meta boxes |
| 21 |
* For TablePress, pagenow has the form "tablepress_{$action}" |
| 22 |
* |
| 23 |
* @since 1.0.0 |
| 24 |
*/ |
| 25 |
postboxes.add_postbox_toggles( pagenow ); |
| 26 |
|
| 27 |
/** |
| 28 |
* Check that numerical fields (e.g. column/row number fields) only contain numbers |
| 29 |
* |
| 30 |
* Provides this functionality for browsers that don't yet support <input type="number" />. |
| 31 |
* |
| 32 |
* @since 1.0.0 |
| 33 |
*/ |
| 34 |
$( '#tablepress-page' ).on( 'blur', '.numbers-only, .form-field-numbers-only input', function( /* event */ ) { |
| 35 |
var $input = $(this); |
| 36 |
$input.val( $input.val().replace( /[^0-9]/g, '' ) ); |
| 37 |
} ); |
| 38 |
|
| 39 |
/** |
| 40 |
* Show a AYS warning when a "Delete" link is clicked |
| 41 |
* |
| 42 |
* @since 1.0.0 |
| 43 |
*/ |
| 44 |
$( '#tablepress-page' ).on( 'click', '.delete-link', function() { |
| 45 |
if ( ! confirm( tablepress_common.ays_delete_single_table ) ) { |
| 46 |
return false; |
| 47 |
} |
| 48 |
|
| 49 |
// Prevent onunload warning. |
| 50 |
tp.made_changes = false; |
| 51 |
} ); |
| 52 |
|
| 53 |
/** |
| 54 |
* Select all text in the Shortcode (readonly) text fields, when clicked |
| 55 |
* |
| 56 |
* @since 1.0.0 |
| 57 |
*/ |
| 58 |
$( '#tablepress-page' ).on( 'click', '.table-shortcode', function() { |
| 59 |
$(this).trigger( 'focus' ).trigger( 'select' ); |
| 60 |
} ); |
| 61 |
|
| 62 |
} ); |
| 63 |
|