From 2a1b25b8ac246373ae56aab6d23998cdce314f98 Mon Sep 17 00:00:00 2001 From: Mavis Ou Date: Tue, 16 Jul 2019 13:02:22 -0700 Subject: [PATCH] Add share buttons to blog pages (#3383) * Add share buttons to blog pages * update button right margin * fixed typo and styling updates * conditionally toggle sticky share buttons * conditionally toggle sticky share buttons --- .../templates/wagtailpages/blog_page.html | 9 +++++- .../share-button-group/share-button-group.jsx | 20 ++++++++----- .../share-button-group.scss | 29 ++++++++++++++----- source/js/main.js | 28 ++++++++++++++++++ source/sass/views/blog.scss | 7 +++++ 5 files changed, 77 insertions(+), 16 deletions(-) diff --git a/network-api/networkapi/wagtailpages/templates/wagtailpages/blog_page.html b/network-api/networkapi/wagtailpages/templates/wagtailpages/blog_page.html index 7a46e771d7..1b00449c25 100644 --- a/network-api/networkapi/wagtailpages/templates/wagtailpages/blog_page.html +++ b/network-api/networkapi/wagtailpages/templates/wagtailpages/blog_page.html @@ -2,13 +2,20 @@ {% load wagtailcore_tags mini_site_tags %} +{% block bodyID %}blog{% endblock %} {% block subcontent %} -
+
+
+ +
+
+

{{ page.title }}

By {{ page.author }} | {% if page.first_published_at %}{{ page.first_published_at|date:"F j, Y" }}{% else %}not published yet{% endif %}

{{ page.body }} +
{% include "./fragments/post_tags.html" %} diff --git a/source/js/components/share-button-group/share-button-group.jsx b/source/js/components/share-button-group/share-button-group.jsx index 7e924cbdd4..4baa8363ed 100644 --- a/source/js/components/share-button-group/share-button-group.jsx +++ b/source/js/components/share-button-group/share-button-group.jsx @@ -22,7 +22,7 @@ export default class ShareButtonGroup extends React.Component { this.props.version === `mini` ? ( Share on Facebook ) : ( - `Faceook` + `Facebook` ); let link = this.props.link || ``; @@ -31,7 +31,7 @@ export default class ShareButtonGroup extends React.Component { @@ -61,7 +62,10 @@ export default class ShareButtonGroup extends React.Component { } renderEmailButton() { - let shareText = this.props.shareText || ``; + let shareText = this.props.shareText + ? encodeURIComponent(this.props.shareText) + : ``; + let link = this.props.link ? ` ${encodeURIComponent(this.props.link)}` : ``; let label = this.props.version === `mini` ? ( Share by email @@ -72,7 +76,7 @@ export default class ShareButtonGroup extends React.Component { return ( diff --git a/source/js/components/share-button-group/share-button-group.scss b/source/js/components/share-button-group/share-button-group.scss index 19734639f3..75f4050968 100644 --- a/source/js/components/share-button-group/share-button-group.scss +++ b/source/js/components/share-button-group/share-button-group.scss @@ -6,10 +6,8 @@ margin-bottom: 16px; } - .btn { - &:last-child { - margin-right: 0; - } + .btn:last-child { + margin-right: 0; } .subgroup { @@ -18,8 +16,20 @@ } display: flex; + flex-wrap: wrap; &.rectangle { + .subgroup { + display: flex; + flex: 1; + + &:last-child { + .btn:last-child { + margin-right: 0; + } + } + } + @media (max-width: $bp-md) { @include stacked-rectangle(); } @@ -29,7 +39,8 @@ } .btn { - width: 130px; + min-width: 130px; + flex: 1; &::before { position: relative; @@ -44,8 +55,12 @@ &.stacked { flex-direction: column; - .btn:not(:last-child) { - margin-bottom: 16px; + .btn { + margin-right: 0; + + &:not(:last-child) { + margin-bottom: 16px; + } } } diff --git a/source/js/main.js b/source/js/main.js index 744c31d241..539375ed65 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -155,6 +155,34 @@ let main = { window.addEventListener(`scroll`, onScroll); + // Toggle sticky share buttons on blog page + + let blogPageStickyButtons = document.querySelector( + `#view-blog .blog-sticky-side .share-button-group` + ); + let blogPageFullButtons = document.querySelector( + `#view-blog .blog-body .share-button-group` + ); + + if (blogPageStickyButtons && blogPageFullButtons) { + const isInViewport = element => { + let box = element.getBoundingClientRect(); + + return box.top <= window.innerHeight && box.top + box.height >= 0; + }; + + const toggleStickyButtons = () => { + if (isInViewport(blogPageFullButtons)) { + blogPageStickyButtons.classList.add(`d-none`); + } else { + blogPageStickyButtons.classList.remove(`d-none`); + } + }; + + window.addEventListener(`scroll`, toggleStickyButtons); + toggleStickyButtons(); + } + // Call once to get scroll position on initial page load. onScroll(); diff --git a/source/sass/views/blog.scss b/source/sass/views/blog.scss index fcfed7b727..bbe35fbdfa 100644 --- a/source/sass/views/blog.scss +++ b/source/sass/views/blog.scss @@ -1,3 +1,10 @@ .blog-ih-cta-wrapper { margin-top: 95px; } + +.blog-sticky-side { + position: sticky; + top: 140px; + display: flex; + justify-content: flex-end; +}