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

📄 jquery.tablednd.js

📁 news新闻系统. news新闻系统 news新闻系统
💻 JS
📖 第 1 页 / 共 2 页
字号:
    /** Get the position of an element by going up the DOM tree and adding up all the offsets */    getPosition: function(e){        var left = 0;        var top  = 0;        /** Safari fix -- thanks to Luis Chato for this! */        if (e.offsetHeight == 0) {            /** Safari 2 doesn't correctly grab the offsetTop of a table row            this is detailed here:            http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in-safari/            the solution is likewise noted there, grab the offset of a table cell in the row - the firstChild.            note that firefox will return a text node as a first child, so designing a more thorough            solution may need to take that into account, for now this seems to work in firefox, safari, ie */            e = e.firstChild; // a table cell        }		if (e && e.offsetParent) {        	while (e.offsetParent){            	left += e.offsetLeft;            	top  += e.offsetTop;            	e     = e.offsetParent;        	}        	left += e.offsetLeft;        	top  += e.offsetTop;        }        return {x:left, y:top};    },    mousemove: function(ev) {        if (jQuery.tableDnD.dragObject == null) {            return;        }        var dragObj = jQuery(jQuery.tableDnD.dragObject);        var config = jQuery.tableDnD.currentTable.tableDnDConfig;        var mousePos = jQuery.tableDnD.mouseCoords(ev);        var y = mousePos.y - jQuery.tableDnD.mouseOffset.y;        //auto scroll the window	    var yOffset = window.pageYOffset;	 	if (document.all) {	        // Windows version	        //yOffset=document.body.scrollTop;	        if (typeof document.compatMode != 'undefined' &&	             document.compatMode != 'BackCompat') {	           yOffset = document.documentElement.scrollTop;	        }	        else if (typeof document.body != 'undefined') {	           yOffset=document.body.scrollTop;	        }	    }		    		if (mousePos.y-yOffset < config.scrollAmount) {	    	window.scrollBy(0, -config.scrollAmount);	    } else {            var windowHeight = window.innerHeight ? window.innerHeight                    : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;            if (windowHeight-(mousePos.y-yOffset) < config.scrollAmount) {                window.scrollBy(0, config.scrollAmount);            }        }        if (y != jQuery.tableDnD.oldY) {            // work out if we're going up or down...            var movingDown = y > jQuery.tableDnD.oldY;            // update the old value            jQuery.tableDnD.oldY = y;            // update the style to show we're dragging			if (config.onDragClass) {				dragObj.addClass(config.onDragClass);			} else {	            dragObj.css(config.onDragStyle);			}            // If we're over a row then move the dragged row to there so that the user sees the            // effect dynamically            var currentRow = jQuery.tableDnD.findDropTargetRow(dragObj, y);            if (currentRow) {                // TODO worry about what happens when there are multiple TBODIES                if (movingDown && jQuery.tableDnD.dragObject != currentRow) {                    jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow.nextSibling);                } else if (! movingDown && jQuery.tableDnD.dragObject != currentRow) {                    jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject, currentRow);                }            }        }        return false;    },    /** We're only worried about the y position really, because we can only move rows up and down */    findDropTargetRow: function(draggedRow, y) {        var rows = jQuery.tableDnD.currentTable.rows;        for (var i=0; i<rows.length; i++) {            var row = rows[i];            var rowY    = this.getPosition(row).y;            var rowHeight = parseInt(row.offsetHeight)/2;            if (row.offsetHeight == 0) {                rowY = this.getPosition(row.firstChild).y;                rowHeight = parseInt(row.firstChild.offsetHeight)/2;            }            // Because we always have to insert before, we need to offset the height a bit            if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) {                // that's the row we're over				// If it's the same as the current row, ignore it				if (row == draggedRow) {return null;}                var config = jQuery.tableDnD.currentTable.tableDnDConfig;                if (config.onAllowDrop) {                    if (config.onAllowDrop(draggedRow, row)) {                        return row;                    } else {                        return null;                    }                } else {					// If a row has nodrop class, then don't allow dropping (inspired by John Tarr and Famic)                    var nodrop = jQuery(row).hasClass("nodrop");                    if (! nodrop) {                        return row;                    } else {                        return null;                    }                }                return row;            }        }        return null;    },    mouseup: function(e) {        if (jQuery.tableDnD.currentTable && jQuery.tableDnD.dragObject) {            var droppedRow = jQuery.tableDnD.dragObject;            var config = jQuery.tableDnD.currentTable.tableDnDConfig;            // If we have a dragObject, then we need to release it,            // The row will already have been moved to the right place so we just reset stuff			if (config.onDragClass) {	            jQuery(droppedRow).removeClass(config.onDragClass);			} else {	            jQuery(droppedRow).css(config.onDropStyle);			}            jQuery.tableDnD.dragObject   = null;            if (config.onDrop) {                // Call the onDrop method if there is one                config.onDrop(jQuery.tableDnD.currentTable, droppedRow);            }            jQuery.tableDnD.currentTable = null; // let go of the table too        }    },    serialize: function() {        if (jQuery.tableDnD.currentTable) {            return jQuery.tableDnD.serializeTable(jQuery.tableDnD.currentTable);        } else {            return "Error: No Table id set, you need to set an id on your table and every row";        }    },	serializeTable: function(table) {        var result = "";        var tableId = table.id;        var rows = table.rows;        for (var i=0; i<rows.length; i++) {            if (result.length > 0) result += "&";            var rowId = rows[i].id;            if (rowId && rowId && table.tableDnDConfig && table.tableDnDConfig.serializeRegexp) {                rowId = rowId.match(table.tableDnDConfig.serializeRegexp)[0];            }            result += tableId + '[]=' + rowId;        }        return result;	},	serializeTables: function() {        var result = "";        this.each(function() {			// this is now bound to each matching table			result += jQuery.tableDnD.serializeTable(this);		});        return result;    }}jQuery.fn.extend(	{		tableDnD : jQuery.tableDnD.build,		tableDnDUpdate : jQuery.tableDnD.updateTables,		tableDnDSerialize: jQuery.tableDnD.serializeTables	});

⌨️ 快捷键说明

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