0

in admin panel when I add a widget to the page the javascript doesn't execute. Here is code for my plugin:

class Mosaic extends WP_Widget {
    // class constructor
    public function __construct() {
        $widget_ops = array( 
        'classname' => 'Mosaic',
        'description' => 'Widget provides mosaic jquery.',
        );
        parent::__construct( 'mosaic', 'mosaic', $widget_ops );


    }

    // output the widget content on the front-end
    public function widget( $args, $instance ) {
        echo $args['before_widget'];
        echo $args['after_widget'];
    }

    // output the option form field in admin Widgets screen
    public function form( $instance ) {
        wp_enqueue_media();
    ?>
        <ul id="sortable123">
        <li class="ui-state-default">test1</li>
        <li class="ui-state-default">test12</li>
        <li class="ui-state-default">test122</li>
        </ul>
    <?php
    }

    // save options
    public function update( $new_instance, $old_instance ) {}   
}

add_action( 'widgets_init', function(){register_widget( 'Mosaic' );});
function my_enqueue() {
    wp_enqueue_script( 'mosaic-js', 'mymosaic.js' );
}
add_action( 'admin_enqueue_scripts', 'my_enqueue' );
wp_enqueue_script( 'mosaic-js', '/wp-content/plugins/mosaic/mymosaic.js', array( 'jquery' ), '0.0.1', true );

and javascript is simple, based on Jquery:

jQuery( document ).ready( function( $ ) {
        $('.ui-state-default').click(function() {
          alert( "Handler click called." );
        });
});

If I put it in javascript alert function, it works fine. But everything else, like click doesn't work, could you help me with the issue?

charan kumar
  • 2,038
  • 2
  • 17
  • 23

0 Answers0