From 67c677eee9652a2fb3050aa5cc440ee6960ba6d9 Mon Sep 17 00:00:00 2001 From: Caleb Evans Date: Thu, 30 May 2024 11:43:45 -0700 Subject: [PATCH] Fix mouse events for image layers This was due to the fact that _addLayer() was returning the current layer object only immediately after layer creation. --- src/jcanvas.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/jcanvas.ts b/src/jcanvas.ts index bc6f4af..a61773f 100644 --- a/src/jcanvas.ts +++ b/src/jcanvas.ts @@ -1776,10 +1776,8 @@ function _addLayer( params: JCanvasObject, args?: Partial, method?: (args: JCanvasObject) => JQuery -): JCanvasLayer | null { - const layer: JCanvasObject | JCanvasLayer = params._layer - ? (args as JCanvasLayer) - : params; +): JCanvasObject | null { + const layer: JCanvasObject = params._layer ? (args as JCanvasLayer) : params; // Store arguments object for later use params._args = args; @@ -1879,7 +1877,7 @@ function _addLayer( _coerceNumericProps(params); } - return null; + return layer; } // Add a jCanvas layer @@ -4055,7 +4053,7 @@ $.fn.drawImage = function drawImage(args) { ctx: CanvasRenderingContext2D, data: JCanvasInternalData, params: JCanvasObject, - layer: JCanvasLayer | null + layer: JCanvasObject | null ) { if (!img) { return; @@ -4171,12 +4169,12 @@ $.fn.drawImage = function drawImage(args) { ctx: CanvasRenderingContext2D, data: JCanvasInternalData, params: JCanvasObject, - layer: JCanvasLayer | null + layer: JCanvasObject | null ) { return function () { const $canvas = $(canvas); draw(canvas, ctx, data, params, layer); - if (params.layer && layer) { + if (params.layer && layer instanceof jCanvasLayer) { // Trigger 'load' event for layers _triggerLayerEvent($canvas, data, layer, "load"); } else if (params.load) {