UNPKG

cnl

Version:
73 lines (63 loc) 1.82 kB
var Shape, extend = require("extends__"), hasProp = {}.hasOwnProperty; module.exports = Shape = (function(superClass) { extend(Shape, superClass); function Shape() { var name, region, regions; Shape.__super__.constructor.apply(this, arguments); if (regions = this.regions) { this.regions = {}; for (name in regions) { region = regions[name]; this.regions[name] = region; } } } Shape.prototype.draw = function() { return this; }; Shape.prototype.getEventRegions = function(event) { var $, name, ref, result, x, y; result = null; if (event && ((x = event.localX) != null) && ((y = event.localY) != null)) { ref = this.regions; for (name in ref) { $ = ref[name]; if (($[0] <= x && x <= ($[0] + $[2])) && ($[1] <= y && y <= ($[1] + $[3]))) { result || (result = {}); result[name] = $; } } } return result; }; Shape.prototype.mousemoveCaptureListener = function(event) { Shape.__super__.mousemoveCaptureListener.apply(this, arguments); if (event) { if (event.regions = this.getEventRegions(event)) { event.target = this; } } return this; }; Shape.prototype.mousedownCaptureListener = function(event) { Shape.__super__.mousedownCaptureListener.apply(this, arguments); if (event) { if (event.regions = this.getEventRegions(event)) { event.target = this; } } return this; }; Shape.prototype.mouseupCaptureListener = function(event) { Shape.__super__.mouseupCaptureListener.apply(this, arguments); if (event) { if (event.regions = this.getEventRegions(event)) { event.target = this; } } return this; }; return Shape; })(require('./element'));