Passed
Push — master ( a9037b...23c6f9 )
by Swen
02:05
created

localized_fields/static/localized_fields/localized-fields-admin.js   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 35
rs 8.8571
nc 1
nop 1

2 Functions

Rating   Name   Duplication   Size   Complexity  
B localized-fields-admin.js ➔ $ 0 24 3
A localized-fields-admin.js ➔ syncTabs 0 8 1
1
(function($) {
2
    var syncTabs = function(lang) {
3
        $('.localized-fields-widget.tab a:contains("'+lang+'")').each(function(){
4
            $(this).parents('.localized-fields-widget[role="tabs"]').find('.localized-fields-widget.tab').removeClass('active');
5
            $(this).parents('.localized-fields-widget.tab').addClass('active');
6
            $(this).parents('.localized-fields-widget[role="tabs"]').children('.localized-fields-widget [role="tabpanel"]').hide();
7
            $($(this).attr('href')).show();
8
        });
9
    }
10
11
    $(function (){
12
        $('.localized-fields-widget [role="tabpanel"]').hide();
13
        // set first tab as active
14
        $('.localized-fields-widget[role="tabs"]').each(function () {
15
            $(this).find('.localized-fields-widget.tab:first').addClass('active');
16
            $($(this).find('.localized-fields-widget.tab:first a').attr('href')).show();
17
        });
18
        // try set active last selected tab
19
        if (window.sessionStorage) {
20
            var lang = window.sessionStorage.getItem('localized-field-lang');
21
            if (lang) {
22
                syncTabs(lang);
23
            }
24
        }
25
26
        $('.localized-fields-widget.tab a').click(function(event) {
27
            event.preventDefault();
28
            syncTabs(this.innerText);
29
            if (window.sessionStorage) {
30
                window.sessionStorage.setItem('localized-field-lang', this.innerText);
31
            }
32
            return false;
33
        });
34
    });
35
})(django.jQuery)
0 ignored issues
show
Bug introduced by
The variable django seems to be never declared. If this is a global, consider adding a /** global: django */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
36