jQuery UI & Tabs: Sortable tabs

This entry is part 6 of 7 in the series jQuery UI Tabs

jQuery UI Tabs – Sortable

Drag the tabs above to re-order them.

Making tabs sortable is as simple as calling .sortable() on the .ui-tabs-nav element.

<!doctype html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <title>jQuery UI Tabs - Sortable</title>
    <link rel='stylesheet' href='//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css'>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
    <script src='//code.jquery.com/ui/1.10.4/jquery-ui.js'></script>
    <link rel='stylesheet' href='https://codecrawl.com/code/jqueryui/jqueryui_style.css'>
    <script>
        $(function () {
            var tabs = $('#tabs').tabs();
            tabs.find('.ui-tabs-nav').sortable({
                axis: 'x',
                stop: function () {
                    tabs.tabs('refresh');
                }
            });
        });
    </script>
</head>
<body>

<div id='tabs'>
    <ul>
        <li><a href='#tabs-1'>Pitbull</a></li>
        <li><a href='#tabs-2'>Sean Kingston</a></li>
        <li><a href='#tabs-3'>Taylor Swift</a></li>
    </ul>
    <div id='tabs-1'>
        <p>Pitbull is a Cubanā€“American recording artist and Latin Grammy winning rapper from Miami, Florida.</p>
    </div>
    <div id='tabs-2'>
        <p>Sean Kingston pursued a music career and debuted in 2007 with the album Sean Kingston.</p>
    </div>
    <div id='tabs-3'>
        <p>Taylor Swift, raised in Wyomissing, Pennsylvania. She moved to Nashville, Tennessee at the age of
            fourteen.</p>

        <p>She is known for her narrative songs about her personal experiences.</p>
    </div>
</div>

</body>
</html>
Try The Code

jQuery UI & Accordion: Sortable

This entry is part 2 of 7 in the series jQuery UI Accordion

jQuery UI Accordion – Sortable

You can drag the header to re-order panels.

<!doctype html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <title>jQuery UI Accordion - Sortable</title>
    <link rel='stylesheet' href='//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css'>
    <script src='//code.jquery.com/jquery-1.9.1.js'></script>
    <script src='//code.jquery.com/ui/1.10.4/jquery-ui.js'></script>
    <link rel='stylesheet' href='https://codecrawl.com/code/jqueryui/jqueryui_style.css'>
    <style>
        /* IE has layout issues when sorting (see #5413) */
        .group {
            zoom: 1
        }
    </style>
    <script>
        $(function () {
            $('#accordion')
                    .accordion({
                        header: '> div > h3'
                    })
                    .sortable({
                        axis: 'y',
                        handle: 'h3',
                        stop: function (event, ui) {
                            // IE doesn't register the blur when sorting
                            // so trigger focusout handlers to remove .ui-state-focus
                            ui.item.children('h3').triggerHandler('focusout');
                        }
                    });
        });
    </script>
</head>
<body>

<div id='accordion'>
    <div class='group'>
        <h3>Section 1</h3>

        <div>
            <p>Content of section 1.</p>
        </div>
    </div>
    <div class='group'>
        <h3>Section 2</h3>

        <div>
            <p>Content of section 2.</p>
        </div>
    </div>
    <div class='group'>
        <h3>Section 3</h3>

        <div>
            <p>Content of section 3.</p>
            <ul>
                <li>List item one</li>
                <li>List item two</li>
                <li>List item three</li>
            </ul>
        </div>
    </div>
    <div class='group'>
        <h3>Section 4</h3>

        <div>
            <p>Content of section 4</p>
        </div>
    </div>
</div>

</body>
</html>
Try The Code

jQuery UI & Draggable: Sortable

This entry is part 4 of 11 in the series jQuery UI Draggable

jQuery UI Draggable + Sortable

Draggables are built to interact seamlessly with sortable.

We haveĀ $(“ul, li”).disableSelection() so that when the mouse is moved over the boxes, the text will not be selected.

When setting helper: ‘clone’, then the element will be cloned and the clone is the element that is going to be dragged.

The revert: ‘invalid’ will prevent the draggable element to return to its original postion once it is dragged and positioned in the sortable boxes.

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>jQuery UI Draggable + Sortable</title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.9.1.js"></script>
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <link rel='stylesheet' href='https://codecrawl.com/code/jqueryui/jqueryui_style.css'>
    <style>
        ul {
            list-style-type: none;
            margin: 0;
            padding: 0;
            margin-bottom: 10px;
        }

        li {
            margin: 5px;
            padding: 5px;
            width: 150px;
        }
    </style>
    <script>
        $(function () {
            $("#sortable").sortable({
                revert: true
            });
            $("#draggable").draggable({
                connectToSortable: "#sortable",
                helper: "clone",
                revert: "invalid"
            });
            $("ul, li").disableSelection();
        });
    </script>
</head>
<body>

<ul>
    <li id="draggable" class="ui-state-highlight">Drag me down</li>
</ul>

<ul id="sortable">
    <li class="ui-state-default">Item 1</li>
    <li class="ui-state-default">Item 2</li>
    <li class="ui-state-default">Item 3</li>
    <li class="ui-state-default">Item 4</li>
    <li class="ui-state-default">Item 5</li>
</ul>


</body>
</html>
Try The Code