main.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. (function($){
  2. var toTop = ($('#sidebar').height() - $(window).height()) + 60;
  3. // Caption
  4. $('.article-entry').each(function(i){
  5. $(this).find('img').each(function(){
  6. if ($(this).parent().hasClass('fancybox')) {
  7. return;
  8. }
  9. var alt = this.alt;
  10. if (alt) {
  11. $(this).after('<span class="caption">' + alt + '</span>');
  12. }
  13. $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
  14. });
  15. $(this).find('.fancybox').each(function(){
  16. $(this).attr('rel', 'article' + i);
  17. });
  18. });
  19. if ($.fancybox){
  20. $('.fancybox').fancybox();
  21. }
  22. // Profile card
  23. $(document).on('click', function () {
  24. $('#profile').removeClass('card');
  25. }).on('click', '#profile-anchor', function (e) {
  26. e.stopPropagation();
  27. $('#profile').toggleClass('card');
  28. }).on('click', '.profile-inner', function (e) {
  29. e.stopPropagation();
  30. });
  31. // To Top
  32. if ($('#sidebar').length) {
  33. $(document).on('scroll', function () {
  34. if ($(document).width() >= 800) {
  35. if(($(this).scrollTop() > toTop) && ($(this).scrollTop() > 0)) {
  36. $('#toTop').fadeIn();
  37. $('#toTop').css('left', $('#sidebar').offset().left);
  38. } else {
  39. $('#toTop').fadeOut();
  40. }
  41. } else {
  42. $('#toTop').fadeIn();
  43. $('#toTop').css('right', 20);
  44. }
  45. }).on('click', '#toTop', function () {
  46. $('body, html').animate({ scrollTop: 0 }, 600);
  47. });
  48. }
  49. })(jQuery);