From 3cc92ef01b8d025e9112d182fc2aeba1a04eb596 Mon Sep 17 00:00:00 2001 From: savvasha Date: Tue, 28 Nov 2017 10:04:51 +0200 Subject: [PATCH 1/4] Tweak - Enable CodeMirror on Custom CSS field --- includes/admin/sp-admin-functions.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/includes/admin/sp-admin-functions.php b/includes/admin/sp-admin-functions.php index 2c6312a6..33a3768d 100755 --- a/includes/admin/sp-admin-functions.php +++ b/includes/admin/sp-admin-functions.php @@ -57,3 +57,23 @@ function sp_get_screen_ids() { 'edit-sp_role', ) ); } +add_action( 'admin_enqueue_scripts', 'add_codemirror_to_custom_css' ); +function add_codemirror_to_custom_css() { + if ( 'toplevel_page_sportspress' == get_current_screen()->id && (isset($_GET['tab']) && $_GET['tab'] == 'general') ) { + + // Enqueue code editor and settings for manipulating HTML. + $settings = wp_enqueue_code_editor( array( 'type' => 'css' ) ); + // Bail if user disabled CodeMirror. + if ( false === $settings ) { + return; + } + wp_add_inline_script( + 'code-editor', + sprintf( + 'jQuery( function() { wp.codeEditor.initialize( "sportspress_custom_css", %s ); } );', + wp_json_encode( $settings ) + ) + ); + } +} + From f191f0491bb6ca3f55e763459c1e4db09a47a639 Mon Sep 17 00:00:00 2001 From: savvasha Date: Tue, 28 Nov 2017 13:31:46 +0200 Subject: [PATCH 2/4] Revert "Tweak - Enable CodeMirror on Custom CSS field" This reverts commit 3cc92ef01b8d025e9112d182fc2aeba1a04eb596. --- includes/admin/sp-admin-functions.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/includes/admin/sp-admin-functions.php b/includes/admin/sp-admin-functions.php index 33a3768d..2c6312a6 100755 --- a/includes/admin/sp-admin-functions.php +++ b/includes/admin/sp-admin-functions.php @@ -57,23 +57,3 @@ function sp_get_screen_ids() { 'edit-sp_role', ) ); } -add_action( 'admin_enqueue_scripts', 'add_codemirror_to_custom_css' ); -function add_codemirror_to_custom_css() { - if ( 'toplevel_page_sportspress' == get_current_screen()->id && (isset($_GET['tab']) && $_GET['tab'] == 'general') ) { - - // Enqueue code editor and settings for manipulating HTML. - $settings = wp_enqueue_code_editor( array( 'type' => 'css' ) ); - // Bail if user disabled CodeMirror. - if ( false === $settings ) { - return; - } - wp_add_inline_script( - 'code-editor', - sprintf( - 'jQuery( function() { wp.codeEditor.initialize( "sportspress_custom_css", %s ); } );', - wp_json_encode( $settings ) - ) - ); - } -} - From b1f7a415df8a09b4dadcacc1808769f135762a62 Mon Sep 17 00:00:00 2001 From: savvasha Date: Tue, 28 Nov 2017 13:33:37 +0200 Subject: [PATCH 3/4] Tweak - Enable CodeMirror on Custom CSS field Using Sportspress Action hooks --- includes/admin/sp-admin-functions.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/includes/admin/sp-admin-functions.php b/includes/admin/sp-admin-functions.php index 2c6312a6..1c13690f 100755 --- a/includes/admin/sp-admin-functions.php +++ b/includes/admin/sp-admin-functions.php @@ -57,3 +57,19 @@ function sp_get_screen_ids() { 'edit-sp_role', ) ); } +add_action( 'sportspress_settings_general', 'add_codemirror_to_custom_css' ); +function add_codemirror_to_custom_css() { + // Enqueue code editor and settings for manipulating HTML. + $settings = wp_enqueue_code_editor( array( 'type' => 'css' ) ); + // Bail if user disabled CodeMirror. + if ( false === $settings ) { + return; + } + wp_add_inline_script( + 'code-editor', + sprintf( + 'jQuery( function() { wp.codeEditor.initialize( "sportspress_custom_css", %s ); } );', + wp_json_encode( $settings ) + ) + ); +} \ No newline at end of file From 9f6b0af83a37d4a8d174d85058982ff8c2aa6d9c Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 17 Jan 2018 11:07:25 +1100 Subject: [PATCH 4/4] Add CodeMirror styles to match settings page --- assets/css/admin.css | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/assets/css/admin.css b/assets/css/admin.css index afcc4171..d844138d 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -538,6 +538,18 @@ table.widefat.sp-sortable-table tbody tr .icon { -webkit-transition: none; } +/* CodeMirror */ + +.sp-settings-section .CodeMirror { + border: 1px solid #ddd; + box-shadow: inset 0 1px 2px rgba(0,0,0,.07); +} + +.sp-settings-section .CodeMirror-gutters { + background: #f9f9f9; + border-color: #e1e1e1; +} + /* Paragraph */ .sp-para { margin: 1em 0;