Skip to content

Commit 31fb364

Browse files
committed
new twitter and email sharing buttons
1 parent db42ca0 commit 31fb364

6 files changed

Lines changed: 103 additions & 1 deletion

File tree

examples/project_website/data-config_base.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var data_config = {
2828
context_most_relevant_tooltip: true,
2929

3030
embed_modal: true,
31-
share_modal: true,
31+
share_modal: false,
3232

3333
doi_outlink: true,
3434
filter_menu_dropdown: true,
@@ -46,4 +46,7 @@ var data_config = {
4646

4747
highlight_query_terms: true,
4848
show_context_oa_number: false,
49+
50+
show_twitter_button: true,
51+
show_email_button: true,
4952
};

vis/js/components/ModalButtons.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import EmbedButton from "../templates/buttons/EmbedButton";
1111
import FAQsButton from "../templates/buttons/FAQsButton";
1212
import ReloadButton from "../templates/buttons/ReloadButton";
1313
import ShareButton from "../templates/buttons/ShareButton";
14+
import TwitterButton from "../templates/buttons/TwitterButton";
15+
import EmailButton from "../templates/buttons/EmailButton";
1416

1517
const ModalButtons = ({
1618
showShareButton,
@@ -28,6 +30,8 @@ const ModalButtons = ({
2830
visTag,
2931
service,
3032
showCitationButton,
33+
showTwitterButton,
34+
showEmailButton,
3135
}) => {
3236
useEffect(() => {
3337
if (["base", "pubmed"].includes(service) && !isEmbedded) {
@@ -38,6 +42,8 @@ const ModalButtons = ({
3842
return (
3943
<div id="modals">
4044
{showShareButton && <ShareButton twitterHashtags={twitterHashtags} />}
45+
{showTwitterButton && <TwitterButton />}
46+
{showEmailButton && <EmailButton />}
4147
{showEmbedButton && <EmbedButton onClick={onEmbedButtonClick} />}
4248
{showFAQsButton && <FAQsButton url={FAQsUrl} />}
4349
{showViperEditButton && (
@@ -68,6 +74,8 @@ const mapStateToProps = (state) => ({
6874
visTag: state.misc.visTag,
6975
service: state.service,
7076
showCitationButton: state.modals.showCitationButton,
77+
showTwitterButton: state.modals.showTwitterButton,
78+
showEmailButton: state.modals.showEmailButton,
7179
});
7280

7381
const mapDispatchToProps = (dispatch) => ({

vis/js/default-config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ var config = {
179179
show_cite_button: false,
180180
// show citation button for each paper
181181
cite_papers: false,
182+
// show twitter sharing button
183+
show_twitter_button: false,
184+
// show email sharing button
185+
show_email_button: false,
182186

183187
/*** streamgraph settings ***/
184188
//streamgraph color definition

vis/js/reducers/modals.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ const modals = (
4444
openCitationModal: false,
4545
citedPaper: null,
4646
exportedPaper: null,
47+
showTwitterButton: !!action.configObject.show_twitter_button,
48+
showEmailButton: !!action.configObject.show_email_button,
4749
};
4850
case "OPEN_EMBED_MODAL":
4951
return {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from "react";
2+
3+
import { Button } from "react-bootstrap";
4+
import useMatomo from "../../utils/useMatomo";
5+
6+
const EmailButton = () => {
7+
const title = encodeURIComponent(document.title);
8+
const pageUrl = encodeURIComponent(window.location.href);
9+
const description = encodeURIComponent(
10+
$("meta[name='description']").attr("content")
11+
);
12+
13+
const url = `mailto:?subject=${title}&body=${description} ${pageUrl}`;
14+
15+
const { trackEvent } = useMatomo();
16+
17+
const handleClick = () =>
18+
trackEvent("Added components", "Share", "E-mail button");
19+
20+
// TODO localize
21+
return (
22+
<div>
23+
<a
24+
className="sharebutton_mail"
25+
href={url}
26+
target="_blank"
27+
rel="noreferrer"
28+
>
29+
<Button
30+
bsStyle="primary"
31+
title="Share this knowledge map via email"
32+
onClick={handleClick}
33+
>
34+
<i className="fa fa-envelope"></i>
35+
</Button>
36+
</a>
37+
</div>
38+
);
39+
};
40+
41+
export default EmailButton;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from "react";
2+
import { connect } from "react-redux";
3+
4+
import { Button } from "react-bootstrap";
5+
import useMatomo from "../../utils/useMatomo";
6+
7+
const TwitterButton = ({ twitterHashtags }) => {
8+
const title = encodeURIComponent(document.title);
9+
const pageUrl = encodeURIComponent(window.location.href);
10+
twitterHashtags = encodeURIComponent(twitterHashtags);
11+
12+
const url = `https://twitter.com/intent/tweet?url=${pageUrl}&hashtags=${twitterHashtags}&text=${title}`;
13+
14+
const { trackEvent } = useMatomo();
15+
16+
const handleClick = () =>
17+
trackEvent("Added components", "Share", "Twitter button");
18+
19+
// TODO localize
20+
return (
21+
<div>
22+
<a
23+
className="sharebutton_twitter"
24+
href={url}
25+
target="_blank"
26+
rel="noreferrer"
27+
>
28+
<Button
29+
bsStyle="primary"
30+
title="Share this knowledge map via Twitter"
31+
onClick={handleClick}
32+
>
33+
<i className="fab fa-twitter"></i>
34+
</Button>
35+
</a>
36+
</div>
37+
);
38+
};
39+
40+
const mapStateToProps = (state) => ({
41+
twitterHashtags: state.modals.twitterHashtags,
42+
});
43+
44+
export default connect(mapStateToProps)(TwitterButton);

0 commit comments

Comments
 (0)