summaryrefslogtreecommitdiff
path: root/misc/tabledrag.js
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-03-08 03:16:26 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-03-08 03:16:26 +0000
commitb179a944a36df0196a8f8ab9209eb96c1c936d8a (patch)
treefc112264b832f698773d713ffd30cc062fa8a42e /misc/tabledrag.js
parent53ef28ec4a954170a39987ef86dd30066a515b12 (diff)
downloadbrdo-b179a944a36df0196a8f8ab9209eb96c1c936d8a.tar.gz
brdo-b179a944a36df0196a8f8ab9209eb96c1c936d8a.tar.bz2
#350275 by Rob Loach, starbow, and quicksketch: Upgrade to jQuery 1.3.2 and jQuery Forms 2.21.
Diffstat (limited to 'misc/tabledrag.js')
-rw-r--r--misc/tabledrag.js50
1 files changed, 12 insertions, 38 deletions
diff --git a/misc/tabledrag.js b/misc/tabledrag.js
index aea64d617..78854406d 100644
--- a/misc/tabledrag.js
+++ b/misc/tabledrag.js
@@ -206,7 +206,7 @@ Drupal.tableDrag.prototype.makeDraggable = function(item) {
self.rowObject = new self.row(item, 'mouse', self.indentEnabled, self.maxDepth, true);
// Save the position of the table.
- self.table.topY = self.getPosition(self.table).y;
+ self.table.topY = $(self.table).offset().top;
self.table.bottomY = self.table.topY + self.table.offsetHeight;
// Add classes to the handle and row.
@@ -486,31 +486,6 @@ Drupal.tableDrag.prototype.dropRow = function(event, self) {
};
/**
- * Get the position of an element by adding up parent offsets in the DOM tree.
- */
-Drupal.tableDrag.prototype.getPosition = function(element){
- var left = 0;
- var top = 0;
- // Because Safari doesn't report offsetHeight on table rows, but does on table
- // cells, grab the firstChild of the row and use that instead.
- // http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in-safari
- if (element.offsetHeight == 0) {
- element = element.firstChild; // A table cell.
- }
-
- while (element.offsetParent){
- left += element.offsetLeft;
- top += element.offsetTop;
- element = element.offsetParent;
- }
-
- left += element.offsetLeft;
- top += element.offsetTop;
-
- return {x:left, y:top};
-};
-
-/**
* Get the mouse coordinates from the event (allowing for browser differences).
*/
Drupal.tableDrag.prototype.mouseCoords = function(event){
@@ -528,9 +503,9 @@ Drupal.tableDrag.prototype.mouseCoords = function(event){
* element. To do this we need the element's position and the mouse position.
*/
Drupal.tableDrag.prototype.getMouseOffset = function(target, event) {
- var docPos = this.getPosition(target);
+ var docPos = $(target).offset();
var mousePos = this.mouseCoords(event);
- return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
+ return { x: mousePos.x - docPos.left, y: mousePos.y - docPos.top };
};
/**
@@ -547,16 +522,8 @@ Drupal.tableDrag.prototype.findDropTargetRow = function(x, y) {
for (var n=0; n<rows.length; n++) {
var row = rows[n];
var indentDiff = 0;
- // Safari fix see Drupal.tableDrag.prototype.getPosition()
- if (row.offsetHeight == 0) {
- var rowY = this.getPosition(row.firstChild).y;
- var rowHeight = parseInt(row.firstChild.offsetHeight)/2;
- }
- // Other browsers.
- else {
- var rowY = this.getPosition(row).y;
- var rowHeight = parseInt(row.offsetHeight)/2;
- }
+ var rowY = $(row).offset().top;
+ var rowHeight = parseInt($(row).outerHeight()) / 2;
// Because we always insert before, we need to offset the height a bit.
if ((y > (rowY - rowHeight)) && (y < (rowY + rowHeight))) {
@@ -568,6 +535,13 @@ Drupal.tableDrag.prototype.findDropTargetRow = function(x, y) {
}
}
}
+ else {
+ // Do not allow a row to be swapped with itself.
+ if (row == this.rowObject.element) {
+ return null;
+ }
+ }
+
// Check that swapping with this row is allowed.
if (!this.rowObject.isValidSwap(row)) {
return null;