From 8d880fc9dd71288231b7695a3329fa550c29b1ec Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 18 May 2023 13:48:22 -0500 Subject: [PATCH] Add workaround for "share grid link" on insecure sites --- tailbone/templates/grids/buefy.mako | 33 ++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tailbone/templates/grids/buefy.mako b/tailbone/templates/grids/buefy.mako index 98de939d..48c3a081 100644 --- a/tailbone/templates/grids/buefy.mako +++ b/tailbone/templates/grids/buefy.mako @@ -315,6 +315,12 @@ + + ## dummy input field needed for sharing links on *insecure* sites + % if request.scheme == 'http': + + % endif + @@ -349,6 +355,11 @@ filters: ${json.dumps(filters_data if grid.filterable else None)|n}, filtersSequence: ${json.dumps(filters_sequence if grid.filterable else None)|n}, selectedFilter: null, + + ## dummy input value needed for sharing links on *insecure* sites + % if request.scheme == 'http': + shareLink: null, + % endif } let ${grid.component_studly} = { @@ -382,7 +393,27 @@ methods: { copyDirectLink() { - navigator.clipboard.writeText(this.directLink) + + if (navigator.clipboard) { + // this is the way forward, but requires HTTPS + navigator.clipboard.writeText(this.directLink) + + } else { + // use deprecated 'copy' command, but this just + // tells the browser to copy currently-selected + // text..which means we first must "add" some text + // to screen, and auto-select that, before copying + // to clipboard + this.shareLink = this.directLink + this.$nextTick(() => { + let input = this.$refs.shareLink.$el.firstChild + input.select() + document.execCommand('copy') + // re-hide the dummy input + this.shareLink = null + }) + } + this.$buefy.toast.open({ message: "Link was copied to clipboard", type: 'is-info',