Add persistence across sessions
This commit is contained in:
@@ -33,6 +33,8 @@ Jordi Boggiano - <j.boggiano@seld.be><br />
|
|||||||
Changelog
|
Changelog
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
- 1.3.0
|
||||||
|
- Added code persistence across sessions in localStorage + a reset button
|
||||||
- 1.2.3
|
- 1.2.3
|
||||||
- Fixed syntax highlighting
|
- Fixed syntax highlighting
|
||||||
- Fixed some styling issues
|
- Fixed some styling issues
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ if (!in_array($_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'), true)) {
|
|||||||
die('ERR/401 Go Away');
|
die('ERR/401 Go Away');
|
||||||
}
|
}
|
||||||
|
|
||||||
define('PHP_CONSOLE_VERSION', '1.3.0-dev');
|
define('PHP_CONSOLE_VERSION', '1.3.0');
|
||||||
require 'krumo/class.krumo.php';
|
require 'krumo/class.krumo.php';
|
||||||
|
|
||||||
ini_set('log_errors', 0);
|
ini_set('log_errors', 0);
|
||||||
@@ -112,6 +112,7 @@ if (isset($_POST['code'])) {
|
|||||||
/>
|
/>
|
||||||
</object>
|
</object>
|
||||||
</span>
|
</span>
|
||||||
|
<a href="" class="reset">Reset</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<input type="submit" name="subm" value="Try this!" />
|
<input type="submit" name="subm" value="Try this!" />
|
||||||
|
|||||||
+30
-2
@@ -1,3 +1,5 @@
|
|||||||
|
/*jslint browser: true */
|
||||||
|
/*global ace, jQuery */
|
||||||
/**
|
/**
|
||||||
* PHP Console
|
* PHP Console
|
||||||
*
|
*
|
||||||
@@ -14,7 +16,7 @@
|
|||||||
(function (require, $, ace) {
|
(function (require, $, ace) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var updateStatusBar, prepareClippyButton, refreshKrumoState, handleSubmit, initializeAce,
|
var updateStatusBar, prepareClippyButton, refreshKrumoState, handleSubmit, initializeAce, handleAjaxError,
|
||||||
options, editor;
|
options, editor;
|
||||||
options = {
|
options = {
|
||||||
tabsize: 4,
|
tabsize: 4,
|
||||||
@@ -66,6 +68,12 @@
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
$('div.output').html('<img src="loader.gif" class="loader" alt="" /> Loading ...');
|
$('div.output').html('<img src="loader.gif" class="loader" alt="" /> Loading ...');
|
||||||
|
|
||||||
|
// store session
|
||||||
|
if (window.localStorage) {
|
||||||
|
localStorage.setItem('phpCode', editor.getSession().getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
// eval server-side
|
||||||
$.post('?js=1', { code: editor.getSession().getValue() }, function (res) {
|
$.post('?js=1', { code: editor.getSession().getValue() }, function (res) {
|
||||||
if (res.match(/#end-php-console-output#$/)) {
|
if (res.match(/#end-php-console-output#$/)) {
|
||||||
$('div.output').html(res.substring(0, res.length - 24));
|
$('div.output').html(res.substring(0, res.length - 24));
|
||||||
@@ -82,9 +90,18 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
initializeAce = function () {
|
initializeAce = function () {
|
||||||
var PhpMode, code;
|
var PhpMode, code, storedCode;
|
||||||
|
|
||||||
code = $('#' + options.editor).text();
|
code = $('#' + options.editor).text();
|
||||||
|
|
||||||
|
// reload last session
|
||||||
|
if (window.localStorage && code.match(/(<\?php)?\s*/)) {
|
||||||
|
storedCode = localStorage.getItem('phpCode');
|
||||||
|
if (storedCode) {
|
||||||
|
code = storedCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$('#' + options.editor).replaceWith('<div id="' + options.editor + '" class="' + options.editor + '"></div>');
|
$('#' + options.editor).replaceWith('<div id="' + options.editor + '" class="' + options.editor + '"></div>');
|
||||||
$('#' + options.editor).text(code);
|
$('#' + options.editor).text(code);
|
||||||
|
|
||||||
@@ -107,6 +124,17 @@
|
|||||||
editor.getSession().selection.on('changeSelection', prepareClippyButton);
|
editor.getSession().selection.on('changeSelection', prepareClippyButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reset button
|
||||||
|
if (window.localStorage) {
|
||||||
|
$('.statusbar .reset').on('click', function (e) {
|
||||||
|
editor.getSession().setValue('<?php\n\n');
|
||||||
|
editor.focus();
|
||||||
|
editor.gotoLine(3, 0);
|
||||||
|
window.localStorage.setItem('phpCode', '');
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// commands
|
// commands
|
||||||
editor.commands.addCommand({
|
editor.commands.addCommand({
|
||||||
name: 'submitForm',
|
name: 'submitForm',
|
||||||
|
|||||||
Reference in New Issue
Block a user