Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function widgets_scripts( $hook ) {
- if ( 'widgets.php' != $hook ) {
- return;
- }
- wp_enqueue_style( 'wp-color-picker' );
- wp_enqueue_script( 'wp-color-picker' );
- }
- add_action( 'admin_enqueue_scripts', 'widgets_scripts' );
- <script type="text/javascript">
- jQuery(document).ready(function($) {
- $('#<?php echo $this->get_field_id( 'color' ); ?>').wpColorPicker();
- });
- </script>
- <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'] ); ?>" />
- <script type="text/javascript">
- jQuery(document).ready(function($) {
- jQuery('.color-picker').on('focus', function(){
- var parent = jQuery(this).parent();
- jQuery(this).wpColorPicker()
- parent.find('.wp-color-result').click();
- });
- });
- </script>
- <p>
- <label for="<?php echo $this->get_field_id( 'font_color' ); ?>" style="display:block;"><?php _e( 'Font Color:' ); ?></label>
- <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 ); ?>" />
- </p>
- jQuery(document).ready(function($) {
- $('#widgets-right .color-picker, .inactive-sidebar .color-picker').wpColorPicker();
- // Executes wpColorPicker function after AJAX is fired on saving the widget
- $(document).ajaxComplete(function() {
- $('#widgets-right .color-picker, .inactive-sidebar .color-picker').wpColorPicker();
- });
- });
- <script type="text/javascript">
- ( function( $ ){
- function initColorPicker( widget ) {
- widget.find( '.color-picker' ).not('[id*="__i__"]').wpColorPicker( {
- change: _.throttle( function() {
- $(this).trigger( 'change' );
- }, 3000 )
- });
- }
- function onFormUpdate( event, widget ) {
- initColorPicker( widget );
- }
- $( document ).on( 'widget-added widget-updated', onFormUpdate );
- $( document ).ready( function() {
- $( '.widget-inside:has(.color-picker)' ).each( function () {
- initColorPicker( $( this ) );
- } );
- } );
- }( jQuery ) );
- </script>
- <p>
- <label for="<?php echo esc_attr( $this->get_field_id( 'rm_background' ) ); ?>"><?php _e
- ( 'Background', 'text-domain' ); ?></label>
- <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"/>
- </p>
Add Comment
Please, Sign In to add comment