//>>built
define("dijit/tree/_dndSelector","dojo/_base/array,dojo/_base/connect,dojo/_base/declare,dojo/_base/Deferred,dojo/_base/kernel,dojo/_base/lang,dojo/cookie,dojo/mouse,dojo/on,dojo/touch,./_dndContainer".split(","),function(e,i,k,o,l,d,j,m,f,g,n){return k("dijit.tree._dndSelector",n,{constructor:function(){this.selection={};this.anchor=null;if(!this.cookieName&&this.tree.id)this.cookieName=this.tree.id+"SaveSelectedCookie";this.events.push(f(this.tree.domNode,g.press,d.hitch(this,"onMouseDown")),f(this.tree.domNode,
g.release,d.hitch(this,"onMouseUp")),f(this.tree.domNode,g.move,d.hitch(this,"onMouseMove")))},singular:!1,getSelectedTreeNodes:function(){var a=[],b=this.selection,c;for(c in b)a.push(b[c]);return a},selectNone:function(){this.setSelection([]);return this},destroy:function(){this.inherited(arguments);this.selection=this.anchor=null},addTreeNode:function(a,b){this.setSelection(this.getSelectedTreeNodes().concat([a]));if(b)this.anchor=a;return a},removeTreeNode:function(a){this.setSelection(this._setDifference(this.getSelectedTreeNodes(),
[a]));return a},isTreeNodeSelected:function(a){return a.id&&!!this.selection[a.id]},setSelection:function(a){var b=this.getSelectedTreeNodes();e.forEach(this._setDifference(b,a),d.hitch(this,function(a){a.setSelected(!1);this.anchor==a&&delete this.anchor;delete this.selection[a.id]}));e.forEach(this._setDifference(a,b),d.hitch(this,function(a){a.setSelected(!0);this.selection[a.id]=a}));this._updateSelectionProperties()},_setDifference:function(a,b){e.forEach(b,function(a){a.__exclude__=!0});var c=
e.filter(a,function(a){return!a.__exclude__});e.forEach(b,function(a){delete a.__exclude__});return c},_updateSelectionProperties:function(){var a=this.getSelectedTreeNodes(),b=[],c=[],h=[];e.forEach(a,function(a){var d=a.getTreePath(),f=this.tree.model;c.push(a);b.push(d);d=e.map(d,function(a){return f.getIdentity(a)},this);h.push(d.join("/"))},this);a=e.map(c,function(a){return a.item});this.tree._set("paths",b);this.tree._set("path",b[0]||[]);this.tree._set("selectedNodes",c);this.tree._set("selectedNode",
c[0]||null);this.tree._set("selectedItems",a);this.tree._set("selectedItem",a[0]||null);this.tree.persist&&0<h.length&&j(this.cookieName,h.join(","),{expires:365})},_getSavedPaths:function(){var a=this.tree;if(a.persist&&a.dndController.cookieName){var b=[];(a=j(a.dndController.cookieName))&&(b=e.map(a.split(","),function(a){return a.split("/")}));return b}},onMouseDown:function(a){if(this.current&&!this.tree.isExpandoNode(a.target,this.current)){if("mousedown"==a.type&&m.isLeft(a))a.preventDefault();
else if("touchstart"!=a.type)return;var b=this.current,c=i.isCopyKey(a),d=b.id;!this.singular&&!a.shiftKey&&this.selection[d]?this._doDeselect=!0:(this._doDeselect=!1,this.userSelect(b,c,a.shiftKey))}},onMouseUp:function(a){if(this._doDeselect)this._doDeselect=!1,this.userSelect(this.current,i.isCopyKey(a),a.shiftKey)},onMouseMove:function(){this._doDeselect=!1},_compareNodes:function(a,b){if(a===b)return 0;if("sourceIndex"in document.documentElement)return a.sourceIndex-b.sourceIndex;if("compareDocumentPosition"in
document.documentElement)return a.compareDocumentPosition(b)&2?1:-1;if(document.createRange){var c=doc.createRange();c.setStartBefore(a);var d=doc.createRange();d.setStartBefore(b);return c.compareBoundaryPoints(c.END_TO_END,d)}throw Error("dijit.tree._compareNodes don't know how to compare two different nodes in this browser");},userSelect:function(a,b,c){if(this.singular)this.anchor==a&&b?this.selectNone():(this.setSelection([a]),this.anchor=a);else if(c&&this.anchor){c=this.anchor;0>this._compareNodes(this.anchor.rowNode,
a.rowNode)?b=c:(b=a,a=c);for(c=[];b!=a;)c.push(b),b=this.tree._getNextNode(b);c.push(a);this.setSelection(c)}else this.selection[a.id]&&b?this.removeTreeNode(a):b?this.addTreeNode(a,!0):(this.setSelection([a]),this.anchor=a)},getItem:function(a){return{data:this.selection[a],type:["treeNode"]}},forInSelectedItems:function(a,b){var b=b||l.global,c;for(c in this.selection)a.call(b,this.getItem(c),c,this)}})});