diff options
author | Andrew Dolgov <[email protected]> | 2012-08-14 18:59:10 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-08-14 18:59:18 +0400 |
commit | 1354d17270961fff662d40f90521223f8fd0d73b (patch) | |
tree | e9266be71587e47c800303446e968a6d3565e2cf /lib/dojo/dnd/Manager.js | |
parent | d04f8c826f5283765f52cf6b98b42a1ed8f2d6bc (diff) |
update dojo to 1.7.3
Diffstat (limited to 'lib/dojo/dnd/Manager.js')
-rw-r--r-- | lib/dojo/dnd/Manager.js | 216 |
1 files changed, 2 insertions, 214 deletions
diff --git a/lib/dojo/dnd/Manager.js b/lib/dojo/dnd/Manager.js index 38611fbd4..079dffa19 100644 --- a/lib/dojo/dnd/Manager.js +++ b/lib/dojo/dnd/Manager.js @@ -4,217 +4,5 @@ see: http://dojotoolkit.org/license for details */ - -if(!dojo._hasResource["dojo.dnd.Manager"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dojo.dnd.Manager"] = true; -dojo.provide("dojo.dnd.Manager"); -dojo.require("dojo.dnd.common"); -dojo.require("dojo.dnd.autoscroll"); -dojo.require("dojo.dnd.Avatar"); - - -dojo.declare("dojo.dnd.Manager", null, { - // summary: - // the manager of DnD operations (usually a singleton) - constructor: function(){ - this.avatar = null; - this.source = null; - this.nodes = []; - this.copy = true; - this.target = null; - this.canDropFlag = false; - this.events = []; - }, - - // avatar's offset from the mouse - OFFSET_X: 16, - OFFSET_Y: 16, - - // methods - overSource: function(source){ - // summary: - // called when a source detected a mouse-over condition - // source: Object - // the reporter - if(this.avatar){ - this.target = (source && source.targetState != "Disabled") ? source : null; - this.canDropFlag = Boolean(this.target); - this.avatar.update(); - } - dojo.publish("/dnd/source/over", [source]); - }, - outSource: function(source){ - // summary: - // called when a source detected a mouse-out condition - // source: Object - // the reporter - if(this.avatar){ - if(this.target == source){ - this.target = null; - this.canDropFlag = false; - this.avatar.update(); - dojo.publish("/dnd/source/over", [null]); - } - }else{ - dojo.publish("/dnd/source/over", [null]); - } - }, - startDrag: function(source, nodes, copy){ - // summary: - // called to initiate the DnD operation - // source: Object - // the source which provides items - // nodes: Array - // the list of transferred items - // copy: Boolean - // copy items, if true, move items otherwise - this.source = source; - this.nodes = nodes; - this.copy = Boolean(copy); // normalizing to true boolean - this.avatar = this.makeAvatar(); - dojo.body().appendChild(this.avatar.node); - dojo.publish("/dnd/start", [source, nodes, this.copy]); - this.events = [ - dojo.connect(dojo.doc, "onmousemove", this, "onMouseMove"), - dojo.connect(dojo.doc, "onmouseup", this, "onMouseUp"), - dojo.connect(dojo.doc, "onkeydown", this, "onKeyDown"), - dojo.connect(dojo.doc, "onkeyup", this, "onKeyUp"), - // cancel text selection and text dragging - dojo.connect(dojo.doc, "ondragstart", dojo.stopEvent), - dojo.connect(dojo.body(), "onselectstart", dojo.stopEvent) - ]; - var c = "dojoDnd" + (copy ? "Copy" : "Move"); - dojo.addClass(dojo.body(), c); - }, - canDrop: function(flag){ - // summary: - // called to notify if the current target can accept items - var canDropFlag = Boolean(this.target && flag); - if(this.canDropFlag != canDropFlag){ - this.canDropFlag = canDropFlag; - this.avatar.update(); - } - }, - stopDrag: function(){ - // summary: - // stop the DnD in progress - dojo.removeClass(dojo.body(), ["dojoDndCopy", "dojoDndMove"]); - dojo.forEach(this.events, dojo.disconnect); - this.events = []; - this.avatar.destroy(); - this.avatar = null; - this.source = this.target = null; - this.nodes = []; - }, - makeAvatar: function(){ - // summary: - // makes the avatar; it is separate to be overwritten dynamically, if needed - return new dojo.dnd.Avatar(this); - }, - updateAvatar: function(){ - // summary: - // updates the avatar; it is separate to be overwritten dynamically, if needed - this.avatar.update(); - }, - - // mouse event processors - onMouseMove: function(e){ - // summary: - // event processor for onmousemove - // e: Event - // mouse event - var a = this.avatar; - if(a){ - dojo.dnd.autoScrollNodes(e); - //dojo.dnd.autoScroll(e); - var s = a.node.style; - s.left = (e.pageX + this.OFFSET_X) + "px"; - s.top = (e.pageY + this.OFFSET_Y) + "px"; - var copy = Boolean(this.source.copyState(dojo.isCopyKey(e))); - if(this.copy != copy){ - this._setCopyStatus(copy); - } - } - }, - onMouseUp: function(e){ - // summary: - // event processor for onmouseup - // e: Event - // mouse event - if(this.avatar){ - if(this.target && this.canDropFlag){ - var copy = Boolean(this.source.copyState(dojo.isCopyKey(e))), - params = [this.source, this.nodes, copy, this.target, e]; - dojo.publish("/dnd/drop/before", params); - dojo.publish("/dnd/drop", params); - }else{ - dojo.publish("/dnd/cancel"); - } - this.stopDrag(); - } - }, - - // keyboard event processors - onKeyDown: function(e){ - // summary: - // event processor for onkeydown: - // watching for CTRL for copy/move status, watching for ESCAPE to cancel the drag - // e: Event - // keyboard event - if(this.avatar){ - switch(e.keyCode){ - case dojo.keys.CTRL: - var copy = Boolean(this.source.copyState(true)); - if(this.copy != copy){ - this._setCopyStatus(copy); - } - break; - case dojo.keys.ESCAPE: - dojo.publish("/dnd/cancel"); - this.stopDrag(); - break; - } - } - }, - onKeyUp: function(e){ - // summary: - // event processor for onkeyup, watching for CTRL for copy/move status - // e: Event - // keyboard event - if(this.avatar && e.keyCode == dojo.keys.CTRL){ - var copy = Boolean(this.source.copyState(false)); - if(this.copy != copy){ - this._setCopyStatus(copy); - } - } - }, - - // utilities - _setCopyStatus: function(copy){ - // summary: - // changes the copy status - // copy: Boolean - // the copy status - this.copy = copy; - this.source._markDndStatus(this.copy); - this.updateAvatar(); - dojo.replaceClass(dojo.body(), - "dojoDnd" + (this.copy ? "Copy" : "Move"), - "dojoDnd" + (this.copy ? "Move" : "Copy")); - } -}); - -// dojo.dnd._manager: -// The manager singleton variable. Can be overwritten if needed. -dojo.dnd._manager = null; - -dojo.dnd.manager = function(){ - // summary: - // Returns the current DnD manager. Creates one if it is not created yet. - if(!dojo.dnd._manager){ - dojo.dnd._manager = new dojo.dnd.Manager(); - } - return dojo.dnd._manager; // Object -}; - -} +//>>built +define("dojo/dnd/Manager",["../main","../Evented","./common","./autoscroll","./Avatar"],function(_1,_2){var _3=_1.declare("dojo.dnd.Manager",[_2],{constructor:function(){this.avatar=null;this.source=null;this.nodes=[];this.copy=true;this.target=null;this.canDropFlag=false;this.events=[];},OFFSET_X:16,OFFSET_Y:16,overSource:function(_4){if(this.avatar){this.target=(_4&&_4.targetState!="Disabled")?_4:null;this.canDropFlag=Boolean(this.target);this.avatar.update();}_1.publish("/dnd/source/over",[_4]);},outSource:function(_5){if(this.avatar){if(this.target==_5){this.target=null;this.canDropFlag=false;this.avatar.update();_1.publish("/dnd/source/over",[null]);}}else{_1.publish("/dnd/source/over",[null]);}},startDrag:function(_6,_7,_8){this.source=_6;this.nodes=_7;this.copy=Boolean(_8);this.avatar=this.makeAvatar();_1.body().appendChild(this.avatar.node);_1.publish("/dnd/start",[_6,_7,this.copy]);this.events=[_1.connect(_1.doc,"onmousemove",this,"onMouseMove"),_1.connect(_1.doc,"onmouseup",this,"onMouseUp"),_1.connect(_1.doc,"onkeydown",this,"onKeyDown"),_1.connect(_1.doc,"onkeyup",this,"onKeyUp"),_1.connect(_1.doc,"ondragstart",_1.stopEvent),_1.connect(_1.body(),"onselectstart",_1.stopEvent)];var c="dojoDnd"+(_8?"Copy":"Move");_1.addClass(_1.body(),c);},canDrop:function(_9){var _a=Boolean(this.target&&_9);if(this.canDropFlag!=_a){this.canDropFlag=_a;this.avatar.update();}},stopDrag:function(){_1.removeClass(_1.body(),["dojoDndCopy","dojoDndMove"]);_1.forEach(this.events,_1.disconnect);this.events=[];this.avatar.destroy();this.avatar=null;this.source=this.target=null;this.nodes=[];},makeAvatar:function(){return new _1.dnd.Avatar(this);},updateAvatar:function(){this.avatar.update();},onMouseMove:function(e){var a=this.avatar;if(a){_1.dnd.autoScrollNodes(e);var s=a.node.style;s.left=(e.pageX+this.OFFSET_X)+"px";s.top=(e.pageY+this.OFFSET_Y)+"px";var _b=Boolean(this.source.copyState(_1.isCopyKey(e)));if(this.copy!=_b){this._setCopyStatus(_b);}}},onMouseUp:function(e){if(this.avatar){if(this.target&&this.canDropFlag){var _c=Boolean(this.source.copyState(_1.isCopyKey(e))),_d=[this.source,this.nodes,_c,this.target,e];_1.publish("/dnd/drop/before",_d);_1.publish("/dnd/drop",_d);}else{_1.publish("/dnd/cancel");}this.stopDrag();}},onKeyDown:function(e){if(this.avatar){switch(e.keyCode){case _1.keys.CTRL:var _e=Boolean(this.source.copyState(true));if(this.copy!=_e){this._setCopyStatus(_e);}break;case _1.keys.ESCAPE:_1.publish("/dnd/cancel");this.stopDrag();break;}}},onKeyUp:function(e){if(this.avatar&&e.keyCode==_1.keys.CTRL){var _f=Boolean(this.source.copyState(false));if(this.copy!=_f){this._setCopyStatus(_f);}}},_setCopyStatus:function(_10){this.copy=_10;this.source._markDndStatus(this.copy);this.updateAvatar();_1.replaceClass(_1.body(),"dojoDnd"+(this.copy?"Copy":"Move"),"dojoDnd"+(this.copy?"Move":"Copy"));}});_1.dnd._manager=null;_3.manager=_1.dnd.manager=function(){if(!_1.dnd._manager){_1.dnd._manager=new _1.dnd.Manager();}return _1.dnd._manager;};return _3;});
\ No newline at end of file |