mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
features: - tool - Maps: * finally supports multi-layered zones * should also support icons if needed (questgiver, ect) - tool - Item Comparison: * fully functional (yes, that includes heirlooms and items with random props) * may throw a minor js-error if using arrow-keys/esc/ret in input-fields in the LightboxPopus (but wowhead does also) * icons for prismatic sockets are not displayed if no other sockets are present (calculation is correct though) * modelviewer will still 'call home' - tool - Talent Calculator: * got rid of a VERY dirty hack for the icons (they are now supplied as texture, not laoded one at a time) * glyphs should also be a bit more informative * talent data is pulled from static file, that should a) speed up load and b) prevent lockups if it cant be generated on the fly * you can now set the level for your build, which affects available talent points, glyphs and glyph-slots - tool - Pet Calculator: * initial implementation; basically the same as the Talent Calculator - general concept changed: * dropped ajax.php; json is now supplied by the appropriate page if &json is appended to the url * search.php and opensearch.php are being merged; again, output will depend on the appended parameter (&openserach, &json) * data included via data.php will be static and assembled only on installation and when the database changes (should speed up load) * locale strings are now in a single file instead of being split up to the template * still getting rid of criss-cross-includes, global variables and string-defines
230 lines
4.3 KiB
JavaScript
230 lines
4.3 KiB
JavaScript
var Draggable = new function () {
|
|
var
|
|
start = {},
|
|
mouse = {},
|
|
clickObj,
|
|
dragObj;
|
|
|
|
function onMouseDown(e) {
|
|
e = $E(e);
|
|
|
|
if (this._handle) {
|
|
var _ = e._target,
|
|
found = false,
|
|
i = 0;
|
|
|
|
while (_ && i <= 3) {
|
|
if (_ == this._handle) {
|
|
found = true;
|
|
break;
|
|
}
|
|
|
|
_ = _.parentNode;
|
|
++i;
|
|
}
|
|
|
|
if (!found) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
clickObj = this;
|
|
|
|
start = g_getCursorPos(e);
|
|
|
|
aE(document, 'mousemove', onMouseMove);
|
|
aE(document, 'mouseup', onMouseUp);
|
|
|
|
if (clickObj.onClick) {
|
|
clickObj.onClick(e, clickObj);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
function onMouseMove(e) {
|
|
e = $E(e);
|
|
|
|
var pos = g_getCursorPos(e);
|
|
|
|
if (clickObj) {
|
|
if (Math.abs(pos.x - start.x) > 5 || Math.abs(pos.y - start.y) > 5) {
|
|
onDragStart(e, clickObj);
|
|
clickObj = null;
|
|
}
|
|
}
|
|
|
|
if (!dragObj || !dragObj._bounds) {
|
|
return false;
|
|
}
|
|
|
|
var
|
|
bounds = getBounds(dragObj),
|
|
dX = pos.x - start.x,
|
|
dY = pos.y - start.y;
|
|
|
|
dX = Math.max(dragObj._bounds.x1 - mouse.x, Math.min(dragObj._bounds.x2 - mouse.x - (bounds.x2 - bounds.x1), dX));
|
|
dY = Math.max(dragObj._bounds.y1 - mouse.y, Math.min(dragObj._bounds.y2 - mouse.y - (bounds.y2 - bounds.y1), dY));
|
|
|
|
setPosition(dX, dY);
|
|
|
|
return false;
|
|
}
|
|
|
|
function onMouseUp(e) {
|
|
e = $E(e);
|
|
|
|
clickObj = null;
|
|
|
|
if (dragObj) {
|
|
onDragEnd(e);
|
|
}
|
|
}
|
|
|
|
function onDragStart(e, obj) {
|
|
if (dragObj) {
|
|
onDragEnd(e);
|
|
}
|
|
|
|
var foo = ac(obj);
|
|
mouse.x = foo[0];
|
|
mouse.y = foo[1];
|
|
|
|
if (obj._targets.length) {
|
|
dragObj = obj.cloneNode(true);
|
|
dragObj._orig = obj;
|
|
|
|
ae(ge('layers'), dragObj);
|
|
// ae(document.body, dragObj); // 5.0.. why does it do that?
|
|
setPosition(-2323, -2323);
|
|
}
|
|
else {
|
|
dragObj = obj;
|
|
}
|
|
|
|
Tooltip.disabled = true;
|
|
Tooltip.hide();
|
|
|
|
if (obj.onDrag) {
|
|
obj.onDrag(e, dragObj, obj);
|
|
}
|
|
|
|
dragObj._bounds = getBounds(obj._container);
|
|
dragObj.className += ' dragged';
|
|
}
|
|
|
|
function onDragEnd(e) {
|
|
var
|
|
found = false,
|
|
cursor = g_getCursorPos(e);
|
|
|
|
if (dragObj._orig && dragObj._orig._targets.length) {
|
|
clearPosition();
|
|
|
|
var pos = {
|
|
x1: dragObj._x,
|
|
x2: dragObj._x + parseInt(dragObj.offsetWidth),
|
|
y1: dragObj._y,
|
|
y2: dragObj._y + parseInt(dragObj.offsetHeight)
|
|
};
|
|
|
|
de(dragObj);
|
|
dragObj = dragObj._orig;
|
|
|
|
for (var i = 0, len = dragObj._targets.length; i < len; ++i) {
|
|
var targObj = dragObj._targets[i],
|
|
bounds = getBounds(targObj);
|
|
|
|
if (pos.x2 >= bounds.x1 && pos.x1 < bounds.x2 && pos.y2 >= bounds.y1 && pos.y1 < bounds.y2) {
|
|
found = true;
|
|
if (dragObj.onDrop) {
|
|
dragObj.onDrop(e, dragObj, targObj, (cursor.x >= bounds.x1 && cursor.x <= bounds.x2 && cursor.y >= bounds.y1 && cursor.y <= bounds.y2));
|
|
}
|
|
else {
|
|
ae(targObj, dragObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!found && dragObj.onDrop) {
|
|
dragObj.onDrop(e, dragObj, null);
|
|
}
|
|
|
|
dE(document, 'mousemove', onMouseMove);
|
|
dE(document, 'mouseup', onMouseUp);
|
|
|
|
Tooltip.disabled = false;
|
|
|
|
dragObj.className = dragObj.className.replace(/dragged/, '');
|
|
dragObj = null;
|
|
}
|
|
|
|
function setPosition(dX, dY) {
|
|
dragObj.style.position = 'absolute';
|
|
dragObj.style.left = mouse.x + dX + 'px';
|
|
dragObj.style.top = mouse.y + dY + 'px';
|
|
|
|
dragObj._x = mouse.x + dX;
|
|
dragObj._y = mouse.y + dY;
|
|
}
|
|
|
|
function clearPosition() {
|
|
dragObj.style.left = '-2323px';
|
|
dragObj.style.top = '-2323px';
|
|
}
|
|
|
|
function getBounds(obj) {
|
|
var pos = ac(obj);
|
|
|
|
return {
|
|
x1: pos[0],
|
|
x2: pos[0] + parseInt(obj.offsetWidth),
|
|
y1: pos[1],
|
|
y2: pos[1] + parseInt(obj.offsetHeight)
|
|
};
|
|
}
|
|
|
|
this.init = function (obj, opt) {
|
|
obj.onmousedown = onMouseDown;
|
|
|
|
var a = obj.getElementsByTagName('a');
|
|
for (var i = 0, len = a.length; i < len; ++i) {
|
|
ns(a[i]);
|
|
}
|
|
|
|
if (!obj._targets) {
|
|
obj._targets = [];
|
|
}
|
|
|
|
if (!obj._container) {
|
|
obj._container = document.body;
|
|
}
|
|
|
|
if (opt != null) {
|
|
if (opt.targets) {
|
|
for (var i = 0, len = opt.targets.length; i < len; ++i) {
|
|
obj._targets.push(ge(opt.targets[i]));
|
|
}
|
|
}
|
|
|
|
if (opt.container) {
|
|
obj._container = $(opt.container);
|
|
}
|
|
|
|
// Functions
|
|
if (opt.onClick) {
|
|
obj.onClick = opt.onClick;
|
|
}
|
|
|
|
if (opt.onDrop) {
|
|
obj.onDrop = opt.onDrop;
|
|
}
|
|
|
|
if (opt.onDrag) {
|
|
obj.onDrag = opt.onDrag;
|
|
}
|
|
}
|
|
}
|
|
};
|