From 82a362a54bea072533dc7a9cbbb82ead65ab818e Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sat, 17 May 2014 13:04:54 +0200 Subject: [PATCH] Combine click events --- compiled/radium.js | 22 ++++++---------------- radium/scene.coffee | 18 ++++++------------ 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/compiled/radium.js b/compiled/radium.js index d708451..7190948 100644 --- a/compiled/radium.js +++ b/compiled/radium.js @@ -1453,8 +1453,6 @@ this.iteration = __bind(this.iteration, this); this.checkActive = __bind(this.checkActive, this); this.removeTargetSurface = __bind(this.removeTargetSurface, this); - this.handleMouseDown = __bind(this.handleMouseDown, this); - this.handleMouseUp = __bind(this.handleMouseUp, this); this.handleClick = __bind(this.handleClick, this); this.addTargetSurface = __bind(this.addTargetSurface, this); this.instances = {}; @@ -1482,34 +1480,34 @@ })(this)); $(surface).on("click.radium", (function(_this) { return function(event) { - return _this.handleClick(event); + return _this.handleClick("click", event); }; })(this)); $(surface).on("mouseup.radium", (function(_this) { return function(event) { - return _this.handleMouseUp(event); + return _this.handleClick("mouse_up", event); }; })(this)); $(surface).on("mousedown.radium", (function(_this) { return function(event) { - return _this.handleMouseDown(event); + return _this.handleClick("mouse_down", event); }; })(this)); return this.checkActive(); }; - Scene.prototype.handleClick = function(event) { + Scene.prototype.handleClick = function(event_name, event) { var id, instance, _ref; _ref = this.instances; for (id in _ref) { instance = _ref[id]; - instance.callEvent("click_global", { + instance.callEvent("" + event_name + "_global", { x: this.mouse_x, y: this.mouse_y, button: event.which }); if (instance.checkPointCollision(this.mouse_x, this.mouse_y)) { - instance.callEvent("click", { + instance.callEvent(event_name, { x: this.mouse_x, y: this.mouse_y, button: event.which @@ -1521,14 +1519,6 @@ return false; }; - Scene.prototype.handleMouseUp = function(event) { - return pass; - }; - - Scene.prototype.handleMouseDown = function(event) { - return pass; - }; - Scene.prototype.removeTargetSurface = function(surface) { this.surfaces = this.surfaces.filter(function(obj) { return obj !== surface; diff --git a/radium/scene.coffee b/radium/scene.coffee index c51d63f..ae6ba3b 100644 --- a/radium/scene.coffee +++ b/radium/scene.coffee @@ -22,37 +22,31 @@ class Scene ) $(surface).on("click.radium", (event) => - @handleClick(event) + @handleClick("click", event) ) $(surface).on("mouseup.radium", (event) => - @handleMouseUp(event) + @handleClick("mouse_up", event) ) $(surface).on("mousedown.radium", (event) => - @handleMouseDown(event) + @handleClick("mouse_down", event) ) @checkActive() - handleClick: (event) => + handleClick: (event_name, event) => for id, instance of @instances - instance.callEvent("click_global", {x: @mouse_x, y: @mouse_y, button: event.which}) + instance.callEvent("#{event_name}_global", {x: @mouse_x, y: @mouse_y, button: event.which}) if instance.checkPointCollision(@mouse_x, @mouse_y) - instance.callEvent("click", {x: @mouse_x, y: @mouse_y, button: event.which}) + instance.callEvent(event_name, {x: @mouse_x, y: @mouse_y, button: event.which}) # Prevent default browser events from occurring on eg. right or middle click event.preventDefault() event.stopPropagation() return false - handleMouseUp: (event) => - pass - - handleMouseDown: (event) => - pass - removeTargetSurface: (surface) => @surfaces = @surfaces.filter (obj) -> obj isnt surface $(surface).off("mousemove.radium")