fix 第一次复制碰链失败

fix 复制多行文本
This commit is contained in:
doolb 2019-01-17 10:55:31 +08:00
parent b223afce7f
commit 6b6663f91b
2 changed files with 12 additions and 118 deletions

File diff suppressed because one or more lines are too long

View File

@ -967,7 +967,7 @@ var system = {
} }
}); });
} else { } else {
menu = this.getContentMenuWithKey(key); menu = this.getContentMenuWithKey(key, parent);
if (menu) { if (menu) {
parent.menu("appendItem", menu); parent.menu("appendItem", menu);
} }
@ -996,9 +996,10 @@ var system = {
/** /**
* 根据指定的key获取右键菜单 * 根据指定的key获取右键菜单
* @param key * @param key
* @param parent 父节点
* @return 菜单对象 * @return 菜单对象
*/ */
getContentMenuWithKey: function(key) { getContentMenuWithKey: function(key, parent) {
switch (key) { switch (key) {
case "setLabels": case "setLabels":
return { return {
@ -1036,6 +1037,7 @@ var system = {
onclick: function() { onclick: function() {
system.getTorrentMagnetLink(function(data){ system.getTorrentMagnetLink(function(data){
system.copyToClipboard(data); system.copyToClipboard(data);
parent.css("display","block"); // 防止第一次复制碰链失败
}); });
} }
} }
@ -1214,9 +1216,13 @@ var system = {
// by https://stackoverflow.com/questions/22581345/click-button-copy-to-clipboard-using-jquery?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa // by https://stackoverflow.com/questions/22581345/click-button-copy-to-clipboard-using-jquery?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
copyToClipboard: function (text) { copyToClipboard: function (text) {
// Create a "hidden" input // Create a "hidden" input
var aux = document.createElement("input"); var id = "copy_to_clipboard_textarea";
var aux = document.getElementById(id);
if(!aux) aux = document.createElement("textarea"); // <input/> 不接受换行
aux.id = id;
aux.style.display = "block";
// Assign it the value of the specified element // Assign it the value of the specified element
aux.setAttribute("value", text); aux.value = text; // <textarea/> 不能使用 setAttribute
// Append it to the body // Append it to the body
document.body.appendChild(aux); document.body.appendChild(aux);
// Highlight its content // Highlight its content
@ -1224,7 +1230,7 @@ var system = {
// Copy the highlighted text // Copy the highlighted text
document.execCommand("copy"); document.execCommand("copy");
// Remove it from the body // Remove it from the body
document.body.removeChild(aux); aux.style.display = "none";
}, },
// Initialize the System Toolbar // Initialize the System Toolbar
initToolbar: function () { initToolbar: function () {