﻿/// <summary>
/// FileName : DragBehavior.js
/// Author : 
/// Description : 自定义ASP.NET Ajax客户端行为，用于为元素添加可拖动行为
/// ClassName : NBBS.CustomBehavior.DragBehavior
/// Namespace : NBBS.CustomBehavior
/// Inheritee : Sys.UI.Behavior
/// implement : Sys.Preview.UI.IDragSource
/// </summary>

Type.registerNamespace('NBBS.CustomBehavior');

NBBS.CustomBehavior.DragBehavior = function(associatedElement) {
    NBBS.CustomBehavior.DragBehavior.initializeBase(this, [associatedElement]);
    this._mouseDownHandler = Function.createDelegate(this, this.onMouseDown);
}

NBBS.CustomBehavior.DragBehavior.prototype = {
    _dragElement :null,
    
    /// <summary>
    /// 属性
    /// </summary>
    
    get_dragElement: function() {
        return this._dragElement;
    },

    set_dragElement: function(value) {
        if (this._dragElement !== value) {
            this._dragElement = value;
            this.raisePropertyChanged('dragElement');
        }
    },
    
    //可拖动元素的数据信息    
    getDragData: function() {
        return this.get_element();
    },
    
    //指明可拖动元素的类型
    get_dragDataType: function() {
        return "DragableWindow"
    },
    
    //拖动类型 Copy - 生成源元素的拷贝 Move - 移动源元素
    get_dragMode: function() {
        return Sys.Preview.UI.DragMode.Move;
    },

    /// <summary>
    /// 构造函数
    /// </summary>
    initialize: function() {
        NBBS.CustomBehavior.DragBehavior.callBaseMethod(this, 'initialize');
        $addHandler(this.get_element(), "mousedown", this._mouseDownHandler);
    },

    /// <summary>
    /// 析构函数
    /// </summary>
    dispose: function() {
        NBBS.CustomBehavior.DragBehavior.callBaseMethod(this, 'dispose');
    },

    /// <summary>
    /// 当拖动开始时，此方法将被DragDropManager调用，在这个类中什么也不做
    /// </summary>
    onDragStart: function() {
    },

    /// <summary>
    /// 在拖动中，此方法将被DragDropManager调用，在这个类中什么也不做
    /// </summary>
    onDrag: function() {
    },

    /// <summary>
    /// 在拖动结束时，此方法将被DragDropManager调用，在这个类中什么也不做
    /// </summary>
    onDragEnd: function() {
    },

    /// <summary>
    /// IDragSource._mouseDownHandler的委托事件，用于按下鼠标时通知DragDropManager拖动开始
    /// </summary>
    onMouseDown: function(ev) {
        window._event = ev;
        Sys.Preview.UI.DragDropManager.startDragDrop(this,this.get_dragElement(),null);
    }
}

NBBS.CustomBehavior.DragBehavior.registerClass('NBBS.CustomBehavior.DragBehavior', Sys.UI.Behavior,Sys.Preview.UI.IDragSource);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
