⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atlasuidragdrop.js

📁 《圣殿祭司的ASP.NET 2.0开发详解——使用C#》光盘内容.包含了书籍所含的源代码.非常经典的一本asp.net2.0的书籍
💻 JS
📖 第 1 页 / 共 4 页
字号:
Web.TypeDescriptor.addType('script', 'dragDropList', Web.UI.DragDropList);
Web.UI.DataSourceDropTarget = function() {
    Web.UI.DataSourceDropTarget.initializeBase(this);
    
    var _acceptedDataTypes;
    var _append = true;
    var _target;
    var _property = "data";
    
    this.get_append = function() {
        return _append;
    }
    
    this.set_append = function(value) {
        _append = value;
    }
    
    this.get_target = function() {
        return _target;
    }
    
    this.set_target = function(value) {
        _target = value;
    }
    
    this.get_property = function() {
        return _property;
    }
    
    this.set_property = function(value) {
        _property = value;
    }
    
    this.get_acceptedDataTypes = function() {
        return _acceptedDataTypes;
    }
    this.set_acceptedDataTypes = function(value) {
        _acceptedDataTypes = value;
    }
    
    this.initialize = function() {
        Web.UI.DataSourceDropTarget.callBaseMethod(this, 'initialize');
        Web.UI.DragDropManager.registerDropTarget(this);
    }
    
    this.getDescriptor = function() {
        var td = Web.UI.DataSourceDropTarget.callBaseMethod(this, 'getDescriptor');
        td.addProperty("acceptedDataTypes", Array);
        td.addProperty("append", Boolean);
        td.addProperty("target", Object);
        td.addProperty("property", String);
        return td;
    }

    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, type, data) {
        if (data) {
            var p;
            var target = _target ? _target : this.control;
            if (_append) {
                p = target["get_" + _property];
                if (p) {
                    var targetData = p();
                    if (targetData) {
                        targetData.add(data);
                    } else {
                                                p = target["set_" + _property];
                        if (p) {
                            p.call(target, data);
                        }
                    }
                }
            }
            else {
                p = target["set_" + _property];
                if (p) {
                    p.call(target, data);
                }
            }
        }
    }
    
        this.onDragEnterTarget = function(dragMode, type, data) {
            }
    
        this.onDragLeaveTarget = function(dragMode, type, data) {
            }
    
        this.onDragInTarget = function(dragMode, type, data) {
            }
}
Type.registerSealedClass('Web.UI.DataSourceDropTarget', Web.UI.Behavior, Web.UI.IDropTarget);
Web.TypeDescriptor.addType('script', 'dataSourceDropTarget', Web.UI.DataSourceDropTarget);
Web.UI.DraggableListItem = function() {
    Web.UI.DraggableListItem.initializeBase(this);
    
    var _data;
    var _handle;
    var _dragVisualTemplate;
    var _dragVisualTemplateInstance;
    
    this.get_data = function() {
        if (_data == null) {
            var dragSource = this._findDragSource();
            if (dragSource != null && dragSource.get_dataType() == "HTML") {
                return this.control.element;
            }
        }
        
        return _data;
    }
    
    this.set_data = function(value) {
        _data = value;
    }
    
    this.get_handle = function() {
        return _handle;
    }
    
    this.set_handle = function(value) {
        if (_handle != null) {
            _handle.detachEvent("onmousedown", this._handleMouseDown);
            _handle.__draggableBehavior = null;
        }

        if (value.element) {
            value = value.element;
        }
        _handle = value;
        _handle.__draggableBehavior = this;
        
        _handle.attachEvent("onmousedown", this._handleMouseDown);
        _handle.__draggableBehavior = this;
    }
    
    this.get_dragVisualTemplate = function() {
        return _dragVisualTemplate;
    }
    
    this.set_dragVisualTemplate = function(value) {
        _dragVisualTemplate = value;
    }
    
    this.getDescriptor = function() {
        var td = Web.UI.DraggableListItem.callBaseMethod(this, 'getDescriptor');
        td.addProperty("data", Object);
        td.addProperty("handle", Object, false, Web.Attributes.Element, true);
        td.addProperty("dragVisualTemplate", Web.UI.ITemplate);
        return td;
    }
    
    this._handleMouseDown = function() {
        _handle.__draggableBehavior._handleMouseDownInternal();
    }
    
    this._handleMouseDownInternal = function() {
        var ev = window.testEvent ? window.testEvent : window.event;
        if (ev.button <= 1) {
            var dragSource = this._findDragSource();
            if (dragSource != null) {
debug.trace("Found drag source. Starting drag and drop...");
                var dragVisual = this._createDragVisual();
                dragSource.startDragDrop(this.control.element, this.get_data(), dragVisual);
                ev.returnValue = false;
            }
            else {
                debug.trace("No drag source found. Unable to start drag and drop.");
            }
        }
        else {
            debug.trace("Ignoring event; only the left mouse button can be used to start drag and drop.");
        }
    }
    
    this._createDragVisual = function() {
        var ev = window.testEvent ? window.testEvent : window.event;
        if (_dragVisualTemplate != null) {
            if (_dragVisualTemplateInstance == null) {
                _dragVisualTemplateInstance = _dragVisualTemplate.createInstance(this.control.element).instanceElement;
            }
            else if (!Web.UI.DragDropManager._getInstance().hasParent(_dragVisualTemplateInstance)) {
                this.control.element.appendChild(_dragVisualTemplateInstance);
            }
            
            var location = { x: ev.clientX, y: ev.clientY };
            location = Web.UI.DragDropManager._getInstance().addPoints(location, Web.UI.DragDropManager._getInstance().getScrollOffset(document.body, true));
            Web.UI.Control.setLocation(_dragVisualTemplateInstance, location);
        }
        return _dragVisualTemplateInstance;
    }
    
    this._findDragSource = function() {
        var element = this.control.element;
        while (element != null) {
            if (element.__dragDropList != null) {
                return element.__dragDropList;
            }
            element = element.parentNode;
        }
        return null;
    }
}
Type.registerSealedClass('Web.UI.DraggableListItem', Web.UI.Behavior);
Web.TypeDescriptor.addType('script', 'draggableListItem', Web.UI.DraggableListItem);
Web.UI.FloatingBehavior = function() {
    Web.UI.FloatingBehavior.initializeBase(this);
    
    var _handle;
    var _location;
    var _dragStartLocation;
    
    var _mouseDownHandler = Function.createDelegate(this, mouseDownHandler);
    
    this.move = this.createEvent();
    
    this.get_handle = function() {
        return _handle;
    }
    this.set_handle = function(value) {
        if (_handle != null) {
            _handle.detachEvent("onmousedown", _mouseDownHandler);
        }
    
        _handle = value;
        _handle.attachEvent("onmousedown", _mouseDownHandler);
    }
    
    this.get_location = function() {
        return _location;
    }
    this.set_location = function(value) {
        if (_location != value) {
            _location = value;
            if (this.get_isInitialized()) {
                var numbers = _location.split(',');
                var location = { x : parseInt(numbers[0]), y : parseInt(numbers[1]) };
                Web.UI.Control.setLocation(this.control.element, location);
            }
            this.raisePropertyChanged('location');
        }
    }
    
    this.initialize = function() {
        Web.UI.FloatingBehavior.callBaseMethod(this, 'initialize');
        Web.UI.DragDropManager.registerDropTarget(this);

        var el = this.control.element;

        var location;
        if (_location) {
            var numbers = _location.split(',');
            location = { x : parseInt(numbers[0]), y : parseInt(numbers[1]) };
        }
        else {
            location = Web.UI.Control.getLocation(el);
        }
        
        el.style.width = el.offsetWidth + "px";
        el.style.height = el.offsetHeight + "px";
        el.style.position = "absolute";
        Web.UI.Control.setLocation(el, location);
    }
    
    this.dispose = function() {
        if (_handle != null) {
            _handle.detachEvent("onmousedown", _mouseDownHandler);
        }
        _mouseDownHandler = null;
        Web.UI.FloatingBehavior.callBaseMethod(this, 'dispose');
    }
    
    this.getDescriptor = function() {
        var td = Web.UI.FloatingBehavior.callBaseMethod(this, 'getDescriptor');
        
        td.addProperty("handle", Object, false, Web.Attributes.Element, true);
        td.addProperty('location', String);
        td.addEvent("move", true);
        return td;
    }
    
    function mouseDownHandler() {
        var el = this.control.element;
        _dragStartLocation = Web.UI.Control.getLocation(el);
        
        window.event.returnValue = false;
        this.startDragDrop(el);
    }

        this.get_dataType = function() {
        return "_floatingObject";
    }
    
        this.get_data = function(context) {
        return null;
    }
    
        this.get_dragMode = function() {
        return Web.UI.DragMode.Move;
    }
    
        this.onDragStart = Function.emptyMethod;
    
        this.onDrag = Function.emptyMethod;
    
        this.onDragEnd = function(canceled) {
        if (!canceled) {
            var cancelArgs = new Web.CancelEventArgs();
            this.move.invoke(this, cancelArgs);
            canceled = cancelArgs.get_canceled();
        }
        
        var el = this.control.element;
        if (canceled) {
                        Web.UI.Control.setLocation(el, _dragStartLocation);
        }
        else {
            var location = Web.UI.Control.getLocation(el);
            _location = location.x + ',' + location.y;
            this.raisePropertyChanged('location');
        }
    }
    
    this.startDragDrop = function(dragVisual) {
        Web.UI.DragDropManager.startDragDrop(this, dragVisual, null);
    }
    
    this.get_dropTargetElement = function() {
        return document.body;
    }
    
        this.canDrop = function(dragMode, dataType) {
        return (dataType == "_floatingObject");
    }
    
        this.drop = Function.emptyMethod;
    
        this.onDragEnterTarget = Function.emptyMethod;
    
        this.onDragLeaveTarget = Function.emptyMethod;
    
        this.onDragInTarget = Function.emptyMethod;
}
Type.registerSealedClass('Web.UI.FloatingBehavior', Web.UI.Behavior, Web.UI.IDragSource, Web.UI.IDropTarget, Web.IDisposable);
Web.TypeDescriptor.addType('script', 'floatingBehavior', Web.UI.FloatingBehavior);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -