JSFiddle - React, Tailwind, and code Playground
by AntonTrollback
HTML
<div class="preload"></div>
<div class="Share" data-url="URL-ATT-DELA" data-title="EN-FIN-TITEL" data-desc="EN-FIN-KORT-BESKRIVNING">
<button class="Share-button Button">Dela, om du vågar</button>
<div class="Share-window">
<button class="Share-option is-facebook Button">Facebook <div class="Share-icon"></div></button>
<button class="Share-option is-twitter Button">Twitter <div class="Share-icon"></div></button>
<input class="Share-input" type="text" value="URL-ATT-DELA">
</div>
</div>
CSS
/* Preload icons */
.preload {
background-image: url(http://xn--g4h.trollback.se/image/3s1X2E0y0X07/social.png);
visibility: hidden;
position: absolute;
height: 1px;
width: 1px;
}
@media print, (-o-min-device-pixel-ratio: 5/4), (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi) {
.preload {
background-image: url(http://xn--g4h.trollback.se/image/2n3s471h3R0y/social_2x.png);
}
}
/* ==========================================================================
SUIT Button
========================================================================== */
.Button {
-webkit-appearance: none;
background: transparent;
border: 1px solid;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
color: inherit;
cursor: pointer;
display: block;
font: inherit;
line-height: normal;
margin: 0;
padding: 0.4em 0.75em;
position: relative;
text-align: center;
text-decoration: none;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
user-select: none;
white-space: normal;
width: 100%;
}
.Button:hover,
.Button:focus,
.Button:active {
text-decoration: none;
}
.Button:disabled,
.Button.is-disabled {
cursor: default;
}
.Button::-moz-focus-inner {
border: 0;
padding: 0;
}
/**
* Extends the SUIT button component
*/
.Button {
border: 0;
padding: 20px;
font-size: 16px;
font-family: "klinic_slabbook", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-style: normal;
font-weight: normal;
text-rendering: optimizeLegibility;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
-webkit-tap-highlight-color: transparent;
-webkit-transition: outline 0.2s ease;
transition: outline 0.2s ease;
color: white;
background: #cd1b68;
outline-width: 0;
outline-style: solid;
outline-color: #cd1b68;
}
.Button:hover,
.Button:focus {
outline: 2px solid #cd1b68;
-webkit-transition: outline 0.1s ease;
transition: outline 0.1s...
JavaScript
// Init at bottom
// Setup
var App = {};
App.templateDirectory = "/stuff"; // result: /stuff/img/share.png?v=2
App.facebookID = "...";
// Share module
(function(win, doc, $) {
var Share = {
init: function() {
this.elm = $('.Share');
this.binds();
if (this.elm.length) {
this.initFacebook()
}
},
binds: function() {
var that = this;
that.elm.on('click', '.Share-button', function(e) {
e.preventDefault();
e.stopPropagation();
var $share = $(this).parent('.Share'),
$shareWindow = $share.find('.Share-window');
$share.toggleClass('is-open');
$(doc).on('click', close = function(e) {
if ($shareWindow[0] !== e.target && $shareWindow.find(e.target).length !== 1) {
$share.removeClass('is-open');
$(doc).off('click', close);
}
});
});
that.elm.on('click', '.Share-option.is-facebook', function(e) {
e.preventDefault();
var $this = $(this);
var settings = {
name: $this.closest('.Share').data('title'),
url: $this.closest('.Share').data('url'),
description: $this.closest('.Share').data('desc')
}
that.shareToFacebook(settings)
});
that.elm.on('click', '.Share-option.is-twitter', function(e) {
e.preventDefault();
var $this = $(this);
var settings = {
name: $this.closest('.Share').data('title'),
url: $this.closest('.Share').data('url'),
}
that.shareToTwitter(settings)
});
that.elm.on('click', '.Share-input', function(e) {
var $this = $(this);
$this.focus().select();
// For iOS
$this[0].selectionStart = 0;
$this[0].selectionEnd = $this.val().length;
});
},
initFacebook: function() {
$('body').append('<div id="fb-root"></div>');
$.ajaxSetup({ cache: true });
...