-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from saferwall/2022-fixing
✂ Copy button feature + env setup
- Loading branch information
Showing
22 changed files
with
285 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
VUE_APP_ANALYTICS_GOOGLE_TAG= | ||
VUE_APP_CSP_HOSTS="*.saferwall.com saferwall.com" | ||
|
||
VUE_APP_BASE_URI="https://saferwall.com/" | ||
VUE_APP_API_BASE_URL="https://api.saferwall.com/v1/" | ||
VUE_APP_AVATAR_BASE_URL="https://avatar.saferwall.com/" | ||
VUE_APP_AVATAR_BASE_URL="https://avatar.saferwall.com/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ node_modules | |
package-lock.json | ||
|
||
# local env files | ||
.env | ||
.env.local | ||
.env.*.local | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,34 @@ | ||
#!/bin/sh | ||
|
||
echo "Starting Nginx" | ||
# Replace env in app.*.js | ||
for file in /usr/share/nginx/html/js/app.*.js; | ||
do | ||
echo "[Info] Processing $file ..."; | ||
|
||
# Use the existing JS file as template | ||
if [ ! -f $file.tmpl.js ]; then | ||
cp $file $file.tmpl.js | ||
fi | ||
|
||
envsubst '$VUE_APP_BASE_URI' < $file.tmpl.js > $file | ||
envsubst '$VUE_APP_API_BASE_URL' < $file > $file | ||
envsubst '$VUE_APP_AVATAR_BASE_URL' < $file > $file | ||
done | ||
|
||
# Replace env in index.html | ||
file="/usr/share/nginx/html/index.html"; | ||
|
||
echo "[Info] Processing $file ..."; | ||
cp $file $file.tmp | ||
|
||
head_tag="<\/head>" | ||
if [ -z "${VUE_APP_ANALYTICS_GOOGLE_TAG}" ]; then | ||
echo "[Info] VUE_APP_ANALYTICS_GOOGLE_TAG env value is not defined"; | ||
else | ||
# Inject google analytics | ||
g_tag='<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;ga("create", "'$VUE_APP_ANALYTICS_GOOGLE_TAG'", "auto");ga("send", "pageview");<\/script><script async src="https:\/\/www.google-analytics.com\/analytics.js"><\/script>\n'$head_tag | ||
sed -i "s/$head_tag/$g_tag/g" $file | ||
fi | ||
|
||
echo "[Info] Starting Nginx ..." | ||
nginx -g 'daemon off;' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<template> | ||
<div | ||
@click="copyContent($event)" | ||
@mouseenter="showCopyIcon($event)" | ||
@mouseleave="removeCopyIcon($event)" | ||
> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
|
||
<script> | ||
const svgCopyIcon = ` | ||
<span data-copy-btn><svg xmlns="http://www.w3.org/2000/svg" height="18px" viewBox="0 0 24 24" width="18px" fill="currentColor"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M19 2h-4.18C14.4.84 13.3 0 12 0S9.6.84 9.18 2H5c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-7 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm7 18H5V4h2v3h10V4h2v16z"/></svg><label>Copy</label></span>`; | ||
export default { | ||
methods: { | ||
copyContent(event) { | ||
// clone node and remove copy button | ||
const nodeContent = event.target.parentNode.cloneNode(true); | ||
nodeContent.querySelector("div[data-copy-element]").remove(); | ||
this.selectContent(event.target.parentNode); | ||
this.updateClipboard(nodeContent.textContent, () => { | ||
const copySvg = this.getCopyButton(event); | ||
if (!copySvg) return; | ||
copySvg.querySelector("label").innerText = "Copied !"; | ||
}); | ||
}, | ||
showCopyIcon(event) { | ||
event.target.setAttribute("data-copy-parent", 1); | ||
const copySvg = this.getCopyButton(event); | ||
if (copySvg) return; | ||
const copyElement = document.createElement("div"); | ||
copyElement.setAttribute("data-copy-element", 1); | ||
copyElement.innerHTML = svgCopyIcon; | ||
event.target.prepend(copyElement); | ||
}, | ||
removeCopyIcon(event) { | ||
const copySvg = this.getCopyButton(event); | ||
if (!copySvg) return; | ||
copySvg.remove(); | ||
}, | ||
getCopyButton(event) { | ||
return event.target.parentNode.querySelector("div[data-copy-element]"); | ||
}, | ||
selectContent(node) { | ||
var r = document.createRange(); | ||
r.selectNodeContents(node); | ||
var sel = window.getSelection(); | ||
sel.removeAllRanges(); | ||
sel.addRange(r); | ||
}, | ||
updateClipboard(content, done = () => {}) { | ||
navigator.clipboard && | ||
navigator.clipboard.writeText(content).then( | ||
() => { | ||
done(); | ||
}, | ||
function () { | ||
/* clipboard write failed */ | ||
console.error("Copy action is not granted"); | ||
} | ||
); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
|
||
<style lang="scss" > | ||
*[data-copy-parent] { | ||
@apply relative; | ||
label { | ||
@apply text-xs; | ||
} | ||
} | ||
div[data-copy-element] { | ||
@apply bg-green-500 bg-opacity-10; | ||
@apply absolute flex items-center justify-center; | ||
@apply w-full h-full; | ||
@apply select-none; | ||
span[data-copy-btn] { | ||
@apply text-white; | ||
@apply flex items-center justify-center gap-x-1; | ||
@apply p-1 px-2 bg-primary bg-opacity-90 rounded; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.