Skip to content

Instantly share code, notes, and snippets.

@ten1seven
Last active September 28, 2022 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ten1seven/8339751976117c7ff2af0b2c46accdc3 to your computer and use it in GitHub Desktop.
Save ten1seven/8339751976117c7ff2af0b2c46accdc3 to your computer and use it in GitHub Desktop.
module.exports = {
// opens a centered popup window
openWindow: function(url, width, height) {
var left = screen.width / 2 - width / 2;
var top = screen.height / 2 - height / 2;
window.open(
url,
'',
'width=' + width + ',height=' + height + ', top=' + top + ', left=' + left
);
}
};
import H from '../globals/helpers';
var Share = function(elem) {
this.elem = elem;
this.init();
};
Share.prototype = {
init: function() {
this.bindEvents();
},
bindEvents: function() {
this.elem.addEventListener(
'click',
this.elem.getAttribute('data-js') === 'share'
? this.shareIt
: this.printIt
);
},
shareIt: function(event) {
event.preventDefault();
H.openWindow(this.getAttribute('href'), 630, 265);
},
printIt: function() {
window.print();
}
};
module.exports = Share;
<ul class="share__list">
<li class="share__item">
<a
class="svg-icon svg-icon--facebook"
data-js="share"
href="https://www.facebook.com/sharer/sharer.php?u={{ post.link }}">
<span class="sr-only">Share on Facebook</span>
</a>
</li>
<li class="share__item">
<a
class="svg-icon svg-icon--twitter"
data-js="share"
href="https://twitter.com/share?url={{post.link}}&amp;text={{post.title}}&amp;via=atlantic">
<span class="sr-only">Tweet this Page</span>
</a>
</li>
<li class="share__item">
<a
class="svg-icon svg-icon--email"
href="mailto:?subject={{"#{post.title} | The Atlantic Philanthropies"|url_encode}}&amp;body={{ "#{post.link}
- Sent via The Atlantic Philanthropies"|url_encode }}">
<span class="sr-only">Email Page</span>
</a>
</li>
<li class="share__item">
<button
class="svg-icon svg-icon--print"
data-js="print">
<span class="sr-only">Print this Page</span>
</button>
</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment