Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script>
- function AjaxForm(f,ret)
- {
- var inps = [], txts = [],xmlhttp;
- for(var a=0; a<f.childNodes.length; a++)
- {
- var b = f.childNodes[a];
- if(b.value!==undefined&&b.name!==undefined)inps.push(b);
- }
- for(var a=0; a<inps.length; a++)
- {
- var txt=escape(inps[a].name)+"=";
- if(inps[a].type=="file")
- {
- if(inps[a].fileData)
- {
- txt+=encodeURIComponent(inps[a].fileData);
- txt+="&"+escape(inps[a].name+"Title")+"="+encodeURIComponent(inps[a].value.match(/(?:[^\
- \]*){1}$/));
- }
- }
- else txt+=encodeURIComponent(inps[a].value);
- txts.push(txt);
- }
- var postData = txts.join("&");
- if (window.XMLHttpRequest)
- {
- xmlhttp=new XMLHttpRequest();
- }
- else
- {
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- ret(xmlhttp.responseText);
- }
- }
- switch(f.method.toUpperCase())
- {
- case "GET":
- xmlhttp.open(f.method,f.action+"?"+postData,true);
- xmlhttp.send();
- break;
- case "POST":
- xmlhttp.open(f.method,f.action,true);
- xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
- xmlhttp.send(postData);
- break;
- }
- }
- </script>
- <style>
- .folder,.file
- {
- display:block;
- padding:5px;
- padding-right:0px;
- white-space: nowrap;
- width:20px;
- }
- .folder
- {
- margin:10px;
- margin-right:0px;
- background: linear-gradient(to right, rgba(255,183,50,1) 63%,rgba(255,255,255,1) 78%);
- border:1px solid;
- border-right:0px solid;
- }
- .file
- {
- margin-left:10px;
- background: linear-gradient(to right, rgba(50,183,255,1) 63%,rgba(255,255,255,1) 78%);
- }
- #localFileExplorerWrap
- {
- position:absolute;
- left:0;top:0;bottom:0;
- width:300px;
- overflow-y:scroll;
- }
- #explorer
- {
- position:absolute;
- left:300px;
- top:0;bottom:0;right:0;
- }
- .menuButton
- {
- border:1px solid;
- display:block;
- z-index:100;
- padding-left:20px;
- padding-right:20px;
- background-color:#FFF;
- white-space: nowrap;
- }
- .menuButton >.menu
- {
- position:absolute;
- display:none;
- }
- .menuButton:hover >.menu
- {
- display:block;
- }
- .cover
- {
- position:absolute;
- display:block;
- top:18px;
- bottom:0;right:0;left:0;
- background-color:rgba(0,0,0,0.5);
- padding:20px;
- color:#FFF;
- overflow-y:scroll;
- }
- .cover.hide
- {
- position:relative;
- display:inline-block;
- height:18px;
- padding:0px;
- padding-left:10px;
- width:90px;
- margin-top:-18px;
- white-space: nowrap;
- overflow:hidden;
- }
- .cover.hide .title
- {
- position:absolute;
- background-color:rgb(0,0,0);
- opacity:1;
- display:block;
- left:0;
- top:0;
- width:100%;
- padding:0px;
- }
- .cover.hide:hover .title
- {
- position:absolute;
- opacity:0;
- display:block;
- z-index:-1;
- }
- .cover .hex {
- display: inline-block;
- font-family:Courier New;
- padding: 2px;
- }
- .cover .close,
- .cover .show,
- .cover .hide,
- .cover .title,
- .cover .toggle
- {
- padding:5px;
- display:inline;
- }
- .cover .content
- {
- background-color:#FFF;
- color:#000;
- background-repeat: no-repeat;
- background-size: contain;
- background-position: 50% 50%;
- width:100%;
- height:100%;
- resize:none;
- }
- </style>
- <script>
- var FileModule =
- {
- modules:new Array(),
- create:function(name,process,accept)
- {
- var mod = {process:process,accepts:accept};
- FileModule.modules[name] = mod;
- },
- run:function(file,result)
- {
- for(var a in FileModule.modules)
- {
- if(FileModule.modules[a].accepts(file,result))
- {
- FileModule.modules[a].process(file.name,result);
- break;
- }
- }
- }
- };
- var folder = new Array();
- function CreateLocalDir(dir,path,index,file)
- {
- if(index<path.length-1)
- {
- if(!dir["/"+path[index]]){dir["/"+path[index]] = new Array();}
- CreateLocalDir(dir["/"+path[index]],path,index+1,file);
- }
- else
- {
- dir.push({path:path[index],file:file});
- }
- }
- function UpdateLocalFiles(elem,event)
- {
- folder = new Array();
- localFileExplorer.innerHTML = "";
- var files = elem.files;
- for (var i = 0; i < files.length; i++)
- {
- var path = files[i].webkitRelativePath.split("/");
- CreateLocalDir(folder,path,0,files[i]);
- }
- for(var a in folder)
- {
- var div = document.createElement("div");
- div.innerText = a;
- div.className = "folder";
- div.setAttribute("path",a);
- div.addEventListener("click",function(event){DisplayLocalFolder(event,this)},false);
- localFileExplorer.appendChild(div);
- }
- }
- function DisplayLocalFile(event,clicked)
- {
- if(clicked == event.target)
- {
- var file = clicked.file;
- var fr = new FileReader();
- fr.onload = function()
- {
- if(fr.readyState==2){FileModule.run(file,this.result)};
- }
- switch(file.type)
- {
- case "text/plain":
- case "text/html":
- case "text/css":
- case "application/javascript":
- fr.readAsText(file);
- break;
- case "image/jpeg":
- case "image/png":
- case "image/gif":
- fr.readAsDataURL(file);
- break;
- default:
- fr.readAsBinaryString(file);
- }
- }
- }
- function CreateUnknownDisplay(name,result)
- {
- var cover = document.createElement("div");
- var content = document.createElement("div");
- cover.className="cover";
- content.className="content";
- content.innerText ="Unknown file type!\nDisplay \""+name+"\" using:\n";
- for(var a in FileModule.modules)
- {
- if(a!="Unknown")
- {
- var button = document.createElement("button");
- button.innerHTML = a;
- button.module = FileModule.modules[a];
- button.onclick = function()
- {
- this.module.process(name,result);
- cover.parentNode.removeChild(cover);
- }
- content.appendChild(button);
- }
- }
- cover.appendChild(content);
- explorer.appendChild(cover);
- }
- function CreateTextDisplay(name,result)
- {
- var cover = document.createElement("div");
- var close = document.createElement("div");
- var hide = document.createElement("div");
- var show = document.createElement("div");
- var title = document.createElement("div");
- var menu = document.createElement("div");
- var content = document.createElement("textarea");
- cover.className="cover";
- close.className="close";
- hide.className="hide";
- show.className="show";
- menu.className="menu";
- title.className = "title";
- content.className="content";
- cover.title = title.innerText = name;
- close.innerText = "[x]";
- hide.innerText = "[-]";
- show.innerText = "[+]";
- hide.addEventListener("click",function()
- {
- cover.className = "cover hide";
- },false);
- show.addEventListener("click",function()
- {
- cover.className = "cover";
- },false);
- close.addEventListener("click",function()
- {
- cover.parentNode.removeChild(cover);
- },false);
- menu.appendChild(close);
- menu.appendChild(hide);
- menu.appendChild(show);
- menu.appendChild(title);
- content.value = result;
- cover.appendChild(menu);
- cover.appendChild(content);
- explorer.appendChild(cover);
- return new Array(cover,close,hide,show,title,menu,content);
- }
- function CreateHexDisplay(name,result)
- {
- var cover = document.createElement("div");
- var close = document.createElement("div");
- var hide = document.createElement("div");
- var show = document.createElement("div");
- var title = document.createElement("div");
- var menu = document.createElement("div");
- var content = document.createElement("div");
- cover.className="cover";
- close.className="close";
- hide.className="hide";
- show.className="show";
- menu.className="menu";
- title.className = "title";
- content.className="content";
- cover.title = title.innerText = name;
- close.innerText = "[x]";
- hide.innerText = "[-]";
- show.innerText = "[+]";
- hide.addEventListener("click",function()
- {
- cover.className = "cover hide";
- },false);
- show.addEventListener("click",function()
- {
- cover.className = "cover";
- },false);
- close.addEventListener("click",function()
- {
- cover.parentNode.removeChild(cover);
- },false);
- menu.appendChild(close);
- menu.appendChild(hide);
- menu.appendChild(show);
- menu.appendChild(title);
- for(var a=0; a<result.length; a+=3)
- {
- var arr = new Array(result.charCodeAt(a),result.charCodeAt(a+1),result.charCodeAt(a+2));
- var int = (arr[0]<<16)+(arr[1]<<8)+(arr[2]);
- var foreground = "000000"+(int).toString(16);
- var background = "000000"+(16777215-int).toString(16);
- var res=document.createElement("span");
- res.className="hex";
- res.title=result[a]+result[a+1]+result[a+2];
- res.innerText=foreground.substr(foreground.length-6);
- res.style.backgroundColor ="#"+background.substr(background.length-6);
- res.style.color ="#"+foreground.substr(foreground.length-6);
- content.appendChild(res);
- }
- cover.appendChild(menu);
- cover.appendChild(content);
- explorer.appendChild(cover);
- return new Array(cover,close,hide,show,title,menu,content);
- }
- function CreateHTMLDisplay(name,result)
- {
- var cover = document.createElement("div");
- var close = document.createElement("div");
- var hide = document.createElement("div");
- var show = document.createElement("div");
- var title = document.createElement("div");
- var toggle = document.createElement("div");
- var menu = document.createElement("div");
- var content = document.createElement("div");
- var inp = document.createElement("textarea");
- var prev = document.createElement("iframe");
- cover.className="html cover";
- close.className="close";
- hide.className="hide";
- show.className="show";
- menu.className="menu";
- title.className = "title";
- toggle.className = "toggle";
- content.className="content";
- inp.className="content";
- prev.className="content";
- cover.title = title.innerText = name;
- close.innerText = "[x]";
- hide.innerText = "[-]";
- show.innerText = "[+]";
- toggle.innerText = "[preview]";
- hide.addEventListener("click",function()
- {
- cover.className = "cover hide";
- },false);
- show.addEventListener("click",function()
- {
- cover.className = "cover";
- },false);
- close.addEventListener("click",function()
- {
- cover.parentNode.removeChild(cover);
- },false);
- toggle.addEventListener("click",function()
- {
- if(toggle.innerText=="[preview]")
- {
- toggle.innerText="[code]";
- inp.style.display="none";
- prev.style.display="";
- }
- else
- {
- toggle.innerText="[preview]";
- inp.style.display="";
- prev.style.display="none";
- }
- },false);
- prev.style.display="none";
- inp.value = result;
- inp.onchange = function(event)
- {
- prev.contentDocument.open();
- prev.contentDocument.write(inp.value);
- prev.contentDocument.close();
- };
- content.appendChild(inp);
- content.appendChild(prev);
- menu.appendChild(close);
- menu.appendChild(hide);
- menu.appendChild(show);
- menu.appendChild(title);
- menu.appendChild(toggle);
- cover.appendChild(menu);
- cover.appendChild(content);
- explorer.appendChild(cover);
- inp.onchange();
- return new Array(cover,close,hide,show,title,toggle,menu,content,inp,prev);
- }
- function CreatePHPDisplay(name,result)
- {
- var html = CreateHTMLDisplay(name,result);
- var inp = html[8];
- var prev = html[9];
- inp.onchange = function(event)
- {
- dataInp.value = inp.value;
- AjaxForm(previewForm,function(data)
- {
- prev.contentDocument.open();
- prev.contentDocument.write(data);
- prev.contentDocument.close();
- });
- };
- inp.onchange();
- }
- function CreateImageDisplay(name,result)
- {
- var cover = document.createElement("div");
- var close = document.createElement("div");
- var hide = document.createElement("div");
- var show = document.createElement("div");
- var title = document.createElement("div");
- var menu = document.createElement("div");
- var content = document.createElement("div");
- cover.className="cover";
- close.className="close";
- hide.className="hide";
- show.className="show";
- menu.className="menu";
- title.className = "title";
- content.className="content";
- cover.title = title.innerText = name;
- close.innerText = "[x]";
- hide.innerText = "[-]";
- show.innerText = "[+]";
- hide.addEventListener("click",function()
- {
- cover.className = "cover hide";
- },false);
- show.addEventListener("click",function()
- {
- cover.className = "cover";
- },false);
- close.addEventListener("click",function()
- {
- cover.parentNode.removeChild(cover);
- },false);
- menu.appendChild(close);
- menu.appendChild(hide);
- menu.appendChild(show);
- menu.appendChild(title);
- content.style.backgroundImage = "url("+result+")";
- cover.appendChild(menu);
- cover.appendChild(content);
- explorer.appendChild(cover);
- return new Array(cover,close,hide,show,title,menu,content);
- }
- FileModule.create("Text", CreateTextDisplay, function(file,result){return /application
- \/javascript|text\/(plain|css)/.test(file.type);});
- FileModule.create("HTML", CreateHTMLDisplay, function(file,result){return /text\/html/.test
- (file.type);});
- FileModule.create("PHP", CreatePHPDisplay, function(file,result){return /.php$/.test
- (file.name);});
- FileModule.create("Image", CreateImageDisplay, function(file,result){return /^image\//.test
- (file.type);});
- FileModule.create("Hex", CreateHexDisplay, function(file,result){return /.exe$/.test
- (file.name);});
- FileModule.create("Unknown",CreateUnknownDisplay,function(file,result){return true;});
- function DisplayLocalFolder(event,clicked)
- {
- if(clicked == event.target)
- {
- var parent = event.target;
- var alreadyOpen = parent.getElementsByTagName("div");
- if(alreadyOpen.length>0)
- {
- while(alreadyOpen.length>0)
- {
- parent.removeChild(alreadyOpen[0]);
- }
- }
- else
- {
- var path = parent.getAttribute("path").split(/(?=\/)/).filter(Boolean);
- var dir = folder[path[0]];
- for(var a=1; a<path.length; a++)
- {
- dir = dir[path[a]];
- }
- for(var a in dir)
- {
- if(!/^[0-9]+$/.test(a))
- {
- var div = document.createElement("div");
- div.innerText = a.substr(1);
- div.className = "folder";
- div.setAttribute("path",path.join("")+a);
- div.addEventListener("click",function(event){DisplayLocalFolder(event,this)},false);
- parent.appendChild(div);
- }
- }
- for(var a in dir)
- {
- if(/^[0-9]+$/.test(a))
- {
- var div = document.createElement("div");
- div.className = "file";
- div.innerText = dir[a].path;
- div.file = dir[a].file;
- div.addEventListener("click",function(event){DisplayLocalFile(event,this)},false);
- parent.appendChild(div);
- }
- }
- }
- }
- }
- </script>
- </head>
- <body>
- <form method="POST" action="ajax.php" id="previewForm">
- <input type="hidden" name="data" id="dataInp" value=""/>
- <input type="hidden" name="debug" id="debugInp" value="true"/>
- <input type="hidden" name="save" id="save" value="no"/>
- <input type="hidden" name="location" id="loc" value=""/>
- <input type="hidden" id="autosave" name="savecb"/>
- </form>
- <div id="localFileExplorerWrap">
- <input type="file" id="localFilesInput" webkitdirectory directory multiple
- onchange="UpdateLocalFiles(this,event)" style="display:none"/>
- <div id="localFileExplorerMenu">
- <div class="menuButton">File Explorer
- <div class="menu">
- <div class="menuButton">New
- <div class="menu" id="fileTypes">
- <div class="menuButton" type="text/plain">Text File</div>
- <div class="menuButton" type="image/png">Image</div>
- <div class="menuButton" type="text/html">PHP page</div>
- </div>
- </div>
- <div class="menuButton" onclick="Save()">Save all</div>
- <div class="menuButton" onclick="localFilesInput.click()">Open</div>
- </div>
- </div>
- </div>
- <div id="localFileExplorer" oncontextmenu="ShowOptions(event)"></div>
- </div>
- <div id="explorer">
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement