lib/tabs.js   A
last analyzed

Complexity

Total Complexity 11
Complexity/F 1.83

Size

Lines of Code 63
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 37
mnd 5
bc 5
fnc 6
dl 0
loc 63
rs 10
bpm 0.8333
cpm 1.8333
noi 0
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A tabs.js ➔ switchTab 0 5 1
A tabs.js ➔ render 0 4 1
A tabs.js ➔ add 0 20 4
A tabs.js ➔ gotoTab 0 16 5
1
define(function () {
2
  'use strict';
3
4
  return function () {
5
    var self = this;
6
7
    var tabs = document.createElement('ul');
8
    tabs.classList.add('tabs');
9
10
    var container = document.createElement('div');
11
12
    function gotoTab(li) {
13
      for (var i = 0; i < tabs.children.length; i++) {
14
        tabs.children[i].classList.remove('visible');
15
      }
16
17
      while (container.firstChild) {
18
        container.removeChild(container.firstChild);
19
      }
20
21
      li.classList.add('visible');
22
23
      var tab = document.createElement('div');
24
      tab.classList.add('tab');
25
      container.appendChild(tab);
26
      li.child.render(tab);
27
    }
28
29
    function switchTab() {
30
      gotoTab(this);
31
32
      return false;
33
    }
34
35
    self.add = function add(title, d) {
36
      var li = document.createElement('li');
37
      li.textContent = _.t(title);
38
      li.onclick = switchTab;
39
      li.child = d;
40
      tabs.appendChild(li);
41
42
      var anyVisible = false;
43
44
      for (var i = 0; i < tabs.children.length; i++) {
45
        if (tabs.children[i].classList.contains('visible')) {
46
          anyVisible = true;
47
          break;
48
        }
49
      }
50
51
      if (!anyVisible) {
52
        gotoTab(li);
53
      }
54
    };
55
56
    self.render = function render(el) {
57
      el.appendChild(tabs);
58
      el.appendChild(container);
59
    };
60
61
    return self;
62
  };
63
});
64