View difference between Paste ID: PryQuHwV and WvM66Hsg
SHOW: | | - or go back to the newest paste.
1
function ElementSelector_Init(){
2
	var Body = document.getElementsByTagName("body")[0];
3
4
	function MoveSelection(e){
5
		var ev = e ? e : event;
6
		var Element = ev.srcElement ? ev.srcElement : ev.target;
7
8
		// Если ивент приходится на тот самый слой с рамкой, прерываемся
9
		// TODO: Проблема здесь
10
		if (Element == document.getElementById("ElementSelector_SelectionMain"))
11
			return;
12
13
		var SelectionMain;
14
		// Если слой с рамкой уже имеется, выбираем его
15
		if (document.getElementById("ElementSelector_SelectionMain"))
16
			SelectionMain = document.getElementById("ElementSelector_SelectionMain");
17
		// Иначе создаем новый
18
		else {
19
			SelectionMain = document.createElement("div");
20
			SelectionMain.setAttribute("id", "ElementSelector_SelectionMain");
21
			SelectionMain.style.position = "absolute";
22
		}
23
24
		// Перемещаем к позиции над элементом
25
		var Position = ElementSelector_GetOffset(Element);
26
		SelectionMain.style.top = Position.top + "px";
27
		SelectionMain.style.left = Position.left + "px";
28
		SelectionMain.style.width = Element.offsetWidth + "px";
29
		SelectionMain.style.height = Element.offsetHeight + "px";
30
		Body.appendChild(SelectionMain);
31
	}
32
	// Вешаем ивенты на действия с мышкой
33
	document.addEventListener("mouseover", MoveSelection);
34
	document.addEventListener("mousemove", MoveSelection);
35
	document.addEventListener("mouseout", MoveSelection);
36
}