Skip to content

Commit 3743157

Browse files
Add share button to content pages with referral ID support
Agent-Logs-Url: https://github.com/IntelliTect/EssentialCSharp.Web/sessions/1b04636e-1e3d-4243-a8a5-9f9d3afa169b Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
1 parent ff2429b commit 3743157

3 files changed

Lines changed: 47 additions & 13 deletions

File tree

EssentialCSharp.Web/src/components/PageNavigation.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ const shell = inject("shell");
1616
( or use the <i class="fa-solid fa-square-caret-left" /> key)
1717
</span>
1818
</div>
19+
<div v-if="shell.isContentPage" class="turn-page-tooltip">
20+
<button id="share-btn" class="arrow-btn" aria-label="Share this page" @click="shell.shareCurrentPage()">
21+
<i class="fa-solid fa-share-from-square arrow-icon" />
22+
</button>
23+
<span class="turn-page-tooltip-text tooltip-center">
24+
<b>Share Page</b>
25+
<br />
26+
Copies a link to this page
27+
</span>
28+
</div>
1929
<div class="turn-page-tooltip">
2030
<a v-if="shell.nextPageUrl" id="next-btn" :href="shell.nextPageUrl" class="arrow-btn">
2131
<i class="fa fa-solid fa-arrow-right icon-light arrow-icon" />

EssentialCSharp.Web/src/composables/useSiteShell.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,21 @@ export function useSiteShell() {
8989
return urlObject.toString();
9090
}
9191

92-
function copyToClipboard(copyText) {
93-
let url;
94-
95-
if (copyText.includes("#")) {
96-
url = `${window.location.origin}/${copyText}`;
97-
}
98-
else {
99-
const currentUrl = window.location.href.split("#")[0];
100-
url = `${currentUrl}#${copyText}`;
101-
}
102-
92+
function addReferralIdToUrl(url) {
10393
const referralId = window.REFERRAL_ID;
10494
if (typeof referralId === "string" && referralId.trim().length > 0) {
105-
url = addQueryParam(url, "rid", referralId);
95+
return addQueryParam(url, "rid", referralId);
10696
}
97+
return url;
98+
}
10799

100+
function writeToClipboard(url, successMessage = "Copied to clipboard!") {
108101
navigator.clipboard
109102
.writeText(url)
110103
.then(
111104
() => {
112105
snackbarColor.value = "white";
113-
snackbarMessage.value = "Copied url to clipboard!";
106+
snackbarMessage.value = successMessage;
114107
},
115108
(error) => {
116109
console.error("Could not copy text to clipboard: ", error);
@@ -129,6 +122,25 @@ export function useSiteShell() {
129122
}, 3000);
130123
}
131124

125+
function copyToClipboard(copyText) {
126+
let url;
127+
128+
if (copyText.includes("#")) {
129+
url = `${window.location.origin}/${copyText}`;
130+
}
131+
else {
132+
const currentUrl = window.location.href.split("#")[0];
133+
url = `${currentUrl}#${copyText}`;
134+
}
135+
136+
writeToClipboard(addReferralIdToUrl(url), "Copied url to clipboard!");
137+
}
138+
139+
function shareCurrentPage() {
140+
const url = window.location.href.split("#")[0];
141+
writeToClipboard(addReferralIdToUrl(url), "Copied page url to clipboard!");
142+
}
143+
132144
function goToPrevious() {
133145
if (window.PREVIOUS_PAGE !== null) {
134146
window.location.href = `/${window.PREVIOUS_PAGE}`;
@@ -276,6 +288,7 @@ export function useSiteShell() {
276288
isContentPage,
277289
filteredTocData,
278290
copyToClipboard,
291+
shareCurrentPage,
279292
goToPrevious,
280293
goToNext,
281294
openSearch,

EssentialCSharp.Web/wwwroot/css/styles.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,17 @@ a:hover {
437437
right: 3rem;
438438
}
439439

440+
.turn-page-tooltip .tooltip-center {
441+
left: 50%;
442+
transform: translateX(-50%);
443+
}
444+
445+
/* Share button reset */
446+
.turn-page button.arrow-btn {
447+
border: none;
448+
padding: 0;
449+
}
450+
440451
/* Chapter Navigation Sidebar Styles */
441452

442453
.sidebar {

0 commit comments

Comments
 (0)