diff --git a/adminer/sql.inc.php b/adminer/sql.inc.php index 44ccef61..c5747392 100644 --- a/adminer/sql.inc.php +++ b/adminer/sql.inc.php @@ -97,7 +97,7 @@ if (!$error && $_POST) { $empty = false; $q = substr($query, 0, $pos); $commands++; - $print = "
" . $adminer->sqlCommandQuery($q) . "
\n"; + $print = "
" . $adminer->sqlCommandQuery($q) . "
\n"; $print .= generate_linksbar(["" . lang('Copy to clipboard') . ""]); if ($jush == "sqlite" && preg_match("~^$space*+ATTACH\\b~i", $q, $match)) { // PHP doesn't support setting SQLITE_LIMIT_ATTACHED diff --git a/adminer/static/default.css b/adminer/static/default.css index 0af283ea..4462e43f 100644 --- a/adminer/static/default.css +++ b/adminer/static/default.css @@ -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 .references { position: absolute; } #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,'); } .rtl h2 { margin: 0 -18px 20px 0; } .rtl p, .rtl table, .rtl .error, .rtl .message { margin: 1em 0 0 20px; } diff --git a/adminer/static/functions.js b/adminer/static/functions.js index 087e2510..2eb2473d 100644 --- a/adminer/static/functions.js +++ b/adminer/static/functions.js @@ -868,7 +868,13 @@ function setupCopyToClipboard(document) { var node = document.querySelector("a.copy-to-clipboard"); if (node) { 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 */ function copyToClipboard(el) { - var range = document.createRange(); - range.selectNode(el); - window.getSelection().removeAllRanges(); - window.getSelection().addRange(range); - document.execCommand("copy"); - window.getSelection().removeAllRanges(); + var nodeName = el.nodeName.toLowerCase(); + if (nodeName == 'code') { + var range = document.createRange(); + range.selectNode(el); + window.getSelection().removeAllRanges(); + window.getSelection().addRange(range); + document.execCommand("copy"); + 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