📄 dragdrop-debug.js
字号:
YAHOO.log("firing endDrag events", "info", "DragDropMgr"); 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) { YAHOO.log("firing dragdrop onMouseUp event", "info", "DragDropMgr"); 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 * 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) { //YAHOO.log("handlemousemove"); var dc = this.dragCurrent; if (dc) { // YAHOO.log("no current drag obj"); // var button = e.which || e.button; // YAHOO.log("which: " + e.which + ", button: "+ e.button); // check for IE mouseup outside of page boundary if (YAHOO.util.Event.isIE && !e.button) { YAHOO.log("button failure", "info", "DragDropMgr"); this.stopEvent(e); return this.handleMouseUp(e); } else { if (e.clientX < 0 || e.clientY < 0) { //This will stop the element from leaving the viewport in FF, Opera & Safari //Not turned on yet //YAHOO.log("Either clientX or clientY is negative, stop the event.", "info", "DragDropMgr"); //this.stopEvent(e); //return false; } } 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)); // YAHOO.log("diffX: " + diffX + "diffY: " + diffY); if (diffX > this.clickPixelThresh || diffY > this.clickPixelThresh) { YAHOO.log("pixel threshold met", "info", "DragDropMgr"); this.startDrag(this.startX, this.startY); } } if (this.dragThreshMet) { if (dc && dc.events.b4Drag) { dc.b4Drag(e); dc.fireEvent('b4DragEvent', { e: e}); } if (dc && dc.events.drag) { dc.onDrag(e); dc.fireEvent('dragEvent', { e: e}); } if (dc) { this.fireEvents(e, false); } } this.stopEvent(e); } }, /** * 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 the config option dragOnly is true, bail out and don't fire the events if (!dc || dc.isLocked() || dc.dragOnly) { return; } var x = YAHOO.util.Event.getPageX(e), y = YAHOO.util.Event.getPageY(e), pt = new YAHOO.util.Point(x,y), pos = dc.getTargetCoord(pt.x, pt.y), el = dc.getDragEl(), events = ['out', 'over', 'drop', 'enter'], curRegion = new YAHOO.util.Region( pos.y, pos.x + el.offsetWidth, pos.y + el.offsetHeight, pos.x ), oldOvers = [], // cache the previous dragOver array inGroupsObj = {}, inGroups = [], data = { outEvts: [], overEvts: [], dropEvts: [], 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, curRegion)) { data.outEvts.push( ddo ); } oldOvers[i] = true; delete this.dragOvers[i]; } for (var sGroup in dc.groups) { // YAHOO.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, curRegion)) { inGroupsObj[sGroup] = true; // look for drop interactions if (isDrop) { data.dropEvts.push( oDD ); // look for drag enter and drag over interactions } else { // initial drag over: dragEnter fires if (!oldOvers[oDD.id]) { data.enterEvts.push( oDD ); // subsequent drag overs: dragOver fires } else { data.overEvts.push( oDD ); } this.dragOvers[oDD.id] = oDD; } } } } } this.interactionInfo = { out: data.outEvts, enter: data.enterEvts, over: data.overEvts, drop: data.dropEvts, point: pt, draggedRegion: curRegion, sourceRegion: this.locationCache[dc.id], validDrop: isDrop }; for (var inG in inGroupsObj) { inGroups.push(inG); } // notify about a drop that did not find a target if (isDrop && !data.dropEvts.length) { YAHOO.log(dc.id + " dropped, but not on a target", "info", "DragDropMgr"); this.interactionInfo.validDrop = false; if (dc.events.invalidDrop) { dc.onInvalidDrop(e); dc.fireEvent('invalidDropEvent', { e: e }); } } for (i = 0; i < events.length; i++) { var tmp = null; if (data[events[i] + 'Evts']) { tmp = data[events[i] + 'Evts']; } if (tmp && tmp.length) { var type = events[i].charAt(0).toUpperCase() + events[i].substr(1), ev = 'onDrag' + type, b4 = 'b4Drag' + type, cev = 'drag' + type + 'Event', check = 'drag' + type; if (this.mode) { YAHOO.log(dc.id + ' ' + ev + ': ' + tmp, "info", "DragDropMgr"); if (dc.events[b4]) { dc[b4](e, tmp, inGroups); dc.fireEvent(b4 + 'Event', { event: e, info: tmp, group: inGroups }); } if (dc.events[check]) { dc[ev](e, tmp, inGroups); dc.fireEvent(cev, { event: e, info: tmp, group: inGroups }); } } else { for (var b = 0, len = tmp.length; b < len; ++b) { YAHOO.log(dc.id + ' ' + ev + ': ' + tmp[b].id, "info", "DragDropMgr"); if (dc.events[b4]) { dc[b4](e, tmp[b].id, inGroups[0]); dc.fireEvent(b4 + 'Event', { event: e, info: tmp[b].id, group: inGroups[0] }); } if (dc.events[check]) { dc[ev](e, tmp[b].id, inGroups[0]); dc.fireEvent(cev, { event: e, info: tmp[b].id, group: inGroups[0] }); } } } } } }, /** * 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; 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 (this.mode == this.INTERSECT && dd.cursorIsOver) { winner = dd; break; // Otherwise the object with the most overlap wins } else { if (!winner || !winner.overlap || (dd.overlap && 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) { YAHOO.log("refreshing element location cache", "info", "DragDropMgr"); // refresh everything if group array is not provided var g = groups || this.ids; for (var sGroup in g) { if ("string" != typeof sGroup) { continue; } for (var i in this.ids[sGroup]) { var oDD = this.ids[sGroup][i]; if (this.isTypeOfDD(oDD)) { var loc = this.getLocation(oDD); if (loc) { this.locationCache[oDD.id] = loc; } else { delete this.locationCache[oDD.id];YAHOO.log("Could not get the loc for " + oDD.id, "warn", "DragDropMgr"); } } } } }, /** * This checks to make sure an element exists and is in the DOM. The * main purpose is to handle cases where innerHTML is used to remove * drag and drop objects from the DOM. IE provides an 'unspecified * error' when trying to access the offsetParent of such an element * @method verifyEl * @param {HTMLElement} el the element to check * @return {boolean} true if the element looks usable * @static */ verifyEl: function(el) { try { if (el) { var parent = el.offsetParent; if (parent) { return true; } } } catch(e) { YAHOO.log("detected problem with an element", "info", "DragDropMgr"); } return false; }, /** * Returns a Region object containing the drag and drop element's position * and size, including the padding configured for it * @method getLocation * @param {DragDrop} oDD the drag and drop object to get the * location for * @return {YAHOO.util.Region} a Region object representing the total area * the element occupies, including any padding * the instance is configured for. * @static */ getLocation: function(oDD) { if (! this.isTypeOfDD(oDD)) { YAHOO.log(oDD + " is not a DD obj", "info", "DragDropMgr"); return null; } var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l; try { pos= YAHOO.util.Dom.getXY(el); } catch (e) { } if (!pos) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -