Skip to content

Commit

Permalink
fixed js codemirror loading, added cm.css to dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafa0x committed Apr 27, 2012
1 parent 461ee90 commit c11389c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ then scroll down till you see `/** configuration **/`

## Recent Changes

### 1.5.4
### 1.5.5
* Rewrote CodeMirror installation method
* Minor code changes

Expand Down
69 changes: 24 additions & 45 deletions pafm-files/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function $(element) {
return document.getElementById(element);
}
var popup, fOp, edit, upload, __AJAX_ACTIVE,
__CODEMIRROR, __CODEMIRROR_MODE, __LOAD_COUNT = 0, __CODEMIRROR_PATH = "_codemirror",
__CODEMIRROR, __CODEMIRROR_MODE, __CODEMIRROR_LOADED, __CODEMIRROR_PATH = "_cm",
__CODEMIRROR_MODES = {
"html": "htmlmixed",
"js": "javascript",
Expand Down Expand Up @@ -217,11 +217,6 @@ popup = {
]
], document.body);
var popupEl = $("popup"), popOverlayEl = $("popOverlay"), xEl = $('x'), mlEl;
if (window.ActiveXObject){ //I can't even begin to tell you how much I hate IE
xEl.style.cssFloat = "none";
xEl.style.position = "absolute";
xEl.style.right = xEl.parentNode.offsetLeft + 3;
}
json2markup(content, $("body"));
if (mlEl = $('moveListUL')) {
if (mlEl.offsetHeight > (document.body.offsetHeight - 150))
Expand Down Expand Up @@ -489,11 +484,11 @@ edit = {
},
events : {
click : function(){
if (codeMirrorInstalled || __LOAD_COUNT)
if (codeMirrorInstalled)
edit.codeMirrorLoad();
else if (confirm("Install CodeMirror?"))
ajax("?do=installCodeMirror", "get", null, function(response){
if (response == "1")
if (response == "")
edit.codeMirrorLoad();
else
alert("Install failed. Manually upload CodeMirror and place it in _codemirror, in the same directory as pafm");
Expand Down Expand Up @@ -546,56 +541,40 @@ edit = {
});
location = "#header";
},
codeMirrorResourceLoad : function(e){
if (++__LOAD_COUNT == 2)
return edit.codeMirrorLoad();

json2markup([ //this has to load after codemirror.js
"script",
{
attributes : {
"src" : __CODEMIRROR_PATH + "/lib/util/loadmode.js",
"type" : "text/javascript"
},
events : {
load : edit.codeMirrorResourceLoad
}
}
], document.getElementsByTagName("head")[0]);
},
codeMirrorLoad: function(){
if (__LOAD_COUNT == 2) {
var modeName = __CODEMIRROR_MODES[__CODEMIRROR_MODE] || __CODEMIRROR_MODE;

CodeMirror.modeURL = "_codemirror/mode/%N/%N.js";
__CODEMIRROR = CodeMirror.fromTextArea($("ta"), {
lineNumbers: true
});

__CODEMIRROR.setOption("mode", modeName);
CodeMirror.autoLoadMode(__CODEMIRROR, modeName);
}
else {
if(!__CODEMIRROR_LOADED)
json2markup([
"script",
{
attributes : {
"src" : __CODEMIRROR_PATH + "/lib/codemirror.js",
"type" : "text/javascript"
attributes: {
"src": __CODEMIRROR_PATH + "/cm.js",
"type": "text/javascript"
},
events : {
load : edit.codeMirrorResourceLoad
events: {
load: function(){
__CODEMIRROR_LOADED = true;
edit.codeMirrorLoad();
}
}
},
"link",
{
attributes : {
"rel" : "stylesheet",
"href" : __CODEMIRROR_PATH + "/lib/codemirror.css"
attributes: {
"rel": "stylesheet",
"href": __CODEMIRROR_PATH + "/cm.css"
}
},
], document.getElementsByTagName("head")[0]);
else {
var modeName = __CODEMIRROR_MODES[__CODEMIRROR_MODE] || __CODEMIRROR_MODE;

__CODEMIRROR = CodeMirror.fromTextArea($("ta"), {
lineNumbers: true
});

__CODEMIRROR.setOption("mode", modeName);
}

},
save : function(subject, path){
__CODEMIRROR && __CODEMIRROR.save();
Expand Down
21 changes: 13 additions & 8 deletions pafm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
@name: PHP AJAX File Manager (PAFM)
@filename: pafm.php
@version: 1.5.4
@version: 1.5.5
@date: April 27th, 2012
@author: mustafa
Expand Down Expand Up @@ -66,9 +66,9 @@
*/
define('DEV', 1);

define('VERSION', '1.5.4');
define('VERSION', '1.5.5');

define('CODEMIRROR_PATH', dirname(realpath($_SERVER['SCRIPT_FILENAME'])) . '/_codemirror.js');
define('CODEMIRROR_PATH', dirname(realpath($_SERVER['SCRIPT_FILENAME'])) . '/_cm');

$pathRegEx = SanitizePath ? '/\.\.|\/\/|\/$|^\/|^$/' : '//';

Expand Down Expand Up @@ -175,8 +175,7 @@
case 'moveList':
exit(moveList($subject, $path, $to));
case 'installCodeMirror':
//TODO: file checksum
exit(copy('http://cloud.github.com/downloads/mustafa0x/pafm/_codemirror.js', CODEMIRROR_PATH));
exit(installCodeMirror());
case 'fileExists':
exit(file_exists($path .'/'. $subject));
case 'getfs':
Expand Down Expand Up @@ -359,6 +358,12 @@ function doCreate($file, $folder, $path){
return refresh(htmlspecialchars($file).htmlspecialchars($folder).' already exists');
redirect();
}
function installCodeMirror(){
mkdir(CODEMIRROR_PATH);
//TODO: checksum
copy('http://cloud.github.com/downloads/mustafa0x/pafm/_codemirror.js', CODEMIRROR_PATH . '/cm.js');
copy('http://cloud.github.com/downloads/mustafa0x/pafm/_codemirror.css', CODEMIRROR_PATH . '/cm.css');
}
function doUpload($path){
if (!$_FILES)
return refresh('$_FILES array can not be read. Check file size limits and the max execution time limit.');
Expand Down Expand Up @@ -390,7 +395,7 @@ function doChmod($subject, $path, $mod){
chmod($path . '/' . $subject, octdec(strlen($mod) == 3 ? 0 . $mod : $mod));
redirect();
}
function doExtract($subject, $path, $codeMirror = false){
function doExtract($subject, $path){
global $subjectHTML;
switch (zipSupport()) {
case 'function':
Expand Down Expand Up @@ -424,7 +429,7 @@ function doExtract($subject, $path, $codeMirror = false){
case 'exec':
shell_exec('unzip ' . escapeshellarg($path.'/'.$subject));
}
$codeMirror || redirect();
redirect();
}
function doReadFile($subject, $path){
return file_get_contents($path.'/'.$subject);
Expand Down Expand Up @@ -686,7 +691,7 @@ function getFiles($path){

$mod = getmod($fullPath);
$ext = getExt($dirItem);
$codeMirrorExists = (int)is_file(CODEMIRROR_PATH);
$codeMirrorExists = (int)is_dir(CODEMIRROR_PATH);

echo ' <li title="' . $dirItemHTML . '">' .
"\n\t" . '<a href="' . escape(ROOT . $filePath . $dirItem) . '" title="' . $dirItemHTML . '" class="file">'.$dirItemHTML.'</a>' .
Expand Down

0 comments on commit c11389c

Please sign in to comment.