# All files / src item.js

100% Statements 30/30
100% Branches 24/24
100% Functions 8/8
100% Lines 30/30

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    6117x
    166x
    816x

    816x

    816x
    816x

    816x
    816x
    627x
    45x

    582x

    189x
    189x
    189x

    816x
    4958x
    924x
    1415x

    924x
    879x

    4034x

    816x
    2247x

    816x
    730x

    816x
    3744x

    816x
    92x

    816x

     module.exports = function(list) {
      return function(initValues, element, notCreate) {
        var item = this;

        this._values = {};

        this.found = false; // Show if list.searched == true and this.found == true
        this.filtered = false;// Show if list.filtered == true and this.filtered == true

        var init = function(initValues, element, notCreate) {
          if (element === undefined) {
            if (notCreate) {
              item.values(initValues, notCreate);
            } else {
              item.values(initValues);
            }
          } else {
            item.elm = element;
            var values = list.templater.get(item, initValues);
            item.values(values);
          }
        };

        this.values = function(newValues, notCreate) {
          if (newValues !== undefined) {
            for(var name in newValues) {
              item._values[name] = newValues[name];
            }
            if (notCreate !== true) {
              list.templater.set(item, item.values());
            }
          } else {
            return item._values;
          }
        };

        this.show = function() {
          list.templater.show(item);
        };

        this.hide = function() {
          list.templater.hide(item);
        };

        this.matching = function() {
          return (
            (list.filtered && list.searched && item.found && item.filtered) ||
            (list.filtered && !list.searched && item.filtered) ||
            (!list.filtered && list.searched && item.found) ||
            (!list.filtered && !list.searched)
          );
        };

        this.visible = function() {
          return (item.elm && (item.elm.parentNode == list.list)) ? true : false;
        };

        init(initValues, element, notCreate);
      };
    };