WordPress.org

Ready to get started?Download WordPress

Forums

jquery ui sortable library not getting included (4 posts)

  1. bsohal
    Member
    Posted 3 years ago #

    I have ajax sack, jquery ajax, and jquery working fine, but not jquery ui (sortable).

    In beginning of plugin file I do: -

    ...
    add_action('init','biz_init');
    function biz_init() {
      //wp_enqueue_script('jquery');
      //wp_enqueue_script('jquery-ui-sortable');
      //wp_enqueue_script('jquery-ui-widget');
      //wp_enqueue_script('jquery-ui-mouse');
      //wp_enqueue_script('jquery-ui-core');
      //wp_enqueue_script( array("jquery", "jquery-ui-core", "interface", "jquery-ui-sortable", "wp-lists", "jquery-ui-sortable") );
      //wp_enqueue_script('item-jui',plugins_url('/js/item.js',__FILE__),array("jquery-ui-core", "interface", "jquery-ui-widget", "jquery-ui-mouse", "wp-lists", "jquery-ui-sortable"), '', true);
    }
    ...
    add_action('admin_print_scripts','biz_subsc_catg_js_admin_header'); //Add Ajax to the admin side
    add_action('admin_head','biz_items_js_admin_header'); //Add JQuery to the admin side
    add_action('admin_head','biz_items_jui_admin_header'); //Add JQuery to the admin side
    ...
    function biz_items_jui_admin_header() {
    //  wp_enqueue_script('item-js', plugins_url( '/js/item.js', __FILE__ ), array("jquery-ui-core", "interface", "jquery-ui-widget", "jquery-ui-mouse", "wp-lists", "jquery-ui-sortable"), '', true);
    wp_enqueue_script(array("jquery-ui-core", "interface", "jquery-ui-widget", "jquery-ui-mouse", "wp-lists", "jquery-ui-sortable"));
    ?>
      <script type="text/javascript" >
      $(function() {
        $( "#sortable1, #sortable2" ).sortable().disableSelection();
      });
      </script>
    <?php
    }
    function biz_items_js_admin_header() { // Set JQuery calls for Items
    ?>
      <script type="text/javascript" >
        jQuery(document).ready(function($) {
    ...
    function biz_subsc_catg_js_admin_header() { //Set Ajax Calls for manager
      wp_print_scripts(array('sack')); //use JavaScript SACK library for Ajax
      ?>
        <script type="text/javascript">
          function <func_name>() {
    ...

    You can see I have tried to place wp_enqueue_scripts at different places, but its not working.
    Any help would be appreciated.

  2. bsohal
    Member
    Posted 3 years ago #

    Back again ....
    There were other problems that I couldn't get this working.

    However for the solution -
    1. download jquery ui from its official site. You can find the jquery & ui js files that i have included in solution.
    2. copy these to your plugin/js folder
    3. add in beginning of plugin main file: -

    add_action('admin_print_scripts','plugin_init'); // plugin is any name
    function plugin_init() {
      wp_deregister_script('jquery');
      wp_register_script('jqua', plugins_url('js/jquery-1.5.1.min.js',__FILE__), false, '1.5.1');
      wp_enqueue_script('jqua');
      wp_deregister_script('jquery-ui-core');
      wp_deregister_script('jquery-ui-sortable');
      wp_deregister_script('jquery-ui-mouse');
      wp_register_script('jqueryui', plugins_url('js/jquery-ui-1.8.12.custom.min.js',__FILE__), false, '1.8.2');
      wp_enqueue_script('jqueryui');
    }
    add_action('admin_head','biz_items_jui_admin_header'); //Add JQuery UI to the admin side
    
    function biz_items_jui_admin_header() {
    ?>
    <script type="text/javascript">
      $(function() {
        $("#sortable1, #sortable2").sortable().disableSelection();
      });
    </script>
    <?php
    }

    If anyone has better ways to tackle the way I did, please let me know.

  3. Billyben
    Member
    Posted 3 years ago #

    Hi, I'm just trying to add sortable to my option page (in a class) and

    add_action( 'admin_menu', array( &$this, 'add_pages' ) );
    
    public function add_pages() {
    $my_option_page =add_menu_page(.. args..);
    add_action( 'admin_print_scripts-' . $my_option_page, array( &$this, 'scripts' ) );
    [...]
    }
    
    public function scripts() {
    		wp_enqueue_script( 'jquery-ui-tabs' );
    		wp_enqueue_script('jquery-ui-sortable');
    }

    works fine for me with wp 3.1.1

  4. Cyber Sprocket Labs
    Member
    Posted 2 years ago #

    BTW, you should not bind script enqueue to the init action, bind to the wp_enqueue_scripts action instead.

Topic Closed

This topic has been closed to new replies.

About this Topic