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

📄 dragdrop.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
/*Copyright (c) 2008, Yahoo! Inc. All rights reserved.Code licensed under the BSD License:http://developer.yahoo.net/yui/license.txtversion: 2.6.0*//** * The drag and drop utility provides a framework for building drag and drop * applications.  In addition to enabling drag and drop for specific elements, * the drag and drop elements are tracked by the manager class, and the * interactions between the various elements are tracked during the drag and * the implementing code is notified about these important moments. * @module dragdrop * @title Drag and Drop * @requires yahoo,dom,event * @namespace YAHOO.util */// Only load the library once.  Rewriting the manager class would orphan // existing drag and drop instances.if (!YAHOO.util.DragDropMgr) {/** * DragDropMgr is a singleton that tracks the element interaction for  * all DragDrop items in the window.  Generally, you will not call  * this class directly, but it does have helper methods that could  * be useful in your DragDrop implementations. * @class DragDropMgr * @static */YAHOO.util.DragDropMgr = function() {    var Event = YAHOO.util.Event,        Dom = YAHOO.util.Dom;    return {        /**        * This property is used to turn on global use of the shim element on all DragDrop instances, defaults to false for backcompat. (Use: YAHOO.util.DDM.useShim = true)        * @property useShim        * @type Boolean        * @static        */        useShim: false,        /**        * This property is used to determine if the shim is active over the screen, default false.        * @private        * @property _shimActive        * @type Boolean        * @static        */        _shimActive: false,        /**        * This property is used when useShim is set on a DragDrop object to store the current state of DDM.useShim so it can be reset when a drag operation is done.        * @private        * @property _shimState        * @type Boolean        * @static        */        _shimState: false,        /**        * This property is used when useShim is set to true, it will set the opacity on the shim to .5 for debugging. Use: (YAHOO.util.DDM._debugShim = true;)        * @private        * @property _debugShim        * @type Boolean        * @static        */        _debugShim: false,        /**        * This method will create a shim element (giving it the id of yui-ddm-shim), it also attaches the mousemove and mouseup listeners to it and attaches a scroll listener on the window        * @private        * @method _sizeShim        * @static        */        _createShim: function() {            var s = document.createElement('div');            s.id = 'yui-ddm-shim';            if (document.body.firstChild) {                document.body.insertBefore(s, document.body.firstChild);            } else {                document.body.appendChild(s);            }            s.style.display = 'none';            s.style.backgroundColor = 'red';            s.style.position = 'absolute';            s.style.zIndex = '99999';            Dom.setStyle(s, 'opacity', '0');            this._shim = s;            Event.on(s, "mouseup",   this.handleMouseUp, this, true);            Event.on(s, "mousemove", this.handleMouseMove, this, true);            Event.on(window, 'scroll', this._sizeShim, this, true);        },        /**        * This method will size the shim, called from activate and on window scroll event        * @private        * @method _sizeShim        * @static        */        _sizeShim: function() {            if (this._shimActive) {                var s = this._shim;                s.style.height = Dom.getDocumentHeight() + 'px';                s.style.width = Dom.getDocumentWidth() + 'px';                s.style.top = '0';                s.style.left = '0';            }        },        /**        * This method will create the shim element if needed, then show the shim element, size the element and set the _shimActive property to true        * @private        * @method _activateShim        * @static        */        _activateShim: function() {            if (this.useShim) {                if (!this._shim) {                    this._createShim();                }                this._shimActive = true;                var s = this._shim,                    o = '0';                if (this._debugShim) {                    o = '.5';                }                Dom.setStyle(s, 'opacity', o);                this._sizeShim();                s.style.display = 'block';            }        },        /**        * This method will hide the shim element and set the _shimActive property to false        * @private        * @method _deactivateShim        * @static        */        _deactivateShim: function() {            this._shim.style.display = 'none';            this._shimActive = false;        },        /**        * The HTML element created to use as a shim over the document to track mouse movements        * @private        * @property _shim        * @type HTMLElement        * @static        */        _shim: null,        /**         * Two dimensional Array of registered DragDrop objects.  The first          * dimension is the DragDrop item group, the second the DragDrop          * object.         * @property ids         * @type {string: string}         * @private         * @static         */        ids: {},        /**         * Array of element ids defined as drag handles.  Used to determine          * if the element that generated the mousedown event is actually the          * handle and not the html element itself.         * @property handleIds         * @type {string: string}         * @private         * @static         */        handleIds: {},        /**         * the DragDrop object that is currently being dragged         * @property dragCurrent         * @type DragDrop         * @private         * @static         **/        dragCurrent: null,        /**         * the DragDrop object(s) that are being hovered over         * @property dragOvers         * @type Array         * @private         * @static         */        dragOvers: {},        /**         * the X distance between the cursor and the object being dragged         * @property deltaX         * @type int         * @private         * @static         */        deltaX: 0,        /**         * the Y distance between the cursor and the object being dragged         * @property deltaY         * @type int         * @private         * @static         */        deltaY: 0,        /**         * Flag to determine if we should prevent the default behavior of the         * events we define. By default this is true, but this can be set to          * false if you need the default behavior (not recommended)         * @property preventDefault         * @type boolean         * @static         */        preventDefault: true,        /**         * Flag to determine if we should stop the propagation of the events          * we generate. This is true by default but you may want to set it to         * false if the html element contains other features that require the         * mouse click.         * @property stopPropagation         * @type boolean         * @static         */        stopPropagation: true,        /**         * Internal flag that is set to true when drag and drop has been         * initialized         * @property initialized         * @private         * @static         */        initialized: false,        /**         * All drag and drop can be disabled.         * @property locked         * @private         * @static         */        locked: false,        /**         * Provides additional information about the the current set of         * interactions.  Can be accessed from the event handlers. It         * contains the following properties:         *         *       out:       onDragOut interactions         *       enter:     onDragEnter interactions         *       over:      onDragOver interactions         *       drop:      onDragDrop interactions         *       point:     The location of the cursor         *       draggedRegion: The location of dragged element at the time         *                      of the interaction         *       sourceRegion: The location of the source elemtn at the time         *                     of the interaction         *       validDrop: boolean         * @property interactionInfo         * @type object         * @static         */        interactionInfo: null,        /**         * Called the first time an element is registered.         * @method init         * @private         * @static         */        init: function() {            this.initialized = true;        },        /**         * In point mode, drag and drop interaction is defined by the          * location of the cursor during the drag/drop         * @property POINT         * @type int         * @static         * @final         */        POINT: 0,        /**         * In intersect mode, drag and drop interaction is defined by the          * cursor position or the amount of overlap of two or more drag and          * drop objects.         * @property INTERSECT         * @type int         * @static         * @final         */        INTERSECT: 1,        /**         * In intersect mode, drag and drop interaction is defined only by the          * overlap of two or more drag and drop objects.         * @property STRICT_INTERSECT         * @type int         * @static         * @final         */        STRICT_INTERSECT: 2,        /**         * The current drag and drop mode.  Default: POINT         * @property mode         * @type int         * @static         */        mode: 0,        /**         * Runs method on all drag and drop objects         * @method _execOnAll         * @private         * @static         */        _execOnAll: function(sMethod, args) {            for (var i in this.ids) {                for (var j in this.ids[i]) {                    var oDD = this.ids[i][j];                    if (! this.isTypeOfDD(oDD)) {                        continue;                    }                    oDD[sMethod].apply(oDD, args);                }            }        },        /**         * Drag and drop initialization.  Sets up the global event handlers         * @method _onLoad         * @private         * @static         */        _onLoad: function() {            this.init();            Event.on(document, "mouseup",   this.handleMouseUp, this, true);            Event.on(document, "mousemove", this.handleMouseMove, this, true);            Event.on(window,   "unload",    this._onUnload, this, true);            Event.on(window,   "resize",    this._onResize, this, true);            // Event.on(window,   "mouseout",    this._test);        },        /**         * Reset constraints on all drag and drop objs         * @method _onResize         * @private         * @static         */        _onResize: function(e) {            this._execOnAll("resetConstraints", []);        },        /**         * Lock all drag and drop functionality         * @method lock         * @static         */        lock: function() { this.locked = true; },        /**         * Unlock all drag and drop functionality         * @method unlock         * @static         */        unlock: function() { this.locked = false; },        /**         * Is drag and drop locked?         * @method isLocked         * @return {boolean} True if drag and drop is locked, false otherwise.         * @static         */        isLocked: function() { return this.locked; },        /**         * Location cache that is set for all drag drop objects when a drag is         * initiated, cleared when the drag is finished.         * @property locationCache         * @private         * @static         */        locationCache: {},        /**         * Set useCache to false if you want to force object the lookup of each         * drag and drop linked element constantly during a drag.         * @property useCache         * @type boolean         * @static         */        useCache: true,        /**         * The number of pixels that the mouse needs to move after the          * mousedown before the drag is initiated.  Default=3;         * @property clickPixelThresh

⌨️ 快捷键说明

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