summaryrefslogtreecommitdiffstats
path: root/js/other/windowStack.js
blob: 9bf2e0dcedda9e60156473a2c6d93af6bfacdaf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
"use strict";
var windowStacks = [];
function windowCreate(sId, bShow) {
	var oWindow = new windowStack(document.getElementById(sId));
	if (bShow) {
		oWindow.show();
	}
	return oWindow;
}
function windowStack(element) {
	if (element != null && typeof element == "object") {
		this.lastOpacity = null;
		this.domObject = element;
		this.hadFocus = true;
		this.hookedMouse = false;
		var thisObj2 = this;
		this.events = [
			["mousedown", function (event) { thisObj2.dragEnable(event); }],
			["mousemove", function (event) { thisObj2.drag(event); }],
			["mouseup", function (event) { thisObj2.dragDisable(); }]
		];
	}
}
windowStack.prototype.registerMouseEvents = function () {
	if (!this.hookedMouse) {
		this.hookedMouse = true;
		var eventIndex = null;
		for (eventIndex in this.events) {
			addEvent(this.events[eventIndex][0], document, this.events[eventIndex][1]);
		}
		this.center();
	}
}
windowStack.prototype.unregisterMouseEvents = function () {
	if (this.hookedMouse) {
		this.hookedMouse = false;
		var eventIndex = null;
		for (eventIndex in this.events) {
			removeEvent(this.events[eventIndex][0], document, this.events[eventIndex][1]);
		}
	}
}
windowStack.prototype.getStyleFloatOf = function (propertyNameOf, JSpropertyNameOf) {
	try {
		var dirtyValue = window.getComputedStyle(this.domObject, null).getPropertyValue(propertyNameOf);
	}
	catch (error) {
		try {
			var dirtyValue = this.domObject.currentStyle.getAttribute(JSpropertyNameOf);	/*JS object notation style keywords, not the CSS keywords!*/
		}
		catch (error) {
			cout(error.message, 2);
		}
	}
	var cleanValue = parseFloat((dirtyValue != null && dirtyValue.length) ? dirtyValue : "0");
	return (!isNaN(cleanValue) && cleanValue != -1) ? cleanValue : 0;	/*Note: Opera gives -1, not NaN for cleanValue when no number is found.*/
}
windowStack.prototype.dragEnable = function (event) {
	var elementAt = document.elementFromPoint(event.clientX, event.clientY);
	this.leftPos = this.getStyleFloatOf("left", "left");
	this.topPos = this.getStyleFloatOf("top", "top");
	var highX = this.leftPos + this.domObject.offsetWidth - document.documentElement.scrollLeft - document.getElementsByTagName("body")[0].scrollLeft;
	var highY = this.topPos + this.domObject.offsetHeight - document.documentElement.scrollTop - document.getElementsByTagName("body")[0].scrollTop;
	var mousedWindow = isSameNode(elementAt, this.domObject);
	this.mousedInsideWindow = (mousedWindow) ? false : isDescendantOf(this.domObject, elementAt);
	if (mousedWindow || this.mousedInsideWindow) {
		this.movable = true;
		this.leftLast = event.clientX;
		this.topLast = event.clientY;
		this.domObject.style.zIndex = 2;
		if (highX - this.leftLast < 25 && highY - this.topLast < 25) {	/*Inivisible resize corner area for windows.*/
			this.resize = true;
		}
		else {
			this.resize = false;
		}
		this.coordDiffLeft = this.leftLast - this.leftPos;
		this.coordDiffTop = this.topLast - this.topPos;
		this.lastLeft = 0;
		this.lastTop = 0;
	}
	else {
		this.lostFocus();
	}
}
windowStack.prototype.drag = function (event) {
	if (this.movable) {
		this.lastLeft += event.clientX - this.coordDiffLeft;
		this.lastTop += event.clientY - this.coordDiffTop;
		if (this.resize) {
			var newWidth = this.domObject.clientWidth + event.clientX - this.leftLast - this.getStyleFloatOf("padding-left", "paddingLeft") - this.getStyleFloatOf("padding-right", "paddingRight");
			var newHeight = this.domObject.clientHeight + event.clientY - this.topLast - this.getStyleFloatOf("padding-top", "paddingTop") - this.getStyleFloatOf("padding-bottom", "paddingBottom");
			if (this.getStyleFloatOf("min-width", "minWidth") <= newWidth && this.getStyleFloatOf("min-height", "minHeight") <= newHeight && ((this.getStyleFloatOf("max-width", "maxWidth") >= newWidth || this.getStyleFloatOf("max-width", "maxWidth") == 0) && (this.getStyleFloatOf("max-height", "maxHeight") >= newHeight || this.getStyleFloatOf("max-height", "maxHeight") == 0))) {
				this.domObject.style.width = newWidth + "px";
				this.domObject.style.height = newHeight + "px";
			}
		}
		else if (!this.mousedInsideWindow) {
			this.domObject.style.left = this.lastLeft + "px";
			this.domObject.style.top = this.lastTop + "px";
		}
		this.coordDiffLeft = this.leftLast = event.clientX;
		this.coordDiffTop = this.topLast = event.clientY;
	}
}
windowStack.prototype.dragDisable = function () {
	this.movable = false;
	this.hadFocus = true;
}
windowStack.prototype.lostFocus = function () {
	if (this.hadFocus) {
		this.domObject.style.zIndex = 1;
		this.hadFocus = false;
	}
}
windowStack.prototype.interceptOpacity = function () {
	if (this.lastOpacity != null) {
		this.lastOpacity.bDoneRun = true;
		return this.lastOpacity.RefOpacityAREABegin;
	}
	var sampledOpacity = this.getStyleFloatOf("opacity", "opacity") * 100;
	return (sampledOpacity > 0) ? sampledOpacity : 100;	/*Dirty opacity first-set for IE*/
}
windowStack.prototype.center = function () {
	var docWidth = Math.max(document.documentElement.clientWidth, document.getElementsByTagName("body")[0].clientWidth);
	var docHeight = Math.max(document.documentElement.clientHeight, document.getElementsByTagName("body")[0].clientHeight);
	var docLeft = Math.max(document.documentElement.scrollLeft, document.getElementsByTagName("body")[0].scrollLeft);
	var docTop = Math.max(document.documentElement.scrollTop, document.getElementsByTagName("body")[0].scrollTop);
	this.domObject.style.left = Math.round(((docWidth - this.domObject.offsetWidth) / 2) + docLeft) + "px";
	this.domObject.style.top = Math.round(((docHeight - this.domObject.offsetHeight) / 2) + docTop) + "px";
}
windowStack.prototype.hide = function () {
	this.domObject.style.display = "none";
	this.unregisterMouseEvents();
}
windowStack.prototype.show = function () {
	this.domObject.style.display = "block";
	this.registerMouseEvents();
}
function popupMenu(oClick, oMenu) {
	this.clickElement = oClick;
	this.menuElement = oMenu;
	var thisObj2 = this;
	this.eventHandle = [
		function (event) { thisObj2.startPopup(event); },
		function (event) { thisObj2.endPopup(event); }
	];
	this.open = false;
	addEvent("click", this.clickElement, this.eventHandle[0]);
}
popupMenu.prototype.startPopup = function (event) {
	if (!this.open) {
		this.open = true;
		this.menuElement.style.display = "block";
		removeEvent("click", this.clickElement, this.eventHandle[0]);
		this.position(event);
		addEvent("mouseout", this.menuElement, this.eventHandle[1]);
	}
}
popupMenu.prototype.endPopup = function (event) {
	if (this.open) {
		if (mouseLeaveVerify(this.menuElement, event)) {
			this.open = false;
			this.menuElement.style.display = "none";
			removeEvent("mouseout", this.menuElement, this.eventHandle[1]);
			addEvent("click", this.clickElement, this.eventHandle[0]);
		}
	}
}
popupMenu.prototype.position = function (event) {
	if (this.open) {
		this.menuElement.style.left = (pageXCoord(event) - 5) + "px";
		this.menuElement.style.top = (pageYCoord(event) - 5) + "px";
	}
}