EoiCustomCssBox

The Mailchimp Forms by Optin Cat EoiCustomCssBox class.

Defined (1)

The class is defined in the following location(s).

/powerups/2_custom_css/powerup.php  
  1. class EoiCustomCssBox { 
  2.  
  3. public function __construct() { 
  4. add_action( 'fca_eoi_powerups', array( $this, 'show_custom_css_field' ) );  
  5. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); 
  6. add_action( 'admin_print_footer_scripts', array( $this, 'enqueue_admin_footer_js' ) ); 
  7. add_filter( 'fca_eoi_alter_form', array( $this, 'append_css_to_form' ) , 10 , 2 ); 
  8.  
  9. public function init() { 
  10.  
  11. public function append_css_to_form( $content , $fca_eoi_meta ) { 
  12.  
  13. if( $css = K::get_var( 'custom_css', $fca_eoi_meta ) ) { 
  14. $content .= "<style>$css</style>"; 
  15.  
  16. return $content; 
  17.  
  18. /** 
  19. * Add fieldset custom css box 
  20. */ 
  21. public function show_custom_css_field( $fca_eoi_meta ) { 
  22. echo '<div class="eoi-custom-css-form" style="width:40.5em;">'; 
  23. K::textarea( 'fca_eoi[custom_css]' 
  24. , array( 
  25. 'class' => 'fca_eoi_custom_css_textbox',  
  26. 'placeholder' => __( 'Enter your custom CSS here...' ),  
  27. , array( 
  28. 'value' => K::get_var( 'custom_css', $fca_eoi_meta, '' ),  
  29. 'format' => '<label> Custom CSS</label><br />:textarea',  
  30. ); 
  31. echo '</div>'; 
  32.  
  33. public function enqueue_admin_scripts() { 
  34.  
  35. $protocol = is_ssl() ? 'https' : 'http'; 
  36. $screen = get_current_screen(); 
  37.  
  38. // Exit function if not in one of our plugin pages 
  39. if( 'easy-opt-ins' !== $screen->id ) { 
  40. return; 
  41.  
  42. // Enqueue CodeMirror JS and CSS 
  43. $codemirror_prefix = "$protocol://cdnjs.cloudflare.com/ajax/libs/codemirror/4.7.0/"; 
  44. $codemirror_js = array( 
  45. 'codemirror' => 'codemirror.min.js',  
  46. 'codemirror-css' => 'mode/css/css.min.js',  
  47. 'codemirror-placeholder' => 'addon/display/placeholder.min.js',  
  48. ); 
  49. foreach ( $codemirror_js as $handle => $path) { 
  50. wp_enqueue_script( $handle, $codemirror_prefix . $path, array(), FCA_EOI_VER, true ); 
  51. wp_enqueue_style('codemirror', $codemirror_prefix . 'codemirror.min.css', array(), FCA_EOI_VER ); 
  52.  
  53. public function enqueue_admin_footer_js() { 
  54. ?><script type="text/javascript"> 
  55.  
  56. jQuery( document ).ready( function( $ ) { 
  57.  
  58. // Add CodeMirrors 
  59. $( '.fca_eoi_custom_css_textbox' ).each( function( i, el ) { 
  60. var editor = CodeMirror.fromTextArea( el, { 
  61. mode: "text/css",  
  62. matchBrackets: true,  
  63. lineNumbers: true,  
  64. lineWrapping: true,  
  65. foldGutter: true,  
  66. gutters: [ "CodeMirror-linenumbers", "CodeMirror-foldgutter" ] 
  67. } ); 
  68. } ); 
  69. } ); 
  70. </script><?php