diff --git a/php-console.js b/php-console.js
index 7c6dc67..bc41db5 100644
--- a/php-console.js
+++ b/php-console.js
@@ -17,9 +17,11 @@
options = {
tab: ' '
- }
+ };
- // updates the text of the status bar
+ /**
+ * updates the text of the status bar
+ */
updateStatusBar = function() {
var caret, part, matches, charCount, lineCount;
caret = $('textarea[name="code"]').getCaret();
@@ -38,6 +40,9 @@
$('.statusbar').text('Line: ' + lineCount + ', Column: ' + charCount);
};
+ /**
+ * handler for keypress/keydown events
+ */
handleKeyPress = function(e) {
var caret, part, matches, re;
switch(e.keyCode) {
@@ -84,6 +89,38 @@
updateStatusBar();
};
+ /**
+ * adds a toggle button to expand/collapse all krumo sub-trees at once
+ */
+ refreshKrumoState = function() {
+ if ($('.krumo-expand').length > 0) {
+ $('Toggle all')
+ .click(function(e) {
+ $('div.krumo-element.krumo-expand').each(function(idx, el) {
+ krumo.toggle(el);
+ });
+ e.preventDefault();
+ })
+ .prependTo('.output');
+ }
+ };
+
+ /**
+ * does an async request to eval the php code and displays the result
+ */
+ handleSubmit = function(e) {
+ e.preventDefault();
+ $('div.output').html(' Loading ...');
+ $.post('?js=1', $(this).serializeArray(), function(res) {
+ if (res.match(/#end-php-console-output#$/)) {
+ $('div.output').html(res.substring(0, res.length-24));
+ } else {
+ $('div.output').html(res + "
Script ended unexpectedly.");
+ }
+ refreshKrumoState();
+ });
+ }
+
$.console = function(settings) {
$.extend(options, settings);
@@ -99,40 +136,18 @@
$('textarea[name="code"]').keydown(handleKeyPress);
}
+ $('form').submit(handleSubmit);
+
updateStatusBar();
+ refreshKrumoState();
+ // set the focus back to the textarea if pressing tab moved
+ // the focus to the submit button (opera bug)
$('input[name="subm"]').keyup(function(e) {
- // set the focus back to the textarea if pressing tab moved
- // the focus to the submit button (opera bug)
if (e.keyCode === 9) {
$('textarea[name="code"]').focus();
}
});
-
- $('form').submit(function(e){
- e.preventDefault();
- $('div.output').html(' Loading ...');
- $.post('?js=1', $(this).serializeArray(), function(res) {
- if (res.match(/#end-php-console-output#$/)) {
- $('div.output').html(res.substring(0, res.length-24));
- } else {
- $('div.output').html(res + "
Script ended unexpectedly.");
- }
- });
- });
-
- // adds a toggle button to expand/collapse all krumo sub-trees at once
- if ($('.krumo-expand').length > 0) {
- $('Toggle all')
- .click(function(e) {
- $('div.krumo-element.krumo-expand').each(function(idx, el) {
- krumo.toggle(el);
- });
- e.preventDefault();
- })
- .prependTo('.output');
- }
});
-
- }
+ };
}());
\ No newline at end of file