# Code coverage report for lib/attributes/class.js

## Statements: 100% (23 / 23) Branches: 92.86% (13 / 14) Functions: 100% (2 / 2) Lines: 100% (23 / 23) Ignored: none

All files » lib/attributes/ » class.js

    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
    541

    1

    6

    6
    2

    4
    1

    3
    3

    3

    6
    6

    6
    6
    6
    6
    5
    4

    1
    1

    3

    1
    11

     var ScriptAttribute = require("./script");

    /**
     */

    module.exports = ScriptAttribute.extend({

      /**
       */

      update: function() {

        var classes = this.currentValue;

        if (typeof classes === "string") {
          return this.node.setAttribute("class", classes);
        }

        if (!classes) {
          return this.node.removeAttribute("class");
        }

        var classesToUse = this.node.getAttribute("class");
        classesToUse     = classesToUse ? classesToUse.split(" ") : [];

        for (var classNames in classes) {

          var useClass = classes[classNames];
          var classNamesArray = classNames.split(/,\s*/);

          for (var i = 0, n = classNamesArray.length; i < n; i++) {
            var className = classNamesArray[i];
            var j = classesToUse.indexOf(className);
            if (useClass) {
              if (!~j) {
                classesToUse.push(className);
              }
            } else Eif (~j) {
              classesToUse.splice(j, 1);
            }
          }
        }

        this.node.setAttribute("class", classesToUse.join(" "));
      }
    });

    module.exports.test = function(value) {
      return typeof value === "object" && !value.buffered;
    };