Search code examples
jquery-uijquery-tabs

jQuery UI Tabs - how can I disable top menu?


I'm trying to disable top menu on jQuery UI Tabs - so the tabs would be operated with next/prev buttons only.

Disable option form the doc does not seams to work as expected.

Please see my example here: Live Demo

jQuery code:

    $(document).ready( function() {

  $(function() {

            var $tabs = $('#tabs').tabs();

            $(".ui-tabs-panel").each(function(i){

              var totalSize = $(".ui-tabs-panel").size() - 1;

              if (i != totalSize) {
                  next = i + 2;
                     $(this).append("<a href='#' class='next-tab mover' rel='" + next + "'>Next Page &#187;</a>");
              }

              if (i != 0) {
                  prev = i;
                     $(this).append("<a href='#' class='prev-tab mover' rel='" + prev + "'>&#171; Prev Page</a>");
              }

            });

            $('.next-tab, .prev-tab').click(function() { 
                   $tabs.tabs('select', $(this).attr("rel"));
                   return false;
               });


        });

});

Any ideas how can I disable top menu, but keep the structure, style etc.. ?


Solution

  • How about just enable the tab to be selected just before selecting it, and then disable the tabs again?

    So, at the initialisation, all tabs are disabled:

        var $tabs = $('#tabs').tabs({
            disabled: [0, 1, 2]
        });
    

    And when selecting the tab, enable it before selecting it, and then disable all tabs again:

            $tabs.tabs('enable', tabIndex)
                .tabs('select', tabIndex)
                .tabs("option","disabled", [0, 1, 2]);
    

    See it in action: http://jsfiddle.net/william/y6QeV/21/.


    EDIT: You can simply disable just the old tab:

            var newTabIndex = $(this).attr("rel");
            var oldTabIndex = $tabs.tabs('option', 'selected');
            $tabs.tabs('enable', newTabIndex)
                .tabs('select', newTabIndex)
                .tabs('disable', oldTabIndex);
    

    Example: http://jsfiddle.net/william/y6QeV/22/.