Skip to content

Commit

Permalink
Fix mouse events for image layers
Browse files Browse the repository at this point in the history
This was due to the fact that _addLayer() was returning the current
layer object only immediately after layer creation.
  • Loading branch information
caleb531 committed May 30, 2024
1 parent fcb53a0 commit 67c677e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/jcanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1776,10 +1776,8 @@ function _addLayer(
params: JCanvasObject,
args?: Partial<JCanvasObject>,
method?: (args: JCanvasObject) => JQuery<HTMLElement>
): 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;
Expand Down Expand Up @@ -1879,7 +1877,7 @@ function _addLayer(
_coerceNumericProps(params);
}

return null;
return layer;
}

// Add a jCanvas layer
Expand Down Expand Up @@ -4055,7 +4053,7 @@ $.fn.drawImage = function drawImage(args) {
ctx: CanvasRenderingContext2D,
data: JCanvasInternalData,
params: JCanvasObject,
layer: JCanvasLayer | null
layer: JCanvasObject | null
) {
if (!img) {
return;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 67c677e

Please sign in to comment.