more normalization and copy button

This commit is contained in:
Thelonius Kort
2020-08-11 20:15:16 +02:00
parent a26afef638
commit 2a43868956
3 changed files with 14 additions and 6 deletions

View File

@ -20,10 +20,7 @@ import {LiveSocket} from "phoenix_live_view"
let Hooks = {}
Hooks.SnippetInput = {
updated(){
// + cursor reposition logic
// console.log(['dings', this.el.dataset])
this.el.value = this.el.dataset.updatedVal
// this.el.select()
}
}
@ -41,3 +38,13 @@ 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
}

View File

@ -13,11 +13,12 @@ defmodule Clip.Board do
end
def normalize(pnumber, local_pref \\ "0351", country_pref \\ "0049") do
pnumber
outp = pnumber
|> String.replace(~r/^\s*\+/, "00")
|> String.replace(~r/\D/, "")
|> String.replace(~r/^00+/, "00")
|> String.replace(~r/^(?=[1-9])/, local_pref)
|> String.replace(~r/^0(?=[1-9])/, country_pref)
"0#{outp}#"
end
end

View File

@ -10,8 +10,8 @@ defmodule ClipWeb.BoardLive do
<form phx-change="paste">
<textarea type="text" name="snippet" data-updated-val="<%= @snippet %>" phx-hook="SnippetInput" autocomplete="off"><%= @snippet %></textarea>
</form>
Current content: <%= @snippet %><br>
<button phx-click="normalize">-> 004930112</button>
<!-- Current content: < %= @snippet %><br> -->
<button phx-click="normalize">+4930112 -> 0004930112#</button> <button id="copy-button">copy</button>
"""
end