Opened 11 years ago

Closed 11 years ago

#7910 closed defect (wontfix)

There is no way to get dnd objects when used wia dojotype attribute

Reported by: kiuma Owned by: Eugene Lazutkin
Priority: high Milestone: tbd
Component: DnD Version: 1.2.0
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by Eugene Lazutkin)

Sometime it's needed to recreate a dnd object, for example when replacing a div content via a xhr call. If it is not done the dojo.connect on dnd objects is duplicated. A solution that I have applied is to have a dojo.dnd.byId a sample of what Ive done is the following and seems to work:

dojo.provide("claw.dnd.common");

claw.dnd = {};

claw.dnd._map = {};

claw.dnd._cache = {'clawDnd': 0};

claw.dnd.byId = function(id){
    // summary: returns the dojo.dnd instance bound to a HTML object element
    return claw.dnd._map[id]; // assume it's a node
};

dojo.declare("claw.dnd._DndMixin", null, {
    id: "",
    _putInCache: function (node) {
        this.id = dojo.attr(node, "dndId");
        if(!this.id) {
            this.id = dojo.attr(node, "id");
            if (!this.id) {
                var index = claw.dnd._cache._clawDnd;
                claw.dnd._cache._clawDnd = index++;
                this.id = "clawDnd" + index;
            }
            dojo.attr(node, "dndId", this.id);
        }
        claw.dnd._map[this.id] = this;
    },
    constructor: function (node, params) {
        this._putInCache(this.node);
    },
    destroy: function() {
        // summary: warning. Like dojo.dnd.Container destroy method, but cleans up claw.dnd._map. Remember to eventually remove its node.
        delete claw.dnd._map[this.id];
        dojo.dnd.Source.prototype.destroy.call(this);
    }
});

//now the Source subclassing
dojo.provide("claw.dnd.Source");

dojo.require("claw.dnd.common");
dojo.require("dojo.dnd.Source");

dojo.declare("claw.dnd.Source",[dojo.dnd.Source,claw.dnd._DndMixin], {
    markupFactory: function(params, node){
        params._skipStartup = true;
        return new claw.dnd.Source(node, params);
    }
});

Change History (5)

comment:1 Changed 11 years ago by Eugene Lazutkin

Description: modified (diff)

Did you try jsId? If you did, why isn't it sufficient for you?

comment:2 Changed 11 years ago by kiuma

well: for what I've understood jsId has the same meaninig of fooId. If I don't specify it it isn't written. Then I the dndId solution always generates an id (whatever the attribute is called, jsId if you prefer) The solution suggested may be used by a function such as dojo.dnd.byId (faster then dojo.query)

comment:3 Changed 11 years ago by Eugene Lazutkin

I don't really know what fooId is. The parser creates a JavaScript object (of dojoType) and assigns it the the global variable named by jsId. Basically this HTML code:

<div dojoType="dojo.dnd.Source" jsId="src1"></div>

Makes following code possible without any complicated registries:

src1.insertNodes(...);
// yes, src1 is a variable that was defined by jsId in the HTML snippet
// we can use it as we use any regular JavaScript variable
dojo.connect(src1, "onDraggingOver", function(){
  dojo.addClass(src1.node, "mySuperClassName");
});
dojo.connect(src1, "onDraggingOut", function(){
  dojo.removeClass(src1.node, "mySuperClassName");
});

It is similar to creating an object (a source in this case) with JavaScript code:

src1 = new dojo.dnd.Source(node);

comment:4 Changed 11 years ago by kiuma

Ok thank you for explanation, I hadn't fully understood the jsId thing. This would be sufficient, so the issue can be closed.

comment:5 Changed 11 years ago by Eugene Lazutkin

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.