default.ejs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <a data-url="<%- post.permalink %>" data-id="<%= post._id %>" class="article-share-link"><i class="fa fa-share"></i><%=__('article.share')%></a>
  2. <script>
  3. (function ($) {
  4. // Prevent duplicate binding
  5. if (typeof(__SHARE_BUTTON_BINDED__) === 'undefined' || !__SHARE_BUTTON_BINDED__) {
  6. __SHARE_BUTTON_BINDED__ = true;
  7. } else {
  8. return;
  9. }
  10. $('body').on('click', function() {
  11. $('.article-share-box.on').removeClass('on');
  12. }).on('click', '.article-share-link', function(e) {
  13. e.stopPropagation();
  14. var $this = $(this),
  15. url = $this.attr('data-url'),
  16. encodedUrl = encodeURIComponent(url),
  17. id = 'article-share-box-' + $this.attr('data-id'),
  18. offset = $this.offset(),
  19. box;
  20. if ($('#' + id).length) {
  21. box = $('#' + id);
  22. if (box.hasClass('on')){
  23. box.removeClass('on');
  24. return;
  25. }
  26. } else {
  27. var html = [
  28. '<div id="' + id + '" class="article-share-box">',
  29. '<input class="article-share-input" value="' + url + '">',
  30. '<div class="article-share-links">',
  31. '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="fa fa-twitter article-share-twitter" target="_blank" title="Twitter"></a>',
  32. '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="fa fa-facebook article-share-facebook" target="_blank" title="Facebook"></a>',
  33. '<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="fa fa-pinterest article-share-pinterest" target="_blank" title="Pinterest"></a>',
  34. '<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="fa fa-google article-share-google" target="_blank" title="Google+"></a>',
  35. '</div>',
  36. '</div>'
  37. ].join('');
  38. box = $(html);
  39. $('body').append(box);
  40. }
  41. $('.article-share-box.on').hide();
  42. box.css({
  43. top: offset.top + 25,
  44. left: offset.left
  45. }).addClass('on');
  46. }).on('click', '.article-share-box', function (e) {
  47. e.stopPropagation();
  48. }).on('click', '.article-share-box-input', function () {
  49. $(this).select();
  50. }).on('click', '.article-share-box-link', function (e) {
  51. e.preventDefault();
  52. e.stopPropagation();
  53. window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
  54. });
  55. })(jQuery);
  56. </script>