public/themes/templates/1/includes/js/ui.tabs.js   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 1

Size

Lines of Code 35
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 6
mnd 0
bc 0
fnc 6
bpm 0
cpm 1
noi 0
1
(function ($) {
2
    /**
3
     * jQuery plugin to manage simple tabs */
4
    $.fn.tabs = function () {
5
        this.each(function () {
6
            // Get the root of our tabs
7
            var tabRoot = $(this),
8
                // Get all our tab buttons
9
                allTabButtons = tabRoot.find('li'),
10
                // Get all the ID of the content panes
11
                allTabsIds = allTabButtons.map(function () {
12
                    return $(this).find('a').attr('href');
13
                });
14
15
            // Whenever a tab is clicked...
16
            allTabButtons.click(function () {
17
                // Remove the active class from all buttons
18
                allTabButtons.removeClass('active');
19
                // ...and set the one that was clicked on active
20
                $(this).addClass('active');
21
22
                // Then remove the active class from all content panes
23
                $.each(allTabsIds, function (i, id) {
24
                    $(id).removeClass('active');
25
                });
26
                // Find out the target content pane, and mark it active
27
                var targetTabId = $(this).find('a').attr('href');
28
                $(targetTabId).addClass('active');
29
30
                // Prevent the click event on the anchor to be processed
31
                return false;
32
            });
33
        });
34
    }
35
}(jQuery));
36