1.0.2 • Published 5 years ago
wind-open v1.0.2
Wind Open
window.open helper: opens a minimal popup in a new window perfectly centered.
Install
npm i wind-open --save
yarn add wind-open
Usage
// helper stringify method
function stringify(params) {
return Object.keys(params).map(key =>
`${key}=${encodeURIComponent(params[key])}`
).join('&');
}
// the url to share
const url = window.location.origin + `/products/${p.handle}`;
const image = 'https://via.placeholder.com/950x700';
// tumbler
windOpen(
'http://www.tumblr.com/share/photo?' +
stringify({
source: image,
clickthru: url,
media: image,
utm_source: 'tumblr',
caption: 'short description'
}),
'Share on Tumbler'
);
// pinterest
windOpen(
'http://pinterest.com/pin/create/button?' +
stringify({
url,
media: image,
utm_source: 'pinterest',
description: 'short description'
}),
'Share on Pinterest'
);
// google plus RIP
windOpen(
'https://plus.google.com/share?' +
stringify({
url,
utm_source: 'googleplus'
}),
'Share on Google Plus'
);
// facebook
windOpen(
`https://www.facebook.com/sharer.php?${stringify({ u: url })}`,
'Share on Facebook'
);
// twitter
windOpen(
`https://twitter.com/intent/tweet?${stringify({
text: `${SITE_NAME} ${p.title}\n${url}`,
url,
})}`,
'Share on Twitter',
300
);
License
MIT License © Lane Goldberg