Copyright (C) 2007-2013 mustafa
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation.
return document.getElementById(element);
var popup, fOp, edit, upload, shell, __AJAX_ACTIVE,
__CODEMIRROR, __CODEMIRROR_MODE, __CODEMIRROR_LOADED, __CODEMIRROR_PATH = "_cm",
function ajax(url, method, data, handler, upload, uploadProgressHandler) {
"src" : "pafm-files/images/ajax.gif",
$("ajaxOverlay").style.height = document.body.offsetHeight + "px";
fade($("ajaxOverlay"), 0, 6, 25, "in");
var xhr = window.ActiveXObject ? new ActiveXObject("MSXML2.XMLHTTP.3.0") : new XMLHttpRequest();
uploadProgressHandler && xhr.upload.addEventListener("progress", uploadProgressHandler, false);
xhr.open(method, url, true);
xhr.onreadystatechange = function(){
upload || fade($("ajaxOverlay"), 6, 0, 25, "out", function(){
document.body.removeChild($("ajaxOverlay"));
document.body.removeChild($("ajaxImg"));
if (xhr.status == 200 || xhr.statusText == "OK") {
if (xhr.responseText == "Please refresh the page and login")
handler(xhr.responseText);
alert("AJAX request unsuccessful."
+ "\nStatus Code: " + xhr.status
+ "\nStatus Text: " + xhr.statusText
+ "\nParameters: " + url);
if (method.toLowerCase() == "post" && !upload)
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
function json2markup(json, path) {
var i = 0, l = json.length, el, attrib, event;
if (json[i].constructor == Array)
json2markup(json[i], el);
else if (json[i].constructor == Object){
for (attrib in json[i].attributes)
switch (attrib.toLowerCase()){
el.className = json[i].attributes[attrib];
el.style.cssText = json[i].attributes[attrib];
el.htmlFor = json[i].attributes[attrib];
el.setAttribute(attrib, json[i].attributes[attrib]);
for (event in json[i].events)
el.addEventListener(event, json[i].events[event], false);
path.appendChild(document.createTextNode(json[i].preText));
el.appendChild(document.createTextNode(json[i].text));
path.parentNode.insertBefore(el, path);
path.parentNode.insertBefore(el, path.nextSibling);
path.appendChild(document.createTextNode(json[i].postText));
el = document.createElement(json[i]);
function fade(element, fadeFrom, fadeTo, speed, type, callback) {
var which = element.style.opacity != undefined, condition, interval;
element.style[which ? "opacity" : "filter"] = which ? fadeFrom / 10 : "alpha(opacity="+ fadeFrom * 10 +")";
interval = setInterval(function(){
condition = fadeFrom <= fadeTo;
condition = fadeFrom >= fadeTo;
element.style[which ? "opacity" : "filter"] = which ? fadeFrom / 10 : "alpha(opacity="+ fadeFrom * 10 +")";
init : function(title, content) {
e.preventDefault ? e.preventDefault() : e.returnValue = false;
var popupEl = $("popup"), popOverlayEl = $("popOverlay"), mlEl;
json2markup(content, $("body"));
if (mlEl = $('moveListUL')) {
if (mlEl.offsetHeight > (document.body.offsetHeight - 150))
mlEl.style.height = document.body.offsetHeight - 150 + "px";
popupEl.style.marginTop = "-" + parseInt(popupEl.offsetHeight) / 2 + "px";
popupEl.style.marginLeft = "-" + parseInt(popupEl.offsetWidth) / 2 + "px";
fade(popOverlayEl, 0, 6, 25, "in");
document.onkeydown = function(e) {
if ((e || window.event).keyCode == 27) {
var popOverlayEl = $("popOverlay");
fade(popOverlayEl, 6, 0, 25, "out", function(){
document.body.removeChild(popOverlayEl);
document.body.removeChild($("popup"));
document.onkeydown = null;
rename : function(subject, path) {
"action" : "?do=rename&subject=" + subject + "&path=" + path + "&nonce=" + nonce,
create : function(type, path) {
popup.init("Create " + type + ":", [
"action" : "?do=create&path=" + path + "&f_type=" + type + "&nonce=" + nonce
chmod : function(path, subject, chmod){
popup.init("Chmod " + unescape(subject) + ":", [
"action" : "?do=chmod&subject=" + subject + "&path=" + path + "&nonce=" + nonce
copy : function(subject, path){
popup.init("Copy " + unescape(subject) + ":", [
"action" : "?do=copy&subject=" + subject + "&path=" + path + "&nonce=" + nonce
"value" : "copy-" + subject
moveList : function(subject, path, to){
ajax(("?do=moveList&subject=" + subject + "&path=" + path + "&to=" + to), "get", null, function (response) {
popup.init("Move " + unescape(subject) + " to:", Function("return " + response)());
var popupEl = $("popup"), mlEl;
$("body").innerHTML = "";
json2markup(Function("return " + response)(), $("body"));
if ((mlEl = $('moveListUL')).offsetHeight > (document.body.offsetHeight - 150))
mlEl.style.height = document.body.offsetHeight - 150 + "px";
popupEl.style.marginTop = "-" + parseInt(popupEl.offsetHeight) / 2 + "px";
popupEl.style.marginLeft = "-" + parseInt(popupEl.offsetWidth) / 2 + "px";
remoteCopy : function(path){
popup.init("Remote Copy:", [
"action" : "?do=remoteCopy&path=" + path + "&nonce=" + nonce,
$('remoteCopyName').value = this.value.substring(this.value.lastIndexOf('/') + 1);
init : function(subject, path, mode, codeMirrorInstalled) {
__CODEMIRROR_MODE = mode;
attributes: {"id": "editOverlay"}
$("editOverlay").style.height = "100%";
attributes : {"id": "ea"}
window.__FILECHANGED = true;
"value": unescape(subject),
else if (confirm("Install CodeMirror?"))
ajax("?do=installCodeMirror", "get", null, function(response){
alert("Install failed. Manually upload CodeMirror"
+ "and place it in _codemirror, in the same directory as pafm");