dojox/dnd/Selector.js

  • Provides:

    • dojox.dnd.Selector
  • Requires:

    • dojo.dnd.Selector in common in project dojo
  • dojox.dnd.Selector

    • type
      Function
    • chains:
      • dojo.dnd.Selector: (prototype)
      • dojo.dnd.Selector: (call)
    • summary
  • dojox.dnd.Selector.isSelected

    • type
      Function
    • parameters:
      • node: (typeof String|DomNode)
        Node to check (id or DOM Node)
    • source: [view]
         var id = dojo.isString(node) ? node : node.id,
          item = this.getItem(id);
         return item && this.selected[id]; // Boolean
    • summary
      checks if node is selected
    • returns
      Boolean
  • dojox.dnd.Selector.selectNode

    • type
      Function
    • parameters:
      • node: (typeof String|DomNode)
        Node to select (id or DOM Node)
      • add: (typeof Boolean)
        If true, node is added to selection, otherwise current
        selection is removed, and node will be the only selection.
    • source: [view]
         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
    • summary
      selects a node
    • returns
      self
  • dojox.dnd.Selector.deselectNode

    • type
      Function
    • parameters:
      • node: (typeof String|DomNode)
        Node to deselect (id or DOM Node)
    • source: [view]
         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
    • summary
      deselects a node
    • returns
      self
  • dojox.dnd.Selector.selectByBBox

    • type
      Function
    • parameters:
      • left: (typeof Number)
        Left coordinate of the bounding box
      • top: (typeof Number)
        Top coordinate of the bounding box
      • right: (typeof Number)
        Right coordinate of the bounding box
      • bottom: (typeof Number)
        Bottom coordinate of the bounding box
      • add: (typeof )
    • 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
    • summary
      selects nodes by bounding box
    • returns
      Boolean|self
  • dojox.dnd.Selector._isBoundedByBox

    • type
      Function
    • parameters:
      • node: (typeof String|DomNode)
        Node to check (id or DOM Node)
      • left: (typeof Number)
        Left coordinate of the bounding box
      • top: (typeof Number)
        Top coordinate of the bounding box
      • right: (typeof Number)
        Right coordinate of the bounding box
      • bottom: (typeof Number)
        Bottom coordinate of the bounding box
    • source: [view]
         var c = dojo.coords(node), t;
         // normalize input
         if(left > right){
          t = left;
          left = right;
          right = t;
         }
         if(top > bottom){
          t = top;
          top = bottom;
          bottom = t;
         }
         return c.x >= left && c.x + c.w <= right && c.y >= top && c.y + c.h <= bottom; // Boolean
    • summary
      figures out whether certain coodinates bound a particular
      dom node.
    • returns
      Boolean
  • dojox.dnd.Selector.shift

    • type
      Function
    • parameters:
      • toNext: (typeof Boolean)
        If true, we select the next node, otherwise the previous one.
      • add: (typeof Boolean)
        If true, add to selection, otherwise current selection is
        removed before adding any nodes.
    • source: [view]
         var selectedNodes = this.getSelectedNodes();
         if(selectedNodes && selectedNodes.length) {
          // only delegate to selectNode if at least one node is selected.
          // If multiple nodes are selected assume that we go with
          // the last selected node.
          this.selectNode(this._getNodeId(selectedNodes[selectedNodes.length - 1].id, toNext), add);
         }
    • summary
      shifts the currently selected dnd item forwards and backwards.
      One possible use would be to allow a user select different
      dnd items using the right and left keys.
  • dojox.dnd.Selector._getNodeId

    • type
      Function
    • parameters:
      • nodeId: (typeof String)
        the id of the node to use as the base node
      • toNext: (typeof Boolean)
        If true, we select the next node, otherwise the previous one.
    • source: [view]
         var allNodes = this.getAllNodes(), newId = nodeId;
         for(var i = 0, l = allNodes.length; i < l; ++i) {
          if(allNodes[i].id == nodeId) {
           // have a match ... make sure we don't go outside
           var j = Math.min(l - 1, Math.max(0, i + (toNext ? 1 : -1)));
           if(i != j){
            // we should be fine to go with the id the user has requested.
            newId = allNodes[j].id;
           }
           break;
          }
         }
         // if we don't get a match, the newId defaults to the currently selected node
         return newId;
    • summary
      finds a next/previous node in relation to nodeId
  • dojox.dnd.Selector.anchor

    • summary
  • dojox.dnd

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary