Skip to content

Commit f54dc12

Browse files
committed
Script execution is now done via an async js request, preventing die() and exception to mess up the entire console
1 parent 300372e commit f54dc12

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

README.mdown

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Changelog
3131
---------
3232

3333
- 1.1.0
34+
- Script execution is now done via an async js request, preventing die() and exception to mess up the entire console
3435
- Added a toggle button to expand/collapse all krumo sub-trees at once
3536
- 1.0.0
3637
- Initial Public Release

index.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@
4848

4949
ob_start();
5050
eval($code);
51-
$debugOutput = '<div class="output">'.ob_get_clean().'</div>';
51+
$debugOutput = ob_get_clean();
52+
53+
if (isset($_GET['js'])) {
54+
header('Content-Type: text/plain');
55+
echo $debugOutput;
56+
die('#end-php-console-output#');
57+
}
5258
}
5359

5460
?>
@@ -63,7 +69,8 @@
6369
<script type="text/javascript" src="php-console.js"></script>
6470
</script>
6571
</head>
66-
<body><?php echo $debugOutput ?>
72+
<body>
73+
<div class="output"><?php echo $debugOutput ?></div>
6774
<form method="POST" action="">
6875
<textarea cols="100" rows="20" name="code"><?php echo (isset($_POST['code']) ? htmlentities($_POST['code'], ENT_QUOTES, 'UTF-8') : null) ?></textarea>
6976
<input type="submit" name="subm" value="Try this!" />

loader.gif

673 Bytes
Loading

php-console.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ $(function() {
3636
}
3737
caret = $(this).getCaret();
3838
part = $(this).val().substring(0, caret);
39-
if (matches = part.match(/(\r?\n +)[^\r\n]*$/)) {
39+
matches = part.match(/(\r?\n +)[^\r\n]*$/);
40+
if (matches) {
4041
$(this).val(function(idx, val) {
4142
return val.substring(0, caret) + matches[1] + val.substring(caret);
4243
});
@@ -56,6 +57,18 @@ $(function() {
5657
}
5758
});
5859

60+
$('form').submit(function(e){
61+
e.preventDefault();
62+
$('div.output').html('<img src="loader.gif" class="loader" alt="" /> Loading ...');
63+
$.post('?js=1', $(this).serializeArray(), function(res) {
64+
if (res.match(/#end-php-console-output#$/)) {
65+
$('div.output').html(res.substring(0, res.length-24));
66+
} else {
67+
$('div.output').html(res + "<br /><br /><em>Script ended unexpectedly.</em>");
68+
}
69+
});
70+
});
71+
5972
// adds a toggle button to expand/collapse all krumo sub-trees at once
6073
if ($('.krumo-expand').length > 0) {
6174
$('<a class="expand" href="#">Toggle all</a>')

styles.css

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ a {
2929
margin: 10px .4%;
3030
}
3131

32+
.output img.loader {
33+
margin-bottom: -4px;
34+
}
35+
3236
.output, textarea {
3337
-moz-border-radius: 5px;
3438
-webkit-border-radius: 5px;

0 commit comments

Comments
 (0)