Merge pull request #20 from adminerevo/copy_to_clipboard
Copy to clipboard
This commit is contained in:
commit
3152e38041
|
@ -238,8 +238,9 @@ class Adminer {
|
|||
. "$return<div id='$id' class='hidden'>\n$warnings</div>\n"
|
||||
;
|
||||
}
|
||||
return "<p><code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <span class='time'>(" . format_time($start) . ")</span>"
|
||||
return "<p class='links'><code class='jush-$jush copy-to-clipboard'>" . h(str_replace("\n", " ", $query)) . "</code> <span class='time'>(" . format_time($start) . ")</span>"
|
||||
. (support("sql") ? " <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>" : "")
|
||||
. " <a href='#' class='copy-to-clipboard'>" . lang('Copy to clipboard') . "</a>"
|
||||
. $return
|
||||
;
|
||||
}
|
||||
|
@ -652,9 +653,9 @@ class Adminer {
|
|||
$return = "<a href='#$id' class='toggle'>" . lang('Warnings') . "</a>, $return<div id='$id' class='hidden'>\n$warnings</div>\n";
|
||||
}
|
||||
return " <span class='time'>" . @date("H:i:s") . "</span>" // @ - time zone may be not set
|
||||
. " $return<div id='$sql_id' class='hidden'><pre><code class='jush-$jush'>" . shorten_utf8($query, 1000) . "</code></pre>"
|
||||
. " $return<div id='$sql_id' class='hidden'><pre><code class='jush-$jush copy-to-clipboard'>" . shorten_utf8($query, 1000) . "</code></pre>"
|
||||
. ($time ? " <span class='time'>($time)</span>" : '')
|
||||
. (support("sql") ? '<p><a href="' . h(str_replace("db=" . urlencode(DB), "db=" . urlencode($_GET["db"]), ME) . 'sql=&history=' . (count($history[$_GET["db"]]) - 1)) . '">' . lang('Edit') . '</a>' : '')
|
||||
. (support("sql") ? '<p class="links"><a href="' . h(str_replace("db=" . urlencode(DB), "db=" . urlencode($_GET["db"]), ME) . 'sql=&history=' . (count($history[$_GET["db"]]) - 1)) . '">' . lang('Edit') . '</a> <a href="#" class="copy-to-clipboard">' . lang('Copy to clipboard') . '</a>' : '')
|
||||
. '</div>'
|
||||
;
|
||||
}
|
||||
|
|
|
@ -192,4 +192,6 @@ function page_footer($missing = "") {
|
|||
</div>
|
||||
<?php
|
||||
echo script("setupSubmitHighlight(document);");
|
||||
echo script("setupCopyToClipboard(document);");
|
||||
echo "</body>\n</html>";
|
||||
}
|
||||
|
|
|
@ -97,7 +97,8 @@ if (!$error && $_POST) {
|
|||
$empty = false;
|
||||
$q = substr($query, 0, $pos);
|
||||
$commands++;
|
||||
$print = "<pre id='sql-$commands'><code class='jush-$jush'>" . $adminer->sqlCommandQuery($q) . "</code></pre>\n";
|
||||
$print = "<pre id='sql-$commands'><code class='jush-$jush copy-to-clipboard'>" . $adminer->sqlCommandQuery($q) . "</code></pre>\n";
|
||||
$print .= "<a href='#' class='copy-to-clipboard'>" . lang('Copy to clipboard') . "</a>";
|
||||
if ($jush == "sqlite" && preg_match("~^$space*+ATTACH\\b~i", $q, $match)) {
|
||||
// PHP doesn't support setting SQLITE_LIMIT_ATTACHED
|
||||
echo $print;
|
||||
|
|
|
@ -662,7 +662,7 @@ function ajaxForm(form, message, button) {
|
|||
}
|
||||
}
|
||||
data = data.join('&');
|
||||
|
||||
|
||||
var url = form.action;
|
||||
if (!/post/i.test(form.method)) {
|
||||
url = url.replace(/\?.*/, '') + '?' + data;
|
||||
|
@ -861,7 +861,29 @@ function findDefaultSubmit(el) {
|
|||
}
|
||||
}
|
||||
|
||||
/** Initialize the copy to clipboard feature
|
||||
* @param HTMLElement
|
||||
*/
|
||||
function setupCopyToClipboard(document) {
|
||||
var node = document.querySelector("a.copy-to-clipboard");
|
||||
if (node) {
|
||||
node.addEventListener("click", function() {
|
||||
copyToClipboard(document.querySelector("code.copy-to-clipboard"));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** Copy element's content in clipboard
|
||||
* @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();
|
||||
}
|
||||
|
||||
/** Add event listener
|
||||
* @param HTMLElement
|
||||
|
|
Loading…
Reference in a new issue