UNPKG

cnl

Version:
104 lines (92 loc) 2.78 kB
var Element, extend = require("extends__"), hasProp = {}.hasOwnProperty; module.exports = Element = (function(superClass) { extend(Element, superClass); function Element() { var fn, i, j, len, len1, ref, ref1, type; Element.__super__.constructor.apply(this, arguments); if (this.origin) { this.origin = { x: this.origin.x || 0, y: this.origin.y || 0 }; } ref = ['mousemove', 'mousedown', 'mouseup']; fn = (function(_this) { return function(type) { _this.addListener({ type: type, capture: true, listener: function(event) { var ref1; if (!((ref1 = this.events) != null ? ref1[type] : void 0)) { return event.cancel().stop(); } } }); return _this.addListener({ type: type, capture: false, listener: function(event) { var ref1; if (!((ref1 = this.events) != null ? ref1[type] : void 0)) { return event.cancel().stop(); } } }); }; })(this); for (i = 0, len = ref.length; i < len; i++) { type = ref[i]; fn(type); } ref1 = ['mousemove', 'mousedown', 'mouseup']; for (j = 0, len1 = ref1.length; j < len1; j++) { type = ref1[j]; this.addListener(type, this[type + "CaptureListener"], true); this.addListener(type, this[type + "Listener"], false); } } Element.prototype.localizeEventCoordinates = function(event) { var ref, ref1, x, y; if (event) { x = (event.localX != null ? event.localX : event.x); event.localX = x - (((ref = this.origin) != null ? ref.x : void 0) || 0); y = (event.localY != null ? event.localY : event.y); event.localY = y - (((ref1 = this.origin) != null ? ref1.y : void 0) || 0); } return this; }; Element.prototype.mousemoveCaptureListener = function(event) { if (event) { this.___runtime.mousemoveEvent = event; this.localizeEventCoordinates(event); } return this; }; Element.prototype.mousedownCaptureListener = function(event) { if (event) { this.___runtime.mousedownEvent = event; this.localizeEventCoordinates(event); } return this; }; Element.prototype.mouseupCaptureListener = function(event) { if (event) { this.___runtime.mouseupEvent = event; this.localizeEventCoordinates(event); } return this; }; Element.prototype.mousemoveListener = function() { return this; }; Element.prototype.mousedownListener = function() { return this; }; Element.prototype.mouseupListener = function() { return this; }; return Element; })(require('ecl/dist/evented'));