All files / src item.js

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

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 172x 877x   877x   877x 877x   877x 877x 687x 60x   627x     190x 190x 190x       877x 5797x 985x 1534x   985x 925x     4812x       877x 2396x     877x 896x     877x 4225x               877x 92x     877x      
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)
  }
}