mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-04-19 21:07:21 +00:00
1 line
10 KiB
HTML
1 line
10 KiB
HTML
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><title>File Editor</title><style media=screen>.cm{z-index:300;position:absolute;left:5px;border:1px solid #444;background-color:#f5f5f5;display:none;box-shadow:0 0 10px rgba(0,0,0,.4);font-size:12px;font-family:sans-serif;font-weight:700}.cm ul{list-style:none;top:0;left:0;margin:0;padding:0}.cm li{position:relative;min-width:60px;cursor:pointer}.cm span{color:#444;display:inline-block;padding:6px}.cm li:hover{background:#444}.cm li:hover span{color:#eee}.tvu li,.tvu ul{padding:0;margin:0;list-style:none}.tvu input{position:absolute;opacity:0}.tvu{font:normal 12px Verdana,Arial,Sans-serif;-moz-user-select:none;-webkit-user-select:none;user-select:none;color:#444;line-height:16px}.tvu span{margin-bottom:5px;padding:0 0 0 18px;white-space:nowrap;cursor:pointer;display:inline-block;height:16px;vertical-align:middle;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADoSURBVBgZBcExblNBGAbA2ceegTRBuIKOgiihSZNTcC5LUHAihNJR0kGKCDcYJY6D3/77MdOinTvzAgCw8ysThIvn/VojIyMjIyPP+bS1sUQIV2s95pBDDvmbP/mdkft83tpYguZq5Jh/OeaYh+yzy8hTHvNlaxNNczm+la9OTlar1UdA/+C2A4trRCnD3jS8BB1obq2Gk6GU6QbQAS4BUaYSQAf4bhhKKTFdAzrAOwAxEUAH+KEM01SY3gM6wBsEAQB0gJ+maZoC3gI6iPYaAIBJsiRmHU0AALOeFC3aK2cWAACUXe7+AwO0lc9eTHYTAAAAAElFTkSuQmCC) no-repeat;background-position:0 0}.tvu span:hover{text-decoration:underline}@media screen and (-webkit-min-device-pixel-ratio:0){.tvu{-webkit-animation:webkit-adjacent-element-selector-bugfix infinite 1s}}@-webkit-keyframes webkit-adjacent-element-selector-bugfix{from{padding:0}to{padding:0}}#uploader{position:absolute;top:0;right:0;left:0;height:28px;line-height:24px;padding-left:10px;padding-right:10px;background-color:#444;color:#eee}#tree{position:absolute;top:28px;bottom:0;left:0;width:160px;padding:8px}#editor,#preview{position:absolute;top:28px;right:0;bottom:0;left:160px;border-left:1px solid #eee}#preview{background-color:#eee;padding:5px}button.right{float:right}input.number{float:right;width:48px}</style><script>function createFileUploader(p,y,g){var w=document.createElement("button");w.innerHTML="Main Menu",document.getElementById(p).appendChild(w);var f,q=document.createElement("input");q.type="file",q.multiple=!1,q.name="data",document.getElementById(p).appendChild(q);var v=document.createElement("input");v.id="upload-path",v.type="text",v.name="path",v.defaultValue="/",document.getElementById(p).appendChild(v);var j=document.createElement("button");j.innerHTML="Upload",document.getElementById(p).appendChild(j);var k=document.createElement("button");k.innerHTML="Create",document.getElementById(p).appendChild(k);var z=document.createElement("button");z.innerHTML="Reload Pages",document.getElementById(p).appendChild(z),z.className="right";var b=document.createElement("button");b.innerHTML="Clear Pages",document.getElementById(p).appendChild(b),b.className="right";var h=document.createElement("input");function x(){4==f.readyState&&(200!=f.status?alert("ERROR["+f.status+"]: "+f.responseText):y.refreshPath(v.value))}h.setAttribute("type","number"),h.setAttribute("min",1),h.setAttribute("max",12),document.getElementById(p).appendChild(h),h.className="number",k.onclick=function(a){-1!==v.value.indexOf(".")&&(function(d){(f=new XMLHttpRequest).onreadystatechange=x;var c=new FormData;c.append("path",d),f.open("PUT","/edit"),f.send(c)}(v.value),g.loadUrl(v.value))},j.onclick=function(c){if(0!==q.files.length){(f=new XMLHttpRequest).onreadystatechange=x;var a=new FormData;a.append("data",q.files[0],v.value),f.open("POST","/edit"),f.send(a)}},q.onchange=function(i){if(0!==q.files.length){var d=q.files[0].name,l=/(?:\.([^.]+))?$/.exec(d)[1],c=/(.*)\.[^.]+$/.exec(d)[1];void 0!==typeof c&&(d=c),void 0!==typeof l&&("html"===l?l="htm":"jpeg"===l&&(l="jpg"),d=d+"."+l),"/"===v.value||0===v.value.lastIndexOf("/")?v.value="/"+d:v.value=v.value.substring(0,v.value.lastIndexOf("/")+1)+d}},z.onclick=function(a){!function(d){(f=new XMLHttpRequest).onreadystatechange=x;var c=new FormData;c.append("load",d),f.open("PUT","/edit"),f.send(c)}(v.value)},b.onclick=function(a){!function(d){(f=new XMLHttpRequest).onreadystatechange=x;var c=new FormData;c.append("init",d),f.open("PUT","/edit"),f.send(c)}(v.value)},w.onclick=function(a){v.value,window.location.href="/"},h.onchange=function(a){!function(d){(f=new XMLHttpRequest).onreadystatechange=x;var c=new FormData;c.append("page",d),f.open("PUT","/edit"),f.send(c)}(h.value)}}function createTree(j,q){var f=document.getElementById("preview"),p=document.createElement("div");function b(a){document.getElementById("editor").style.display="none",f.style.display="block",f.innerHTML='<img src="'+a+"?_cb="+Date.now()+'" style="max-width:100%; max - height: 100 % ; margin: auto; display: block;" />'}function k(l,t){var o=document.createElement("ul");l.appendChild(o);var s=document.createElement("li");o.appendChild(s),g(t)?(s.innerHTML="<span>Edit</span>",s.onclick=function(c){q.loadUrl(t),document.body.getElementsByClassName("cm").length>0&&document.body.removeChild(l)}):h(t)&&(s.innerHTML="<span>Preview</span>",s.onclick=function(c){b(t),document.body.getElementsByClassName("cm").length>0&&document.body.removeChild(l)});var i=document.createElement("li");o.appendChild(i),i.innerHTML="<span>Download</span>",i.onclick=function(c){!function(d){document.getElementById("download-frame").src=d+"?download=true"}(t),document.body.getElementsByClassName("cm").length>0&&document.body.removeChild(l)};var a=document.createElement("li");o.appendChild(a),a.innerHTML="<span>Delete</span>",a.onclick=function(c){!function(n){xmlHttp=new XMLHttpRequest,xmlHttp.onreadystatechange=function(){4==xmlHttp.readyState&&(200!=xmlHttp.status?alert("ERROR["+xmlHttp.status+"]: "+xmlHttp.responseText):(p.removeChild(p.childNodes[0]),r(p,"/")))};var d=new FormData;d.append("path",n),xmlHttp.open("DELETE","/edit"),xmlHttp.send(d)}(t),document.body.getElementsByClassName("cm").length>0&&document.body.removeChild(l)}}function m(l,t,d){var o=document.createElement("li");o.id=("/"==l?"":l)+"/"+t;var i=document.createElement("span");return i.innerText=t,o.appendChild(i),o.onclick=function(a){g(o.id.toLowerCase())?q.loadUrl(o.id):h(o.id.toLowerCase())&&b(o.id)},o.oncontextmenu=function(a){a.preventDefault(),a.stopPropagation(),function(z,C,w){var B=document.createElement("div"),v=document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop,A=document.body.scrollLeft?document.body.scrollLeft:document.documentElement.scrollLeft,x=event.clientX+A,y=event.clientY+v;B.className="cm",B.style.display="block",B.style.left=x+"px",B.style.top=y+"px",k(B,C),document.body.appendChild(B);var D=B.offsetWidth,u=B.offsetHeight;B.onmouseout=function(c){(c.clientX<x||c.clientX>x+D||c.clientY<y||c.clientY>y+u)&&document.body.getElementsByClassName("cm").length>0&&document.body.removeChild(B)}}(0,o.id)},o}function g(c){var a=/(?:\.([^.]+))?$/.exec(c)[1];if(void 0!==typeof a){switch(a){case"txt":case"cmd":case"json":case"jsonl":case"htm":case"js":case"c":case"cpp":case"css":case"xml":return !0}}return !1}function h(c){var a=/(?:\.([^.]+))?$/.exec(c)[1];if(void 0!==typeof a){switch(a){case"bmp":case"png":case"jpg":case"gif":return !0}}return !1}function r(c,a){xmlHttp=new XMLHttpRequest(c,a),xmlHttp.onreadystatechange=function(i,d){return function(){4==xmlHttp.readyState&&200==xmlHttp.status&&function(u,s,x){var l=document.createElement("ul");u.appendChild(l);for(var w=x.length,v=0;v<w;v++){"file"===x[v].type&&l.appendChild(m(s,x[v].name,x[v].size))}}(i,d,JSON.parse(xmlHttp.responseText))}}(c,a),xmlHttp.open("GET","/list?dir="+a,!0),xmlHttp.send(null)}return p.className="tvu",document.getElementById(j).appendChild(p),this.refreshPath=function(a){p.removeChild(p.childNodes[0]),r(p,"/")},r(p,"/"),this}function createEditor(k,u,g,q,f){function m(c){var a="plain",d=/(?:\.([^.]+))?$/.exec(c)[1];if(void 0!==typeof d){switch(d){case"txt":case"cmd":a="plain";break;case"htm":a="html";break;case"js":a="javascript";break;case"jsonl":a="json";break;case"c":case"cpp":a="c_cpp";break;case"css":case"scss":case"php":case"html":case"json":case"xml":a=d}}return a}void 0===u&&(u="/"),void 0===g&&(g=m(u)),void 0===q&&(q="textmate"),void 0===f&&(f="text/"+g,"c_cpp"===g&&(f="text/plain"));var p=null,h=ace.edit(k,{useWorker:!1,wrap:!0,indentedSoftWrap:!1});function j(){4==p.readyState&&200!=p.status&&alert("ERROR["+p.status+"]: "+p.responseText)}function v(){4==p.readyState&&(document.getElementById("preview").style.display="none",document.getElementById("editor").style.display="block",function(c,a){if(200==a.status){try{var d=JSON.parse(a.responseText);c.setValue(JSON.stringify(d,null,4))}catch(d){c.setValue(a.responseText)}}else{c.setValue("")}c.resize(!0),c.scrollToLine(1,!0,!0,function(){}),c.gotoLine(1,0,!0),c.clearSelection()}(h,p))}function b(a){(p=new XMLHttpRequest).onreadystatechange=v,p.open("GET",a,!0),p.send(null)}return"plain"!==g&&h.getSession().setMode("ace/mode/"+g),h.setTheme("ace/theme/"+q),h.$blockScrolling=1/0,h.getSession().setUseSoftTabs(!0),h.getSession().setTabSize(2),h.setHighlightActiveLine(!0),h.setShowPrintMargin(!1),h.commands.addCommand({name:"saveCommand",bindKey:{win:"Ctrl-S",mac:"Command-S"},exec:function(a){!function(i,d,l){(p=new XMLHttpRequest).onreadystatechange=j;var c=new FormData;c.append("data",new Blob([d],{type:l}),i),p.open("POST","/edit"),p.send(c)}(u,function(d){var c=d.getValue();try{var i=JSON.parse(c);return JSON.stringify(i)}catch(d){return c+""}}(a),f)},readOnly:!1}),h.commands.addCommand({name:"undoCommand",bindKey:{win:"Ctrl-Z",mac:"Command-Z"},exec:function(a){a.getSession().getUndoManager().undo(!1)},readOnly:!1}),h.commands.addCommand({name:"redoCommand",bindKey:{win:"Ctrl-Shift-Z",mac:"Command-Shift-Z"},exec:function(a){a.getSession().getUndoManager().redo(!1)},readOnly:!1}),b(u),h.loadUrl=function(a){g=m(u=a),f="text/"+g,"plain"!==g&&h.getSession().setMode("ace/mode/"+g),b(u),document.getElementById("upload-path").value=a},h}function onBodyLoad(){var b={},a=(window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(d,e,c){b[e]=c}),createEditor("editor",b.file,b.lang,b.theme));createFileUploader("uploader",createTree("tree",a),a),b.file&&(document.getElementById("upload-path").value=b.file)};</script><script src=https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js></script></head><body onload=onBodyLoad()><div id=uploader></div><div id=tree></div><div id=editor></div><div id=preview style=display:none></div><iframe id=download-frame style=display:none></iframe></body></html> |