Skip to content

Commit a82093c

Browse files
authored
Add 'Print' button (#100)
2 parents 82965c4 + 65223a7 commit a82093c

File tree

6 files changed

+22
-4
lines changed

6 files changed

+22
-4
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1111
- [#99](https://github.com/kytta/shareon/pull/99)
1212
Email button
1313

14+
- [#100](https://github.com/kytta/shareon/pull/100)
15+
Print button
16+
1417
## [2.3.0] - 2023-08-01
1518

1619
### Added

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Shareon.init();
8989

9090
Create a container with class `shareon` and populate it with elements, class
9191
names of which match the names of the social networks (or `copy-url`, for the
92-
'Copy URL' button):
92+
'Copy URL' button, or `print` for the 'Print' button):
9393

9494
```html
9595
<div class="shareon">
@@ -111,6 +111,7 @@ names of which match the names of the social networks (or `copy-url`, for the
111111
<a class="whatsapp"></a>
112112
<a class="copy-url"></a>
113113
<a class="email"></a>
114+
<a class="print"></a>
114115
</div>
115116
```
116117

index.html

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ <h2><code>&lt;a&gt;</code></h2>
4646
<a class="whatsapp"></a>
4747
<a class="copy-url"></a>
4848
<a class="email"></a>
49+
<a class="print"></a>
4950
<a class="web-share"></a>
5051
</div>
5152
</section>
@@ -69,6 +70,7 @@ <h2><code>&lt;button&gt;</code></h2>
6970
<button class="whatsapp"></button>
7071
<button class="copy-url"></button>
7172
<button class="email"></button>
73+
<button class="print"></button>
7274
<button class="web-share"></button>
7375
</div>
7476
</section>

src/icons/print.svg

+1
Loading

src/shareon.css

+4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@
137137
background-image: url("icons/pocket.svg");
138138
}
139139

140+
.shareon > .print:before {
141+
background-image: url("icons/print.svg");
142+
}
143+
140144
.shareon > .reddit {
141145
background-color: #ff4500;
142146
}

src/shareon.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import "./shareon.css";
1717
* }) => string}}
1818
*/
1919
const urlBuilderMap = {
20-
facebook: (d) => `https://www.facebook.com/sharer/sharer.php?u=${d.url}${d.hashtags? `&hashtag=%23${d.hashtags.split('%2C')[0]}` : ''}`,
20+
facebook: (d) => `https://www.facebook.com/sharer/sharer.php?u=${d.url}${d.hashtags ? `&hashtag=%23${d.hashtags.split('%2C')[0]}` : ''}`,
2121
email: (d) => `mailto:?subject=${d.title}&body=${d.url}`,
2222
linkedin: (d) => `https://www.linkedin.com/sharing/share-offsite/?url=${d.url}`,
2323
mastodon: (d) => `https://toot.kytta.dev/?text=${d.title}%0D%0A${d.url}${d.text ? `%0D%0A%0D%0A${d.text}` : ''}${d.via ? `%0D%0A%0D%0A${d.via}` : ''}`,
@@ -28,8 +28,8 @@ const urlBuilderMap = {
2828
reddit: (d) => `https://www.reddit.com/submit?title=${d.title}&url=${d.url}`,
2929
teams: (d) => `https://teams.microsoft.com/share?href=${d.url}${d.text ? `&msgText=${d.text}` : ''}`,
3030
telegram: (d) => `https://telegram.me/share/url?url=${d.url}${d.text ? `&text=${d.text}` : ''}`,
31-
tumblr: (d) => `https://www.tumblr.com/widgets/share/tool?posttype=link${d.hashtags? `&tags=${d.hashtags}` : ''}&title=${d.title}&content=${d.url}&canonicalUrl=${d.url}${d.text? `&caption=${d.text}`:''}${d.via? `&show-via=${d.via}`:''}`,
32-
twitter: (d) => `https://twitter.com/intent/tweet?url=${d.url}&text=${d.title}${d.via ? `&via=${d.via}` : ''}${d.hashtags? `&hashtags=${d.hashtags}` : ''}`,
31+
tumblr: (d) => `https://www.tumblr.com/widgets/share/tool?posttype=link${d.hashtags ? `&tags=${d.hashtags}` : ''}&title=${d.title}&content=${d.url}&canonicalUrl=${d.url}${d.text ? `&caption=${d.text}` : ''}${d.via ? `&show-via=${d.via}` : ''}`,
32+
twitter: (d) => `https://twitter.com/intent/tweet?url=${d.url}&text=${d.title}${d.via ? `&via=${d.via}` : ''}${d.hashtags ? `&hashtags=${d.hashtags}` : ''}`,
3333
viber: (d) => `viber://forward?text=${d.title}%0D%0A${d.url}${d.text ? `%0D%0A%0D%0A${d.text}` : ''}`,
3434
vkontakte: (d) => `https://vk.com/share.php?url=${d.url}&title=${d.title}${d.media ? `&image=${d.media}` : ''}`,
3535
whatsapp: (d) => `https://wa.me/?text=${d.title}%0D%0A${d.url}${d.text ? `%0D%0A%0D%0A${d.text}` : ''}`,
@@ -68,6 +68,13 @@ const init = () => {
6868
});
6969
}
7070

71+
// if it's "Print"
72+
if (cls === "print") {
73+
child.addEventListener("click", () => {
74+
window.print();
75+
});
76+
}
77+
7178
// if it's "Web Share"
7279
if (cls === "web-share") {
7380
const data = {

0 commit comments

Comments
 (0)