3

I made an element dragable using element.drag(start, move, up);

When I want to make the element undragable, I can somewhat achieve this using the method from the documentation:

element.undrag(f); // Any undefined variable works as the argument

This makes it so that the element cannot be moved anymore.

This method has 2 problems:

  1. This makes all elements on the page undragable.
  2. start() still fires once for each element. I have an opacity change triggered in start() so it's quite obvious.

How do I make an element undragable so that only that element is affected and start() is not fired?

Here's what I have so far. The following tries to make the element undragable after one drag:

wiwindow.onload = function() {
    var R = Raphael("canvas", 500, 500),
    c = R.circle(100, 100, 50).attr({
        fill: "hsb(.8, 1, 1)",
        stroke: "none",
        opacity: .5
    }),
    d = R.circle(200, 200, 50).attr({
        fill: "hsb(1, 1, .8)",
        stroke: "none",
        opacity: .5
    }),        
    start = function () {
        // storing original coordinates
        this.ox = this.attr("cx");
        this.oy = this.attr("cy");
        this.attr({opacity: 1});
    },
    move = function (dx, dy) {
        // move will be called with dx and dy
        this.attr({cx: this.ox + dx, cy: this.oy + dy});
    },
    up = function () {
        // restoring state
        this.attr({opacity: .5});
        this.undrag(notDefinedVariable); // Try to make it undragable
    };

    c.drag(move, start, up);    
    d.drag(move, start, up);     
};​

Try it out with this jsFiddle

Peter Ajtai
  • 56,972
  • 13
  • 121
  • 140
  • 1
    http://stackoverflow.com/questions/3902610/how-do-you-make-an-element-undragable-in-raphael/3905018#3905018 Has this issue been fixed or not? – Falak Sep 21 '11 at 05:42
  • @user880479 I'm using the same fiddle as above with 2.0 and it still doesn't work. – AHungerArtist Oct 03 '12 at 19:07
  • @AHungerArtist - Got it to work in 2.0 - I had some sort of funky "notDefinedVariable" ==> http://jsfiddle.net/pajtai/VBVWa/ - It had to be included in previous version for it to work. – Peter Ajtai Oct 03 '12 at 20:21

2 Answers2

3

Got it to work in 2.0

I had to change

this.undrag(notDefinedVariable); // Try to make it undragable

to

this.undrag(); // Try to make it undragable

Undefined had to be included in previous version to make it 1/2 work as described above.

Peter Ajtai
  • 56,972
  • 13
  • 121
  • 140
2

This is known bug. Will be fixed in the next release.

Dmitry Baranovskiy
  • 1,200
  • 6
  • 10
  • Thanks for the answer Dmitry. You have any idea when the next version will come out? Great library by the way; it's great fun to play with. – Peter Ajtai Oct 11 '10 at 14:25
  • It should happen before Sencha Conference in November, but I am not giving any promises. It is going to be big 1.6 release. – Dmitry Baranovskiy Oct 12 '10 at 09:16
  • 1
    @DmitryBaranovskiy For the record, using the same fiddle as linked above, it still shows this bug for Raphael 2.0. I'm using the latest version of Raphael and am also seeing this issue. – AHungerArtist Oct 03 '12 at 19:06