1
|
|
|
// WWW: http://www.isocra.com/ |
2
|
|
|
|
3
|
|
|
var currenttable = null; |
4
|
|
|
|
5
|
|
|
document.onmousemove = function(ev) { |
6
|
|
|
if (currenttable && currenttable.dragObject) { |
|
|
|
|
7
|
|
|
ev = ev || window.event; |
8
|
|
|
var mousePos = currenttable.mouseCoords(ev); |
9
|
|
|
var y = mousePos.y - currenttable.mouseOffset.y; |
10
|
|
|
|
11
|
|
|
var yOffset = window.pageYOffset; |
12
|
|
|
var currentY = mousePos.y; |
13
|
|
|
if (document.all) { |
14
|
|
|
yOffset=document.body.scrollTop; |
15
|
|
|
currentY = event.clientY; |
|
|
|
|
16
|
|
|
} |
17
|
|
|
if (currentY-yOffset < 5) { |
18
|
|
|
window.scrollBy(0, -5); |
19
|
|
|
} else { |
20
|
|
|
var windowHeight = window.innerHeight ? window.innerHeight |
21
|
|
|
: document.documentElement.clientHeight ? document.documentElement.clientHeight |
22
|
|
|
: document.body.clientHeight; |
23
|
|
|
if (windowHeight-currentY-yOffset < 5) { |
24
|
|
|
window.scrollBy(0, 5); |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
if (y != currenttable.oldY) { |
29
|
|
|
var movingDown = y > currenttable.oldY; |
30
|
|
|
currenttable.oldY = y; |
31
|
|
|
currenttable.dragObject.style.backgroundColor.value="#aaa"; |
32
|
|
|
var currentRow = currenttable.findDropTargetRow(y); |
33
|
|
|
if (currentRow) { |
34
|
|
|
if (movingDown && currenttable.dragObject != currentRow) { |
35
|
|
|
currenttable.dragObject.parentNode.insertBefore(currenttable.dragObject, currentRow.nextSibling); |
36
|
|
|
} |
37
|
|
|
else if (! movingDown && currenttable.dragObject != currentRow) { |
38
|
|
|
currenttable.dragObject.parentNode.insertBefore(currenttable.dragObject, currentRow); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return false; |
44
|
|
|
} |
45
|
|
|
}; |
46
|
|
|
|
47
|
|
|
document.onmouseup = function(ev){ |
|
|
|
|
48
|
|
|
if (currenttable && currenttable.dragObject) { |
49
|
|
|
var droppedRow = currenttable.dragObject; |
50
|
|
|
droppedRow.style.backgroundColor = 'transparent'; |
51
|
|
|
currenttable.dragObject = null; |
52
|
|
|
currenttable.onDrop(currenttable.table, droppedRow); |
53
|
|
|
currenttable = null; |
54
|
|
|
} |
55
|
|
|
}; |
56
|
|
|
|
57
|
|
|
function getEventSource(evt) { |
58
|
|
|
if (window.event) { |
59
|
|
|
evt = window.event; |
60
|
|
|
return evt.srcElement; |
61
|
|
|
} else { |
|
|
|
|
62
|
|
|
return evt.target; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
function TableDnD() { |
67
|
|
|
this.dragObject = null; |
68
|
|
|
this.mouseOffset = null; |
69
|
|
|
this.table = null; |
70
|
|
|
this.oldY = 0; |
71
|
|
|
|
72
|
|
|
this.init = function(table) { |
73
|
|
|
this.table = table; |
74
|
|
|
var rows = table.tBodies[0].rows; |
75
|
|
|
for (var i=0; i<rows.length; i++) { |
76
|
|
|
var nodrag = rows[i].getAttribute("NoDrag"); |
77
|
|
|
if (nodrag == null || nodrag == "undefined") { |
|
|
|
|
78
|
|
|
this.makeDraggable(rows[i]); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
}; |
82
|
|
|
|
83
|
|
|
this.onDrop = function(table, droppedRow) {}; |
|
|
|
|
84
|
|
|
|
85
|
|
|
this.getPosition = function(e) { |
86
|
|
|
var left = 0; |
87
|
|
|
var top = 0; |
88
|
|
|
if (e.offsetHeight == 0) { |
|
|
|
|
89
|
|
|
e = e.firstChild; |
90
|
|
|
} |
91
|
|
|
while (e.offsetParent) { |
92
|
|
|
left += e.offsetLeft; |
93
|
|
|
top += e.offsetTop; |
94
|
|
|
e = e.offsetParent; |
95
|
|
|
} |
96
|
|
|
left += e.offsetLeft; |
97
|
|
|
top += e.offsetTop; |
98
|
|
|
return {x:left, y:top}; |
99
|
|
|
}; |
100
|
|
|
this.mouseCoords = function(ev) { |
101
|
|
|
if(ev.pageX || ev.pageY) { |
102
|
|
|
return {x:ev.pageX, y:ev.pageY}; |
103
|
|
|
} |
104
|
|
|
return {x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,y:ev.clientY + document.body.scrollTop - document.body.clientTop}; |
105
|
|
|
}; |
106
|
|
|
this.getMouseOffset = function(target, ev) { |
107
|
|
|
ev = ev || window.event; |
108
|
|
|
var docPos = this.getPosition(target); |
109
|
|
|
var mousePos = this.mouseCoords(ev); |
110
|
|
|
return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y}; |
111
|
|
|
}; |
112
|
|
|
this.makeDraggable = function(item) { |
113
|
|
|
if(!item) return; |
|
|
|
|
114
|
|
|
var self = this; |
115
|
|
|
item.onmousedown = function(ev) { |
116
|
|
|
var target = getEventSource(ev); |
117
|
|
|
if (target.tagName == 'INPUT' || target.tagName == 'SELECT') return true; |
|
|
|
|
118
|
|
|
currenttable = self; |
119
|
|
|
self.dragObject = this; |
120
|
|
|
self.mouseOffset = self.getMouseOffset(this, ev); |
121
|
|
|
return false; |
122
|
|
|
}; |
123
|
|
|
item.style.cursor="move"; |
124
|
|
|
}; |
125
|
|
|
this.findDropTargetRow = function(y) { |
126
|
|
|
var rows = this.table.tBodies[0].rows; |
127
|
|
|
for (var i=0; i<rows.length; i++) { |
128
|
|
|
var row = rows[i]; |
129
|
|
|
var nodrop = row.getAttribute("NoDrop"); |
130
|
|
|
if (nodrop == null || nodrop == "undefined") { |
|
|
|
|
131
|
|
|
var rowY = this.getPosition(row).y; |
132
|
|
|
var rowHeight = parseInt(row.offsetHeight)/2; |
133
|
|
|
if (row.offsetHeight == 0) { |
|
|
|
|
134
|
|
|
rowY = this.getPosition(row.firstChild).y; |
135
|
|
|
rowHeight = parseInt(row.firstChild.offsetHeight)/2; |
136
|
|
|
} |
137
|
|
|
if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) { |
138
|
|
|
return row; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
return null; |
143
|
|
|
}; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
var table = document.getElementById('weapon_reorder'); |
147
|
|
|
var tableDnD = new TableDnD(); |
148
|
|
|
tableDnD.init(table); |
149
|
|
|
|
150
|
|
|
function moveRow(cell, move) { |
151
|
|
|
var currentRow = cell.parentNode; |
152
|
|
|
var currentRowID = false; |
153
|
|
|
var rows = currentRow.parentNode.rows; |
154
|
|
|
for(var i = 1; i < rows.length; i++) { |
155
|
|
|
if(rows[i] == currentRow) currentRowID = i; |
|
|
|
|
156
|
|
|
} |
157
|
|
|
if(currentRowID==false) return; |
|
|
|
|
158
|
|
|
if(move>0) |
159
|
|
|
move++; |
|
|
|
|
160
|
|
|
var newRowID = currentRowID+move; |
161
|
|
|
if(newRowID>rows.length) |
162
|
|
|
newRowID = 1; |
|
|
|
|
163
|
|
|
else if(newRowID<1) |
164
|
|
|
newRowID = rows.length; |
|
|
|
|
165
|
|
|
|
166
|
|
|
currentRow.parentNode.insertBefore(currentRow, rows[newRowID]); |
167
|
|
|
}; |
168
|
|
|
|
169
|
|
|
function doSubmit() { |
170
|
|
|
var rows = document.getElementById('weapon_reorder').rows; |
171
|
|
|
var ret = new Array(); |
|
|
|
|
172
|
|
|
for(var i = 0; i < rows.length;i++) { |
173
|
|
|
ret[ret.length] = rows[i].getElementsByTagName('td')[0].innerHTML; |
174
|
|
|
} |
175
|
|
|
return ret.join('|'); |
176
|
|
|
} |
177
|
|
|
|
This check looks for functions where a
return
statement is found in some execution paths, but not in all.Consider this little piece of code
The function
isBig
will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly returnundefined
.This behaviour may not be what you had intended. In any case, you can add a
return undefined
to the other execution path to make the return value explicit.