dragdrop.js

来自「国外很不错的一个开源OA系统Group-Office」· JavaScript 代码 · 共 2,084 行 · 第 1/5 页

JS
2,084
字号
/*Copyright (c) 2006, Yahoo! Inc. All rights reserved.Code licensed under the BSD License:http://developer.yahoo.net/yui/license.txtversion: 0.12.0*/(function() {var Event=YAHOO.util.Event;var Dom=YAHOO.util.Dom;/** * Defines the interface and base operation of items that that can be * dragged or can be drop targets.  It was designed to be extended, overriding * the event handlers for startDrag, onDrag, onDragOver, onDragOut. * Up to three html elements can be associated with a DragDrop instance: * <ul> * <li>linked element: the element that is passed into the constructor. * This is the element which defines the boundaries for interaction with * other DragDrop objects.</li> * <li>handle element(s): The drag operation only occurs if the element that * was clicked matches a handle element.  By default this is the linked * element, but there are times that you will want only a portion of the * linked element to initiate the drag operation, and the setHandleElId() * method provides a way to define this.</li> * <li>drag element: this represents an the element that would be moved along * with the cursor during a drag operation.  By default, this is the linked * element itself as in {@link YAHOO.util.DD}.  setDragElId() lets you define * a separate element that would be moved, as in {@link YAHOO.util.DDProxy} * </li> * </ul> * This class should not be instantiated until the onload event to ensure that * the associated elements are available. * The following would define a DragDrop obj that would interact with any * other DragDrop obj in the "group1" group: * <pre> *  dd = new YAHOO.util.DragDrop("div1", "group1"); * </pre> * Since none of the event handlers have been implemented, nothing would * actually happen if you were to run the code above.  Normally you would * override this class or one of the default implementations, but you can * also override the methods you want on an instance of the class... * <pre> *  dd.onDragDrop = function(e, id) { *  &nbsp;&nbsp;alert("dd was dropped on " + id); *  } * </pre> * @namespace YAHOO.util * @class DragDrop * @constructor * @param {String} id of the element that is linked to this instance * @param {String} sGroup the group of related DragDrop objects * @param {object} config an object containing configurable attributes *                Valid properties for DragDrop: *                    padding, isTarget, maintainOffset, primaryButtonOnly */YAHOO.util.DragDrop = function(id, sGroup, config) {    if (id) {        this.init(id, sGroup, config);    }};YAHOO.util.DragDrop.prototype = {    /**     * The id of the element associated with this object.  This is what we     * refer to as the "linked element" because the size and position of     * this element is used to determine when the drag and drop objects have     * interacted.     * @property id     * @type String     */    id: null,    /**     * Configuration attributes passed into the constructor     * @property config     * @type object     */    config: null,    /**     * The id of the element that will be dragged.  By default this is same     * as the linked element , but could be changed to another element. Ex:     * YAHOO.util.DDProxy     * @property dragElId     * @type String     * @private     */    dragElId: null,    /**     * the id of the element that initiates the drag operation.  By default     * this is the linked element, but could be changed to be a child of this     * element.  This lets us do things like only starting the drag when the     * header element within the linked html element is clicked.     * @property handleElId     * @type String     * @private     */    handleElId: null,    /**     * An associative array of HTML tags that will be ignored if clicked.     * @property invalidHandleTypes     * @type {string: string}     */    invalidHandleTypes: null,    /**     * An associative array of ids for elements that will be ignored if clicked     * @property invalidHandleIds     * @type {string: string}     */    invalidHandleIds: null,    /**     * An indexted array of css class names for elements that will be ignored     * if clicked.     * @property invalidHandleClasses     * @type string[]     */    invalidHandleClasses: null,    /**     * The linked element's absolute X position at the time the drag was     * started     * @property startPageX     * @type int     * @private     */    startPageX: 0,    /**     * The linked element's absolute X position at the time the drag was     * started     * @property startPageY     * @type int     * @private     */    startPageY: 0,    /**     * The group defines a logical collection of DragDrop objects that are     * related.  Instances only get events when interacting with other     * DragDrop object in the same group.  This lets us define multiple     * groups using a single DragDrop subclass if we want.     * @property groups     * @type {string: string}     */    groups: null,    /**     * Individual drag/drop instances can be locked.  This will prevent     * onmousedown start drag.     * @property locked     * @type boolean     * @private     */    locked: false,    /**     * Lock this instance     * @method lock     */    lock: function() { this.locked = true; },    /**     * Unlock this instace     * @method unlock     */    unlock: function() { this.locked = false; },    /**     * By default, all insances can be a drop target.  This can be disabled by     * setting isTarget to false.     * @method isTarget     * @type boolean     */    isTarget: true,    /**     * The padding configured for this drag and drop object for calculating     * the drop zone intersection with this object.     * @method padding     * @type int[]     */    padding: null,    /**     * Cached reference to the linked element     * @property _domRef     * @private     */    _domRef: null,    /**     * Internal typeof flag     * @property __ygDragDrop     * @private     */    __ygDragDrop: true,    /**     * Set to true when horizontal contraints are applied     * @property constrainX     * @type boolean     * @private     */    constrainX: false,    /**     * Set to true when vertical contraints are applied     * @property constrainY     * @type boolean     * @private     */    constrainY: false,    /**     * The left constraint     * @property minX     * @type int     * @private     */    minX: 0,    /**     * The right constraint     * @property maxX     * @type int     * @private     */    maxX: 0,    /**     * The up constraint     * @property minY     * @type int     * @type int     * @private     */    minY: 0,    /**     * The down constraint     * @property maxY     * @type int     * @private     */    maxY: 0,    /**     * Maintain offsets when we resetconstraints.  Set to true when you want     * the position of the element relative to its parent to stay the same     * when the page changes     *     * @property maintainOffset     * @type boolean     */    maintainOffset: false,    /**     * Array of pixel locations the element will snap to if we specified a     * horizontal graduation/interval.  This array is generated automatically     * when you define a tick interval.     * @property xTicks     * @type int[]     */    xTicks: null,    /**     * Array of pixel locations the element will snap to if we specified a     * vertical graduation/interval.  This array is generated automatically     * when you define a tick interval.     * @property yTicks     * @type int[]     */    yTicks: null,    /**     * By default the drag and drop instance will only respond to the primary     * button click (left button for a right-handed mouse).  Set to true to     * allow drag and drop to start with any mouse click that is propogated     * by the browser     * @property primaryButtonOnly     * @type boolean     */    primaryButtonOnly: true,    /**     * The availabe property is false until the linked dom element is accessible.     * @property available     * @type boolean     */    available: false,    /**     * By default, drags can only be initiated if the mousedown occurs in the     * region the linked element is.  This is done in part to work around a     * bug in some browsers that mis-report the mousedown if the previous     * mouseup happened outside of the window.  This property is set to true     * if outer handles are defined.     *     * @property hasOuterHandles     * @type boolean     * @default false     */    hasOuterHandles: false,    /**     * Code that executes immediately before the startDrag event     * @method b4StartDrag     * @private     */    b4StartDrag: function(x, y) { },    /**     * Abstract method called after a drag/drop object is clicked     * and the drag or mousedown time thresholds have beeen met.     * @method startDrag     * @param {int} X click location     * @param {int} Y click location     */    startDrag: function(x, y) { /* override this */ },    /**     * Code that executes immediately before the onDrag event     * @method b4Drag     * @private     */    b4Drag: function(e) { },    /**     * Abstract method called during the onMouseMove event while dragging an     * object.     * @method onDrag     * @param {Event} e the mousemove event     */    onDrag: function(e) { /* override this */ },    /**     * Abstract method called when this element fist begins hovering over     * another DragDrop obj     * @method onDragEnter     * @param {Event} e the mousemove event     * @param {String|DragDrop[]} id In POINT mode, the element     * id this is hovering over.  In INTERSECT mode, an array of one or more     * dragdrop items being hovered over.     */    onDragEnter: function(e, id) { /* override this */ },    /**     * Code that executes immediately before the onDragOver event     * @method b4DragOver     * @private     */    b4DragOver: function(e) { },    /**     * Abstract method called when this element is hovering over another     * DragDrop obj     * @method onDragOver     * @param {Event} e the mousemove event     * @param {String|DragDrop[]} id In POINT mode, the element     * id this is hovering over.  In INTERSECT mode, an array of dd items     * being hovered over.     */    onDragOver: function(e, id) { /* override this */ },    /**     * Code that executes immediately before the onDragOut event     * @method b4DragOut     * @private     */    b4DragOut: function(e) { },    /**     * Abstract method called when we are no longer hovering over an element     * @method onDragOut     * @param {Event} e the mousemove event     * @param {String|DragDrop[]} id In POINT mode, the element     * id this was hovering over.  In INTERSECT mode, an array of dd items     * that the mouse is no longer over.     */    onDragOut: function(e, id) { /* override this */ },    /**     * Code that executes immediately before the onDragDrop event     * @method b4DragDrop     * @private     */    b4DragDrop: function(e) { },    /**     * Abstract method called when this item is dropped on another DragDrop     * obj     * @method onDragDrop     * @param {Event} e the mouseup event     * @param {String|DragDrop[]} id In POINT mode, the element     * id this was dropped on.  In INTERSECT mode, an array of dd items this     * was dropped on.     */    onDragDrop: function(e, id) { /* override this */ },    /**     * Abstract method called when this item is dropped on an area with no     * drop target     * @method onInvalidDrop     * @param {Event} e the mouseup event     */    onInvalidDrop: function(e) { /* override this */ },    /**     * Code that executes immediately before the endDrag event     * @method b4EndDrag

⌨️ 快捷键说明

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