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

## Statements: 93.75% (15 / 16) Branches: 75% (3 / 4) Functions: 100% (5 / 5) Lines: 100% (15 / 15) 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
    561

    1
    17
    17

    1

    17
    17

    17
    17

    17
    17
    17
    17

    1

    1var protoclass = require("protoclass"),
    _bind          = require("../utils/bind"),
    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 (context) {
        Base.prototype.bind.call(this, context);
        this.bound = true;
      },

      /**
       */

      _onEvent: function (event) {
        Iif (!this.bound) return;
        event.preventDefault();
        this.context.event = event;
        this.value.evaluate(this.context);
      },

      /**
       */

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

    module.exports = EventAttribute;