Implement dragging of speed dial shortcuts

This commit is contained in:
Paweł Forysiuk 2011-12-18 01:51:10 +01:00 committed by Christian Dywan
parent b72e75d32c
commit ee055334ce
2 changed files with 129 additions and 1 deletions

View file

@ -196,6 +196,110 @@
return false; return false;
} }
var firstNode, secondNode;
var cursor;
var dial = document.getElementsByClassName("shortcut");
var click = function (ev) {
ev.preventDefault();
var ele = ev.target;
cursor = ele.style.cursor;
ele.style.cursor = 'move';
var eparent;
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) {
eparent.style.outline = '1px dotted black';
eparent.style.backgroundColor = '#eef';
firstNode = eparent.id;
}
out();
remove();
};
var remove = function () {
document.RemoveEventListener('click', click, false);
document.RemoveEventListener('mouseout', out, false);
};
var up = function (ev) {
ele = ev.target;
var eparent;
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;
secondNode = eparent.id;
/* ommit just mere clicking the dial */
if (firstNode != secondNode && firstNode != undefined)
swap();
};
var over = function (ev) {
var ele = ev.target;
var eparent;
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)
{
eparent.style.outline = '1px dotted black';
eparent.style.backgroundColor = '#eef';
for (var i = 0; i <= dial.length; i++) {
if (eparent.id != firstNode.id && dial[i].id != eparent.id) {
dial[i].style.outline = '0px';
dial[i].style.backgroundColor = '#eee';
}
}
}
ele.style.cursor = cursor;
}
var out = function (ev) {
var ele = ev.target;
var eparent;
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) {
for (var i = 0; i <= dial.length; i++) {
if (eparent.id != firstNode.id && dial[i].id != eparent.id) {
dial[i].style.outline = '0px';
dial[i].backgroundColor = '#eee';
}
}
}
ele.style.cursor = cursor;
}
function swap () {
console.log ("speed_dial-save-swap " + firstNode + " " + secondNode);
};
document.addEventListener('mousedown', click, false);
document.addEventListener('mouseup', up, false);
document.addEventListener('mouseover', over, false);
document.addEventListener('mouseout', out, false);
</script> </script>
</head> </head>
<body> <body>

View file

@ -5602,7 +5602,7 @@ midori_view_speed_dial_save (MidoriView* view,
action = parts[0]; action = parts[0];
if (g_str_equal (action, "add") || g_str_equal (action, "rename") if (g_str_equal (action, "add") || g_str_equal (action, "rename")
|| g_str_equal (action, "delete")) || g_str_equal (action, "delete") || g_str_equal (action, "swap"))
{ {
gchar* tmp = g_strdup (parts[1] + 1); gchar* tmp = g_strdup (parts[1] + 1);
guint slot_id = atoi (tmp); guint slot_id = atoi (tmp);
@ -5633,6 +5633,30 @@ midori_view_speed_dial_save (MidoriView* view,
g_key_file_set_string (key_file, dial_id, "title", title); g_key_file_set_string (key_file, dial_id, "title", title);
g_free (title); g_free (title);
} }
else if (g_str_equal (action, "swap"))
{
gchar* tmp1 = g_strdup (parts[2] + 1);
guint slot2_id = atoi (tmp1);
gchar* dial2_id = g_strdup_printf ("Dial %d", slot2_id);
gchar* uri, *uri2, *title, *title2;
g_free (tmp1);
uri = g_key_file_get_string (key_file, dial_id, "uri", NULL);
title = g_key_file_get_string (key_file, dial_id, "title", NULL);
uri2 = g_key_file_get_string (key_file, dial2_id, "uri", NULL);
title2 = g_key_file_get_string (key_file, dial2_id, "title", NULL);
g_key_file_set_string (key_file, dial_id, "uri", uri2);
g_key_file_set_string (key_file, dial2_id, "uri", uri);
g_key_file_set_string (key_file, dial_id, "title", title2);
g_key_file_set_string (key_file, dial2_id, "title", title);
g_free (uri);
g_free (uri2);
g_free (title);
g_free (title2);
g_free (dial2_id);
}
g_free (dial_id); g_free (dial_id);
} }