Commit 319a0b49 authored by Eugene Lazutkin's avatar Eugene Lazutkin

General cleanup and a typo fix. Thx, Scott. Fixes #3229.

git-svn-id: http://svn.dojotoolkit.org/src/dojo/trunk@9357 560b804f-0ae3-0310-86f3-f6aa0a117693
parent 890f68fd
......@@ -14,6 +14,15 @@ if(navigator.appVersion.indexOf("Macintosh") < 0){
};
}
dojo.dnd._copyKey = navigator.appVersion.indexOf("Macintosh") < 0 ? "ctrlKey" : "metaKey";
dojo.dnd.getCopyKeyState = function(e) {
// summary: abstracts away the difference between selection on Mac and PC,
// and returns the state of the "copy" key to be pressed.
// e: Event: mouse event
return e[dojo.dnd._copyKey]; // Boolean
};
dojo.dnd._uniqueId = 0;
dojo.dnd.getUniqueId = function(){
// summary: returns a unique string for use with any DOM element
......
......@@ -49,7 +49,7 @@ dojo.extend(dojo.dnd.Manager, {
// copy: Boolean: copy items, if true, move items otherwise
this.source = source;
this.nodes = nodes;
this.copy = copy && true || false; // normalizing to true boolean
this.copy = Boolean(copy); // normalizing to true boolean
this.avatar = this.makeAvatar();
dojo.body().appendChild(this.avatar.node);
dojo.publish("dndStart", [source, nodes, this.copy]);
......@@ -96,7 +96,7 @@ dojo.extend(dojo.dnd.Manager, {
var a = this.avatar;
if(a){
dojo.marginBox(a.node, {l: e.pageX + this.OFFSET_X, t: e.pageY + this.OFFSET_Y});
var copy = this.source.copyState(dojo.dnd.multiSelectKey(e)) && true || false;
var copy = Boolean(this.source.copyState(dojo.dnd.getCopyKeyState(e)));
if(this.copy != copy){
this._setCopyStatus(copy);
}
......@@ -107,7 +107,7 @@ dojo.extend(dojo.dnd.Manager, {
// e: Event: mouse event
if(this.avatar){
if(this.target && this.canDropFlag){
dojo.publish("dndDrop", [this.source, this.nodes, this.source.copyState(dojo.dnd.multiSelectKey(e)) && true || false]);
dojo.publish("dndDrop", [this.source, this.nodes, Boolean(this.source.copyState(dojo.dnd.getCopyKeyState(e)))]);
}else{
dojo.publish("dndCancel");
}
......@@ -122,7 +122,7 @@ dojo.extend(dojo.dnd.Manager, {
if(this.avatar){
switch(e.keyCode){
case dojo.keys.CTRL:
var copy = this.source.copyState(true) && true || false;
var copy = Boolean(this.source.copyState(true));
if(this.copy != copy){
this._setCopyStatus(copy);
}
......@@ -138,7 +138,7 @@ dojo.extend(dojo.dnd.Manager, {
// 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 = this.source.copyState(true) && true || false;
var copy = Boolean(this.source.copyState(false));
if(this.copy != copy){
this._setCopyStatus(copy);
}
......
......@@ -34,13 +34,13 @@ function(node, params){
// summary: event processor for onmousedown
// e: Event: mouse event
if(!this.current){ return; }
if(!this.singular && !dojo.dnd.multiSelectKey(e) && !e.shiftKey && (this.current.id in this.selection)){
if(!this.singular && !dojo.dnd.getCopyKeyState(e) && !e.shiftKey && (this.current.id in this.selection)){
this.simpleSelection = true;
dojo.stopEvent(e);
return;
}
if(!this.singular && e.shiftKey){
if(!dojo.dnd.multiSelectKey(e)){
if(!dojo.dnd.getCopyKeyState(e)){
var empty = {};
for(var i in this.selection){
if(!(i in empty)){
......@@ -81,7 +81,7 @@ function(node, params){
}else{
if(this.singular){
if(this.anchor == this.current){
if(dojo.dnd.multiSelectKey(e)){
if(dojo.dnd.getCopyKeyState(e)){
this._removeItemClass(this.anchor, "Anchor");
this.anchor = null;
this.selection = {};
......@@ -96,7 +96,7 @@ function(node, params){
this.selection[this.current.id] = 1;
}
}else{
if(dojo.dnd.multiSelectKey(e)){
if(dojo.dnd.getCopyKeyState(e)){
if(this.anchor == this.current){
this._removeItemClass(this.anchor, "Anchor");
delete this.selection[this.anchor.id];
......
......@@ -101,7 +101,7 @@ function(node, params){
if(this.mouseDown && this.isSource){
var nodes = this.getSelectedNodes();
if(nodes.length){
m.startDrag(this, nodes, this.copyState(dojo.dnd.multiSelectKey(e)));
m.startDrag(this, nodes, this.copyState(dojo.dnd.getCopyKeyState(e)));
}
}
}
......@@ -234,7 +234,7 @@ function(node, params){
copyState: function(keyPressed){
// summary: Returns true, if we need to copy items, false to move.
// It is separate to be overwritten dynamically, if needed.
// keyPressed: Boolean: the "multiSelectKey" was pressed
// keyPressed: Boolean: the "copy" was pressed
return this.copyOnly || keyPressed; // Boolean
},
_markTargetAnchor: function(before){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment