📄 atlasuidragdrop.js
字号:
this.get_data = function() {
return _data;
}
this.set_data = function(value) {
_data = value;
}
this.initialize = function() {
Web.UI.DragDropList.callBaseMethod(this, 'initialize');
this.control.element.__dragDropList = this;
Web.UI.DragDropManager.registerDropTarget(this);
}
this.getDescriptor = function() {
var td = Web.UI.DragDropList.callBaseMethod(this, 'getDescriptor');
td.addProperty("acceptedDataTypes", Array);
td.addProperty("data", Object);
td.addProperty("dataType", String);
td.addProperty("emptyTemplate", Web.UI.ITemplate);
td.addProperty("dropCueTemplate", Web.UI.ITemplate);
td.addProperty("direction", Web.UI.RepeatDirection);
td.addProperty("dragMode", Web.UI.DragMode);
return td;
}
Web.UI.DragDropList.registerBaseMethod(this, 'getDescriptor');
this.startDragDrop = function(dragObject, context, dragVisual) {
if (!_isDragging) {
_isDragging = true;
_currentContext = context;
if (dragVisual == null) {
dragVisual = this.createDragVisual(dragObject);
debug.trace("Using default drag visual.");
}
else {
_dragVisual = dragVisual;
debug.trace("Using user-specified drag visual.");
}
Web.UI.DragDropManager.startDragDrop(this, dragVisual, context);
}
else {
debug.trace("Drag drop rejected by DragDropList: already dragging.");
}
}
this.createDragVisual = function(dragObject) {
if (_dragMode == Web.UI.DragMode.Copy) {
_dragVisual = dragObject.cloneNode(true);
}
else {
_dragVisual = dragObject;
}
var oldOffset = Web.UI.DragDropManager._getInstance().getScrollOffset(dragObject, true);
_dragVisual.style.width = dragObject.offsetWidth + "px";
_dragVisual.style.height = dragObject.offsetHeight + "px";
_dragVisual.style.opacity = "0.4";
_dragVisual.style.filter = "progid:DXImageTransform.Microsoft.BasicImage(opacity=0.4);";
_originalZIndex = _dragVisual.style.zIndex;
_dragVisual.style.zIndex = 99999;
_originalParent = _dragVisual.parentNode;
_originalNextSibling = Web.UI.DragDropManager._getInstance().getNextSibling(_dragVisual);
var currentLocation = Web.UI.Control.getLocation(dragObject, true);
var dragVisualContainer = this._getFloatContainer();
Web.UI.Control.setLocation(dragVisualContainer, currentLocation);
if (Web.UI.DragDropManager._getInstance().hasParent(_dragVisual)) {
_dragVisual.parentNode.removeChild(_dragVisual);
}
dragVisualContainer.appendChild(_dragVisual);
var newOffset = Web.UI.DragDropManager._getInstance().getScrollOffset(dragObject, true);
if (oldOffset.x != newOffset.x || oldOffset.y != newOffset.y) {
var diff = Web.UI.DragDropManager._getInstance().subtractPoints(oldOffset, newOffset);
Web.UI.Control.setLocation(dragVisualContainer, Web.UI.DragDropManager._getInstance().subtractPoints(currentLocation, diff));
}
return dragVisualContainer;
}
this.get_emptyTemplate = function() {
return _emptyTemplate;
}
this.set_emptyTemplate = function(value) {
_emptyTemplate = value;
}
this.get_dataType = function() {
return _dataType;
}
this.set_dataType = function(value) {
_dataType = value;
}
this.get_data = function(context) {
return context;
}
this.get_dragMode = function() {
return _dragMode;
}
this.set_dragMode = function(value) {
_dragMode = value;
}
this.dispose = function() {
this.control.element.__dragDropList = null;
Web.UI.DragDropList.callBaseMethod(this, 'dispose');
}
this.onDragStart = function() {
this._validate();
}
this.onDrag = function() {
}
this.onDragEnd = function(cancelled) {
if (_floatContainerInstance != null) {
if (_dragMode == Web.UI.DragMode.Copy) {
_floatContainerInstance.removeChild(_dragVisual);
}
else {
_dragVisual.style.opacity = "0.999";
_dragVisual.style.filter = "";
_dragVisual.style.zIndex = _originalZIndex ? _originalZIndex : 0;
if (cancelled) {
_dragVisual.parentNode.removeChild(_dragVisual);
if (_originalNextSibling != null) {
_originalParent.insertBefore(_dragVisual, _originalNextSibling);
}
else {
_originalParent.appendChild(_dragVisual);
}
}
else {
if (_dragVisual.parentNode == _floatContainerInstance) {
_dragVisual.parentNode.removeChild(_dragVisual);
}
}
}
document.body.removeChild(_floatContainerInstance);
}
else {
_dragVisual.parentNode.removeChild(_dragVisual);
}
if (!cancelled && _data != null && _dragMode == Web.UI.DragMode.Move) {
var data = this.get_data(_currentContext);
if (_data != null && data != null) {
_data.remove(data);
}
}
_isDragging = false;
this._validate();
}
this.get_direction = function() {
return _direction;
}
this.set_direction = function(value) {
_direction = value;
}
this.get_acceptedDataTypes = function() {
return _acceptedDataTypes;
}
this.set_acceptedDataTypes = function(value) {
_acceptedDataTypes = value;
}
this.get_dropCueTemplate = function() {
return _dropCueTemplate;
}
this.set_dropCueTemplate = function(value) {
_dropCueTemplate = value;
}
this.get_dropTargetElement = function() {
return this.control.element;
}
this.canDrop = function(dragMode, dataType) {
for (var i = 0; i < _acceptedDataTypes.length; i++) {
if (_acceptedDataTypes[i] == dataType) {
return true;
}
}
return false;
}
this.drop = function(dragMode, dataType, data) {
if (dataType == "HTML" && dragMode == Web.UI.DragMode.Move) {
dragVisual = data;
var potentialNextSibling = this._findPotentialNextSibling(dragVisual);
this._setDropCueVisible(false, dragVisual);
dragVisual.parentNode.removeChild(dragVisual);
if (potentialNextSibling != null) {
this.control.element.insertBefore(dragVisual, potentialNextSibling);
}
else {
this.control.element.appendChild(dragVisual);
}
}
else {
this._setDropCueVisible(false);
}
if (_data != null && data != null) {
_data.add(data);
}
}
this.onDragEnterTarget = function(dragMode, dataType, data) {
if (dataType == "HTML") {
this._setDropCueVisible(true, data);
this._validate();
}
}
this.onDragLeaveTarget = function(dragMode, dataType, data) {
if (dataType == "HTML") {
this._setDropCueVisible(false);
this._validate();
}
}
this.onDragInTarget = function(dragMode, dataType, data) {
if (dataType == "HTML") {
this._setDropCueVisible(true, data);
}
}
this._setDropCueVisible = function(visible, dragVisual) {
if (_dropCueTemplate != null) {
if (visible) {
if (_dropCueTemplateInstance == null) {
var documentContext = document.createDocumentFragment();
_dropCueTemplateInstance = _dropCueTemplate.createInstance(documentContext).instanceElement;
}
var potentialNextSibling = this._findPotentialNextSibling(dragVisual);
if (!Web.UI.DragDropManager._getInstance().hasParent(_dropCueTemplateInstance)) {
if (potentialNextSibling != null) {
this.control.element.insertBefore(_dropCueTemplateInstance, potentialNextSibling);
}
else {
this.control.element.appendChild(_dropCueTemplateInstance);
}
_dropCueTemplateInstance.style.width = dragVisual.offsetWidth + "px";
_dropCueTemplateInstance.style.height = dragVisual.offsetHeight + "px";
}
else {
if (Web.UI.DragDropManager._getInstance().getNextSibling(_dropCueTemplateInstance) != potentialNextSibling) {
this.control.element.removeChild(_dropCueTemplateInstance);
if (potentialNextSibling != null) {
this.control.element.insertBefore(_dropCueTemplateInstance, potentialNextSibling);
}
else {
this.control.element.appendChild(_dropCueTemplateInstance);
}
}
}
}
else {
if (_dropCueTemplateInstance != null && Web.UI.DragDropManager._getInstance().hasParent(_dropCueTemplateInstance)) {
this.control.element.removeChild(_dropCueTemplateInstance);
}
}
}
}
this._findPotentialNextSibling = function(dragVisual) {
var dragVisualRect = Web.UI.Control.getBounds(dragVisual);
var isVertical = (_direction == Web.UI.RepeatDirection.Vertical);
var nodeRect;
for (var node = this.control.element.firstChild; node != null; node = node.nextSibling) {
if (node.innerHTML != null && node != _dropCueTemplateInstance && node != _emptyTemplateInstance) {
nodeRect = Web.UI.Control.getBounds(node);
if ((!isVertical && dragVisualRect.x <= nodeRect.x) || (isVertical && dragVisualRect.y <= nodeRect.y)) {
return node;
}
}
}
return null;
}
this._validate = function() {
var visible = (_dropCueTemplateInstance == null || !Web.UI.DragDropManager._getInstance().hasParent(_dropCueTemplateInstance));
var count = 0;
for (var node = this.control.element.firstChild; node != null; node = node.nextSibling) {
if (node.innerHTML != null && node != _emptyTemplateInstance && node != _dropCueTemplateInstance) {
count++;
}
}
if (count > 0) {
visible = false;
}
this._setEmptyTemplateVisible(visible);
}
this._setEmptyTemplateVisible = function(visible) {
if (_emptyTemplate != null) {
if (visible) {
if (_emptyTemplateInstance == null) {
_emptyTemplateInstance = _emptyTemplate.createInstance(this.control.element).instanceElement;
}
else if (!Web.UI.DragDropManager._getInstance().hasParent(_emptyTemplateInstance)) {
this.control.element.appendChild(_emptyTemplateInstance);
}
}
else {
if (_emptyTemplateInstance != null && Web.UI.DragDropManager._getInstance().hasParent(_emptyTemplateInstance)) {
this.control.element.removeChild(_emptyTemplateInstance);
}
}
}
}
this._getFloatContainer = function() {
if (_floatContainerInstance == null) {
_floatContainerInstance = document.createElement(this.control.element.tagName);
var none = "0px 0px 0px 0px";
_floatContainerInstance.style.position = "absolute";
_floatContainerInstance.style.padding = none;
_floatContainerInstance.style.margin = none;
document.body.appendChild(_floatContainerInstance);
}
else if (!Web.UI.DragDropManager._getInstance().hasParent(_floatContainerInstance)) {
document.body.appendChild(_floatContainerInstance);
}
return _floatContainerInstance;
}
}
Type.registerSealedClass('Web.UI.DragDropList', Web.UI.Behavior, Web.UI.IDragSource, Web.UI.IDropTarget, Web.IDisposable);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -