Implemented copy-to-clipboard at 2 places
This commit is contained in:
parent
cdfc70faed
commit
c38dedb7f6
|
@ -238,8 +238,9 @@ class Adminer {
|
||||||
. "$return<div id='$id' class='hidden'>\n$warnings</div>\n"
|
. "$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>" : "")
|
. (support("sql") ? " <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>" : "")
|
||||||
|
. " <a href='#' class='copy-to-clipboard'>" . lang('Copy to clipboard') . "</a>"
|
||||||
. $return
|
. $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 = "<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 " <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>" : '')
|
. ($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>'
|
. '</div>'
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,4 +192,5 @@ function page_footer($missing = "") {
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
echo script("setupSubmitHighlight(document);");
|
echo script("setupSubmitHighlight(document);");
|
||||||
|
echo script("setupCopyToClipboard(document);");
|
||||||
}
|
}
|
||||||
|
|
|
@ -662,7 +662,7 @@ function ajaxForm(form, message, button) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data = data.join('&');
|
data = data.join('&');
|
||||||
|
|
||||||
var url = form.action;
|
var url = form.action;
|
||||||
if (!/post/i.test(form.method)) {
|
if (!/post/i.test(form.method)) {
|
||||||
url = url.replace(/\?.*/, '') + '?' + data;
|
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
|
/** Add event listener
|
||||||
* @param HTMLElement
|
* @param HTMLElement
|
||||||
|
|
Loading…
Reference in a new issue