Use get_dial_div and classes for shortcut dragging

This commit is contained in:
Paweł Forysiuk 2012-01-06 00:27:07 +01:00 committed by Christian Dywan
parent 4de2048f85
commit 618fa82077

View file

@ -126,6 +126,11 @@
-webkit-border-bottom-left-radius: 10px; -webkit-border-bottom-left-radius: 10px;
visibility: hidden; visibility: hidden;
} }
.selected {
outline: 1px dotted black;
background-color: #eef;
}
</style> </style>
<script type="text/javascript"> <script type="text/javascript">
@ -200,23 +205,25 @@
var cursor; var cursor;
var dial = document.getElementsByClassName("shortcut"); var dial = document.getElementsByClassName("shortcut");
var get_dial_div = function (ele) {
var dial_div;
if (ele.nodeName == 'IMG')
dial_div = ele.parentNode.parentNode.parentNode;
if (ele.className == 'title')
dial_div = ele.parentNode;
if (ele.className.indexOf ('shortcut') != -1)
dial_dir = ele;
return dial_div;
}
var click = function (ev) { var click = function (ev) {
ev.preventDefault(); ev.preventDefault();
var ele = ev.target; var ele = ev.target;
cursor = ele.style.cursor; cursor = ele.style.cursor;
ele.style.cursor = 'move'; ele.style.cursor = 'move';
var eparent; var eparent = get_dial_div (ele);
if (ele.nodeName == 'IMG')
eparent = ele.parentNode.parentNode.parentNode;
if (ele.className == 'title')
eparent = ele.parentNode;
if (ele.className == 'shortcut')
eparent = ele;
if (eparent != undefined) { if (eparent != undefined) {
eparent.style.outline = '1px dotted black'; eparent.className = 'shortcut selected';
eparent.style.backgroundColor = '#eef';
firstNode = eparent.id; firstNode = eparent.id;
} }
out(); out();
@ -230,14 +237,7 @@
var up = function (ev) { var up = function (ev) {
ele = ev.target; ele = ev.target;
var eparent; var eparent = get_dial_div (ele);
if (ele.nodeName == 'IMG')
eparent = ele.parentNode.parentNode.parentNode;
if (ele.className == 'title')
eparent = ele.parentNode;
if (ele.className == 'shortcut')
eparent = ele;
ele.style.cursor = cursor; ele.style.cursor = cursor;
secondNode = eparent.id; secondNode = eparent.id;
@ -249,43 +249,26 @@
var over = function (ev) { var over = function (ev) {
var ele = ev.target; var ele = ev.target;
var eparent; var eparent = get_dial_div (ele);
if (ele.nodeName == 'IMG')
eparent = ele.parentNode.parentNode.parentNode;
if (ele.className == 'title')
eparent = ele.parentNode;
if (ele.className == 'shortcut')
eparent = ele;
if (firstNode != undefined) if (firstNode != undefined)
{ {
eparent.style.outline = '1px dotted black'; eparent.className = 'shortcut selected';
eparent.style.backgroundColor = '#eef';
for (var i = 0; i <= dial.length; i++) { for (var i = 0; i <= dial.length; i++) {
if (eparent.id != firstNode.id && dial[i].id != eparent.id) { if (eparent.id != firstNode.id && dial[i].id != eparent.id) {
dial[i].style.outline = '0px'; dial[i].className = 'shortcut';
dial[i].style.backgroundColor = '#eee';
} }
} }
} }
ele.style.cursor = cursor; ele.style.cursor = cursor;
} }
var out = function (ev) { var out = function (ev) {
var ele = ev.target; var ele = ev.target;
var eparent; var eparent = get_dial_div (ev);
if (ele.nodeName == 'IMG')
eparent = ele.parentNode.parentNode.parentNode;
if (ele.className == 'title')
eparent = ele.parentNode;
if (ele.className == 'shortcut')
eparent = ele;
if (firstNode != undefined) { if (firstNode != undefined) {
for (var i = 0; i <= dial.length; i++) { for (var i = 0; i <= dial.length; i++) {
if (eparent.id != firstNode.id && dial[i].id != eparent.id) { if (eparent.id != firstNode.id && dial[i].id != eparent.id) {
dial[i].style.outline = '0px'; dial[i].className = 'shortcut';
dial[i].backgroundColor = '#eee';
} }
} }
} }