From 2a438689566dde96063bceb2522ef1471de62afa Mon Sep 17 00:00:00 2001 From: Thelonius Kort Date: Tue, 11 Aug 2020 20:15:16 +0200 Subject: [PATCH] more normalization and copy button --- assets/js/app.js | 13 ++++++++++--- lib/clip/board.ex | 3 ++- lib/clip_web/live/board_live.ex | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 81d9aa9..abf269c 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -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 +} diff --git a/lib/clip/board.ex b/lib/clip/board.ex index 3b13136..0d100cf 100644 --- a/lib/clip/board.ex +++ b/lib/clip/board.ex @@ -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 \ No newline at end of file diff --git a/lib/clip_web/live/board_live.ex b/lib/clip_web/live/board_live.ex index 0486b34..e6677ad 100644 --- a/lib/clip_web/live/board_live.ex +++ b/lib/clip_web/live/board_live.ex @@ -10,8 +10,8 @@ defmodule ClipWeb.BoardLive do
- Current content: <%= @snippet %>
- + + """ end