WordPress.org

Ready to get started?Download WordPress

Forums

Including jQuery breaks dashboard JavaScript (11 posts)

  1. John
    Member
    Posted 4 years ago #

    I've been working on a few admin dashboard widgets for my plugin. Recently I noticed that I cannot sort any widgets on the dashboard. Firebug is reporting the following error:
    this._mouseInit is not a function

    I also recently upgraded to WordPress 3.0 RC2. My plugin also comes with jQuery, and I updated that from version 1.7 to 1.8. I've just noticed this issue, and I'm not sure if it from updating jQuery, WordPress, or just poor coding on my part.

    The error happens when I include jQuery UI (jquery-ui-1.8.2.custom.min.js).

    public function admin_init ()
    {
        $plugin = "temp";
    
        $scripts = array("/$plugin/js/jquery-1.4.2.min.js",
                "/$plugin/js/jquery-ui-1.8.2.custom.min.js",
                "/$plugin/js/functions.js");
    
        for($i = 0; $i < count($scripts); $i++) {
            $url = WP_PLUGIN_URL . $scripts[$i];
            $file = WP_PLUGIN_DIR . $scripts[$i];
            if (file_exists($file)) {
                wp_register_script($plugin . '_script_' . $i, $url);
                wp_enqueue_script($plugin . '_script_' . $i);
            }
        }
    }

    This function is called using the admin_init hook. Just to be clear, if I remove the following line
    "/$plugin/js/jquery-ui-1.8.2.custom.min.js",
    The WordPress dashboard JavaScript works (FireBug no longer reports an error), but my code does not work because it uses that JavaScript file.

    What do I need to do to fix this issue?

  2. John
    Member
    Posted 4 years ago #

    Anyone have any ideas?

  3. Andy Potanin
    Member
    Posted 4 years ago #

    UI Widget causes that error. In case your particular plugins/theme does not need the UI Widget file, download the UI files separately, and only use the ones you need.

  4. Brig01
    Member
    Posted 4 years ago #

    Sorry to bring an old thread back to life but I'm having this exact problem on a new theme I'm building.

    I've implemented jQuery UI Datepicker in one of my custom post types and while it works fine, loading the latest version of jQuery UI breaks the draggable widgets on the wordpress admin.

    Here's how I'm loading jQuery UI:

    function jquery_ui_initialise()
    {
    	#PAGE IS ADMIN
    	if(is_admin())
    	{
    		#DEREGISTER DEFAULT JQUERY INCLUDES
    		wp_deregister_script('jquery-ui-core');
    		wp_deregister_script('jquery-ui-tabs');
    		wp_deregister_script('jquery-ui-sortable');
    		wp_deregister_script('jquery-ui-draggable');
    		wp_deregister_script('jquery-ui-droppable');
    		wp_deregister_script('jquery-ui-selectable');
    		wp_deregister_script('jquery-ui-resizable');
    		wp_deregister_script('jquery-ui-dialog');
    
    		#LOAD THE GOOGLE API JQUERY INCLUDES
    		wp_register_script('jquery_ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js', false, '1.8.2', false);
    
    		#REGISTER CUSTOM JQUERY INCLUDES
    		wp_enqueue_script('jquery_ui');
    	}
    }
    
    #INITIALISE JQUERY LIBRARY
    add_action('init', 'jquery_ui_initialise');

    The date picker requires the UI Widget so I'm not sure what to do.

    Does anyone have a fix for this please? I just need to get the date picker working.

  5. Andy Potanin
    Member
    Posted 4 years ago #

    Go to http://jqueryui.com/download and download the 1.7.3 version of the datepicker, and use the built-in WP ui library.

  6. Andy Potanin
    Member
    Posted 4 years ago #

    In fact that's what I have to do all the time with a lot of jQuery scripts to keep WP from breaking, just downgrade the version, and it'll work.

  7. oOSilasOo
    Member
    Posted 3 years ago #

    Sorry to revive the post again, again. I want to use jquery ui autocomplete so I cant downgrade.

    wp_enqueue_script('widget',MY_THEME_PATH . '/custom/jquery.ui.widget.js');
        wp_enqueue_script('jquery-ui-mouse',MY_THEME_PATH . '/custom/jquery.ui.mouse.js',array('widget'));
    
        wp_deregister_script( 'jquery-ui-core' );
        wp_enqueue_script( 'jquery-ui-core', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js',array('jquery-ui-mouse'));

    I am getting this._mouseInit is not a function any ideas?

  8. spstieng
    Member
    Posted 3 years ago #

    I'm having the same problem. Not sure what to do.
    I will not downgrade my scripts since that's not really a good approach.

    What UI scripts are by default loaded by WP?

    @Silas: You must load UI Core bedfore any other UI scripts.
    You have also made UI Core dependent on jquery-ui-mouse, that's wrong.
    It should be the other way.

  9. spstieng
    Member
    Posted 3 years ago #

    This worked for me:

    wp_deregister_script('jquery-ui-core','jquery-ui-dialog');
    wp_register_script('jquery-ui','http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.js',array('jquery'));
    wp_enqueue_script('jquery-ui');
  10. oOSilasOo
    Member
    Posted 3 years ago #

    haha! worked for me. this is what I did for auto complete.

    `wp_deregister_script('jquery-ui-core','jquery-ui-dialog');
    wp_register_script('jquery-ui','http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.js',array('jquery'));
    wp_enqueue_script('jquery-ui');

    wp_enqueue_script('widget',MY_THEME_PATH . '/custom/jquery.ui.widget.js');
    wp_enqueue_script('position',MY_THEME_PATH . '/custom/jquery.ui.position.js');
    wp_enqueue_script('autocomp',MY_THEME_PATH . '/custom/jquery.ui.autocomplete.js',array('jquery-ui','jquery-ui-core','widget','position'));`

    thanks for the help.

  11. oOSilasOo
    Member
    Posted 3 years ago #

    hhm, doing it this way seems to have killed my tags matabox...the place holder text does not go away and the ajax script doesn't get called. @spstieng are you having this problem? edit: It has actually killed all the JS on my edit posts page.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.