Passed
Push — develop ( 2604b2...77c94a )
by Xaver
01:09
created

lib/tabs.js (1 issue)

Labels
Severity
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);
0 ignored issues
show
The variable container is changed as part of the for-each loop for example by document.createElement("div") on line 10. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
59
    };
60
61
    return self;
62
  };
63
});
64