Switch off ajax

Added by Edward Hill over 1 year ago

Hi all,
I wrote aplication that can move objects on canvas, all code use Wt functions. But even on my local PC it's very slow, i mean every movement call ajax to server.
I tried use WApplication::setAjaxMethod(DynamicScriptTag); but this doing something another, that need to me.
So is it possible not using ajax for move objects? Also using own javascripts not so good idea.
Thanks!


Replies

RE: Switch off ajax - Added by Koen Deforche over 1 year ago

Hey Edward,

The easiest way to have things move around and program it client-side is to use absolutely positioned widgets (which may themselves be WPaintedWidgets). Then you can have a small amount of JavaScript code which modifies 'left' and 'top' properties based on mouse dragging. See for example how the WDialog's implement moving when the mouse drags the title bar:

(from WDialog.js):

function handleMove(event) {
     var e = event||window.event;
     var nowxy = WT.pageCoordinates(e);
     var wxy = WT.windowCoordinates(e);
     var wsize = WT.windowSize();

     if (wxy.x > 0 && wxy.x < wsize.x && wxy.y > 0 && wxy.y < wsize.y) {
       moved = true;

       el.style.left = (WT.pxself(el, 'left') + nowxy.x - dsx) + 'px';
       el.style.top = (WT.pxself(el, 'top') + nowxy.y - dsy) + 'px';
       dsx = nowxy.x;
       dsy = nowxy.y;
     }
   };

   if (titlebar) {
     titlebar.onmousedown = function(event) {
       var e = event||window.event;
       WT.capture(titlebar);
       var pc = WT.pageCoordinates(e);
       dsx = pc.x;
       dsy = pc.y;

       titlebar.onmousemove = handleMove;
     };

     titlebar.onmouseup = function(event) {
       titlebar.onmousemove = null;

       WT.capture(null);
     };
   }

That means that you will need to split up your painting code over multiple widgets.

Regards,
koen