Code coverage report for lib/attributes/event.js

Statements: 33.33% (6 / 18)      Branches: 0% (0 / 4)      Functions: 0% (0 / 5)      Lines: 35.29% (6 / 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 541 1 1         1               1                                                                         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);
}
 
/**
 */
 
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;