dragdrop-debug.js

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

JS
2,038
字号
        handleMouseDown: function(e, oDD) {            this.currentTarget = YAHOO.util.Event.getTarget(e);            this.logger.log("mousedown - adding event handlers");            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);                    },                    this.clickTimeThresh );        },        /**         * Fired when either the drag pixel threshol 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) {            this.logger.log("firing drag start events");            clearTimeout(this.clickTimeout);            if (this.dragCurrent) {                this.dragCurrent.b4StartDrag(x, y);                this.dragCurrent.startDrag(x, 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) {                return;            }            clearTimeout(this.clickTimeout);            if (this.dragThreshMet) {                this.logger.log("mouseup detected - completing drag");                this.fireEvents(e, true);            } else {                this.logger.log("drag threshold not met");            }            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);            }        },        /**         * Internal function to clean up event handlers after the drag         * operation is complete         * @method stopDrag         * @param {Event} e the event         * @private         * @static         */        stopDrag: function(e) {            // this.logger.log("mouseup - removing event handlers");            // Fire the drag end event for the item that was dragged            if (this.dragCurrent) {                if (this.dragThreshMet) {                    this.logger.log("firing endDrag events");                    this.dragCurrent.b4EndDrag(e);                    this.dragCurrent.endDrag(e);                }                this.logger.log("firing mouseUp event");                this.dragCurrent.onMouseUp(e);            }            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         * detect this in internet explorer by verifying that the mouse is         * down during the mousemove event.  Firefox doesn't give us the         * button state on the mousemove event.         * @method handleMouseMove         * @param {Event} e the event         * @private         * @static         */        handleMouseMove: function(e) {            //this.logger.log("handlemousemove");            if (! this.dragCurrent) {                // this.logger.log("no current drag obj");                return true;            }            // var button = e.which || e.button;            // this.logger.log("which: " + e.which + ", button: "+ e.button);            // check for IE mouseup outside of page boundary            if (YAHOO.util.Event.isIE && !e.button) {                this.logger.log("button failure");                this.stopEvent(e);                return this.handleMouseUp(e);            }            if (!this.dragThreshMet) {                var diffX = Math.abs(this.startX - YAHOO.util.Event.getPageX(e));                var diffY = Math.abs(this.startY - YAHOO.util.Event.getPageY(e));                // this.logger.log("diffX: " + diffX + "diffY: " + diffY);                if (diffX > this.clickPixelThresh ||                            diffY > this.clickPixelThresh) {                    this.logger.log("pixel threshold met");                    this.startDrag(this.startX, this.startY);                }            }            if (this.dragThreshMet) {                this.dragCurrent.b4Drag(e);                this.dragCurrent.onDrag(e);                this.fireEvents(e, false);            }            this.stopEvent(e);            return true;        },        /**         * Iterates over all of the DragDrop elements to find ones we are         * hovering over or dropping on         * @method fireEvents         * @param {Event} e the event         * @param {boolean} isDrop is this a drop op or a mouseover op?         * @private         * @static         */        fireEvents: function(e, isDrop) {            var dc = this.dragCurrent;            // If the user did the mouse up outside of the window, we could            // get here even though we have ended the drag.            if (!dc || dc.isLocked()) {                return;            }            var x = YAHOO.util.Event.getPageX(e);            var y = YAHOO.util.Event.getPageY(e);            var pt = new YAHOO.util.Point(x,y);            // cache the previous dragOver array            var oldOvers = [];            var outEvts   = [];            var overEvts  = [];            var dropEvts  = [];            var enterEvts = [];            // Check to see if the object(s) we were hovering over is no longer            // being hovered over so we can fire the onDragOut event            for (var i in this.dragOvers) {                var ddo = this.dragOvers[i];                if (! this.isTypeOfDD(ddo)) {                    continue;                }                if (! this.isOverTarget(pt, ddo, this.mode)) {                    outEvts.push( ddo );                }                oldOvers[i] = true;                delete this.dragOvers[i];            }            for (var sGroup in dc.groups) {                // this.logger.log("Processing group " + sGroup);                if ("string" != typeof sGroup) {                    continue;                }                for (i in this.ids[sGroup]) {                    var oDD = this.ids[sGroup][i];                    if (! this.isTypeOfDD(oDD)) {                        continue;                    }                    if (oDD.isTarget && !oDD.isLocked() && oDD != dc) {                        if (this.isOverTarget(pt, oDD, this.mode)) {                            // look for drop interactions                            if (isDrop) {                                dropEvts.push( oDD );                            // look for drag enter and drag over interactions                            } else {                                // initial drag over: dragEnter fires                                if (!oldOvers[oDD.id]) {                                    enterEvts.push( oDD );                                // subsequent drag overs: dragOver fires                                } else {                                    overEvts.push( oDD );                                }                                this.dragOvers[oDD.id] = oDD;                            }                        }                    }                }            }            if (this.mode) {                if (outEvts.length) {                    this.logger.log(dc.id+" onDragOut: " + outEvts);                    dc.b4DragOut(e, outEvts);                    dc.onDragOut(e, outEvts);                }                if (enterEvts.length) {                    this.logger.log(dc.id+" onDragEnter: " + enterEvts);                    dc.onDragEnter(e, enterEvts);                }                if (overEvts.length) {                    this.logger.log(dc.id+" onDragOver: " + overEvts);                    dc.b4DragOver(e, overEvts);                    dc.onDragOver(e, overEvts);                }                if (dropEvts.length) {                    this.logger.log(dc.id+" onDragDrop: " + dropEvts);                    dc.b4DragDrop(e, dropEvts);                    dc.onDragDrop(e, dropEvts);                }            } else {                // fire dragout events                var len = 0;                for (i=0, len=outEvts.length; i<len; ++i) {                    this.logger.log(dc.id+" onDragOut: " + outEvts[i].id);                    dc.b4DragOut(e, outEvts[i].id);                    dc.onDragOut(e, outEvts[i].id);                }                // fire enter events                for (i=0,len=enterEvts.length; i<len; ++i) {                    this.logger.log(dc.id + " onDragEnter " + enterEvts[i].id);                    // dc.b4DragEnter(e, oDD.id);                    dc.onDragEnter(e, enterEvts[i].id);                }                // fire over events                for (i=0,len=overEvts.length; i<len; ++i) {                    this.logger.log(dc.id + " onDragOver " + overEvts[i].id);                    dc.b4DragOver(e, overEvts[i].id);                    dc.onDragOver(e, overEvts[i].id);                }                // fire drop events                for (i=0, len=dropEvts.length; i<len; ++i) {                    this.logger.log(dc.id + " dropped on " + dropEvts[i].id);                    dc.b4DragDrop(e, dropEvts[i].id);                    dc.onDragDrop(e, dropEvts[i].id);                }            }            // notify about a drop that did not find a target            if (isDrop && !dropEvts.length) {                this.logger.log(dc.id + " dropped, but not on a target");                dc.onInvalidDrop(e);            }        },        /**         * Helper function for getting the best match from the list of drag         * and drop objects returned by the drag and drop events when we are         * in INTERSECT mode.  It returns either the first object that the         * cursor is over, or the object that has the greatest overlap with         * the dragged element.         * @method getBestMatch         * @param  {DragDrop[]} dds The array of drag and drop objects         * targeted         * @return {DragDrop}       The best single match         * @static         */        getBestMatch: function(dds) {            var winner = null;            // Return null if the input is not what we expect            //if (!dds || !dds.length || dds.length == 0) {               // winner = null;            // If there is only one item, it wins            //} else if (dds.length == 1) {            var len = dds.length;            if (len == 1) {                winner = dds[0];            } else {                // Loop through the targeted items                for (var i=0; i<len; ++i) {                    var dd = dds[i];                    // If the cursor is over the object, it wins.  If the                    // cursor is over multiple matches, the first one we come                    // to wins.                    if (dd.cursorIsOver) {                        winner = dd;                        break;                    // Otherwise the object with the most overlap wins                    } else {                        if (!winner ||                            winner.overlap.getArea() < dd.overlap.getArea()) {                            winner = dd;                        }                    }                }            }            return winner;        },        /**         * Refreshes the cache of the top-left and bottom-right points of the         * drag and drop objects in the specified group(s).  This is in the         * format that is stored in the drag and drop instance, so typical         * usage is:         * <code>         * YAHOO.util.DragDropMgr.refreshCache(ddinstance.groups);         * </code>         * Alternatively:         * <code>         * YAHOO.util.DragDropMgr.refreshCache({group1:true, group2:true});         * </code>         * @TODO this really should be an indexed array.  Alternatively this         * method could accept both.         * @method refreshCache         * @param {Object} groups an associative array of groups to refresh         * @static         */        refreshCache: function(groups) {            this.logger.log("refreshing element location cache");            for (var sGroup in groups) {                if ("string" != typeof sGroup) {                    continue;                }                for (var i in this.ids[sGroup]) {                    var oDD = this.ids[sGroup][i];                    if (this.isTypeOfDD(oDD)) {                    // if (this.isTypeOfDD(oDD) && oDD.isTarget) {                        var loc = this.getLocation(oDD);                        if (loc) {                            this.locationCache[oDD.id] = loc;                        } else {                            delete this.locationCache[oDD.id];                            this.logger.log("Could not get the loc for " + oDD.id,                                    "warn");                            // this will unregister the drag and drop object if                            // the element is not in a usable state                            // oDD.unreg();                        }                   

⌨️ 快捷键说明

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