| 1 |
/** |
| 2 |
* JavaScript code for the CodeMirror handling on the "Options" screen |
| 3 |
* |
| 4 |
* @package TablePress |
| 5 |
* @subpackage Views JavaScript |
| 6 |
* @author Tobias Bäthge |
| 7 |
* @since 1.9.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
/* global wp, tablepress_codemirror_settings */ |
| 11 |
|
| 12 |
jQuery( function( $ ) { |
| 13 |
|
| 14 |
'use strict'; |
| 15 |
|
| 16 |
/** |
| 17 |
* Invoke CodeMirror on the "Custom CSS" textarea. |
| 18 |
* |
| 19 |
* @since 1.9.0 |
| 20 |
*/ |
| 21 |
var CM_custom_css = wp.codeEditor.initialize( document.getElementById( 'option-custom-css' ), tablepress_codemirror_settings ); |
| 22 |
|
| 23 |
/** |
| 24 |
* Make the CodeMirror textarea vertically resizable. |
| 25 |
* |
| 26 |
* @since 1.7.0 |
| 27 |
*/ |
| 28 |
$( CM_custom_css.codemirror.getWrapperElement() ).resizable( { |
| 29 |
handles: 's', |
| 30 |
resize: function() { |
| 31 |
var $this = $(this); |
| 32 |
CM_custom_css.codemirror.setSize( $this.width(), $this.height() ); |
| 33 |
} |
| 34 |
} ); |
| 35 |
|
| 36 |
/** |
| 37 |
* Let CodeMirror textarea grow on first focus, if it is not disabled. |
| 38 |
* |
| 39 |
* @since 1.0.0 |
| 40 |
*/ |
| 41 |
$( '#tablepress-page' ).find( '.CodeMirror' ).on( 'mousedown.codemirror', function() { |
| 42 |
var $this = $(this); |
| 43 |
if ( ! $this.hasClass( 'disabled' ) ) { |
| 44 |
$this.addClass( 'large' ); |
| 45 |
CM_custom_css.codemirror.refresh(); |
| 46 |
$this.off( 'mousedown.codemirror' ); |
| 47 |
} |
| 48 |
} ); |
| 49 |
|
| 50 |
/** |
| 51 |
* Enable/disable CodeMirror according to state of "Load Custom CSS" checkbox. |
| 52 |
* |
| 53 |
* @since 1.0.0 |
| 54 |
*/ |
| 55 |
$( '#option-use-custom-css' ).on( 'change', function() { |
| 56 |
var use_custom_css = $(this).prop( 'checked' ); |
| 57 |
CM_custom_css.codemirror.setOption( 'readOnly', ! use_custom_css ); |
| 58 |
$( '#tablepress-page' ).find( '.CodeMirror' ).toggleClass( 'disabled', ! use_custom_css ); |
| 59 |
} ).trigger( 'change' ); |
| 60 |
|
| 61 |
} ); |
| 62 |
|