Jump to content

AddJS window.addEventListener('resize', resizeCanvas... not updating/working


Ron
 Share

Recommended Posts

Hello!

 

I add some code using UniSession.AddJS, and this code contains:

 

1.insertion of a canvas element, and getting context:

 

var canv = document.createElement("canvas");
canv.id = "daycal";
document.body.appendChild(canv);
var canvas = document.getElementById("daycal");
var ctx = canvas.getContext("2d");
 
2. THen some drawing on that canvas
 
3. Then an event listener on canvas resize, to trigger the drawing function:
 
window.addEventListener('resize', resizeCanvas, true);
  function resizeCanvas() {
    canvas.width = window.innerWidth-2;
    canvas.height = window.innerHeight-40;
    drawDayCalendar();
    drawAppopintments(); 
  }
 
 
4. Then at last I trigger the resizefunction at the JS load
 resizeCanvas();

 

 

 

Now, when I load the application, I get a short glimpse of the calendar graphics,

but then the canvas gets cleared.

 

Why does this happen?

 

The drawing routine works, because I can see the graphics.

 

So the event listener does not work, as the canvas is not redrawn - wonder why?

 

I am doing things this way because I need mouse movements for drag/drop and appointment resize,

so I have 600 lines of javascript loading here, including event code.

 

Btw I had to drop the mouse events while testing because I do not have jQuery, but I guess I could load that too (?),

or use some other method to capture those events if possible.

 

Anyway, there is something not working here.

 

 

Is it a problem that I create the canvas html element in javascript?

 

Does Unigui mess with the event listening setup?

 

Any advise is most welcome!

 

 

Kaj

Link to comment
Share on other sites

Solved - I had to have the AddJS statement in the OnCreate event of the main form,

then the event listener got registered.

 

Now it will be interesting to see if mouse events can be added, and if I can also

 

add websocket support in the client and connect this to a NodeJS server....

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...