From 81bea17aefb26859f825b9293c7c99192874806e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 8 Nov 2011 20:40:44 +0400 Subject: upgrade Dojo to 1.6.1 --- lib/dijit/tree/_dndContainer.js | 216 ++++++++++++++++++++++++++++++++-------- 1 file changed, 177 insertions(+), 39 deletions(-) (limited to 'lib/dijit/tree/_dndContainer.js') diff --git a/lib/dijit/tree/_dndContainer.js b/lib/dijit/tree/_dndContainer.js index e925283df..9ee8e32ba 100644 --- a/lib/dijit/tree/_dndContainer.js +++ b/lib/dijit/tree/_dndContainer.js @@ -1,49 +1,187 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ -if(!dojo._hasResource["dijit.tree._dndContainer"]){ -dojo._hasResource["dijit.tree._dndContainer"]=true; +if(!dojo._hasResource["dijit.tree._dndContainer"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dijit.tree._dndContainer"] = true; dojo.provide("dijit.tree._dndContainer"); dojo.require("dojo.dnd.common"); dojo.require("dojo.dnd.Container"); -dojo.declare("dijit.tree._dndContainer",null,{constructor:function(_1,_2){ -this.tree=_1; -this.node=_1.domNode; -dojo.mixin(this,_2); -this.map={}; -this.current=null; -this.containerState=""; -dojo.addClass(this.node,"dojoDndContainer"); -this.events=[dojo.connect(this.node,"onmouseenter",this,"onOverEvent"),dojo.connect(this.node,"onmouseleave",this,"onOutEvent"),dojo.connect(this.tree,"_onNodeMouseEnter",this,"onMouseOver"),dojo.connect(this.tree,"_onNodeMouseLeave",this,"onMouseOut"),dojo.connect(this.node,"ondragstart",dojo,"stopEvent"),dojo.connect(this.node,"onselectstart",dojo,"stopEvent")]; -},getItem:function(_3){ -var _4=this.selection[_3],_5={data:dijit.getEnclosingWidget(_4),type:["treeNode"]}; -return _5; -},destroy:function(){ -dojo.forEach(this.events,dojo.disconnect); -this.node=this.parent=null; -},onMouseOver:function(_6,_7){ -this.current=_6.rowNode; -this.currentWidget=_6; -},onMouseOut:function(_8,_9){ -this.current=null; -this.currentWidget=null; -},_changeState:function(_a,_b){ -var _c="dojoDnd"+_a; -var _d=_a.toLowerCase()+"State"; -dojo.removeClass(this.node,_c+this[_d]); -dojo.addClass(this.node,_c+_b); -this[_d]=_b; -},_addItemClass:function(_e,_f){ -dojo.addClass(_e,"dojoDndItem"+_f); -},_removeItemClass:function(_10,_11){ -dojo.removeClass(_10,"dojoDndItem"+_11); -},onOverEvent:function(){ -this._changeState("Container","Over"); -},onOutEvent:function(){ -this._changeState("Container",""); -}}); + + +dojo.getObject("tree", true, dojo); + +dijit.tree._compareNodes = function(n1, n2){ + if(n1 === n2){ + return 0; + } + + if('sourceIndex' in document.documentElement){ //IE + //TODO: does not yet work if n1 and/or n2 is a text node + return n1.sourceIndex - n2.sourceIndex; + }else if('compareDocumentPosition' in document.documentElement){ //FF, Opera + return n1.compareDocumentPosition(n2) & 2 ? 1: -1; + }else if(document.createRange){ //Webkit + var r1 = doc.createRange(); + r1.setStartBefore(n1); + + var r2 = doc.createRange(); + r2.setStartBefore(n2); + + return r1.compareBoundaryPoints(r1.END_TO_END, r2); + }else{ + throw Error("dijit.tree._compareNodes don't know how to compare two different nodes in this browser"); + } +}; + +dojo.declare("dijit.tree._dndContainer", + null, + { + + // summary: + // This is a base class for `dijit.tree._dndSelector`, and isn't meant to be used directly. + // It's modeled after `dojo.dnd.Container`. + // tags: + // protected + + /*===== + // current: DomNode + // The currently hovered TreeNode.rowNode (which is the DOM node + // associated w/a given node in the tree, excluding it's descendants) + current: null, + =====*/ + + constructor: function(tree, params){ + // summary: + // A constructor of the Container + // tree: Node + // Node or node's id to build the container on + // params: dijit.tree.__SourceArgs + // A dict of parameters, which gets mixed into the object + // tags: + // private + this.tree = tree; + this.node = tree.domNode; // TODO: rename; it's not a TreeNode but the whole Tree + dojo.mixin(this, params); + + // class-specific variables + this.map = {}; + this.current = null; // current TreeNode's DOM node + + // states + this.containerState = ""; + dojo.addClass(this.node, "dojoDndContainer"); + + // set up events + this.events = [ + // container level events + dojo.connect(this.node, "onmouseenter", this, "onOverEvent"), + dojo.connect(this.node, "onmouseleave", this, "onOutEvent"), + + // switching between TreeNodes + dojo.connect(this.tree, "_onNodeMouseEnter", this, "onMouseOver"), + dojo.connect(this.tree, "_onNodeMouseLeave", this, "onMouseOut"), + + // cancel text selection and text dragging + dojo.connect(this.node, "ondragstart", dojo, "stopEvent"), + dojo.connect(this.node, "onselectstart", dojo, "stopEvent") + ]; + }, + + getItem: function(/*String*/ key){ + // summary: + // Returns the dojo.dnd.Item (representing a dragged node) by it's key (id). + // Called by dojo.dnd.Source.checkAcceptance(). + // tags: + // protected + + var widget = this.selection[key], + ret = { + data: widget, + type: ["treeNode"] + }; + + return ret; // dojo.dnd.Item + }, + + destroy: function(){ + // summary: + // Prepares this object to be garbage-collected + + dojo.forEach(this.events, dojo.disconnect); + // this.clearItems(); + this.node = this.parent = null; + }, + + // mouse events + onMouseOver: function(/*TreeNode*/ widget, /*Event*/ evt){ + // summary: + // Called when mouse is moved over a TreeNode + // tags: + // protected + this.current = widget; + }, + + onMouseOut: function(/*TreeNode*/ widget, /*Event*/ evt){ + // summary: + // Called when mouse is moved away from a TreeNode + // tags: + // protected + this.current = null; + }, + + _changeState: function(type, newState){ + // summary: + // Changes a named state to new state value + // type: String + // A name of the state to change + // newState: String + // new state + var prefix = "dojoDnd" + type; + var state = type.toLowerCase() + "State"; + //dojo.replaceClass(this.node, prefix + newState, prefix + this[state]); + dojo.replaceClass(this.node, prefix + newState, prefix + this[state]); + this[state] = newState; + }, + + _addItemClass: function(node, type){ + // summary: + // Adds a class with prefix "dojoDndItem" + // node: Node + // A node + // type: String + // A variable suffix for a class name + dojo.addClass(node, "dojoDndItem" + type); + }, + + _removeItemClass: function(node, type){ + // summary: + // Removes a class with prefix "dojoDndItem" + // node: Node + // A node + // type: String + // A variable suffix for a class name + dojo.removeClass(node, "dojoDndItem" + type); + }, + + onOverEvent: function(){ + // summary: + // This function is called once, when mouse is over our container + // tags: + // protected + this._changeState("Container", "Over"); + }, + + onOutEvent: function(){ + // summary: + // This function is called once, when mouse is out of our container + // tags: + // protected + this._changeState("Container", ""); + } +}); + } -- cgit v1.2.3