mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-26 20:56:37 +00:00
Fix filename parsing
This commit is contained in:
parent
8d16dfb186
commit
c43403b3f7
141
data/edit.htm
141
data/edit.htm
@ -179,8 +179,8 @@
|
|||||||
}, d.onchange = function(e) {
|
}, d.onchange = function(e) {
|
||||||
if (0 !== d.files.length) {
|
if (0 !== d.files.length) {
|
||||||
var t = d.files[0].name,
|
var t = d.files[0].name,
|
||||||
n = /(?:.([^.]+))?$/.exec(t)[1],
|
n = /(?:\.([^.]+))?$/.exec(t)[1],
|
||||||
a = /(.*).[^.]+$/.exec(t)[1];
|
a = /(.*)\.[^.]+$/.exec(t)[1];
|
||||||
void 0 !== typeof a && (t = a), void 0 !== typeof n && ("html" === n ? n = "htm" : "jpeg" === n && (n = "jpg"), t = t + "." + n), "/" === c.value || 0 === c.value.lastIndexOf("/") ? c.value = "/" + t : c.value = c.value.substring(0, c.value.lastIndexOf("/") + 1) + t
|
void 0 !== typeof a && (t = a), void 0 !== typeof n && ("html" === n ? n = "htm" : "jpeg" === n && (n = "jpg"), t = t + "." + n), "/" === c.value || 0 === c.value.lastIndexOf("/") ? c.value = "/" + t : c.value = c.value.substring(0, c.value.lastIndexOf("/") + 1) + t
|
||||||
}
|
}
|
||||||
}, s.onclick = function(e) {
|
}, s.onclick = function(e) {
|
||||||
@ -206,66 +206,64 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTree(e, t) {
|
function createTree(e, r) {
|
||||||
var n = document.getElementById("preview"),
|
var t = document.getElementById("preview"),
|
||||||
a = document.createElement("div");
|
m = document.createElement("div");
|
||||||
|
|
||||||
function o(e) {
|
function u(e) {
|
||||||
document.getElementById("editor").style.display = "none", n.style.display = "block", n.innerHTML = '<img src="' + e + "?_cb=" + Date.now() + '" style="max-width:100%; max - height: 100 % ; margin: auto; display: block;"/>'
|
document.getElementById("editor").style.display = "none", t.style.display = "block", t.innerHTML = '<img src="' + e + "?_cb=" + Date.now() + '" style="max-width:100%; max - height: 100 % ; margin: auto; display: block;"/>'
|
||||||
}
|
}
|
||||||
|
|
||||||
function d(e, n) {
|
function c(e, t, n) {
|
||||||
var d = document.createElement("ul");
|
var a = document.createElement("li");
|
||||||
e.appendChild(d);
|
a.id = ("/" == e ? "" : e) + "/" + t;
|
||||||
var c = document.createElement("li");
|
var o = document.createElement("span");
|
||||||
d.appendChild(c), l(n) ? (c.innerHTML = "<span>Edit</span>", c.onclick = function(a) {
|
return o.innerText = t, a.appendChild(o), a.onclick = function(e) {
|
||||||
t.loadUrl(n), document.body.getElementsByClassName("cm").length > 0 && document.body.removeChild(e)
|
p(a.id.toLowerCase()) ? r.loadUrl(a.id) : f(a.id.toLowerCase()) && u(a.id)
|
||||||
}) : i(n) && (c.innerHTML = "<span>Preview</span>", c.onclick = function(t) {
|
}, a.oncontextmenu = function(e) {
|
||||||
o(n), document.body.getElementsByClassName("cm").length > 0 && document.body.removeChild(e)
|
|
||||||
});
|
|
||||||
var r = document.createElement("li");
|
|
||||||
d.appendChild(r), r.innerHTML = "<span>Download</span>", r.onclick = function(t) {
|
|
||||||
! function(e) {
|
|
||||||
document.getElementById("download-frame").src = e + "?download=true"
|
|
||||||
}(n), document.body.getElementsByClassName("cm").length > 0 && document.body.removeChild(e)
|
|
||||||
};
|
|
||||||
var m = document.createElement("li");
|
|
||||||
d.appendChild(m), m.innerHTML = "<span>Delete</span>", m.onclick = function(t) {
|
|
||||||
! function(e) {
|
|
||||||
xmlHttp = new XMLHttpRequest, xmlHttp.onreadystatechange = function() {
|
|
||||||
4 == xmlHttp.readyState && (200 != xmlHttp.status ? alert("ERROR[" + xmlHttp.status + "]: " + xmlHttp.responseText) : (a.removeChild(a.childNodes[0]), s(a, "/")))
|
|
||||||
};
|
|
||||||
var t = new FormData;
|
|
||||||
t.append("path", e), xmlHttp.open("DELETE", "/edit"), xmlHttp.send(t)
|
|
||||||
}(n), document.body.getElementsByClassName("cm").length > 0 && document.body.removeChild(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function c(e, n, a) {
|
|
||||||
var c = document.createElement("li");
|
|
||||||
c.id = ("/" == e ? "" : e) + "/" + n;
|
|
||||||
var s = document.createElement("span");
|
|
||||||
return s.innerText = n, c.appendChild(s), c.onclick = function(e) {
|
|
||||||
l(c.id.toLowerCase()) ? t.loadUrl(c.id) : i(c.id.toLowerCase()) && o(c.id)
|
|
||||||
}, c.oncontextmenu = function(e) {
|
|
||||||
e.preventDefault(), e.stopPropagation(),
|
e.preventDefault(), e.stopPropagation(),
|
||||||
function(e, t, n) {
|
function(e, t, n) {
|
||||||
var a = document.createElement("div"),
|
var a = document.createElement("div"),
|
||||||
o = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop,
|
o = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop,
|
||||||
c = document.body.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft,
|
d = document.body.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft,
|
||||||
l = event.clientX + c,
|
c = event.clientX + d,
|
||||||
i = event.clientY + o;
|
l = event.clientY + o;
|
||||||
a.className = "cm", a.style.display = "block", a.style.left = l + "px", a.style.top = i + "px", d(a, t), document.body.appendChild(a);
|
a.className = "cm", a.style.display = "block", a.style.left = c + "px", a.style.top = l + "px",
|
||||||
var s = a.offsetWidth,
|
function(n, a) {
|
||||||
r = a.offsetHeight;
|
var e = document.createElement("ul");
|
||||||
a.onmouseout = function(e) {
|
n.appendChild(e);
|
||||||
(e.clientX < l || e.clientX > l + s || e.clientY < i || e.clientY > i + r) && document.body.getElementsByClassName("cm").length > 0 && document.body.removeChild(a)
|
var t = document.createElement("li");
|
||||||
|
e.appendChild(t), p(a) ? (t.innerHTML = "<span>Edit</span>", t.onclick = function(e) {
|
||||||
|
r.loadUrl(a), 0 < document.body.getElementsByClassName("cm").length && document.body.removeChild(n)
|
||||||
|
}) : f(a) && (t.innerHTML = "<span>Preview</span>", t.onclick = function(e) {
|
||||||
|
u(a), 0 < document.body.getElementsByClassName("cm").length && document.body.removeChild(n)
|
||||||
|
});
|
||||||
|
var o = document.createElement("li");
|
||||||
|
e.appendChild(o), o.innerHTML = "<span>Download</span>", o.onclick = function(e) {
|
||||||
|
var t;
|
||||||
|
t = a, document.getElementById("download-frame").src = t + "?download=true", 0 < document.body.getElementsByClassName("cm").length && document.body.removeChild(n)
|
||||||
|
};
|
||||||
|
var d = document.createElement("li");
|
||||||
|
e.appendChild(d), d.innerHTML = "<span>Delete</span>", d.onclick = function(e) {
|
||||||
|
! function(e) {
|
||||||
|
xmlHttp = new XMLHttpRequest, xmlHttp.onreadystatechange = function() {
|
||||||
|
4 == xmlHttp.readyState && (200 != xmlHttp.status ? alert("ERROR[" + xmlHttp.status + "]: " + xmlHttp.responseText) : (m.removeChild(m.childNodes[0]), h(m, "/")))
|
||||||
|
};
|
||||||
|
var t = new FormData;
|
||||||
|
t.append("path", e), xmlHttp.open("DELETE", "/edit"), xmlHttp.send(t)
|
||||||
|
}(a), 0 < document.body.getElementsByClassName("cm").length && document.body.removeChild(n)
|
||||||
}
|
}
|
||||||
}(0, c.id)
|
}(a, t), document.body.appendChild(a);
|
||||||
}, c
|
var i = a.offsetWidth,
|
||||||
|
s = a.offsetHeight;
|
||||||
|
a.onmouseout = function(e) {
|
||||||
|
(e.clientX < c || e.clientX > c + i || e.clientY < l || e.clientY > l + s) && 0 < document.body.getElementsByClassName("cm").length && document.body.removeChild(a)
|
||||||
|
}
|
||||||
|
}(0, a.id)
|
||||||
|
}, a
|
||||||
}
|
}
|
||||||
|
|
||||||
function l(e) {
|
function p(e) {
|
||||||
var t = /(?:.([^.]+))?$/.exec(e)[1];
|
var t = /(?:.([^.]+))?$/.exec(e)[1];
|
||||||
if (void 0 !== typeof t) switch (t) {
|
if (void 0 !== typeof t) switch (t) {
|
||||||
case "txt":
|
case "txt":
|
||||||
@ -282,7 +280,7 @@
|
|||||||
return !1
|
return !1
|
||||||
}
|
}
|
||||||
|
|
||||||
function i(e) {
|
function f(e) {
|
||||||
var t = /(?:.([^.]+))?$/.exec(e)[1];
|
var t = /(?:.([^.]+))?$/.exec(e)[1];
|
||||||
if (void 0 !== typeof t) switch (t) {
|
if (void 0 !== typeof t) switch (t) {
|
||||||
case "png":
|
case "png":
|
||||||
@ -293,20 +291,19 @@
|
|||||||
return !1
|
return !1
|
||||||
}
|
}
|
||||||
|
|
||||||
function s(e, t) {
|
function h(e, t) {
|
||||||
xmlHttp = new XMLHttpRequest(e, t), xmlHttp.onreadystatechange = function(e, t) {
|
var n, a;
|
||||||
return function() {
|
xmlHttp = new XMLHttpRequest(e, t), xmlHttp.onreadystatechange = (n = e, a = t, function() {
|
||||||
4 == xmlHttp.readyState && 200 == xmlHttp.status && function(e, t, n) {
|
4 == xmlHttp.readyState && 200 == xmlHttp.status && function(e, t, n) {
|
||||||
var a = document.createElement("ul");
|
var a = document.createElement("ul");
|
||||||
e.appendChild(a);
|
e.appendChild(a);
|
||||||
for (var o = n.length, d = 0; d < o; d++) "file" === n[d].type && a.appendChild(c(t, n[d].name, n[d].size))
|
for (var o = n.length, d = 0; d < o; d++) "file" === n[d].type && a.appendChild(c(t, n[d].name, n[d].size))
|
||||||
}(e, t, JSON.parse(xmlHttp.responseText))
|
}(n, a, JSON.parse(xmlHttp.responseText))
|
||||||
|
}), xmlHttp.open("GET", "/list?dir=" + t, !0), xmlHttp.send(null)
|
||||||
}
|
}
|
||||||
}(e, t), xmlHttp.open("GET", "/list?dir=" + t, !0), xmlHttp.send(null)
|
return m.className = "tvu", document.getElementById(e).appendChild(m), this.refreshPath = function(e) {
|
||||||
}
|
m.removeChild(m.childNodes[0]), h(m, "/")
|
||||||
return a.className = "tvu", document.getElementById(e).appendChild(a), this.refreshPath = function(e) {
|
}, h(m, "/"), this
|
||||||
a.removeChild(a.childNodes[0]), s(a, "/")
|
|
||||||
}, s(a, "/"), this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createEditor(e, t, n, a, o) {
|
function createEditor(e, t, n, a, o) {
|
||||||
@ -373,7 +370,7 @@
|
|||||||
win: "Ctrl-S",
|
win: "Ctrl-S",
|
||||||
mac: "Command-S"
|
mac: "Command-S"
|
||||||
},
|
},
|
||||||
exec: function(e) {
|
exec: function(a) {
|
||||||
! function(e, t, n) {
|
! function(e, t, n) {
|
||||||
(c = new XMLHttpRequest).onreadystatechange = i;
|
(c = new XMLHttpRequest).onreadystatechange = i;
|
||||||
var a = new FormData;
|
var a = new FormData;
|
||||||
@ -381,14 +378,14 @@
|
|||||||
type: n
|
type: n
|
||||||
}), e), c.open("POST", "/edit"), c.send(a)
|
}), e), c.open("POST", "/edit"), c.send(a)
|
||||||
}(t, function(e) {
|
}(t, function(e) {
|
||||||
var t = e.getValue();
|
var t = a.getValue();
|
||||||
try {
|
try {
|
||||||
var n = JSON.parse(t);
|
var n = JSON.parse(t);
|
||||||
return JSON.stringify(n)
|
return JSON.stringify(n)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return t + ""
|
return t + ""
|
||||||
}
|
}
|
||||||
}(e), o)
|
}(), o)
|
||||||
},
|
},
|
||||||
readOnly: !1
|
readOnly: !1
|
||||||
}), l.commands.addCommand({
|
}), l.commands.addCommand({
|
||||||
@ -417,21 +414,21 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onBodyLoad() {
|
function onBodyLoad() {
|
||||||
var e = {},
|
var a = {},
|
||||||
t = (window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(t, n, a) {
|
e = (window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(e, t, n) {
|
||||||
e[n] = a
|
a[t] = n
|
||||||
}), createEditor("editor", e.file, e.lang, e.theme));
|
}), createEditor("editor", a.file, a.lang, a.theme));
|
||||||
createFileUploader("uploader", createTree("tree", t), t), e.file && (document.getElementById("upload-path").value = e.file)
|
createFileUploader("uploader", createTree("tree", e), e), a.file && (document.getElementById("upload-path").value = a.file)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script charset=utf-8 src=https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js></script>
|
<script charset=utf-8 src=https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body onload=onBodyLoad();>
|
<body onload=onBodyLoad()>
|
||||||
<div id=uploader></div>
|
<div id=uploader></div>
|
||||||
<div id=tree></div>
|
<div id=tree></div>
|
||||||
<div id=editor></div>
|
<div id=editor></div>
|
||||||
<div id=preview style=display:none;></div><iframe id=download-frame style=display:none;></iframe>
|
<div id=preview style=display:none></div><iframe id=download-frame style=display:none></iframe>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
BIN
data/edit.htm.gz
BIN
data/edit.htm.gz
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user