Skip to content

Commit 7c9addb

Browse files
committed
Make formatting help area movable
1 parent 3f018f1 commit 7c9addb

File tree

3 files changed

+69
-10
lines changed

3 files changed

+69
-10
lines changed

index.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,14 @@ img {
312312

313313
#drawer {
314314
display: inline-block;
315-
position: fixed;
315+
position: absolute;
316316
width: 300px;
317317
background-color: rgb(240, 240, 240);
318318
opacity: 0.5;
319319
border: 1px solid black;
320320
border-radius: 5px;
321-
margin-top: 1.8em;
322321
padding: 0;
322+
cursor: move;
323323
}
324324
#drawer h5 {
325325
border-bottom: 1px solid black;
@@ -338,10 +338,10 @@ img.icon {
338338
width: 1.5em;
339339
vertical-align: middle;
340340
}
341-
a img.icon:hover {
341+
a > img.icon:hover, a > span.icongroup:hover {
342342
outline: 1px outset white;
343343
}
344-
a img.icon:active {
344+
a > img.icon:active, a > span.icongroup:active {
345345
outline: 1px inset white;
346346
}
347347
.rightaligned

index.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ function printHeader($title, $bodyclass="")
8585
print " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n";
8686
print " <link type=\"text/css\" rel=\"stylesheet\" href=\"" . BASE_URI . "/" . CSS_FILE ."\" />\n";
8787
print " <title>".PAGE_TITLE."$title</title>\n";
88-
print " <script>\n";
89-
print " function toggleDrawer(){\n";
90-
print " document.getElementById('drawer').classList.toggle('inactive');\n";
91-
print " }\n";
92-
print " </script>\n";
88+
print " <script src=\"wiki.js\"></script>\n";
9389
print " </head>\n";
9490
print " <body".($bodyclass != "" ? " class=\"$bodyclass\"":"").">\n";
9591
}
@@ -134,7 +130,7 @@ function printDrawer()
134130
"*** Horizontal rule<br/>".
135131
"--- Horizontal rule</h5><br/>".
136132
"</div></div>".
137-
"<a id=\"drawer-control\" href=\"\" onclick=\"toggleDrawer(); return false;\"><img src=\"/icons/format-text-bold.svg\" alt=\"".__('Show links here')."\" title=\"".__('Formatting help')."\" class=\"icon\"/><img src=\"/icons/format-text-italic.svg\" alt=\"".__('Show links here')."\" title=\"".__('Formatting help')."\" class=\"icon\"/><img src=\"/icons/format-text-code.svg\" alt=\"".__('Show links here')."\" title=\"".__('Formatting help')."\" class=\"icon\"/></span>\n";
133+
"<a id=\"drawer-control\" href=\"\" onclick=\"toggleDrawer(); return false;\"><span class=\"icongroup\"><img src=\"/icons/format-text-bold.svg\" alt=\"".__('Formatting help')."\" title=\"".__('Formatting help')."\" class=\"icon\"/><img src=\"/icons/format-text-italic.svg\" alt=\"".__('Formatting help')."\" title=\"".__('Formatting help')."\" class=\"icon\"/><img src=\"/icons/format-text-code.svg\" alt=\"".__('Formatting help')."\" title=\"".__('Formatting help')."\" class=\"icon\"/></span></a>\n";
138134
}
139135

140136
if ( REQUIRE_PASSWORD && !isset($_SESSION['password']) )

wiki.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
function toggleDrawer()
3+
{
4+
document.getElementById('drawer').classList.toggle('inactive');
5+
}
6+
7+
// based on https://www.w3schools.com/howto/howto_js_draggable.asp
8+
function makeElementDraggable(elmnt)
9+
{
10+
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
11+
/*
12+
if (document.getElementById(elmnt.id + "header"))
13+
{
14+
// if present, the header is where you move the DIV from:
15+
document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
16+
}
17+
else
18+
{
19+
// otherwise, move the DIV from anywhere inside the DIV:
20+
*/
21+
elmnt.onmousedown = dragMouseDown;
22+
// }
23+
24+
function dragMouseDown(e)
25+
{
26+
e = e || window.event;
27+
e.preventDefault();
28+
// get the mouse cursor position at startup:
29+
pos3 = e.clientX;
30+
pos4 = e.clientY;
31+
console.log("Click: "+pos3+", "+pos4);
32+
document.onmouseup = closeDragElement;
33+
// call a function whenever the cursor moves:
34+
document.onmousemove = elementDrag;
35+
}
36+
37+
function elementDrag(e)
38+
{
39+
e = e || window.event;
40+
e.preventDefault();
41+
// calculate the new cursor position:
42+
pos1 = pos3 - e.clientX;
43+
pos2 = pos4 - e.clientY;
44+
console.log("Pos: "+e.clientX+", "+e.clientY+", drag: "+pos1+", "+pos2+", offsetLeftTop: "+elmnt.offsetLeft+", "+elmnt.offsetTop+", newPos: "+(elmnt.offsetLeft-pos1)+", "+(elmnt.offsetTop-pos2));
45+
pos3 = e.clientX;
46+
pos4 = e.clientY;
47+
// set the element's new position:
48+
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
49+
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
50+
}
51+
52+
function closeDragElement()
53+
{
54+
// stop moving when mouse button is released:
55+
document.onmouseup = null;
56+
document.onmousemove = null;
57+
}
58+
}
59+
60+
window.onload = function(e)
61+
{
62+
makeElementDraggable(document.getElementById("drawer"));
63+
};

0 commit comments

Comments
 (0)