Comparing sensitive data, confidential files or internal emails?

Most legal and privacy policies prohibit uploading sensitive data online. Diffchecker Desktop ensures your confidential information never leaves your computer. Work offline and compare documents securely.

drag diff

Created Diff never expires
15 removals
651 lines
34 additions
670 lines
zim.drag = function(obj, boundary, axis, overCursor, dragCursor, all, swipe, localBoundary, onTop, surround, slide, slideFactor, slideSnap, slideSnapDamp, reg, removeTweens, startBounds, rect, currentTarget, offStage, immediateBoundary, singleTouch) {
zim.drag = function(obj, boundary, axis, overCursor, dragCursor, all, swipe, localBoundary, onTop, surround, slide, slideFactor, slideSnap, slideSnapDamp, reg, removeTweens, startBounds, rect, currentTarget, offStage, immediateBoundary, singleTouch) {
var sig = "obj, boundary, axis, overCursor, dragCursor, all, swipe, localBoundary, onTop, surround, slide, slideFactor, slideSnap, slideSnapDamp, reg, removeTweens, startBounds, rect, currentTarget, offStage, immediateBoundary, singleTouch";
var sig = "obj, boundary, axis, overCursor, dragCursor, all, swipe, localBoundary, onTop, surround, slide, slideFactor, slideSnap, slideSnapDamp, reg, removeTweens, startBounds, rect, currentTarget, offStage, immediateBoundary, singleTouch";
var duo; if (duo = zob(zim.drag, arguments, sig)) return duo;
var duo; if (duo = zob(zim.drag, arguments, sig)) return duo;
z_d("31");
z_d("31");


if (zot(obj) || !obj.on) return;
if (zot(obj) || !obj.on) return;


var DA = zim.DRAGALL;
var DA = zim.DRAGALL;
if (WW.DRAGALL != null) DA = WW.DRAGALL;
if (WW.DRAGALL != null) DA = WW.DRAGALL;
if (zot(all) && zot(currentTarget)) all = DA;
if (zot(all) && zot(currentTarget)) all = DA;
if (zot(all) && zot(currentTarget)) currentTarget = false;
if (zot(all) && zot(currentTarget)) currentTarget = false;
else if (!zot(all)) currentTarget = all;
else if (!zot(all)) currentTarget = all;
else if (zot(currentTarget)) currentTarget = false;
else if (zot(currentTarget)) currentTarget = false;
if (obj.type == "Tag" || obj.type == "TextArea" || obj.type == "Loader") currentTarget = true;
if (obj.type == "Tag" || obj.type == "TextArea" || obj.type == "Loader") currentTarget = true;


if (boundary && boundary.getBounds && (obj.type=="Container" || obj.type=="Tile") && obj.mouseChildren==true && !all) {
if (boundary && boundary.getBounds && (obj.type=="Container" || obj.type=="Tile") && obj.mouseChildren==true && !all) {
// recall drags individually on objects
// recall drags individually on objects
var args = Array.prototype.slice.call(arguments);
var args = Array.prototype.slice.call(arguments);
args[4] = true; // all
args[4] = true; // all
setTimeout(function () {
setTimeout(function () {
obj.loop(function (o) {
obj.loop(function (o) {
args[0] = o; // replace container with each child
args[0] = o; // replace container with each child
zim.drag.apply(null, args);
zim.drag.apply(null, args);
});
});
}, immediateBoundary?0:50);
}, immediateBoundary?0:50);
return obj;
return obj;
}
}
if (zot(axis) || axis=="all" || (axis!="horizontal" && axis!="vertical")) axis = "both";
if (zot(axis) || axis=="all" || (axis!="horizontal" && axis!="vertical")) axis = "both";
if (obj.zimDown) obj.noDrag(); // clear any previous drags
if (obj.zimDown) obj.noDrag(); // clear any previous drags

if (obj.cur) obj.cur(zot(overCursor) ? "pointer" : overCursor);
if (obj.cur) obj.cur(zot(overCursor) ? "pointer" : overCursor);
else obj.cursor = zot(overCursor) ? "pointer" : overCursor;
else obj.cursor = zot(overCursor) ? "pointer" : overCursor;

if (zot(swipe)) swipe = false;
if (zot(swipe)) swipe = false;
if (zot(localBoundary)) localBoundary = false;
if (zot(localBoundary)) localBoundary = false;
if (zot(onTop)) onTop = true;
if (zot(onTop)) onTop = true;
if (zot(surround)) surround = false;
if (zot(surround)) surround = false;
if (zot(slide)) slide = false;
if (zot(slide)) slide = false;
if (zot(slideFactor)) slideFactor = .9;
if (zot(slideFactor)) slideFactor = .9;
if (zot(slideSnap)) slideSnap = true;
if (zot(slideSnap)) slideSnap = true;
var snapOptions = ["horizontal", "vertical", "auto"];
var snapOptions = ["horizontal", "vertical", "auto"];
if (slideSnap !== true && snapOptions.indexOf(slideSnap) < 0) slideSnap = false;
if (slideSnap !== true && snapOptions.indexOf(slideSnap) < 0) slideSnap = false;
if (slideSnap == "auto") slideSnap = true;
if (slideSnap == "auto") slideSnap = true;
if (zot(slideSnapDamp)) slideSnapDamp = .1;
if (zot(slideSnapDamp)) slideSnapDamp = .1;
if (zot(reg)) reg = false;
if (zot(reg)) reg = false;
if (zot(removeTweens)) removeTweens = true;
if (zot(removeTweens)) removeTweens = true;
if (zot(startBounds)) startBounds = true;
if (zot(startBounds)) startBounds = true;
if (zot(boundary) && !zot(rect)) boundary = rect;
if (zot(boundary) && !zot(rect)) boundary = rect;
if (zot(singleTouch)) singleTouch = false;
if (zot(singleTouch)) singleTouch = false;
obj.dragPaused = false;
obj.dragPaused = false;
if (slide) {
if (slide) {
// set up damping for slide and variables used to predict future locations
// set up damping for slide and variables used to predict future locations
// these get populated in a setTimeout in the init function
// these get populated in a setTimeout in the init function


var dampX;
var dampX;
var dampY;
var dampY;
var back; // how many ticks ago to estimate trajectory
var back; // how many ticks ago to estimate trajectory
var lastCount;
var lastCount;
var backX;
var backX;
var backY;
var backY;
var backT;
var backT;
var upX; // mouse up translated to local
var upX; // mouse up translated to local
var upY;
var upY;
var upT;
var upT;
var objUpX; // drag object x when mouse up
var objUpX; // drag object x when mouse up
var objUpY;
var objUpY;
var lastBackX; // used to calculate trajectory
var lastBackX; // used to calculate trajectory
var lastBackY;
var lastBackY;
var lastBackT;
var lastBackT;
var lastX; // used to see if sliding object is still moving
var lastX; // used to see if sliding object is still moving
var lastY;
var lastY;
var hasMoved;
var hasMoved;
var tick = WW.M?20:10;
var tick = WW.M?20:10;
var vX;
var vX;
var vY;
var vY;
var dX;
var dX;
var dY;
var dY;
var bX = false;
var bX = false;
var bY = false;
var bY = false;
var vRange = 50;
var vRange = 50;


} else {
} else {
obj.zimDragTicker = function(){};
obj.zimDragTicker = function(){};
}
}


obj._draggable = true;
obj._draggable = true;
zim.setSwipe(obj, swipe);
zim.setSwipe(obj, swipe);
obj.zimBoundary = boundary;
obj.zimBoundary = boundary;
obj.zimlocalBoundary = localBoundary;
obj.zimlocalBoundary = localBoundary;
obj.circleBounds = boundary&&boundary.type=="Circle"?boundary.radius:false;
obj.circleBounds = boundary&&boundary.type=="Circle"?boundary.radius:false;
obj.downCheck = false;
obj.downCheck = false;
var moveCheck = false;
var moveCheck = false;


var diffX,diffY,r,rLocal,point;
var diffX,diffY,r,rLocal,point;


// initialize happens possibly before added to stage - only checking for parent
// initialize happens possibly before added to stage - only checking for parent
obj.zimAdded = obj.on("added", initializeObject, null, true); // if not added to display list
obj.zimAdded = obj.on("added", initializeObject, null, true); // if not added to display list
obj.zimRemoved = obj.on("removed", unInitializeObject, null, true);
obj.zimRemoved = obj.on("removed", unInitializeObject, null, true);
if (obj.parent) initializeObject();
if (obj.parent) initializeObject();


function initializeObject() {
function initializeObject() {
obj.off("added", obj.zimAdded);
obj.off("added", obj.zimAdded);
boundary = obj.zimBoundary;
boundary = obj.zimBoundary;
if (boundary && boundary.getBounds && boundary.type != "Blob") {
if (boundary && boundary.getBounds && boundary.type != "Blob") {
obj.zimlocalBoundary = false;
obj.zimlocalBoundary = false;
if (boundary.type != "Stage" && boundary.type != "StageGL") boundary = boundary.boundsToGlobal();
if (boundary.type != "Stage" && boundary.type != "StageGL") boundary = boundary.boundsToGlobal();
else boundary = new zim.Boundary(0,0,boundary.width,boundary.height);
else boundary = new zim.Boundary(0,0,boundary.width,boundary.height);
if (!surround) {
if (!surround) {
var bounds = obj.boundsToGlobal();
var bounds = obj.boundsToGlobal();
point = obj.localToGlobal(obj.regX,obj.regY);
point = obj.localToGlobal(obj.regX,obj.regY);
var tl = new zim.Point(point.x-bounds.x, point.y-bounds.y);
var tl = new zim.Point(point.x-bounds.x, point.y-bounds.y);
var bw = obj.borderWidth?obj.borderWidth:0;
var bw = obj.borderWidth?obj.borderWidth:0;
boundary.x += tl.x+bw/2;
boundary.x += tl.x+bw/2;
boundary.y += tl.y+bw/2;
boundary.y += tl.y+bw/2;
boundary.width -= bounds.width+bw;
boundary.width -= bounds.width+bw;
boundary.height -= bounds.height+bw;
boundary.height -= bounds.height+bw;
}
}
obj.zimBoundary = boundary;
obj.zimBoundary = boundary;
}
}
// check position right away if there is a bounding box
// check position right away if there is a bounding box
// there is no mousedown so set the diffX and diffY to 0
// there is no mousedown so set the diffX and diffY to 0
diffX = 0; diffY = 0;
diffX = 0; diffY = 0;
// positionObject() is used as well in the dragmove function
// positionObject() is used as well in the dragmove function
// where it expects a global x and y
// where it expects a global x and y
// so convert obj.x and obj.y positions inside its parent to global:
// so convert obj.x and obj.y positions inside its parent to global:
if (obj.zimBoundary && obj.zimBoundary.type != "Blob") {
if (obj.zimBoundary && obj.zimBoundary.type != "Blob") {
if (localBoundary) {
if (localBoundary) {
r = zim.boundsToGlobal(obj.parent, obj.zimBoundary);
r = zim.boundsToGlobal(obj.parent, obj.zimBoundary);
if (surround) rLocal = obj.zimBoundary;
if (surround) rLocal = obj.zimBoundary;
} else {
} else {
r = obj.zimBoundary;
r = obj.zimBoundary;
if (surround) rLocal = zim.boundsToGlobal(obj.parent, obj.zimBoundary, true); // flips to global to local
if (surround) rLocal = zim.boundsToGlobal(obj.parent, obj.zimBoundary, true); // flips to global to local
}
}
}
}
if (r && startBounds) {
if (r && startBounds) {
point = obj.parent.localToGlobal(obj.x, obj.y);
point = obj.parent.localToGlobal(obj.x, obj.y);
positionObject(obj, point.x, point.y);
positionObject(obj, point.x, point.y);
}
}
if (slide) {
if (slide) {
// little delay to in case position is set directly after drag is called
// little delay to in case position is set directly after drag is called
setTimeout(function() {
setTimeout(function() {
// set up damping for slide and variables used to predict future locations
// set up damping for slide and variables used to predict future locations
if (slide && slideSnap) {
if (slide && slideSnap) {
dampX = new zim.Damp(null, slideSnapDamp);
dampX = new zim.Damp(null, slideSnapDamp);
dampY = new zim.Damp(null, slideSnapDamp);
dampY = new zim.Damp(null, slideSnapDamp);
}
}
obj.zimDragImmediate = function(x, y) {
obj.zimDragImmediate = function(x, y) {
objUpX = x;
objUpX = x;
objUpY = y;
objUpY = y;
vX = vY = 0;
vX = vY = 0;
dX = dY = 0;
dX = dY = 0;
upX = lastBackX = upY = lastBackY = upT = lastBackT = 0;
upX = lastBackX = upY = lastBackY = upT = lastBackT = 0;
if (slide && slideSnap) {
if (slide && slideSnap) {
if (!zot(x)) dampX.immediate(x);
if (!zot(x)) dampX.immediate(x);
if (!zot(y)) dampY.immediate(y);
if (!zot(y)) dampY.immediate(y);
}
}
};
};
back = 3; // how many ticks ago to estimate trajectory
back = 3; // how many ticks ago to estimate trajectory
lastCount = 0;
lastCount = 0;
backX = [];
backX = [];
backY = [];
backY = [];
backT = [];
backT = [];
upX = obj.x; // mouse up translated to local
upX = obj.x; // mouse up translated to local
upY = obj.y;
upY = obj.y;
objUpX = obj.x; // drag object x when mouse up
objUpX = obj.x; // drag object x when mouse up
objUpY = obj.y;
objUpY = obj.y;
lastBackX = obj.x; // used to calculate trajectory
lastBackX = obj.x; // used to calculate trajectory
lastBackY = obj.y;
lastBackY = obj.y;
lastBackT = Date.now();
lastBackT = Date.now();
lastX = -10000; // used to see if sliding object is still moving
lastX = -10000; // used to see if sliding object is still moving
lastY = -10000;
lastY = -10000;
obj.zimDragMoving = true;
obj.zimDragMoving = true;
setUpSlide();
setUpSlide();
}, 50);
}, 50);
}
}
if (!zot(obj.zimMaskDynamic)) obj.zimMaskApply(); // set mask set by zimMask to dynamic
if (!zot(obj.zimMaskDynamic)) obj.zimMaskApply(); // set mask set by zimMask to dynamic
}
}


function unInitializeObject() {
function unInitializeObject() {
if (obj.zimDragTicker) zim.Ticker.remove(obj.zimDragTicker);
if (obj.zimDragTicker) zim.Ticker.remove(obj.zimDragTicker);
}
}


var dragObject;
var dragObject;


var stage;
var stage;
obj.pointers = {};
obj.pointers = {};
var stCheck = false;
var stCheck = false;
obj.zimDown = obj.on("mousedown", function(e) {
obj.zimDown = obj.on("mousedown", function(e) {
if (!obj.stage || obj.dragPaused) return;
if (!obj.stage || obj.dragPaused) return;
if (singleTouch && stCheck) return; // breaking if coming back from iframe until next mousedown
if (singleTouch && stCheck) {
e.preventDefault();
e.stopImmediatePropagation();
return;
}; // breaking if coming back from iframe until next mousedown


// obj.zimMove = obj.on("pressmove", obj.zimMove); // for some reason causing squiggle drag problems
// obj.zimMove = obj.on("pressmove", obj.zimMove); // for some reason causing squiggle drag problems
stCheck = true;
stCheck = true;
stage = obj.stage;
stage = obj.stage;
if (!obj.zmu) obj.zmu = stage.frame.on("mouseupplus", function(e) {
if (!obj.zmu) obj.zmu = stage.frame.on("mouseupplus", function(e) {
if (obj.downCheck) {
if (obj.downCheck) {
if (!slide) obj.downCheck = false;
if (!slide) obj.downCheck = false;
doUp(e, true); // true for cancel slide
doUp(e, true); // true for cancel slide
}
}
});
});
obj.dragMouseX = Math.round(e.stageX/zim.scaX)+stage.x;
obj.dragMouseX = Math.round(e.stageX/zim.scaX)+stage.x;
obj.dragMouseY = Math.round(e.stageY/zim.scaY)+stage.y;
obj.dragMouseY = Math.round(e.stageY/zim.scaY)+stage.y;
var id = "id"+Math.abs(e.pointerID+1);
var id = "id"+Math.abs(e.pointerID+1);
obj.pointers[id] = true; // keep track of multitouch to keep object ticker alive
obj.pointers[id] = true; // keep track of multitouch to keep object ticker alive
// e.stageX and e.stageY are global
// e.stageX and e.stageY are global
// e.target.x and e.target.y are relative to e.target's parent
// e.target.x and e.target.y are relative to e.target's parent
// bring stageX and stageY into the parent's frame of reference
// bring stageX and stageY into the parent's frame of reference
// could use e.localX and e.localY but might be dragging container or contents
// could use e.localX and e.localY but might be dragging container or contents
dragObject = (currentTarget)?e.currentTarget:e.target;
dragObject = (currentTarget)?e.currentTarget:e.target;
if (obj.zimBoundary && !dragObject.getBounds()) {zogy("zim.drag() - drag object needs bounds set"); return;}
if (obj.zimBoundary && !dragObject.getBounds()) {zogy("zim.drag() - drag object needs bounds set"); return;}
obj.downCheck = true;
obj.downCheck = true;
obj.stage.mouseMoveOutside = true;
obj.stage.mouseMoveOutside = true;


if (!zim.Ticker.has(obj.zimDragTicker)) zim.Ticker.add(obj.zimDragTicker, obj.stage);
if (!zim.Ticker.has(obj.zimDragTicker)) zim.Ticker.add(obj.zimDragTicker, obj.stage);


if (removeTweens && obj.zimTweens) {
if (removeTweens && obj.zimTweens) {
for (var tw in obj.zimTweens) {
for (var tw in obj.zimTweens) {
var ao = obj.zimTweens[tw];
var ao = obj.zimTweens[tw];
if (ao.zimObj && (ao.zimObj.x!=null||ao.zimObj.y!=null)) {
if (ao.zimObj && (ao.zimObj.x!=null||ao.zimObj.y!=null)) {
obj.stopAnimate(tw);
obj.stopAnimate(tw);
}
}
}
}
}
}


if (!dragObject.parent) return;
if (!dragObject.parent) return;
if (onTop) {
if (onTop) {
var nc = dragObject.parent.numChildren-1;
var nc = dragObject.parent.numChildren-1;
if (dragObject.parent.getChildAt(nc).type=="Keyboard") nc--;
if (dragObject.parent.getChildAt(nc).type=="Keyboard") nc--;
dragObject.parent.setChildIndex(dragObject,nc);
dragObject.parent.setChildIndex(dragObject,nc);
if (dragObject.ZIMoutlineShape) dragObject.outline();
if (dragObject.ZIMoutlineShape) dragObject.outline();
}
}
if (dragObject.parent == obj.stage) point = new zim.Point(e.stageX/zim.scaX, e.stageY/zim.scaY);
if (dragObject.parent == obj.stage) point = new zim.Point(e.stageX/zim.scaX, e.stageY/zim.scaY);
else point = dragObject.parent.globalToLocal(e.stageX/zim.scaX, e.stageY/zim.scaY);
else point = dragObject.parent.globalToLocal(e.stageX/zim.scaX, e.stageY/zim.scaY);
if (reg) {
if (reg) {
dragObject.x = point.x;
dragObject.x = point.x;
dragObject.y = point.y;
dragObject.y = point.y;
}
}
diffX = point.x - dragObject.x;
diffX = point.x - dragObject.x;
diffY = point.y - dragObject.y;
diffY = point.y - dragObject.y;


r = null;
r = null;
if (obj.zimBoundary) {
if (obj.zimBoundary) {
if (localBoundary) {
if (localBoundary) {
r = zim.boundsToGlobal(dragObject.parent, obj.zimBoundary);
r = zim.boundsToGlobal(dragObject.parent, obj.zimBoundary);
if (surround) rLocal = obj.zimBoundary;
if (surround) rLocal = obj.zimBoundary;
} else {
} else {
r = obj.zimBoundary;
r = obj.zimBoundary;
if (surround) rLocal = zim.boundsToGlobal(dragObject.parent, obj.zimBoundary, true); // true flips to global to local
if (surround) rLocal = zim.boundsToGlobal(dragObject.parent, obj.zimBoundary, true); // true flips to global to local
}
}
}
}
// just a quick way to set a default cursor or use the cursor sent in
// just a quick way to set a default cursor or use the cursor sent in
if (obj.cur) obj.cur(zot(dragCursor)?"pointer":dragCursor);
if (obj.cur) obj.cur(zot(dragCursor)?"pointer":dragCursor);
else obj.cursor = zot(dragCursor)?"pointer":dragCursor;
else obj.cursor = zot(dragCursor)?"pointer":dragCursor;


// extra slide settings to project where the object will slide to
// extra slide settings to project where the object will slide to
if (slide) {
if (slide) {
obj.slideStartX = obj.x;
obj.slideStartX = obj.x;
obj.slideStartY = obj.y;
obj.slideStartY = obj.y;
hasMoved = obj.zimDragMoving; // just in case clicking while it is animating back to position
hasMoved = obj.zimDragMoving; // just in case clicking while it is animating back to position


lastCount = 0;
lastCount = 0;
backX = [point.x];
backX = [point.x];
backY = [point.y];
backY = [point.y];
backT = [Date.now()];
backT = [Date.now()];
lastX = -10000; // reset
lastX = -10000; // reset
lastY = -10000;
lastY = -10000;
obj.zimDragMoving = true;
obj.zimDragMoving = true;
}
}


// extra pen drag
// extra pen drag
if (obj.type == "Pen") {
if (obj.type == "Pen") {
obj.zimDragCheck = true;
obj.zimDragCheck = true;
moveCheck = false;
moveCheck = false;
}
}


}, true);
}, true);


obj.zimMove = obj.on("pressmove", function(e) {
obj.zimMove = obj.on("pressmove", function(e) {
if (singleTouch && !obj.pointers["id"+Math.abs(e.pointerID+1)]) return;
if (singleTouch && !obj.pointers["id"+Math.abs(e.pointerID+1)]) {
if (!obj.downCheck || obj.dragPaused) return;
e.preventDefault();
e.stopImmediatePropagation();
return;
};
if (!obj.downCheck || obj.dragPaused) {
e.preventDefault();
e.stopImmediatePropagation();
return;
};
var x = (offStage?e.rawX:e.stageX)/zim.scaX+stage.x;
var x = (offStage?e.rawX:e.stageX)/zim.scaX+stage.x;
var y = (offStage?e.rawY:e.stageY)/zim.scaY+stage.y;
var y = (offStage?e.rawY:e.stageY)/zim.scaY+stage.y;
obj.dragMouseX = Math.round(x);
obj.dragMouseX = Math.round(x);
obj.dragMouseY = Math.round(y);
obj.dragMouseY = Math.round(y);
positionObject(dragObject, x, y);
positionObject(dragObject, x, y);
if (dragObject.ZIMoutlineShape) dragObject.outline();
if (dragObject.ZIMoutlineShape) dragObject.outline();
if (obj.type == "Pen" && !moveCheck && obj.drawing) moveCheck = true;
if (obj.type == "Pen" && !moveCheck && obj.drawing) moveCheck = true;
else if (obj.type == "Tag" || obj.type == "TextArea" || obj.type == "Loader") obj.resize();
else if (obj.type == "Tag" || obj.type == "TextArea" || obj.type == "Loader") obj.resize();
}, true);
}, true);


// obj.off("pressmove",obj.zimMove); // for some reason causing squiggle drag problems
// obj.off("pressmove",obj.zimMove); // for some reason causing squiggle drag problems


function positionObject(o, x, y) {
function positionObject(o, x, y) {


var diffX_o = diffX;
var diffX_o = diffX;
var diffY_o = diffY;
var diffY_o = diffY;
if (zot(o)) o = (dragObject) ? dragObject : obj; // so zim.dragBoundary can use this
if (zot(o)) o = (dragObject) ? dragObject : obj; // so zim.dragBoundary can use this


// x and y are the desired global positions for the object o
// x and y are the desired global positions for the object o
// checkBounds returns the same values if there are no bounds
// checkBounds returns the same values if there are no bounds
// and returns values inside the bounds if there are bounds set
// and returns values inside the bounds if there are bounds set
// or returns a position so that object o surrounds the bounds if surround is true
// or returns a position so that object o surrounds the bounds if surround is true
// firstly, convert the global x and y to a point relative to the object's parent
// firstly, convert the global x and y to a point relative to the object's parent
if (!o.parent) return;
if (!o.parent) return;
// if (!o.stage) return;
// if (!o.stage) return;


// var noXY = false;
if (zot(x) || zot(y)) {
if (zot(x) || zot(y)) {
// noXY = true;
// so zim.dragBoundary can use this to position on change
// so zim.dragBoundary can use this to position on change
// it may be we are resizing before we even drag at all
// it may be we are resizing before we even drag at all
// so we need to establish variables that would have been made on drag events
// so we need to establish variables that would have been made on drag events
var p = o.parent.localToGlobal(o.x, o.y);
var p = o.parent.localToGlobal(o.x, o.y);
diffX = diffY = 0;
diffX = diffY = 0;
if (obj.zimBoundary) {
if (obj.zimBoundary) {
if (localBoundary) {
if (localBoundary) {
r = zim.boundsToGlobal(o.parent, obj.zimBoundary);
r = zim.boundsToGlobal(o.parent, obj.zimBoundary);
if (surround) rLocal = o.zimBoundary;
if (surround) rLocal = o.zimBoundary;
} else {
} else {
r = obj.zimBoundary;
r = obj.zimBoundary;
if (surround) rLocal = zim.boundsToGlobal(o.parent, obj.zimBoundary, true); // flips to global to local
if (surround) rLocal = zim.boundsToGlobal(o.parent, obj.zimBoundary, true); // flips to global to local
}
}
}
}
x = p.x;
x = p.x;
y = p.y;
y = p.y;
if (slide) {
if (slide) {
objUpX = o.x;
objUpX = o.x;
objUpY = o.y;
objUpY = o.y;
dragObject = o;
dragObject = o;
// if (dampX) dampX.immediate(objUpX);
// if (dampX) dampX.immediate(objUpX);
// if (dampY) dampY.immediate(objUpY);
// if (dampY) dampY.immediate(objUpY);
}
}
}
}


// TODO only need this if boundary - so try and test for that first...
// TODO only need this if boundary - so try and test for that first...
var point;
var point;
if (stage && stage.type) point = o.parent.globalToLocal(x, y);
if (stage && stage.type) point = o.parent.globalToLocal(x, y);
// case where createjs stage - does not have adjusted globalToLocal
// case where createjs stage - does not have adjusted globalToLocal
else point = o.parent.globalToLocal(x*zim.scaX, y*zim.scaY);
else point = o.parent.globalToLocal(x*zim.scaX, y*zim.scaY);


var mX = axis=="both" || axis=="horizontal";
var mX = axis=="both" || axis=="horizontal";
var mY = axis=="both" || axis=="vertical";
var mY = axis=="both" || axis=="vertical";


var checkedPoint;
var checkedPoint;
if (slide && slideSnap) {
if (slide && slideSnap) {
if (slideSnap == "vertical") {
if (slideSnap == "vertical") {
checkedPoint = checkBounds(o,point.x-diffX, point.y-diffY);
checkedPoint = checkBounds(o,point.x-diffX, point.y-diffY);
if (mX) o.x = checkedPoint.x;
if (mX) o.x = checkedPoint.x;
if (mY) o.y = point.y-diffY;
if (mY) o.y = point.y-diffY;
} else if (slideSnap == "horizontal") {
} else if (slideSnap == "horizontal") {
checkedPoint = checkBounds(o,point.x-diffX, point.y-diffY);
checkedPoint = checkBounds(o,point.x-diffX, point.y-diffY);
if (mX) o.x = point.x-diffX;
if (mX) o.x = point.x-diffX;
if (mY) o.y = checkedPoint.y;
if (mY) o.y = checkedPoint.y;
} else {
} else {
if (mX) o.x = point.x-diffX;
if (mX) o.x = point.x-diffX;
if (mY) o.y = point.y-diffY;
if (mY) o.y = point.y-diffY;
}
}
} else {
} else {
checkedPoint = checkBounds(o,point.x-diffX, point.y-diffY);
checkedPoint = checkBounds(o,point.x-diffX, point.y-diffY);
// now set the object's x and y to the resulting checked local point
// now set the object's x and y to the resulting checked local point
if (mX) o.x = checkedPoint.x;
if (mX) o.x = checkedPoint.x;
if (mY) o.y = checkedPoint.y;
if (mY) o.y = checkedPoint.y;
}
}
if (slide && !hasMoved && (o.slideStartX != o.x || o.slideStartY != o.y)) hasMoved = true;
if (slide && !hasMoved && (o.slideStartX != o.x || o.slideStartY != o.y)) hasMoved = true;
if (o.downCheck) {
if (o.downCheck) {
diffX = diffX_o;
diffX = diffX_o;
diffY = diffY_o;
diffY = diffY_o;
}
}
// if (noXY) {
// obj.downCheck = true;
// doUp({pointers:[]});
// }
}
}


obj.zimPosition = positionObject;
obj.zimPosition = positionObject;


obj.zimUp = obj.on("pressup", function(e){doUp(e);}, true);
obj.zimUp = obj.on("pressup", function(e){doUp(e);}, true);
function doUp(e, outsideUp) {
function doUp(e, outsideUp) {


// if (obj.zimMove) obj.off("pressmove", obj.zimMove); // for some reason causing squiggle drag problems
if (singleTouch && !outsideUp && !obj.pointers["id"+Math.abs(e.pointerID+1)]) {
if (singleTouch && !outsideUp && !obj.pointers["id"+Math.abs(e.pointerID+1)]) return;
e.preventDefault();
e.stopImmediatePropagation();
return;
};
stCheck = false;
stCheck = false;


var id = "id"+Math.abs((!zot(e.pointerID)?e.pointerID:0)+1); // avoiding NaN but not sure if correct ZIM 015
var id = "id"+Math.abs((!zot(e.pointerID)?e.pointerID:0)+1); // avoiding NaN but not sure if correct ZIM 015
delete obj.pointers[id];
delete obj.pointers[id];
if (!obj.downCheck || obj.dragPaused) return;

if (!obj.downCheck || obj.dragPaused) {
e.preventDefault();
e.stopImmediatePropagation();
return;
};


if (obj.cur) obj.cur(zot(overCursor)?"pointer":overCursor);
if (obj.cur) obj.cur(zot(overCursor)?"pointer":overCursor);
else obj.cursor = zot(overCursor)?"pointer":overCursor;
else obj.cursor = zot(overCursor)?"pointer":overCursor;

if (e.stageX == null) return; // added for TextureActive drag in 2D view

if (slide) {
if (slide) {
dragObject.dispatchEvent("slidestart");
dragObject.dispatchEvent("slidestart");
if (dragObject.parent) {
if (dragObject.parent) {
var x = offStage?e.rawX:e.stageX;
var x = offStage?e.rawX:e.stageX;
var y = offStage?e.rawY:e.stageY;
var y = offStage?e.rawY:e.stageY;
point = dragObject.parent.globalToLocal(x/zim.scaX, y/zim.scaY);
point = dragObject.parent.globalToLocal(x/zim.scaX, y/zim.scaY);
} else {
} else {
point = new zim.Point(0,0);
point = new zim.Point(0,0);
}
}
// Added ZIM 014 to adjust for velocity effect
// Added ZIM 014 to adjust for velocity effect
upX = point.x;
upX = point.x;
upY = point.y;
upY = point.y;
upT = Date.now();
upT = Date.now();
// Added ZIM 015 if mouseuplus triggers first (TextureActive) then there is no event object
// Added ZIM 015 if mouseuplus triggers first (TextureActive) then there is no event object
if (isNaN(upX)) upX = -1000;
if (isNaN(upX)) upX = -1000;
if (isNaN(upY)) upY = -1000;
if (isNaN(upY)) upY = -1000;


dX = upX-lastBackX;
dX = upX-lastBackX;
dY = upY-lastBackY;
dY = upY-lastBackY;
var t = upT-lastBackT;
var t = upT-lastBackT;


vX = zim.constrain(dX*tick/t, -vRange, vRange);
vX = zim.constrain(dX*tick/t, -vRange, vRange);
vY = zim.constrain(dY*tick/t, -vRange, vRange);
vY = zim.constrain(dY*tick/t, -vRange, vRange);


bX = false; // for damping on slideSnap
bX = false; // for damping on slideSnap
bY = false;
bY = false;
// end add
// end add


obj.downCheck = false;
obj.downCheck = false;


objUpX = dragObject.x;
objUpX = dragObject.x;
objUpY = dragObject.y;
objUpY = dragObject.y;


if (outsideUp) {
if (outsideUp) {
lastBackX = upX = 0;
lastBackX = upX = 0;
lastBackY = upY = 0;
lastBackY = upY = 0;
lastBackT = upT = 0;
lastBackT = upT = 0;
}
}


// if (dampX) dampX.immediate(50);
// if (dampX) dampX.immediate(50);
// if (dampY) dampY.immediate(0);
// if (dampY) dampY.immediate(0);


} else {
} else {
obj.downCheck = false; // added ZIM NFT 01
obj.downCheck = false; // added ZIM NFT 01
var pointerCount = 0;
var pointerCount = 0;
for (var o in obj.pointers) {
for (var o in obj.pointers) {
pointerCount++;
pointerCount++;
}
}
if (pointerCount == 0) zim.Ticker.remove(obj.zimDragTicker);
if (pointerCount == 0) zim.Ticker.remove(obj.zimDragTicker);
// extra pen drag
// extra pen drag
if (obj.type == "Pen") {
if (obj.type == "Pen") {
obj.zimDragCheck = false;
obj.zimDragCheck = false;
if (moveCheck && obj.drawing) obj.stopCheck(); // added drawing check Cat 04
if (moveCheck && obj.drawing) obj.stopCheck(); // added drawing check Cat 04
// if (moveCheck) obj.stopCheck();
// if (moveCheck) obj.stopCheck();
}
}
}
}
if (obj.stage) obj.stage.update();
if (obj.stage) obj.stage.update();
}
}


// the bounds check for registration inside the bounds
// the bounds check for registration inside the bounds
// or if surround is set for the whole object staying outside the bounds
// or if surround is set for the whole object staying outside the bounds
function checkBounds(o, x, y) {
function checkBounds(o, x, y) {
if (!o.parent) return {x:x,y:y};
if (!o.parent) return {x:x,y:y};
if (r) {
if (r) {
if (surround) {
if (surround) {
var w = o.getBounds().width;
var w = o.getBounds().width;
var h = o.getBounds().height;
var h = o.getBounds().height;
var bx = o.getBounds().x;
var bx = o.getBounds().x;
var by = o.getBounds().y;
var by = o.getBounds().y;
if (w < rLocal.width) {
if (w < rLocal.width) {
// put half way between
// put half way between
x = rLocal.x + (rLocal.width - w) / 2 + (o.regX-bx);
x = rLocal.x + (rLocal.width - w) / 2 + (o.regX-bx);
} else {
} else {
if (x - (o.regX-bx) > rLocal.x) {
if (x - (o.regX-bx) > rLocal.x) {
x = rLocal.x + (o.regX-bx);
x = rLocal.x + (o.regX-bx);
}
}
if (x - (o.regX-bx) + w < rLocal.x + rLocal.width) {
if (x - (o.regX-bx) + w < rLocal.x + rLocal.width) {
x = rLocal.x + rLocal.width + (o.regX-bx) - w;
x = rLocal.x + rLocal.width + (o.regX-bx) - w;
}
}
}
}
if (o.height < rLocal.height) {
if (o.height < rLocal.height) {
// put half way between
// put half way between
y = rLocal.y + (rLocal.height - h) / 2 + (o.regY-by);
y = rLocal.y + (rLocal.height - h) / 2 + (o.regY-by);
} else {
} else {
if (y - (o.regY-by) > rLocal.y) {
if (y - (o.regY-by) > rLocal.y) {
y = rLocal.y + (o.regY-by);
y = rLocal.y + (o.regY-by);
}
}
if (y - (o.regY-by) + h < rLocal.y + rLocal.height) {
if (y - (o.regY-by) + h < rLocal.y + rLocal.height) {
y = rLocal.y + rLocal.height + (o.regY-by) - h;
y = rLocal.y + rLocal.height + (o.regY-by) - h;
}
}
}
}
} else {
} else {
if (r.type=="Blob") {
if (r.type=="Blob") {
if (r.shape.hitTestPoint(x,y)) return {x:x,y:y};
if (r.shape.hitTestPoint(x,y)) return {x:x,y:y};
else return {x:obj.x,y:obj.y};
else return {x:obj.x,y:obj.y};
} else {
} else {
// convert the desired drag position to a global point
// convert the desired drag position to a global point
// note that we want the position of the object in its parent
// note that we want the position of the object in its parent
// so we use the parent as the local frame
// so we use the parent as the local frame
point = o.parent.localToGlobal(x,y);
point = o.parent.localToGlobal(x,y);
// r is the bounds rectangle on the global stage
// r is the bounds rectangle on the global stage
// r is set during mousedown to allow for global scaling when in localBoundary mode
// r is set during mousedown to allow for global scaling when in localBoundary mode
// if you scale in localBoundary==false mode, you will need to reset bounds with dragBoundary()
// if you scale in localBoundary==false mode, you will need to reset bounds with dragBoundary()
if (obj.circleBounds) {
if (obj.circleBounds) {
var midX = r.x+r.width/2;
var midX = r.x+r.width/2;
var midY = r.y+r.height/2;
var midY = r.y+r.height/2;
var rad = obj.circleBounds;
var rad = obj.circleBounds;
if (zim.dist(midX, midY, point.x, point.y) <= rad) {
if (zim.dist(midX, midY, point.x, point.y) <= rad) {
x = point.x;
x = point.x;
y = point.y;
y = point.y;
} else {
} else {
var ang = zim.angle(midX, midY, point.x, point.y)*RAD;
var ang = zim.angle(midX, midY, point.x, point.y)*RAD;
x = midX + rad*Math.cos(ang);
x = midX + rad*Math.cos(ang);
y = midY + rad*Math.sin(ang);
y = midY + rad*Math.sin(ang);
}
}
} else {
} else {
x = Math.max(r.x, Math.min(r.x+r.width, point.x));
x = Math.max(r.x, Math.min(r.x+r.width, point.x));
y = Math.max(r.y, Math.min(r.y+r.height, point.y));
y = Math.max(r.y, Math.min(r.y+r.height, point.y));
}
}
// now that the point has been checked on the global scale
// now that the point has been checked on the global scale
// convert the point back to the obj parent frame of reference
// convert the point back to the obj parent frame of reference
point = o.parent.globalToLocal(x, y);
point = o.parent.globalToLocal(x, y);
x = point.x;
x = point.x;
y = point.y;
y = point.y;
}
}
}
}
}
}
return {x:x,y:y};
return {x:x,y:y};
}
}
function testMove(o,x,y,desiredX,desiredY) {
function testMove(o,x,y,desiredX,desiredY) {
if (Math.abs(o.x-lastX) < .1 && Math.abs(o.y-lastY) < .1) {
if (Math.abs(o.x-lastX) < .1 && Math.abs(o.y-lastY) < .1) {
obj.zimDragMoving = false;
obj.zimDragMoving = false;
o.x = desiredX; // snap to final resting place
o.x = desiredX; // snap to final resting place
o.y = desiredY;
o.y = desiredY;
o.slideStartX = null;
o.slideStartX = null;
o.slideStartY = null;
o.slideStartY = null;
if (hasMoved) {
if (hasMoved) {
o.dispatchEvent("slidestop");
o.dispatchEvent("slidestop");
zim.Ticker.remove(obj.zimDragTicker);
zim.Ticker.remove(obj.zimDragTicker);
}
}
// extra pen drag
// extra pen drag
if (obj.type == "Pen") {
if (obj.type == "Pen") {
obj.zimDragCheck = false;
obj.zimDragCheck = false;
if (moveCheck && obj.drawing) obj.stopCheck(); // added drawing check Cat 04
if (moveCheck && obj.drawing) obj.stopCheck(); // added drawing check Cat 04
// if (moveCheck) obj.stopCheck();
// if (moveCheck) obj.stopCheck();
}
}
} else {
} else {
lastX = x;
lastX = x;
lastY = y;
lastY = y;
}
}
}
}


// we store where the object was a few ticks ago and project it forward
// we store where the object was a few ticks ago and project it forward
// then damp until it stops - although the ticker keeps running and updating
// then damp until it stops - although the ticker keeps running and updating
// if it snaps then the object is allowed to go past the bounds and damp back
// if it snaps then the object is allowed to go past the bounds and damp back
// if it is not snapping then the object stops at the bounds when it is slid
// if it is not snapping then the object stops at the bounds when it is slid




function setUpSlide() {
function setUpSlide() {
obj.zimDragTicker = function() {
obj.zimDragTicker = function() {
if (zot(obj.slideStartX)) return; // don't stop other things like window scrollbar from moving object
if (zot(obj.slideStartX)) return; // don't stop other things like window scrollbar from moving object


if (!dragObject) dragObject = obj; // could be risky if intending to drag children
if (!dragObject) dragObject = obj; // could be risky if intending to drag children
if (obj.downCheck) {
if (obj.downCheck) {
var point;
var point;
if (dragObject.parent) {
if (dragObject.parent) {
point = dragObject.parent.globalToLocal(obj.dragMouseX, obj.dragMouseY);
point = dragObject.parent.globalToLocal(obj.dragMouseX, obj.dragMouseY);
} else {
} else {
point = new zim.Point(0,0);
point = new zim.Point(0,0);
}
}
lastCount++;
lastCount++;
backX.push(point.x);
backX.push(point.x);
backY.push(point.y);
backY.push(point.y);
backT.push(Date.now());
backT.push(Date.now());
if (lastCount >= back) {
if (lastCount >= back) {
lastBackX = backX.shift();
lastBackX = backX.shift();
lastBackY = backY.shift();
lastBackY = backY.shift();
lastBackT = backT.shift();
lastBackT = backT.shift();
} else {
} else {
lastBackX = backX[0];
lastBackX = backX[0];
lastBackY = backY[0];
lastBackY = backY[0];
lastBackT = backT[0];
lastBackT = backT[0];
}
}
} else {
} else {
if (!obj.zimDragMoving) return;
if (!obj.zimDragMoving) return;


dX = vX;
dX = vX;
dY = vY;
dY = vY;


var desiredX;
var desiredX;
var desiredY;
var desiredY;
if (axis==BOTH) {
if (axis==BOTH) {
desiredX = dragObject.x + dX;
desiredX = dragObject.x + dX;
desiredY = dragObject.y + dY;
desiredY = dragObject.y + dY;
} else if (axis==HORIZONTAL) {
} else if (axis==HORIZONTAL) {
desiredX = dragObject.x + dX;
desiredX = dragObject.x + dX;
desiredY = dragObject.y;
desiredY = dragObject.y;
} else if (axis==VERTICAL) {
} else if (axis==VERTICAL) {
desiredX = dragObject.x;
desiredX = dragObject.x;
desiredY = dragObject.y + dY;
desiredY = dragObject.y + dY;
}
}
vX = dX*slideFactor;
vX = dX*slideFactor;
vY = dY*slideFactor;
vY = dY*slideFactor;


var checkedPoint;
var checkedPoint;
if (r) {
if (r) {
checkedPoint = checkBounds(dragObject, desiredX, desiredY);
checkedPoint = checkBounds(dragObject, desiredX, desiredY);
if (slideSnap===true || slideSnap == "horizontal") {
if (slideSnap===true || slideSnap == "horizontal") {
if (Math.round(desiredX) != Math.round(checkedPoint.x)) {
if (Math.round(desiredX) != Math.round(checkedPoint.x)) {
if (!bX) {
if (!bX) {
dampX.immediate(desiredX);
dampX.immediate(desiredX);
bX = true;
bX = true;
}
}
vX = 0;
vX = 0;
desiredX = dampX.convert(checkedPoint.x);
desiredX = dampX.convert(checkedPoint.x);
}
}
if (slideSnap == "horizontal") desiredY = checkedPoint.y;
if (slideSnap == "horizontal") desiredY = checkedPoint.y;
}
}


if (slideSnap===true || slideSnap == "vertical") {
if (slideSnap===true || slideSnap == "vertical") {
if (Math.round(desiredY) != Math.round(checkedPoint.y)) {
if (Math.round(desiredY) != Math.round(checkedPoint.y)) {
if (!bY) {
if (!bY) {
bY = true;
bY = true;
dampY.immediate(desiredY);
dampY.immediate(desiredY);
vY = 0;
vY = 0;
}
}
desiredY = dampY.convert(checkedPoint.y);
desiredY = dampY.convert(checkedPoint.y);
}
}
if (slideSnap == "vertical") desiredX = checkedPoint.x;
if (slideSnap == "vertical") desiredX = checkedPoint.x;
}
}


if (!slideSnap) {
if (!slideSnap) {
desiredX = checkedPoint.x;
desiredX = checkedPoint.x;
desiredY = checkedPoint.y;
desiredY = checkedPoint.y;
}
}
}
}


dragObject.x = desiredX;
dragObject.x = desiredX;
dragObject.y = desiredY;
dragObject.y = desiredY;


testMove(dragObject,dragObject.x,dragObject.y,desiredX,desiredY);
testMove(dragObject,dragObject.x,dragObject.y,desiredX,desiredY);


}
}
}
}
}
}
return obj;
return obj;
};//-31
};//-31