script.js 3.3 KB

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