Made tab character(s) configurable (see index.php)

master
Jordi Boggiano 14 years ago
parent 399ee95027
commit a368fe9811
  1. 1
      README.mdown
  2. 9
      index.php
  3. 28
      php-console.js

@ -36,6 +36,7 @@ Changelog
- Added a toggle button to expand/collapse all krumo sub-trees at once - Added a toggle button to expand/collapse all krumo sub-trees at once
- Cross-browser compatibility enhancements - Cross-browser compatibility enhancements
- Removing a tab (i.e. 4 spaces) on backspace now - Removing a tab (i.e. 4 spaces) on backspace now
- Made tab character(s) configurable (see index.php)
- 1.0.0 - 1.0.0
- Initial Public Release - Initial Public Release

@ -1,5 +1,10 @@
<?php <?php
$options = array(
// which string should represent a tab for indentation
'tab' => ' ',
);
/** /**
* PHP Console * PHP Console
* *
@ -67,6 +72,10 @@ if (isset($_POST['code'])) {
<script type="text/javascript" src="jquery-1.4.2.min.js"></script> <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jquery.selections.js"></script> <script type="text/javascript" src="jquery.selections.js"></script>
<script type="text/javascript" src="php-console.js"></script> <script type="text/javascript" src="php-console.js"></script>
<script type="text/javascript">
$.console({
tab: <?php echo json_encode($options['tab']) ?>
});
</script> </script>
</head> </head>
<body> <body>

@ -11,9 +11,13 @@
* *
* Source on Github http://github.com/Seldaek/php-console * Source on Github http://github.com/Seldaek/php-console
*/ */
$(function() { (function() {
var updateStatusBar, handleKeyPress, options;
var updateStatusBar, handleKeyPress; options = {
tab: ' '
}
// updates the text of the status bar // updates the text of the status bar
updateStatusBar = function() { updateStatusBar = function() {
@ -35,12 +39,12 @@ $(function() {
}; };
handleKeyPress = function(e) { handleKeyPress = function(e) {
var caret, part, matches; var caret, part, matches, re;
switch(e.keyCode) { switch(e.keyCode) {
case 9: case 9:
// add 4 spaces when tab is pressed // add 4 spaces when tab is pressed
e.preventDefault(); e.preventDefault();
$(this).injectText(" "); $(this).injectText(options.tab);
break; break;
case 13: case 13:
// submit form on ctrl-enter or alt-enter // submit form on ctrl-enter or alt-enter
@ -53,7 +57,7 @@ $(function() {
// indent automatically the new lines // indent automatically the new lines
caret = $(this).getCaret(); caret = $(this).getCaret();
part = $(this).val().substr(0, caret); part = $(this).val().substr(0, caret);
matches = part.match(/(\n +)[^\r\n]*$/); matches = part.match(/(\n[ \t]+)[^\r\n]*$/);
if (matches) { if (matches) {
$(this).val(function(idx, val) { $(this).val(function(idx, val) {
return val.substring(0, caret) + matches[1] + val.substring(caret); return val.substring(0, caret) + matches[1] + val.substring(caret);
@ -66,11 +70,12 @@ $(function() {
// deindent automatically on backspace // deindent automatically on backspace
caret = $(this).getCaret(); caret = $(this).getCaret();
part = $(this).val().substr(0, caret); part = $(this).val().substr(0, caret);
if (part.match(/\n( {4,})$/)) { re = new RegExp('\n[ \t]*?'+options.tab+'$');
if (part.match(re)) {
$(this).val(function(idx, val) { $(this).val(function(idx, val) {
return val.substring(0, caret - 4) + val.substring(caret); return val.substring(0, caret - options.tab.length) + val.substring(caret);
}); });
$(this).setCaret(caret - 4); $(this).setCaret(caret - options.tab.length);
e.preventDefault(); e.preventDefault();
} }
break; break;
@ -79,6 +84,10 @@ $(function() {
updateStatusBar(); updateStatusBar();
}; };
$.console = function(settings) {
$.extend(options, settings);
$(function() {
$('textarea[name="code"]') $('textarea[name="code"]')
.keyup(updateStatusBar) .keyup(updateStatusBar)
.click(updateStatusBar) .click(updateStatusBar)
@ -124,3 +133,6 @@ $(function() {
.prependTo('.output'); .prependTo('.output');
} }
}); });
}
}());
Loading…
Cancel
Save