2018-11-23 23:46:40 +00:00
|
|
|
let itemObj = undefined;
|
2018-11-19 23:32:16 +00:00
|
|
|
|
2019-04-12 18:20:47 +00:00
|
|
|
// For context menu to have element
|
2018-11-23 23:46:40 +00:00
|
|
|
document.onclick = (event) => {
|
|
|
|
let obj = event.target;
|
|
|
|
let callingID = obj.id;
|
|
|
|
let classNM = obj.className;
|
2018-11-19 23:32:16 +00:00
|
|
|
|
|
|
|
// right-click detect
|
|
|
|
if (event.which == 3) {
|
|
|
|
if (callingID == "imageID") {
|
|
|
|
setSelectedItem(obj.alt);
|
|
|
|
} else if (callingID == "dirID" || callingID == "fileID" ||
|
|
|
|
callingID == "movieID") {
|
2018-11-23 23:46:40 +00:00
|
|
|
let node = obj.parentNode;
|
2018-11-19 23:32:16 +00:00
|
|
|
setSelectedItem(node.children[1].value);
|
|
|
|
} else if (classNM == "fileStyle" || classNM == "dirStyle" ||
|
|
|
|
classNM == "movieStyle") {
|
|
|
|
setSelectedItem(obj.children[1].value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-12 18:20:47 +00:00
|
|
|
// Actions for content
|
2018-11-23 23:46:40 +00:00
|
|
|
document.ondblclick = (event) => {
|
|
|
|
let obj = event.target;
|
|
|
|
let callingID = obj.id;
|
|
|
|
let classNM = obj.className;
|
2018-04-18 10:57:57 +00:00
|
|
|
|
|
|
|
// Left click detect
|
|
|
|
if (event.which == 1) {
|
2018-05-03 08:14:28 +00:00
|
|
|
// If clicking on container
|
2019-01-28 18:56:27 +00:00
|
|
|
if (classNM === "fileStyle" || classNM === "movieStyle" ||
|
|
|
|
classNM === "dirStyle") {
|
|
|
|
if (classNM === "dirStyle") {
|
2018-05-03 08:14:28 +00:00
|
|
|
getDir(obj.children[1].value);
|
2019-01-28 18:56:27 +00:00
|
|
|
} else if (classNM === "movieStyle") {
|
2019-04-12 19:39:24 +00:00
|
|
|
showMedia(obj.children[0].value, "video");
|
2018-05-03 08:14:28 +00:00
|
|
|
} else {
|
2019-01-24 02:11:59 +00:00
|
|
|
showMedia(obj.children[1].value, "file");
|
2018-05-03 08:14:28 +00:00
|
|
|
}
|
2019-03-28 20:26:12 +00:00
|
|
|
} else if (callingID === "dirID") { // If clicking on dir icon
|
2018-11-23 23:46:40 +00:00
|
|
|
let node = obj.parentNode;
|
2019-01-24 04:25:19 +00:00
|
|
|
getDir(node.children[1].value);
|
2019-03-28 20:26:12 +00:00
|
|
|
} else if (callingID === "movieID") { // If clicking on movie thumbnail
|
2018-11-23 23:46:40 +00:00
|
|
|
let node = obj.parentNode;
|
2019-01-28 18:56:27 +00:00
|
|
|
showMedia(node.children[1].value, "video");
|
2019-03-28 20:26:12 +00:00
|
|
|
} else if (callingID === "fileID") { // If clicking on file icon
|
2018-11-23 23:46:40 +00:00
|
|
|
let node = obj.parentNode;
|
2019-01-24 02:11:59 +00:00
|
|
|
showMedia(node.children[1].value, "file");
|
2019-03-28 20:26:12 +00:00
|
|
|
} else if (callingID === "imageID") { // If clicking on image
|
2019-01-24 02:11:59 +00:00
|
|
|
showMedia(obj.alt, "image");
|
2019-03-28 20:26:12 +00:00
|
|
|
} else if (callingID === "titleID") { // If clicking on text title
|
2018-04-18 10:57:57 +00:00
|
|
|
enableEdit(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-23 01:43:19 +00:00
|
|
|
// Mainly for rename event
|
2018-11-23 23:46:40 +00:00
|
|
|
document.onkeydown = (event) => {
|
|
|
|
let obj = event.target;
|
|
|
|
let callingID = event.target.id;
|
|
|
|
let keyCodeVal = event.keyCode;
|
2018-04-18 10:57:57 +00:00
|
|
|
|
|
|
|
// If keycode == Enter
|
|
|
|
if (keyCodeVal == 13) {
|
|
|
|
if (callingID == "titleID") {
|
|
|
|
renameItem(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-23 01:43:19 +00:00
|
|
|
|
2019-03-28 20:26:12 +00:00
|
|
|
const setSelectedItem = (item) => { itemObj = item; }
|
2018-11-19 23:32:16 +00:00
|
|
|
|
2018-05-03 08:14:28 +00:00
|
|
|
// Drage event for the poped out image and media container
|
2018-11-23 23:46:40 +00:00
|
|
|
const dragContainer = (elmnt) => {
|
|
|
|
let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
|
2018-07-07 20:32:45 +00:00
|
|
|
elmnt.onmousedown = dragMouseDown;
|
2018-04-23 01:43:19 +00:00
|
|
|
|
|
|
|
function dragMouseDown(e) {
|
|
|
|
e = e || window.event;
|
|
|
|
pauseEvent(e);
|
|
|
|
// get the mouse cursor position at startup:
|
|
|
|
pos3 = e.clientX;
|
|
|
|
pos4 = e.clientY;
|
|
|
|
document.onmouseup = closeDragElement;
|
|
|
|
// call a function whenever the cursor moves:
|
|
|
|
document.onmousemove = elementDrag;
|
|
|
|
}
|
|
|
|
|
|
|
|
function elementDrag(e) {
|
|
|
|
e = e || window.event;
|
|
|
|
pauseEvent(e);
|
|
|
|
// calculate the new cursor position:
|
|
|
|
pos1 = pos3 - e.clientX;
|
|
|
|
pos2 = pos4 - e.clientY;
|
|
|
|
pos3 = e.clientX;
|
|
|
|
pos4 = e.clientY;
|
|
|
|
// set the element's new position:
|
|
|
|
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
|
|
|
|
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeDragElement(e) {
|
|
|
|
// stop moving when mouse button is released:
|
|
|
|
document.onmouseup = null;
|
|
|
|
document.onmousemove = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function pauseEvent(e) {
|
|
|
|
if(e.stopPropagation) e.stopPropagation();
|
|
|
|
if(e.preventDefault) e.preventDefault();
|
|
|
|
|
|
|
|
e.cancelBubble=true;
|
|
|
|
e.returnValue=false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|