AliasIO / Raphael.FreeTransform

Free transform tool for Raphaël elements.
http://elbertf.com
362 stars 107 forks source link

BUG: apply instead of drag callbacks #120

Open Phoscur opened 10 years ago

Phoscur commented 10 years ago

Updating this library breaks my code:

ft = this.freetransform(surface, opts, function(ft, events) {
  if (events.indexOf("drag") !== -1) {
     set.transform(..) // wont be called any more
});

Inspecting this, only "init", "apply" and "drag end" events are fired. Reverting to older freeTransform revision.

jwarren1980 commented 10 years ago

There is a bug in the current code that causes some events to not be sent to your callback function all the time.

The solution I used, which works for handling all events as they are called, in order, is to replace the function asyncCallback with the one below:

/**
 * Call callback asynchronously for better performance
 */
function asyncCallback(e)
{
     if (ft.callback)
     {
          // Remove empty values
          var events = [];

          e.map(function (e, i) { if (e) { events.push(e); } });

          //clearTimeout(timeout);

          //timeout = setTimeout(function () { if (ft.callback) { ft.callback(ft, events); } }, 1);

          if (ft.callback) { ft.callback(ft, events); }
     }
}