Skip to content

Commit

Permalink
Revert "Highlight SQL code in textarea"
Browse files Browse the repository at this point in the history
This reverts commit 2a1c409.
  • Loading branch information
vrana committed Jun 3, 2011
1 parent 42a422e commit 4787b57
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 53 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Expand Up @@ -13,6 +13,3 @@
[submodule "jquery-timepicker"]
path = externals/jquery-timepicker
url = git://github.com/trentrichardson/jQuery-Timepicker-Addon.git
[submodule "codemirror"]
path = externals/codemirror
url = http://marijnhaverbeke.nl/git/codemirror2
2 changes: 1 addition & 1 deletion adminer/include/editing.inc.php
Expand Up @@ -106,7 +106,7 @@ function referencable_primary($self) {
* @return null
*/
function textarea($name, $value, $rows = 10, $cols = 80) {
echo "<textarea name='$name' rows='$rows' cols='$cols' class='sqlarea' spellcheck='false' wrap='off'>"; // spellcheck, wrap - not valid before HTML5
echo "<textarea name='$name' rows='$rows' cols='$cols' class='sqlarea' spellcheck='false' wrap='off' onkeydown='return textareaKeydown(this, event);'>"; // spellcheck, wrap - not valid before HTML5
if (is_array($value)) {
foreach ($value as $val) { // not implode() to save memory
echo h($val) . "\n\n\n";
Expand Down
1 change: 0 additions & 1 deletion adminer/static/default.css
Expand Up @@ -41,7 +41,6 @@ input[type=image] { vertical-align: middle; }
.options select { width: 20ex; width: auto\9; }
.active { font-weight: bold; }
.sqlarea { width: 98%; }
.CodeMirror { border: 1px solid #777; }
#menu { position: absolute; margin: 10px 0 0; padding: 0 0 30px 0; top: 2em; left: 0; width: 19em; overflow: auto; overflow-y: hidden; white-space: nowrap; }
#menu p { padding: .8em 1em; margin: 0; border-bottom: 1px solid #ccc; }
#content { margin: 2em 0 0 21em; padding: 10px 20px 20px 0; }
Expand Down
52 changes: 10 additions & 42 deletions adminer/static/editing.js
@@ -1,37 +1,6 @@
// Adminer specific functions

// global variables to allow simple customization
var jushRoot = '../externals/jush/';
var codemirrorRoot = '../externals/codemirror/';

function appendScript(src, onload) {
var script = document.createElement('script');
script.src = src;
script.onload = onload;
script.onreadystatechange = function () {
if (/^(loaded|complete)$/.test(script.readyState)) {
onload();
}
};
document.body.appendChild(script);
}

function appendStyle(href) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = href;
document.getElementsByTagName('head')[0].appendChild(link);
}

function codemirrorRun() {
var textareas = document.getElementsByTagName('textarea');
for (var i=0; i < textareas.length; i++) {
if (textareas[i].className == 'sqlarea') {
CodeMirror.fromTextArea(textareas[i], { mode: 'text/x-plsql' });
}
}
}
var jushRoot = '../externals/jush/'; // global variable to allow simple customization

/** Load syntax highlighting
* @param string first three characters of database system version
Expand All @@ -41,7 +10,9 @@ function bodyLoad(version) {
onpopstate(history);
}
if (jushRoot) {
appendScript(jushRoot + 'jush.js', function () {
var script = document.createElement('script');
script.src = jushRoot + 'jush.js';
script.onload = function () {
if (window.jush) { // IE runs in case of an error too
jush.create_links = ' target="_blank" rel="noreferrer"';
jush.urls.sql_sqlset = jush.urls.sql[0] = jush.urls.sqlset[0] = jush.urls.sqlstatus[0] = 'http://dev.mysql.com/doc/refman/' + version + '/en/$key';
Expand All @@ -54,16 +25,13 @@ function bodyLoad(version) {
}
jush.highlight_tag('code', 0);
}
});
}
if (codemirrorRoot) {
appendStyle(codemirrorRoot + 'lib/codemirror.css');
appendStyle(codemirrorRoot + 'mode/plsql/plsql.css');
appendScript(codemirrorRoot + 'lib/codemirror.js', function () {
if (window.CodeMirror) {
appendScript(codemirrorRoot + 'mode/plsql/plsql.js', codemirrorRun);
};
script.onreadystatechange = function () {
if (/^(loaded|complete)$/.test(script.readyState)) {
script.onload();
}
});
};
document.body.appendChild(script);
}
}

Expand Down
38 changes: 35 additions & 3 deletions adminer/static/functions.js
Expand Up @@ -155,6 +155,41 @@ function selectAddRow(field) {



/** Handle Tab and Esc in textarea
* @param HTMLTextAreaElement
* @param KeyboardEvent
* @return boolean
*/
function textareaKeydown(target, event) {
if (!event.shiftKey && !event.altKey && !event.ctrlKey && !event.metaKey) {
if (event.keyCode == 9) { // 9 - Tab
// inspired by http://pallieter.org/Projects/insertTab/
if (target.setSelectionRange) {
var start = target.selectionStart;
var scrolled = target.scrollTop;
target.value = target.value.substr(0, start) + '\t' + target.value.substr(target.selectionEnd);
target.setSelectionRange(start + 1, start + 1);
target.scrollTop = scrolled;
return false; //! still loses focus in Opera, can be solved by handling onblur
} else if (target.createTextRange) {
document.selection.createRange().text = '\t';
return false;
}
}
if (event.keyCode == 27) { // 27 - Esc
var els = target.form.elements;
for (var i=1; i < els.length; i++) {
if (els[i-1] == target) {
els[i].focus();
break;
}
}
return false;
}
}
return true;
}

/** Send form by Ctrl+Enter on <select> and <textarea>
* @param KeyboardEvent
* @param [string]
Expand Down Expand Up @@ -326,9 +361,6 @@ function ajaxSend(url, data, popState) {
if (window.jush) {
jush.highlight_tag('code', 0);
}
if (window.CodeMirror) {
codemirrorRun();
}
}
}
}, data);
Expand Down
1 change: 0 additions & 1 deletion changes.txt
@@ -1,6 +1,5 @@
Adminer 3.3.0-dev:
Use Esc to disable in-place edit
Highlight SQL code in textarea
Shortcut for database privileges
Append new index with auto index selection (bug #3282127)
Bit type default value
Expand Down
1 change: 0 additions & 1 deletion compile.php
Expand Up @@ -269,7 +269,6 @@ function compile_file($match) {
$file = preg_replace('~\\.\\./adminer/static/(default\\.css|functions\\.js|favicon\\.ico)~', '<?php echo ' . $replace . '"; ?>', $file);
$file = preg_replace('~\\.\\./adminer/static/([^\'"]*)~', '" . ' . $replace, $file);
$file = str_replace("'../externals/jush/'", "location.protocol + '//www.adminer.org/static/'", $file);
$file = str_replace("'../externals/codemirror/'", "location.protocol + '//www.adminer.org/static/codemirror/'", $file);
$file = preg_replace("~<\\?php\\s*\\?>\n?|\\?>\n?<\\?php~", '', $file);
$file = php_shrink($file);

Expand Down
1 change: 0 additions & 1 deletion externals/codemirror
Submodule codemirror deleted from 68d004
1 change: 1 addition & 0 deletions todo.txt
@@ -1,6 +1,7 @@
Transactions in export
Create view and routine options
Variables editation
Highlight SQL textarea - may use external CodeMirror
Blob download and image display in edit form (important for Editor with hidden fields in select and SQL command)
Add title to Logout, edit (in select) and select (in menu) for style "hever"
Shift-click in checkboxes to select range
Expand Down

0 comments on commit 4787b57

Please sign in to comment.