added experimental combined normalize/copy-button
This commit is contained in:
@ -17,10 +17,14 @@ import {Socket} from "phoenix"
|
||||
import NProgress from "nprogress"
|
||||
import {LiveSocket} from "phoenix_live_view"
|
||||
|
||||
import '@babel/polyfill'
|
||||
import { copy_func } from './buttons'
|
||||
|
||||
let Hooks = {}
|
||||
Hooks.SnippetInput = {
|
||||
updated(){
|
||||
this.el.value = this.el.dataset.updatedVal
|
||||
copy_func()
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,13 +42,3 @@ liveSocket.connect()
|
||||
// >> liveSocket.enableDebug()
|
||||
// >> liveSocket.enableLatencySim(1000)
|
||||
window.liveSocket = liveSocket
|
||||
|
||||
document.querySelector("button[id='copy-button']").onclick = function(){
|
||||
var ta = document.querySelector("textarea[name='snippet']")
|
||||
var start = ta.selectionStart
|
||||
var end = ta.selectionEnd
|
||||
ta.select()
|
||||
document.execCommand("copy");
|
||||
ta.selectionStart = start
|
||||
ta.selectionEnd = end
|
||||
}
|
||||
|
||||
25
assets/js/buttons.js
Normal file
25
assets/js/buttons.js
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
var copy_on_update
|
||||
|
||||
export async function copy_func(now){
|
||||
console.info([document, copy_on_update, now, "copy_func() executed"])
|
||||
if ( copy_on_update || now ){
|
||||
var ta = document.querySelector("textarea[name='snippet']")
|
||||
ta.focus()
|
||||
try {
|
||||
await navigator.clipboard.writeText(ta.value)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
copy_on_update = false
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelector("button[id='normcop']").onclick = function(ev){
|
||||
copy_func(true)
|
||||
copy_on_update = true
|
||||
}
|
||||
|
||||
document.querySelector("button[id='copy-button']").onclick = function(ev){
|
||||
copy_func(true)
|
||||
}
|
||||
Reference in New Issue
Block a user