source: [view]
dojo.provide("dojox.dnd.Selector");
dojo.require("dojo.dnd.Selector");
dojo.declare(
"dojox.dnd.Selector",
dojo.dnd.Selector,
{
isSelected: function(node){
// summary:
// checks if node is selected
// node: String|DomNode:
// Node to check (id or DOM Node)
var id = dojo.isString(node) ? node : node.id,
item = this.getItem(id);
return item && this.selected[id]; // Boolean
},
selectNode: function(node, add){
// summary:
// selects a node
// node: String|DomNode:
// Node to select (id or DOM Node)
// add: Boolean?:
// If true, node is added to selection, otherwise current
// selection is removed, and node will be the only selection.
if(!add){
this.selectNone();
}
var id = dojo.isString(node) ? node : node.id,
item = this.getItem(id);
if(item){
this._removeAnchor();
this.anchor = dojo.byId(node);
this._addItemClass(this.anchor, "Anchor");
this.selection[id] = 1;
this._addItemClass(this.anchor, "Selected");
}
return this; // self
},
deselectNode: function(node){
// summary:
// deselects a node
// node: String|DomNode:
// Node to deselect (id or DOM Node)
var id = dojo.isString(node) ? node : node.id,
item = this.getItem(id);
if(item && this.selection[id]){
if(this.anchor === dojo.byId(node)){
this._removeAnchor();
}
delete this.selection[id];
this._removeItemClass(this.anchor, "Selected");
}
return this; // self
},
selectByBBox: function(left, top, right, bottom, add) {
// summary:
// selects nodes by bounding box
// left: Number:
// Left coordinate of the bounding box
// top: Number:
// Top coordinate of the bounding box
// right: Number:
// Right coordinate of the bounding box
// bottom: Number:
// Bottom coordinate of the bounding box
// add: Boolean?:
// If true, node is added to selection, otherwise current
// selection is removed, and node will be the only selection.
// user has drawn a bounding box ... time to see whether any dom nodes
// in this container satisfy the bounding box range.
if(!add){
this.selectNone();
}
this.forInItems(function(data, id){
var node = dojo.byId(id);
if(node && this._isBoundedByBox(node, left, top, right, bottom)){
this.selectNode(id, true);
}
}, this);
return this; // self