Fix issue with truncated queries and prevent copying queries > 1Mb to clipboard
This commit is contained in:
parent
2894ed4c67
commit
e3063999c0
|
@ -97,7 +97,7 @@ if (!$error && $_POST) {
|
||||||
$empty = false;
|
$empty = false;
|
||||||
$q = substr($query, 0, $pos);
|
$q = substr($query, 0, $pos);
|
||||||
$commands++;
|
$commands++;
|
||||||
$print = "<pre id='sql-$commands'><code class='jush-$jush copy-to-clipboard'>" . $adminer->sqlCommandQuery($q) . "</code></pre>\n";
|
$print = "<pre id='sql-$commands'><code class='jush-$jush'>" . $adminer->sqlCommandQuery($q) . "</code></pre>\n";
|
||||||
$print .= generate_linksbar(["<a href='#' class='copy-to-clipboard'>" . lang('Copy to clipboard') . "</a>"]);
|
$print .= generate_linksbar(["<a href='#' class='copy-to-clipboard'>" . lang('Copy to clipboard') . "</a>"]);
|
||||||
if ($jush == "sqlite" && preg_match("~^$space*+ATTACH\\b~i", $q, $match)) {
|
if ($jush == "sqlite" && preg_match("~^$space*+ATTACH\\b~i", $q, $match)) {
|
||||||
// PHP doesn't support setting SQLITE_LIMIT_ATTACHED
|
// PHP doesn't support setting SQLITE_LIMIT_ATTACHED
|
||||||
|
|
|
@ -93,6 +93,7 @@ span.separator { margin-left: 5px; margin-right: 5px; }
|
||||||
#schema .table { border: 1px solid silver; padding: 0 2px; cursor: move; position: absolute; }
|
#schema .table { border: 1px solid silver; padding: 0 2px; cursor: move; position: absolute; }
|
||||||
#schema .references { position: absolute; }
|
#schema .references { position: absolute; }
|
||||||
#help { position: absolute; border: 1px solid #999; background: #eee; padding: 5px; font-family: monospace; z-index: 1; }
|
#help { position: absolute; border: 1px solid #999; background: #eee; padding: 5px; font-family: monospace; z-index: 1; }
|
||||||
|
a.copy-to-clipboard.icon { font-size: 0; padding: 12px 8px 5px 8px; margin-left: 5px; background-size: 16px; background-repeat: no-repeat; background-position: 0 0; background-color: transparent; background-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-clipboard-copy" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h3m9 -9v-5a2 2 0 0 0 -2 -2h-2"></path><path d="M13 17v-1a1 1 0 0 1 1 -1h1m3 0h1a1 1 0 0 1 1 1v1m0 3v1a1 1 0 0 1 -1 1h-1m-3 0h-1a1 1 0 0 1 -1 -1v-1"></path><path d="M9 3m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z"></path></svg>'); }
|
||||||
|
|
||||||
.rtl h2 { margin: 0 -18px 20px 0; }
|
.rtl h2 { margin: 0 -18px 20px 0; }
|
||||||
.rtl p, .rtl table, .rtl .error, .rtl .message { margin: 1em 0 0 20px; }
|
.rtl p, .rtl table, .rtl .error, .rtl .message { margin: 1em 0 0 20px; }
|
||||||
|
|
|
@ -868,7 +868,13 @@ function setupCopyToClipboard(document) {
|
||||||
var node = document.querySelector("a.copy-to-clipboard");
|
var node = document.querySelector("a.copy-to-clipboard");
|
||||||
if (node) {
|
if (node) {
|
||||||
node.addEventListener("click", function() {
|
node.addEventListener("click", function() {
|
||||||
copyToClipboard(document.querySelector("code.copy-to-clipboard"));
|
var nodeSql = document.querySelector("code.copy-to-clipboard");
|
||||||
|
if (nodeSql == null || nodeSql == undefined) {
|
||||||
|
nodeSql = document.querySelector("textarea.sqlarea");
|
||||||
|
}
|
||||||
|
if (nodeSql != null && nodeSql != undefined) {
|
||||||
|
copyToClipboard(nodeSql);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -877,12 +883,23 @@ function setupCopyToClipboard(document) {
|
||||||
* @param HTMLElement
|
* @param HTMLElement
|
||||||
*/
|
*/
|
||||||
function copyToClipboard(el) {
|
function copyToClipboard(el) {
|
||||||
|
var nodeName = el.nodeName.toLowerCase();
|
||||||
|
if (nodeName == 'code') {
|
||||||
var range = document.createRange();
|
var range = document.createRange();
|
||||||
range.selectNode(el);
|
range.selectNode(el);
|
||||||
window.getSelection().removeAllRanges();
|
window.getSelection().removeAllRanges();
|
||||||
window.getSelection().addRange(range);
|
window.getSelection().addRange(range);
|
||||||
document.execCommand("copy");
|
document.execCommand("copy");
|
||||||
window.getSelection().removeAllRanges();
|
window.getSelection().removeAllRanges();
|
||||||
|
} else if (nodeName == 'textarea') {
|
||||||
|
el.select();
|
||||||
|
if (document.getSelection().toString().length > 1024 * 1024) {
|
||||||
|
alert('Too large for clipboard');
|
||||||
|
} else {
|
||||||
|
document.execCommand("copy");
|
||||||
|
document.getSelection().removeAllRanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add event listener
|
/** Add event listener
|
||||||
|
|
Loading…
Reference in a new issue