Skip to content

Commit

Permalink
Add 'Print' button (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
kytta committed Dec 7, 2023
2 parents 82965c4 + 65223a7 commit a82093c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- [#99](https://github.com/kytta/shareon/pull/99)
Email button

- [#100](https://github.com/kytta/shareon/pull/100)
Print button

## [2.3.0] - 2023-08-01

### Added
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Shareon.init();

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

```html
<div class="shareon">
Expand All @@ -111,6 +111,7 @@ names of which match the names of the social networks (or `copy-url`, for the
<a class="whatsapp"></a>
<a class="copy-url"></a>
<a class="email"></a>
<a class="print"></a>
</div>
```

Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ <h2><code>&lt;a&gt;</code></h2>
<a class="whatsapp"></a>
<a class="copy-url"></a>
<a class="email"></a>
<a class="print"></a>
<a class="web-share"></a>
</div>
</section>
Expand All @@ -69,6 +70,7 @@ <h2><code>&lt;button&gt;</code></h2>
<button class="whatsapp"></button>
<button class="copy-url"></button>
<button class="email"></button>
<button class="print"></button>
<button class="web-share"></button>
</div>
</section>
Expand Down
1 change: 1 addition & 0 deletions src/icons/print.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/shareon.css
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
background-image: url("icons/pocket.svg");
}

.shareon > .print:before {
background-image: url("icons/print.svg");
}

.shareon > .reddit {
background-color: #ff4500;
}
Expand Down
13 changes: 10 additions & 3 deletions src/shareon.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import "./shareon.css";
* }) => string}}
*/
const urlBuilderMap = {
facebook: (d) => `https://www.facebook.com/sharer/sharer.php?u=${d.url}${d.hashtags? `&hashtag=%23${d.hashtags.split('%2C')[0]}` : ''}`,
facebook: (d) => `https://www.facebook.com/sharer/sharer.php?u=${d.url}${d.hashtags ? `&hashtag=%23${d.hashtags.split('%2C')[0]}` : ''}`,
email: (d) => `mailto:?subject=${d.title}&body=${d.url}`,
linkedin: (d) => `https://www.linkedin.com/sharing/share-offsite/?url=${d.url}`,
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}` : ''}`,
Expand All @@ -28,8 +28,8 @@ const urlBuilderMap = {
reddit: (d) => `https://www.reddit.com/submit?title=${d.title}&url=${d.url}`,
teams: (d) => `https://teams.microsoft.com/share?href=${d.url}${d.text ? `&msgText=${d.text}` : ''}`,
telegram: (d) => `https://telegram.me/share/url?url=${d.url}${d.text ? `&text=${d.text}` : ''}`,
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}`:''}`,
twitter: (d) => `https://twitter.com/intent/tweet?url=${d.url}&text=${d.title}${d.via ? `&via=${d.via}` : ''}${d.hashtags? `&hashtags=${d.hashtags}` : ''}`,
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}` : ''}`,
twitter: (d) => `https://twitter.com/intent/tweet?url=${d.url}&text=${d.title}${d.via ? `&via=${d.via}` : ''}${d.hashtags ? `&hashtags=${d.hashtags}` : ''}`,
viber: (d) => `viber://forward?text=${d.title}%0D%0A${d.url}${d.text ? `%0D%0A%0D%0A${d.text}` : ''}`,
vkontakte: (d) => `https://vk.com/share.php?url=${d.url}&title=${d.title}${d.media ? `&image=${d.media}` : ''}`,
whatsapp: (d) => `https://wa.me/?text=${d.title}%0D%0A${d.url}${d.text ? `%0D%0A%0D%0A${d.text}` : ''}`,
Expand Down Expand Up @@ -68,6 +68,13 @@ const init = () => {
});
}

// if it's "Print"
if (cls === "print") {
child.addEventListener("click", () => {
window.print();
});
}

// if it's "Web Share"
if (cls === "web-share") {
const data = {
Expand Down

0 comments on commit a82093c

Please sign in to comment.