mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-12-14 06:38:28 +09:00
[Client] Improve usability
This commit is contained in:
parent
fa124abbe2
commit
78c185a05a
@ -2,12 +2,32 @@
|
||||
* Clipboardに値をコピー(TODO: 文字列以外も対応)
|
||||
*/
|
||||
export default val => {
|
||||
const form = document.createElement('textarea');
|
||||
form.textContent = val;
|
||||
document.body.appendChild(form);
|
||||
form.select();
|
||||
// 空div 生成
|
||||
const tmp = document.createElement('div');
|
||||
// 選択用のタグ生成
|
||||
const pre = document.createElement('pre');
|
||||
|
||||
// 親要素のCSSで user-select: none だとコピーできないので書き換える
|
||||
pre.style.webkitUserSelect = 'auto';
|
||||
pre.style.userSelect = 'auto';
|
||||
|
||||
tmp.appendChild(pre).textContent = val;
|
||||
|
||||
// 要素を画面外へ
|
||||
const s = tmp.style;
|
||||
s.position = 'fixed';
|
||||
s.right = '200%';
|
||||
|
||||
// body に追加
|
||||
document.body.appendChild(tmp);
|
||||
// 要素を選択
|
||||
document.getSelection().selectAllChildren(tmp);
|
||||
|
||||
// クリップボードにコピー
|
||||
const result = document.execCommand('copy');
|
||||
document.body.removeChild(form);
|
||||
|
||||
// 要素削除
|
||||
document.body.removeChild(tmp);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
@ -87,10 +87,18 @@ export default Vue.extend({
|
||||
|
||||
copyContent() {
|
||||
copyToClipboard(this.note.text);
|
||||
this.$root.dialog({
|
||||
type: 'success',
|
||||
splash: true
|
||||
});
|
||||
},
|
||||
|
||||
copyLink() {
|
||||
copyToClipboard(`${url}/notes/${this.note.id}`);
|
||||
this.$root.dialog({
|
||||
type: 'success',
|
||||
splash: true
|
||||
});
|
||||
},
|
||||
|
||||
pin() {
|
||||
|
Loading…
Reference in New Issue
Block a user