var editor=null,fontSize=1.4;function copyToClipboard(a){var b=document.createElement("textarea");b.textContent=a;document.body.appendChild(b);b.select();document.execCommand("copy");document.body.removeChild(b)} function download(a,b){var c=new Blob([a],{type:"text/plain"});navigator.msSaveBlob?navigator.msSaveBlob(c,b):(a=document.createElement("a"),void 0!==a.download&&(c=URL.createObjectURL(c),a.setAttribute("href",c),a.setAttribute("download",b),a.style.visibility="hidden",document.body.appendChild(a),a.click(),document.body.removeChild(a)))}function incrFontSize(){fontSize+=.2;3<=fontSize&&(fontSize=3);changeFontSize()} function decrFontSize(){fontSize-=.2;.2>=fontSize&&(fontSize=.2);changeFontSize()}function changeFontSize(){editor.getWrapperElement().style["font-size"]=fontSize+"em";editor.refresh()}function closeMenu(a){a=void 0===a?null:a;document.querySelectorAll(".sub-menu ul").forEach(function(b){a&&a===b.parentNode||(b.style.display="none",b.parentNode.querySelectorAll("i.arrow").forEach(function(a){a.classList.remove("up");a.classList.add("down")}))})} function readSingleFile(a,b){if(a.target&&a.target.files)var c=a.target.files;else a.dataTransfer&&a.dataTransfer.files&&(c=a.dataTransfer.files);c&&0!=c.length?Array.prototype.forEach.call(c,function(a){var c=new FileReader;c.onload=function(){b(c.result,{file:a})};c.readAsText(a)}):b(null)} document.querySelectorAll(".sub-menu a").forEach(function(a){a.onclick=function(){for(var b=a.parentNode;b&&!b.classList.contains("sub-menu");)b=b.parentNode;b&&(closeMenu(b),b.querySelectorAll("ul").forEach(function(a){a.style.display=""==a.style.display?"none":""}),b.querySelectorAll("i.arrow").forEach(function(a){a.classList.toggle("up");a.classList.toggle("down")}))}}); window.addEventListener("load",function(){editor=CodeMirror.fromTextArea(document.getElementById("myeditor"),{lineNumbers:!0,viewportMargin:Infinity,lineWrapping:!0,autofocus:!0});changeFontSize();document.getElementById("file-copy").addEventListener("click",function(a){a=editor.getSelection();null!=a&&""!=a?copyToClipboard(a):copyToClipboard(editor.getValue("\n"))});document.getElementById("file-undo").addEventListener("click",function(a){editor.undo()});document.getElementById("file-redo").addEventListener("click", function(a){editor.redo()});document.getElementById("file-select-all").addEventListener("click",function(a){editor.execCommand("selectAll");editor.focus()});document.getElementById("file-new").addEventListener("click",function(a){editor.setValue("");editor.focus()});document.getElementById("file-open").addEventListener("click",function(a){document.getElementById("myfile").click()});document.getElementById("myfile").addEventListener("change",function(a){""!=document.getElementById("myfile").value&& (readSingleFile(a,function(a){editor.setValue(a)}),document.getElementById("myfile").value="")});document.getElementById("file-paste").addEventListener("click",function(a){navigator.clipboard.readText().then(function(a){var b=editor.getCursor();editor.replaceSelection(a);editor.focus();a=a.split("\n");b.line+=a.length-1;b.ch=0===a.length-1?b.ch+a[a.length-1].length:a[a.length-1].length;editor.setCursor(b)})});document.getElementById("file-print").addEventListener("click",function(a){a=window.open("", "","height=500, width=600");a.document.write("");a.document.write("
");a.document.write(""+editor.getValue("\n")+"");a.document.write("");a.document.close();a.print()});document.getElementById("file-save").addEventListener("click",function(a){download(editor.getValue("\n"),"myfile.txt")});document.getElementById("file-save-as").addEventListener("click",function(a){a=prompt("Enter file name");null!=a&&""!=a&&download(editor.getValue("\n"),a)});document.getElementById("view-zoom-in").addEventListener("click",
function(a){incrFontSize()});document.getElementById("view-zoom-out").addEventListener("click",function(a){decrFontSize()});document.addEventListener("keydown",function(a){a.ctrlKey&&a.stopPropagation();a.ctrlKey&&107==a.keyCode&&(incrFontSize(),a.preventDefault(),a.stopPropagation());a.ctrlKey&&109==a.keyCode&&(decrFontSize(),a.preventDefault(),a.stopPropagation())})},!0);