script.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. (function($){
  2. // Share
  3. $('body').on('click', function(){
  4. $('.article-share-box.on').removeClass('on');
  5. }).on('click', '.article-share-link', function(e){
  6. e.stopPropagation();
  7. var $this = $(this),
  8. url = $this.attr('data-url'),
  9. encodedUrl = encodeURIComponent(url),
  10. id = 'article-share-box-' + $this.attr('data-id'),
  11. offset = $this.offset();
  12. if ($('#' + id).length){
  13. var box = $('#' + id);
  14. if (box.hasClass('on')){
  15. box.removeClass('on');
  16. return;
  17. }
  18. } else {
  19. var html = [
  20. '<div id="' + id + '" class="article-share-box">',
  21. '<input class="article-share-input" value="' + url + '">',
  22. '<div class="article-share-links">',
  23. '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="fa fa-twitter article-share-twitter" target="_blank" title="Twitter"></a>',
  24. '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="fa fa-facebook article-share-facebook" target="_blank" title="Facebook"></a>',
  25. '<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="fa fa-pinterest article-share-pinterest" target="_blank" title="Pinterest"></a>',
  26. '<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="fa fa-google article-share-google" target="_blank" title="Google+"></a>',
  27. '</div>',
  28. '</div>'
  29. ].join('');
  30. var box = $(html);
  31. $('body').append(box);
  32. }
  33. $('.article-share-box.on').hide();
  34. box.css({
  35. top: offset.top + 25,
  36. left: offset.left
  37. }).addClass('on');
  38. }).on('click', '.article-share-box', function(e){
  39. e.stopPropagation();
  40. }).on('click', '.article-share-box-input', function(){
  41. $(this).select();
  42. }).on('click', '.article-share-box-link', function(e){
  43. e.preventDefault();
  44. e.stopPropagation();
  45. window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
  46. });
  47. // Caption
  48. $('.article-entry').each(function(i){
  49. $(this).find('img').each(function(){
  50. if ($(this).parent().hasClass('fancybox')) return;
  51. var alt = this.alt;
  52. if (alt) $(this).after('<span class="caption">' + alt + '</span>');
  53. $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
  54. });
  55. $(this).find('.fancybox').each(function(){
  56. $(this).attr('rel', 'article' + i);
  57. });
  58. });
  59. if ($.fancybox){
  60. $('.fancybox').fancybox();
  61. }
  62. // Mobile nav
  63. var $container = $('#container'),
  64. isMobileNavAnim = false,
  65. mobileNavAnimDuration = 200;
  66. var startMobileNavAnim = function(){
  67. isMobileNavAnim = true;
  68. };
  69. var stopMobileNavAnim = function(){
  70. setTimeout(function(){
  71. isMobileNavAnim = false;
  72. }, mobileNavAnimDuration);
  73. }
  74. $('#main-nav-toggle').on('click', function(){
  75. if (isMobileNavAnim) return;
  76. startMobileNavAnim();
  77. $container.toggleClass('mobile-nav-on');
  78. stopMobileNavAnim();
  79. });
  80. $('#wrap').on('click', function(){
  81. if (isMobileNavAnim || !$container.hasClass('mobile-nav-on')) return;
  82. $container.removeClass('mobile-nav-on');
  83. });
  84. })(jQuery);