
{% if has_absolute_url %}
  <div class="sharing-links">
    <h3>Sharing links:</h3>
    <input class="copy-link" type="submit" data-url="http{% if request.is_secure %}s{% endif %}://{{ settings.SITE_DOMAIN }}{{ original.get_absolute_url|urlencode }}" value="Copy link">
    {% if original.get_preview_url %}
      <input class="copy-link" type="submit" data-url="http{% if request.is_secure %}s{% endif %}://{{ settings.SITE_DOMAIN }}{{ original.get_preview_url }}" value="Copy public preview link">
    {% endif %}

    <input class="external-link" type="submit" value="Facebook" name="https://www.facebook.com/sharer.php?u={% if request.is_secure %}https{% else %}http{% endif %}%3A%2F%2F{{ request.META.HTTP_HOST }}{{ original.get_absolute_url|urlencode }}">
    <input class="external-link" type="submit" value="Twitter" name="https://twitter.com/share?url={% if request.is_secure %}https{% else %}http{% endif %}%3A%2F%2F{{ request.META.HTTP_HOST }}{{ original.get_absolute_url|urlencode }}&amp;text={{ original.title|urlencode }}">
    <input class="external-link" type="submit" value="LinkedIn" name="https://www.linkedin.com/shareArticle?url={% if request.is_secure %}https{% else %}http{% endif %}%3A%2F%2F{{ request.META.HTTP_HOST }}{{ original.get_absolute_url|urlencode }}&amp;title={{ original.title|urlencode }} ">
  </div>
  <script>
    jQuery('.sharing-links .external-link').each(function() {
      var $ = jQuery
      $(this).click(function(e) {
        e.preventDefault()
        var url = $(this).attr('name')
        window.open(url, '_blank', 'height=400,width=600,menubar=no,status=no,toolbar=no')
      })
    });

    var copyButtons = document.querySelectorAll('.copy-link')
    for (var i = 0; i < copyButtons.length; i++) {
      copyButtons[i].addEventListener('click', function (i, e) {
        e.preventDefault()
        console.log(copyButtons[i].dataset.url)

        var tempInput = document.createElement('input')
        tempInput.style = "position: absolute; left: -1000px; top: -1000px"
        tempInput.value = copyButtons[i].dataset.url
        document.body.appendChild(tempInput)

        tempInput.select()
        tempInput.setSelectionRange(0, 99999) /*For mobile devices*/

        document.execCommand('copy')

        document.body.removeChild(tempInput)
      }.bind(this, i))
    }
  </script>
{% endif %}
