2
Copyright (c) 2004-2006, The Dojo Foundation
5
Licensed under the Academic Free License version 2.1 or above OR the
6
modified BSD license. For more information on Dojo licensing, see:
8
http://dojotoolkit.org/community/licensing.shtml
11
dojo.require("dojo.lang.common");
12
dojo.require("dojo.lang.declare");
13
dojo.provide("dojo.dnd.DragAndDrop");
15
dojo.declare("dojo.dnd.DragSource", null, {
18
onDragEnd: function(){
21
onDragStart: function(){
25
* This function gets called when the DOM element was
26
* selected for dragging by the HtmlDragAndDropManager.
28
onSelected: function(){
31
unregister: function(){
32
dojo.dnd.dragManager.unregisterDragSource(this);
35
reregister: function(){
36
dojo.dnd.dragManager.registerDragSource(this);
40
//dojo.profile.start("DragSource");
42
var dm = dojo.dnd.dragManager;
43
if(dm["registerDragSource"]){ // side-effect prevention
44
dm.registerDragSource(this);
47
//dojo.profile.end("DragSource");
51
dojo.declare("dojo.dnd.DragObject", null, {
54
onDragStart: function(){
55
// gets called directly after being created by the DragSource
56
// default action is to clone self as icon
59
onDragMove: function(){
60
// this changes the UI for the drag icon
64
onDragOver: function(){
67
onDragOut: function(){
70
onDragEnd: function(){
74
onDragLeave: this.onDragOut,
75
onDragEnter: this.onDragOver,
78
ondragout: this.onDragOut,
79
ondragover: this.onDragOver
81
var dm = dojo.dnd.dragManager;
82
if(dm["registerDragObject"]){ // side-effect prevention
83
dm.registerDragObject(this);
87
dojo.declare("dojo.dnd.DropTarget", null, {
89
acceptsType: function(type){
90
if(!dojo.lang.inArray(this.acceptedTypes, "*")){ // wildcard
91
if(!dojo.lang.inArray(this.acceptedTypes, type)) { return false; }
96
accepts: function(dragObjects){
97
if(!dojo.lang.inArray(this.acceptedTypes, "*")){ // wildcard
98
for (var i = 0; i < dragObjects.length; i++) {
99
if (!dojo.lang.inArray(this.acceptedTypes,
100
dragObjects[i].type)) { return false; }
106
unregister: function(){
107
dojo.dnd.dragManager.unregisterDropTarget(this);
110
onDragOver: function(){
113
onDragOut: function(){
116
onDragMove: function(){
119
onDropStart: function(){
125
onDropEnd: function(){
128
if (this.constructor == dojo.dnd.DropTarget) { return; } // need to be subclassed
129
this.acceptedTypes = [];
130
dojo.dnd.dragManager.registerDropTarget(this);
133
// NOTE: this interface is defined here for the convenience of the DragManager
134
// implementor. It is expected that in most cases it will be satisfied by
135
// extending a native event (DOM event in HTML and SVG).
136
dojo.dnd.DragEvent = function(){
137
this.dragSource = null;
138
this.dragObject = null;
140
this.eventStatus = "success";
143
// [ "dropSuccess", "dropFailure", "dragMove",
144
// "dragStart", "dragEnter", "dragLeave"]
148
* The DragManager handles listening for low-level events and dispatching
149
* them to higher-level primitives like drag sources and drop targets. In
150
* order to do this, it must keep a list of the items.
152
dojo.declare("dojo.dnd.DragManager", null, {
156
registerDragSource: function(){},
158
registerDropTarget: function(){},
159
lastDragTarget: null,
160
currentDragTarget: null,
161
onKeyDown: function(){},
162
onMouseOut: function(){},
163
onMouseMove: function(){},
164
onMouseUp: function(){}
167
// NOTE: despite the existance of the DragManager class, there will be a
168
// singleton drag manager provided by the renderer-specific D&D support code.
169
// It is therefore sane for us to assign instance variables to the DragManager
172
// The renderer-specific file will define the following object:
173
// dojo.dnd.dragManager = null;