Guest User

Untitled

a guest
Jan 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. function widgets_scripts( $hook ) {
  2. if ( 'widgets.php' != $hook ) {
  3. return;
  4. }
  5. wp_enqueue_style( 'wp-color-picker' );
  6. wp_enqueue_script( 'wp-color-picker' );
  7. }
  8. add_action( 'admin_enqueue_scripts', 'widgets_scripts' );
  9.  
  10. <script type="text/javascript">
  11. jQuery(document).ready(function($) {
  12. $('#<?php echo $this->get_field_id( 'color' ); ?>').wpColorPicker();
  13. });
  14. </script>
  15. <input id="<?php echo $this->get_field_id( 'color' ); ?>" type="text" name="<?php echo $this->get_field_name( 'color' ); ?>" value="<?php echo esc_attr( $instance['color'] ); ?>" />
  16.  
  17. <script type="text/javascript">
  18. jQuery(document).ready(function($) {
  19. jQuery('.color-picker').on('focus', function(){
  20. var parent = jQuery(this).parent();
  21. jQuery(this).wpColorPicker()
  22. parent.find('.wp-color-result').click();
  23. });
  24. });
  25. </script>
  26.  
  27. <p>
  28. <label for="<?php echo $this->get_field_id( 'font_color' ); ?>" style="display:block;"><?php _e( 'Font Color:' ); ?></label>
  29. <input class="widefat color-picker" id="<?php echo $this->get_field_id( 'font_color' ); ?>" name="<?php echo $this->get_field_name( 'font_color' ); ?>" type="text" value="<?php echo esc_attr( $font_color ); ?>" />
  30. </p>
  31.  
  32. jQuery(document).ready(function($) {
  33.  
  34. $('#widgets-right .color-picker, .inactive-sidebar .color-picker').wpColorPicker();
  35.  
  36. // Executes wpColorPicker function after AJAX is fired on saving the widget
  37. $(document).ajaxComplete(function() {
  38. $('#widgets-right .color-picker, .inactive-sidebar .color-picker').wpColorPicker();
  39. });
  40. });
  41.  
  42. <script type="text/javascript">
  43.  
  44. ( function( $ ){
  45. function initColorPicker( widget ) {
  46. widget.find( '.color-picker' ).not('[id*="__i__"]').wpColorPicker( {
  47. change: _.throttle( function() {
  48. $(this).trigger( 'change' );
  49. }, 3000 )
  50. });
  51. }
  52.  
  53. function onFormUpdate( event, widget ) {
  54. initColorPicker( widget );
  55. }
  56.  
  57. $( document ).on( 'widget-added widget-updated', onFormUpdate );
  58.  
  59. $( document ).ready( function() {
  60. $( '.widget-inside:has(.color-picker)' ).each( function () {
  61. initColorPicker( $( this ) );
  62. } );
  63. } );
  64.  
  65. }( jQuery ) );
  66.  
  67. </script>
  68.  
  69. <p>
  70. <label for="<?php echo esc_attr( $this->get_field_id( 'rm_background' ) ); ?>"><?php _e
  71. ( 'Background', 'text-domain' ); ?></label>
  72. <input id="<?php echo esc_attr( $this->get_field_id( 'rm_background' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'rm_background' ) ); ?>" value="<?php echo $instance['rm_background']; ?>" class="wp-color-result"/>
  73. </p>
Add Comment
Please, Sign In to add comment