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

📄 dragdrop.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
         * @type int         * @static         */        clickPixelThresh: 3,        /**         * The number of milliseconds after the mousedown event to initiate the         * drag if we don't get a mouseup event. Default=1000         * @property clickTimeThresh         * @type int         * @static         */        clickTimeThresh: 1000,        /**         * Flag that indicates that either the drag pixel threshold or the          * mousdown time threshold has been met         * @property dragThreshMet         * @type boolean         * @private         * @static         */        dragThreshMet: false,        /**         * Timeout used for the click time threshold         * @property clickTimeout         * @type Object         * @private         * @static         */        clickTimeout: null,        /**         * The X position of the mousedown event stored for later use when a          * drag threshold is met.         * @property startX         * @type int         * @private         * @static         */        startX: 0,        /**         * The Y position of the mousedown event stored for later use when a          * drag threshold is met.         * @property startY         * @type int         * @private         * @static         */        startY: 0,        /**         * Flag to determine if the drag event was fired from the click timeout and         * not the mouse move threshold.         * @property fromTimeout         * @type boolean         * @private         * @static         */        fromTimeout: false,        /**         * Each DragDrop instance must be registered with the DragDropMgr.           * This is executed in DragDrop.init()         * @method regDragDrop         * @param {DragDrop} oDD the DragDrop object to register         * @param {String} sGroup the name of the group this element belongs to         * @static         */        regDragDrop: function(oDD, sGroup) {            if (!this.initialized) { this.init(); }                        if (!this.ids[sGroup]) {                this.ids[sGroup] = {};            }            this.ids[sGroup][oDD.id] = oDD;        },        /**         * Removes the supplied dd instance from the supplied group. Executed         * by DragDrop.removeFromGroup, so don't call this function directly.         * @method removeDDFromGroup         * @private         * @static         */        removeDDFromGroup: function(oDD, sGroup) {            if (!this.ids[sGroup]) {                this.ids[sGroup] = {};            }            var obj = this.ids[sGroup];            if (obj && obj[oDD.id]) {                delete obj[oDD.id];            }        },        /**         * Unregisters a drag and drop item.  This is executed in          * DragDrop.unreg, use that method instead of calling this directly.         * @method _remove         * @private         * @static         */        _remove: function(oDD) {            for (var g in oDD.groups) {                if (g) {                    var item = this.ids[g];                    if (item && item[oDD.id]) {                        delete item[oDD.id];                    }                }                            }            delete this.handleIds[oDD.id];        },        /**         * Each DragDrop handle element must be registered.  This is done         * automatically when executing DragDrop.setHandleElId()         * @method regHandle         * @param {String} sDDId the DragDrop id this element is a handle for         * @param {String} sHandleId the id of the element that is the drag          * handle         * @static         */        regHandle: function(sDDId, sHandleId) {            if (!this.handleIds[sDDId]) {                this.handleIds[sDDId] = {};            }            this.handleIds[sDDId][sHandleId] = sHandleId;        },        /**         * Utility function to determine if a given element has been          * registered as a drag drop item.         * @method isDragDrop         * @param {String} id the element id to check         * @return {boolean} true if this element is a DragDrop item,          * false otherwise         * @static         */        isDragDrop: function(id) {            return ( this.getDDById(id) ) ? true : false;        },        /**         * Returns the drag and drop instances that are in all groups the         * passed in instance belongs to.         * @method getRelated         * @param {DragDrop} p_oDD the obj to get related data for         * @param {boolean} bTargetsOnly if true, only return targetable objs         * @return {DragDrop[]} the related instances         * @static         */        getRelated: function(p_oDD, bTargetsOnly) {            var oDDs = [];            for (var i in p_oDD.groups) {                for (var j in this.ids[i]) {                    var dd = this.ids[i][j];                    if (! this.isTypeOfDD(dd)) {                        continue;                    }                    if (!bTargetsOnly || dd.isTarget) {                        oDDs[oDDs.length] = dd;                    }                }            }            return oDDs;        },        /**         * Returns true if the specified dd target is a legal target for          * the specifice drag obj         * @method isLegalTarget         * @param {DragDrop} the drag obj         * @param {DragDrop} the target         * @return {boolean} true if the target is a legal target for the          * dd obj         * @static         */        isLegalTarget: function (oDD, oTargetDD) {            var targets = this.getRelated(oDD, true);            for (var i=0, len=targets.length;i<len;++i) {                if (targets[i].id == oTargetDD.id) {                    return true;                }            }            return false;        },        /**         * My goal is to be able to transparently determine if an object is         * typeof DragDrop, and the exact subclass of DragDrop.  typeof          * returns "object", oDD.constructor.toString() always returns         * "DragDrop" and not the name of the subclass.  So for now it just         * evaluates a well-known variable in DragDrop.         * @method isTypeOfDD         * @param {Object} the object to evaluate         * @return {boolean} true if typeof oDD = DragDrop         * @static         */        isTypeOfDD: function (oDD) {            return (oDD && oDD.__ygDragDrop);        },        /**         * Utility function to determine if a given element has been          * registered as a drag drop handle for the given Drag Drop object.         * @method isHandle         * @param {String} id the element id to check         * @return {boolean} true if this element is a DragDrop handle, false          * otherwise         * @static         */        isHandle: function(sDDId, sHandleId) {            return ( this.handleIds[sDDId] &&                             this.handleIds[sDDId][sHandleId] );        },        /**         * Returns the DragDrop instance for a given id         * @method getDDById         * @param {String} id the id of the DragDrop object         * @return {DragDrop} the drag drop object, null if it is not found         * @static         */        getDDById: function(id) {            for (var i in this.ids) {                if (this.ids[i][id]) {                    return this.ids[i][id];                }            }            return null;        },        /**         * Fired after a registered DragDrop object gets the mousedown event.         * Sets up the events required to track the object being dragged         * @method handleMouseDown         * @param {Event} e the event         * @param oDD the DragDrop object being dragged         * @private         * @static         */        handleMouseDown: function(e, oDD) {            //this._activateShim();            this.currentTarget = YAHOO.util.Event.getTarget(e);            this.dragCurrent = oDD;            var el = oDD.getEl();            // track start position            this.startX = YAHOO.util.Event.getPageX(e);            this.startY = YAHOO.util.Event.getPageY(e);            this.deltaX = this.startX - el.offsetLeft;            this.deltaY = this.startY - el.offsetTop;            this.dragThreshMet = false;            this.clickTimeout = setTimeout(                     function() {                         var DDM = YAHOO.util.DDM;                        DDM.startDrag(DDM.startX, DDM.startY);                        DDM.fromTimeout = true;                    },                     this.clickTimeThresh );        },        /**         * Fired when either the drag pixel threshold or the mousedown hold          * time threshold has been met.         * @method startDrag         * @param x {int} the X position of the original mousedown         * @param y {int} the Y position of the original mousedown         * @static         */        startDrag: function(x, y) {            if (this.dragCurrent && this.dragCurrent.useShim) {                this._shimState = this.useShim;                this.useShim = true;            }            this._activateShim();            clearTimeout(this.clickTimeout);            var dc = this.dragCurrent;            if (dc && dc.events.b4StartDrag) {                dc.b4StartDrag(x, y);                dc.fireEvent('b4StartDragEvent', { x: x, y: y });            }            if (dc && dc.events.startDrag) {                dc.startDrag(x, y);                dc.fireEvent('startDragEvent', { x: x, y: y });            }            this.dragThreshMet = true;        },        /**         * Internal function to handle the mouseup event.  Will be invoked          * from the context of the document.         * @method handleMouseUp         * @param {Event} e the event         * @private         * @static         */        handleMouseUp: function(e) {            if (this.dragCurrent) {                clearTimeout(this.clickTimeout);                if (this.dragThreshMet) {                    if (this.fromTimeout) {                        this.fromTimeout = false;                        this.handleMouseMove(e);                    }                    this.fromTimeout = false;                    this.fireEvents(e, true);                } else {                }                this.stopDrag(e);                this.stopEvent(e);            }        },        /**         * Utility to stop event propagation and event default, if these          * features are turned on.         * @method stopEvent         * @param {Event} e the event as returned by this.getEvent()         * @static         */        stopEvent: function(e) {            if (this.stopPropagation) {                YAHOO.util.Event.stopPropagation(e);            }            if (this.preventDefault) {                YAHOO.util.Event.preventDefault(e);            }        },        /**          * Ends the current drag, cleans up the state, and fires the endDrag         * and mouseUp events.  Called internally when a mouseup is detected         * during the drag.  Can be fired manually during the drag by passing         * either another event (such as the mousemove event received in onDrag)         * or a fake event with pageX and pageY defined (so that endDrag and         * onMouseUp have usable position data.).  Alternatively, pass true         * for the silent parameter so that the endDrag and onMouseUp events         * are skipped (so no event data is needed.)         *         * @method stopDrag         * @param {Event} e the mouseup event, another event (or a fake event)          *                  with pageX and pageY defined, or nothing if the          *                  silent parameter is true         * @param {boolean} silent skips the enddrag and mouseup events if true         * @static         */        stopDrag: function(e, silent) {            var dc = this.dragCurrent;            // Fire the drag end event for the item that was dragged            if (dc && !silent) {                if (this.dragThreshMet) {                    if (dc.events.b4EndDrag) {                        dc.b4EndDrag(e);                        dc.fireEvent('b4EndDragEvent', { e: e });                    }                    if (dc.events.endDrag) {                        dc.endDrag(e);                        dc.fireEvent('endDragEvent', { e: e });                    }                }                if (dc.events.mouseUp) {                    dc.onMouseUp(e);                    dc.fireEvent('mouseUpEvent', { e: e });                }            }            if (this._shimActive) {                this._deactivateShim();                if (this.dragCurrent && this.dragCurrent.useShim) {                    this.useShim = this._shimState;                    this._shimState = false;                }            }            this.dragCurrent = null;            this.dragOvers = {};        },        /**          * Internal function to handle the mousemove event.  Will be invoked          * from the context of the html element.         *         * @TODO figure out what we can do about mouse events lost when the          * user drags objects beyond the window boundary.  Currently we can 

⌨️ 快捷键说明

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