source: Dev/branches/rest-dojo-ui/client/dojox/mdnd/LazyManager.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.0 KB
Line 
1define([
2        "dojo/_base/kernel",    // dojo.addOnUnload
3        "dojo/_base/lang",      // dojo.hitch
4        "dojo/_base/declare",
5        "dojo/_base/html",      // dojo.create, dojo.attr, dojo.addClass
6        "dojo/dnd/Manager",
7        "./PureSource"
8],function(dojo){
9        return dojo.declare(
10                "dojox.mdnd.LazyManager",
11                null,
12        {
13                // summary:
14                //              This class allows to launch a drag and drop dojo on the fly.
15               
16                constructor: function(){
17                        //console.log("dojox.mdnd.LazyManager ::: constructor");
18                        this._registry = {};
19                        // initialization of the _fakeSource to enabled DragAndDrop :
20                        this._fakeSource = new dojox.mdnd.PureSource(dojo.create("div"), {
21                                'copyOnly': false
22                        });
23                        this._fakeSource.startup();
24                        dojo.addOnUnload(dojo.hitch(this, "destroy"));
25                        this.manager = dojo.dnd.manager();
26                },
27               
28                getItem: function(/*DOMNode*/draggedNode){
29                        //console.log("dojox.mdnd.LazyManager ::: getItem");
30                        var type = draggedNode.getAttribute("dndType");
31                        return {
32                                'data' : draggedNode.getAttribute("dndData") || draggedNode.innerHTML,
33                                'type' : type ? type.split(/\s*,\s*/) : ["text"]
34                        }
35                },
36               
37                startDrag: function(/*Event*/e, /*DOMNode?*/draggedNode){
38                        // summary:
39                        //              launch a dojo drag and drop on the fly.
40       
41                        //console.log("dojox.mdnd.LazyManager ::: startDrag");
42                        draggedNode = draggedNode || e.target;
43                        if(draggedNode){
44                                var m = this.manager,
45                                        object = this.getItem(draggedNode);
46                                if(draggedNode.id == ""){
47                                        dojo.attr(draggedNode, "id", dojo.dnd.getUniqueId());
48                                }
49                                dojo.addClass(draggedNode, "dojoDndItem");
50                                this._fakeSource.setItem(draggedNode.id, object);
51                                m.startDrag(this._fakeSource, [draggedNode], false);
52                                m.onMouseMove(e);
53                        }
54                },
55               
56                cancelDrag: function(){
57                        // summary:
58                        //              cancel a drag and drop dojo on the fly.
59       
60                        //console.log("dojox.mdnd.LazyManager ::: cancelDrag");
61                        var m = this.manager;
62                        m.target = null;
63                        m.onMouseUp();
64                },
65               
66               
67                destroy: function(){
68                        //console.log("dojox.mdnd.LazyManager ::: destroy");
69                        this._fakeSource.destroy();
70                }
71        });
72});
Note: See TracBrowser for help on using the repository browser.