123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- if(!dojo._hasResource["dojox.mdnd.dropMode.DefaultDropMode"]){
- dojo._hasResource["dojox.mdnd.dropMode.DefaultDropMode"] = true;
- dojo.provide("dojox.mdnd.dropMode.DefaultDropMode");
- dojo.require("dojox.mdnd.AreaManager");
- dojo.declare("dojox.mdnd.dropMode.DefaultDropMode", null, {
-
-
-
-
-
- _oldXPoint: null,
-
-
- _oldYPoint: null,
-
-
- _oldBehaviour: "up",
- addArea: function(/*Array*/areas, /*Object*/object){
-
-
-
-
-
-
-
-
-
- var length = areas.length;
- var position = dojo.position(object.node, true);
- object.coords = {'x':position.x, 'y':position.y};
- if (length == 0) {
- areas.push(object);
- }else{
- var x = object.coords.x;
- for (var i = 0; i < length; i++) {
- if (x < areas[i].coords.x) {
- for (var j = length-1; j >= i; j--)
- areas[j + 1] = areas[j];
- areas[i] = object;
- break;
- }
- }
- if (i == length)
- areas.push(object);
- }
- return areas;
- },
- updateAreas: function(/*Array*/areaList){
-
-
-
-
-
-
-
-
-
-
- var length = areaList.length;
- if (length > 1){
- var currentRight, nextLeft;
- for (var i = 0; i < length; i++) {
- var area = areaList[i];
- var nextArea;
- area.coords.x1 = -1;
- area.coords.x2 = -1;
- if (i == 0) {
- nextArea = areaList[i+1];
- this._updateArea(area);
- this._updateArea(nextArea);
- currentRight = area.coords.x + area.node.offsetWidth;
- nextLeft = nextArea.coords.x;
- area.coords.x2 = currentRight + (nextLeft-currentRight)/2;
- }
- else if (i == length-1) {
- area.coords.x1 = areaList[i-1].coords.x2;
- }else{
- nextArea = areaList[i+1];
- this._updateArea(nextArea);
- currentRight = area.coords.x + area.node.offsetWidth;
- nextLeft = nextArea.coords.x;
- area.coords.x1 = areaList[i-1].coords.x2;
- area.coords.x2 = currentRight + (nextLeft-currentRight)/2;
- }
- }
- }
- },
- _updateArea : function(/*Object*/area){
-
-
-
-
-
-
-
- var position = dojo.position(area.node, true);
- area.coords.x = position.x;
- area.coords.y = position.y;
- },
- initItems: function(/*Object*/area){
-
-
-
-
-
- dojo.forEach(area.items, function(obj){
-
- var node = obj.item.node;
- var position = dojo.position(node, true);
- var y = position.y + position.h/2;
- obj.y = y;
- });
- area.initItems = true;
- },
- refreshItems: function(/*Object*/area, /*Integer*/indexItem, /*Object*/size, /*Boolean*/added){
-
-
-
-
-
-
-
-
-
-
-
- if (indexItem == -1) {
- return;
- }else if(area && size && size.h){
- var height = size.h;
- if (area.margin){
- height += area.margin.t;
- }
- var length = area.items.length;
- for (var i=indexItem; i<length; i++){
- var item = area.items[i];
- if (added) {
- item.y += height;
- }else{
- item.y -= height;
- }
- }
- }
- },
- getDragPoint: function(/*Object*/coords, /*Object*/size, /*Object*/mousePosition){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var y = coords.y;
- if (this._oldYPoint){
- if (y > this._oldYPoint) {
- this._oldBehaviour = "down";
- y += size.h;
- }
- else
- if (y <= this._oldYPoint) {
- this._oldBehaviour = "up";
- }
- }
- this._oldYPoint = y;
- return {
- 'x': coords.x + (size.w / 2),
- 'y': y
- };
- },
- getTargetArea: function(/*Array*/areaList, /*Object*/ coords, /*integer*/currentIndexArea ){
-
-
-
-
-
-
-
-
-
-
-
-
- var index = 0;
- var x = coords.x;
- var end = areaList.length;
- if (end > 1) {
- var start = 0, direction = "right", compute = false;
- if (currentIndexArea == -1 || arguments.length<3) {
-
- compute = true;
- }
- else {
-
- if (this._checkInterval(areaList, currentIndexArea, x)){
- index = currentIndexArea;
- }else{
- if (this._oldXPoint < x){
- start = currentIndexArea + 1;
- }else{
- start = currentIndexArea - 1;
- end = 0;
- direction = "left";
- }
- compute = true;
- }
- }
- if (compute) {
- if (direction === "right") {
- for (var i = start; i < end; i++) {
- if (this._checkInterval(areaList, i, x)) {
- index = i;
- break;
- }
- }
- }else{
- for (var i = start; i >= end; i--) {
- if (this._checkInterval(areaList, i, x)) {
- index = i;
- break;
- }
- }
- }
- }
- }
- this._oldXPoint = x;
- return index;
- },
- _checkInterval: function(/*Array*/areaList, /*Integer*/index, /*Coord*/x){
-
-
-
-
-
-
-
-
-
-
-
-
-
- var coords = areaList[index].coords;
- if (coords.x1 == -1) {
- if (x <= coords.x2) {
- return true;
- }
- }
- else
- if (coords.x2 == -1) {
- if (x > coords.x1) {
- return true;
- }
- }
- else {
- if (coords.x1 < x && x <= coords.x2) {
- return true;
- }
- }
- return false;
- },
- getDropIndex: function(/*Object*/ targetArea, /*Object*/ coords){
-
-
-
-
-
-
-
-
-
-
- var length = targetArea.items.length;
- var coordinates = targetArea.coords;
- var y = coords.y;
- if (length > 0) {
-
- for (var i = 0; i < length; i++) {
-
- if (y < targetArea.items[i].y) {
- return i;
- }
- else {
- if (i == length-1) {
- return -1;
- }
- }
- }
- }
- return -1;
- },
- destroy: function(){
-
- }
- });
- (function(){
- dojox.mdnd.areaManager()._dropMode = new dojox.mdnd.dropMode.DefaultDropMode();
- }());
- }
|