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

📄 cellselection.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 3 页
字号:
		changedCells = changedCells.concat(this._setCellRangeSelection(rowNum+1, 0, this.data.length-1, this.numCols-1, false));		this.changedCells = changedCells;		return this._cellSelectionsChanged();},selectSingleCol : function (colNum) {	var changedCells = [];		// deselect columns before this one	if (colNum > 0)		changedCells = this._setCellRangeSelection(0, 0, this.data.length-1, colNum-1, false);	// select this column	changedCells = changedCells.concat(this._setCellRangeSelection(0, colNum, this.data.length-1, colNum, true));		// deselect columns after this one	if (colNum < this.numCols-1)		changedCells = changedCells.concat(this._setCellRangeSelection(0, colNum+1, this.data.length-1, this.numCols-1, false));		this.changedCells = changedCells;		return this._cellSelectionsChanged();},//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//~~~~~ Event-based Selection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//>	@method	cellSelection.selectOnMouseDown()	(A)//		@group	selection, mouseEvents//			Update the selection as the result of a mouseDown event.//			Handles shift, control, etc. key selection as well.//			Call this from a mouseDown handler.//		@see	GridRenderer.mouseDown()//      @see    ListGrid.mouseDown()////		@param	target	(Canvas)	target object//		@param	recordNum	(number)	record number mouse went down on////		@return			(boolean)	true == selection was changed, false == no change//<selectOnMouseDown : function (target, rowNum, colNum) {	// if the target's selectionType is NONE, just bail	if (target.selectionType == isc.Selection.NONE)	return false;	    // remember mouseDown location in case we start drag selecting    this.startRow = this.lastRow = rowNum;    this.startCol = this.lastCol = colNum;	var cellSelected = this.cellIsSelected(rowNum, colNum),		selection = this.getSelectedCells(),		selectionBounds = this.getSelectionBounds();	// clear flags for deselecting cells on mouseUp	// these are set in the simple and normal cases below (3 and 5)	// see selectOnMouseUp() for details	this.deselectCellOnMouseUp = false;	this.deselectOthersOnMouseUp = false;		// Case 1: SINGLE selection	if (target.selectionType == isc.Selection.SINGLE) {		this.selectSingleCell(rowNum, colNum);		return true;	// Case 2: Shift-selection (select contiguous range of cells)	} else if (isc.EventHandler.shiftKeyDown()) {		// if nothing was selected,		if (selection.length == 0) {			// simply select that cell			this.selectCell(rowNum, colNum);			return true;						// otherwise since something was selected		} else {			// select a range of cells			var startRow = selectionBounds[0],				startCol = selectionBounds[1],				endRow = selectionBounds[2],				endCol = selectionBounds[3];			if (rowNum < startRow)				startRow = rowNum;			else if (rowNum >= endRow)				endRow = rowNum;			else {	// XXX if rowNum=startRow, rowNum+1 isn't correct				this.deselectCellRange(rowNum+1,startCol,endRow,endCol);				endRow = rowNum;			}						if (colNum < startCol)				startCol = colNum;			else if (colNum >= endCol)				endCol = colNum;			else {				this.deselectCellRange(startRow,colNum+1,endRow,endCol);				endCol = colNum;			}						this.selectCellRange(startRow,startCol,endRow,endCol);						return true;		}	// Case 3: SIMPLE selection (toggle selection of this cell, but defer deselection until mouseUp)	} else if (target.selectionType == isc.Selection.SIMPLE) {		if (!cellSelected) {			this.selectCell(rowNum, colNum);			return true;		} else {			this.deselectCellOnMouseUp = true;			return false;		}	// Case 4: meta-key selection (simply toggle selection of this record)	} else if (isc.Browser.isMac ? isc.EventHandler.metaKeyDown()                                  : isc.EventHandler.ctrlKeyDown()) {		this.setCellSelection(rowNum, colNum, !cellSelected);		return true;	// Case 5: normal selection (no modifier keys)	} else {        if (!cellSelected) {            // if you click outside of the selection, select the new cell and deselect everything            // else            this.selectSingleCell(rowNum, colNum);            return true;        } else if (isc.EventHandler.rightButtonDown()) {            // never deselect if you right click on the selection, unless you start drag selecting            this.deselectOnDragMove = true;            return false;        } else {            // simpleDeselect mode: this mode is designed to make it easy to entirely get rid of            // your selection, so you don't have to know about ctrl-clicking.  In a nutshell, if you            // click on the existing selection, it will be entirely deselected.             if (this.dragSelection) {                if (this.simpleDeselect) {                    // if you click on the selection, deselect the entire selection including the                    // clicked-on cell.  Later, if a drag begins, select the clicked-on cell.                    this.deselectAll();                    this.selectOriginOnDragMove = true;                    return true;                }                // for a drag selection, deselect others immediately; otherwise we'll be dragging                // out a new selection within/overlapping with an existing selection, which we only                // want to do on a ctrl-click.  This matches Excel.                this.selectSingleCell(rowNum, colNum);                return true;            } else {                if (this.simpleDeselect) {                    // deselect everything on mouseUp, including the cell clicked on                    this.deselectAllOnMouseUp = true;                } else {                    // if we click in a multiple selection, deselect everything but the clicked-on                    // item, but don't do it until mouseUp in order to allow dragging the current                    // selection.  This matches Windows Explorer.                    this.deselectOthersOnMouseUp = (selection.length > 1);                }                return false;            }        }	}},//>	@method	cellSelection.selectOnDragMove()	(A)//			during drag selection, update the selection as a result of a dragMove event//		@group	selection, mouseEvents//<selectOnDragMove : function (target, currRow, currCol) {    var startRow = this.startRow,        startCol = this.startCol,        lastRow = this.lastRow,        lastCol = this.lastCol;    if (currRow < 0 || currCol < 0) {        //>DEBUG        this.logWarn("selectOnDragMove: aborting due to negative coordinate: " +                      [currRow, currCol]);        //<DEBUG        return;    }    if (currRow == lastRow && currCol == lastCol) return; // no change    //this.logWarn("selectOnDragMove: start: " + [startRow, startCol] +    //             ", last: " + [lastRow, lastCol] +    //             " current: " + [currRow, currCol]);    var changedCells = [];    if (this.selectOriginOnDragMove) {        this._setCellSelection(startRow, startCol);        changedCells.add([startRow, startCol]);        this.selectOriginOnDragMove = false;    } else if (this.deselectOnDragMove || this.deselectAllOnMouseUp || this.deselectOthersOnMouseUp) {        // deselect on dragMove is for right-dragging.  The others flags are failsafes in case you        // use drag selection without setting the flag.        this.selectSingleCell(startRow, startCol);        this.deselectAllOnMouseUp = this.deselectOthersOnMouseUp = this.deselectOnDragMove = false;    }    // If the mouse has moved further away from the start position since the last dragMove, select    // more cells.  If it's moved closer to the start position, deselect cells.    // There are 6 possible orderings of start, last and current position, thus 6 cases per    // direction.    // The two orderings (per direction) of (last, start, current) and (current, start, last)    // indicate the mouse has moved across the start position.  In this case the old selection area    // and new selection area are guaranteed non-overlapping, except for the single start cell.    if (        // if moved on the "rows" axis and crossed the origin        (currRow != lastRow &&         ((lastRow >= startRow && startRow >= currRow) ||           (currRow >= startRow && startRow >= lastRow)))        ||        // or we moved on the "cols" axis and crossed the origin        (currCol != lastCol &&         ((lastCol >= startCol && startCol >= currCol) ||           (currCol >= startCol && startCol >= lastCol)))        )    {        // NOTE: The start cell doesn't change, but it would appear to deselect and reselect if we        // naively deselected the old rect and selected the new, so we manually deselect and select        // the start cell, so it isn't listed in the changed cells.        // deselect the entire range that has been drag selected so far        this._setCellSelection(startRow, startCol, false);        changedCells.addList(            this._setCellRangeSelection(startRow, startCol, lastRow, lastCol, false));        // then select the new area.         this._setCellSelection(startRow, startCol, true);        changedCells.addList(            this._setCellRangeSelection(startRow, startCol, currRow, currCol, true));                this.changedCells = changedCells;        this._cellSelectionsChanged();                this.lastRow = currRow;        this.lastCol = currCol;        return;    }    // The other four orderings of last, start and current indicate a shrinking or growth of the    // selection area, with the new selection area overlapping the old.    // The increase or decrease in selection always consists of two rectangles, one for the    // increase/decrease of selection in the horizontal direction, one for the increase/decrease of    // selection in the vertical direction.  These rectangles will potentially overlap at the    // corner, so the vertical case includes the corner and the horizontal case does not.    // NOTE: we manually combine the changed cell list from the two selection changes, so that    // there's only one selectionChanged() event seen by observers.    if (currRow >= 0 && currRow != lastRow) {        // moved vertically        if (startRow >= lastRow && lastRow > currRow) {            // increasing selection upward (last < start)            changedCells.addList(                this._setCellRangeSelection(currRow, startCol, lastRow-1, lastCol, true));        } else if (startRow >= currRow && currRow > lastRow) {            // decreasing selection downward (last < start)            changedCells.addList(                this._setCellRangeSelection(lastRow, startCol, currRow-1, lastCol, false));        } else if (startRow <= currRow && currRow < lastRow) {            // decreasing selection upward (last > start)            changedCells.addList(                this._setCellRangeSelection(currRow+1, startCol, lastRow, lastCol, false));        } else if (startRow <= lastRow && lastRow < currRow) {            // increasing selection downward (last > start)            changedCells.addList(                this._setCellRangeSelection(lastRow+1, startCol, currRow, lastCol, true));                }                // NOTE: we change lastRow because we want the horizontal case to handle the corner area        // between current and last.        lastRow = this.lastRow = currRow;    }        if (currCol >= 0 && currCol != lastCol) {        // moved horizontally         if (startCol >= lastCol && lastCol > currCol) {            // increasing selection on the left (last < start)            changedCells.addList(                this._setCellRangeSelection(startRow, currCol, lastRow, lastCol-1, true));        } else if (startCol >= currCol && currCol > lastCol) {            // decreasing selection on the left (last < start)            changedCells.addList(                this._setCellRangeSelection(startRow, lastCol, lastRow, currCol-1, false));        } else if (startCol <= currCol && currCol < lastCol) {            // decreasing selection on the right (last > start)            changedCells.addList(                this._setCellRangeSelection(startRow, currCol+1, lastRow, lastCol, false));        } else if (startCol <= lastCol && lastCol < currCol) {            // increasing selection on the right (last > start)            changedCells.addList(                this._setCellRangeSelection(startRow, lastCol+1, lastRow, currCol, true));                }                this.lastCol = currCol;    }    this.changedCells = changedCells;    this._cellSelectionsChanged();},//>	@method	cellSelection.selectOnMouseUp()	(A)s//			Update the selection as the result of a mouseUp event.//			We currently use this to defer deselection for drag-and-drop of multiple records.//			Call this from a mouseUp handler.//		@group	selection, mouseEvents//		@see	ListGrid.mouseUp()////		@param	target	(Canvas)	target object//		@param	recordNum	(number)	record number mouse went down on////		@return			(boolean)	true == selection was changed, false == no change//<selectOnMouseUp : function (target, rowNum, colNum) {	// if the target's selectionType is NONE, just bail	if (target.selectionType == isc.Selection.NONE)	return false;	//		If multiselection is on and no modifier keys are down, we need to	// deselect any cells other than the one that is clicked. BUT, we can't do this in	// selectOnMouseDown() because the user might be clicking on a cell in a multiple selection	// to initiate a drag operation with all of the selected cells. So in selectOnMouseDown()	// we set a deselectOthersOnMouseUp flag that we can check here and do the deselection	// if necessary.	if (this.deselectOthersOnMouseUp) {		this.selectSingleCell(rowNum, colNum);        this.deselectOthersOnMouseUp = false;		return true;	//		Similarly, if SIMPLE selection is enabled we don't want to deselect the current	// cell if the user is initiating a drag. We set a deselectRecordOnMouseUp flag in this case.	} else if (this.deselectRecordOnMouseUp) {		this.deselectCell(rowNum, colNum);        this.deselectRecordOnMouseUp = false;		return true;    } else if (this.deselectAllOnMouseUp) {        this.deselectAll();        this.deselectAllOnMouseUp = false;	} else		return false;}});	// END isc.CellSelection.addMethods()

⌨️ 快捷键说明

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