home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Narzedzia
/
AIMP2
/
aimp_2.61.583.exe
/
$TEMP
/
YandexPackSetup.msi
/
fil5416424B66568A2C2422AEBF0D768AD4
< prev
next >
Wrap
Text File
|
2010-07-12
|
5KB
|
178 lines
function YaDragWindow(aDragElements, aWindow) {
this.dragElements = [];
for each (var el in aDragElements) {
var elem = document.getAnonymousElementByAttribute(el, "yadraggable", "true");
if (elem)
this.dragElements.push(elem);
}
if (this.dragElements.length) {
this.undragElements = [];
for each (var el in aDragElements) {
var elem = document.getAnonymousElementByAttribute(el, "yadraggable", "false");
if (elem)
this.undragElements.push(elem);
}
this.window = aWindow || window;
this.lastXY = null;
this.lastTS = null;
this._init();
}
}
YaDragWindow.prototype = {
_visiblePixels: 40,
_isInited: false,
_init: function() {
for each (var el in this.dragElements) {
el.addEventListener("mousedown", this, false);
}
this.window.addEventListener("unload", this, false);
this.window.addEventListener("resize", this, false);
this._isInited = true;
this._checkWindowVisible();
},
_destroy: function() {
if (!this._isInited)
return;
for each (var el in this.dragElements) {
el.removeEventListener("mousedown", this, false);
}
this.window.removeEventListener("unload", this, false);
this.window.removeEventListener("resize", this, false);
this.undragElements = null;
this.dragElements = null;
this.window = null;
this._isInited = false;
},
_isEventElementDraggable: function(aEvent) {
var currentTarget = aEvent.currentTarget;
if (this.dragElements.some(function(el) { return el == currentTarget; })) {
var originalTarget = aEvent.originalTarget;
if (!this.undragElements.some(function(el) { return el == originalTarget; }))
return true;
}
return false;
},
_checkWindowVisible: function() {
var x = 0, y = 0;
var win = this.window;
var xDiff = win.screenX + win.outerWidth - this._visiblePixels;
if (xDiff < 0) {
x = xDiff;
} else {
xDiff = win.screenX - (win.screen.availLeft + win.screen.availWidth - this._visiblePixels);
if (xDiff > 0)
x = xDiff;
}
var yDiff = win.screenY;
if (yDiff < 0) {
y = yDiff;
} else {
yDiff = win.screenY - (win.screen.availTop + win.screen.availHeight - this._visiblePixels);
if (yDiff > 0)
y = yDiff;
}
if (x == 0 && y == 0)
return;
this._handleMouseMove({x: x, y: y});
},
_handleMouseMove: function(aDiff) {
var win = this.window;
var x = win.screenX - aDiff.x;
var y = win.screenY - aDiff.y;
if (x < (-win.outerWidth + this._visiblePixels) ||
x > (screen.availLeft + screen.availWidth - this._visiblePixels))
aDiff.x = 0;
if (y < 0 ||
y > (screen.availTop + screen.availHeight - this._visiblePixels))
aDiff.y = 0;
if (aDiff.x == 0 && aDiff.y == 0)
return;
win.moveTo(win.screenX - aDiff.x, win.screenY - aDiff.y);
},
handleEvent: function(aEvent) {
switch (aEvent.type) {
case "unload":
this._destroy();
break;
case "mousemove":
var eventPoints = { x: aEvent.screenX, y: aEvent.screenY };
var ts = Date.now();
if (ts - this.lastTS < 7)
return;
this.lastTS = ts;
var diff = {
x: this.lastXY.x - eventPoints.x,
y: this.lastXY.y - eventPoints.y
};
if (diff.x == 0 && diff.y == 0)
return;
this._handleMouseMove(diff);
this.lastXY = eventPoints;
break;
case "mousedown":
if (aEvent.button == 0 && this._isEventElementDraggable(aEvent)) {
this.lastXY = {x: aEvent.screenX, y: aEvent.screenY};
this.lastTS = Date.now();
this.window.addEventListener("mouseup", this, false);
this.window.addEventListener("mousemove", this, false);
}
break;
case "mouseup":
this.window.removeEventListener("mouseup", this, false);
this.window.removeEventListener("mousemove", this, false);
this._checkWindowVisible();
break;
case "resize":
this._checkWindowVisible();
break;
}
}
}