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

## Statements: 100% (18 / 18) Branches: 100% (4 / 4) Functions: 100% (5 / 5) Lines: 100% (17 / 17) Ignored: none

All files » lib/attributes/ » event.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
    54
    55
    56
    571
    1
    1

    1
    19
    19

    1

    19
    19

    19
    19

    19
    18
    18
    18

    2

    1
     var protoclass = require("protoclass");
    var _bind      = require("../utils/bind");
    var Base       = require("./base");

    /**
     */

    function EventAttribute(options) {
      this._onEvent = _bind(this._onEvent, this);
      Base.call(this, options);

      // TODO - register event handler on view. Don't attach
      // event handler on node here
    }

    /**
     */

    Base.extend(EventAttribute, {

      /**
       */

      initialize: function() {
        // convert onEvent to event
        var event = this.event || (this.event = this.key.toLowerCase().replace(/^on/, ""));
        this.node.addEventListener(event, this._onEvent);
      },

      /**
       */

      bind: function() {
        Base.prototype.bind.call(this);
        this.bound = true;
      },

      /**
       */

      _onEvent: function(event) {
        if (!this.bound) return;
        event.preventDefault();
        this.view.set("event", event);
        this.value.evaluate(this.view);
      },

      /**
       */

      unbind: function() {
        this.bound = false;
      }
    });

    module.exports = EventAttribute;