The version of vichan running on lainchan.org
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

166 wiersze
4.8KB

  1. if (active_page == 'index' || active_page == 'thread')
  2. $(function(){
  3. var gallery_view = false;
  4. $('hr:first').before('<div id="gallery-view" style="text-align:right"><a class="unimportant" href="javascript:void(0)">-</a></div>');
  5. $('#gallery-view a').html(gallery_view ? _("Disable gallery mode") : _("Enable gallery mode")).click(function() {
  6. gallery_view = !gallery_view;
  7. $(this).html(gallery_view ? _("Disable gallery mode") : _("Enable gallery mode"));
  8. toggle_gview(document);
  9. });
  10. var toggle_gview = function(elem) {
  11. if (gallery_view) {
  12. $(elem).find('img.post-image').parent().each(function() {
  13. this.oldonclick = this.onclick;
  14. this.onclick = handle_click;
  15. $(this).attr('data-galid', Math.random());
  16. });
  17. }
  18. else {
  19. $(elem).find('img.post-image').parent().each(function() {
  20. if (this.onclick == handle_click) this.onclick = this.oldonclick;
  21. });
  22. }
  23. };
  24. $(document).on('new_post', toggle_gview);
  25. var gallery_opened = false;
  26. var handle_click = function(e) {
  27. e.stopPropagation();
  28. e.preventDefault();
  29. if (!gallery_opened) open_gallery();
  30. gallery_setimage($(this).attr('data-galid'));
  31. };
  32. var handler, images, active, toolbar;
  33. var open_gallery = function() {
  34. $('body').css('overflow', 'hidden');
  35. gallery_opened = true;
  36. handler = $("<div id='alert_handler'></div>").hide().appendTo('body').css('text-align', 'left');
  37. $("<div id='alert_background'></div>").click(close_gallery).appendTo(handler);
  38. images = $("<div id='gallery_images'></div>").appendTo(handler);
  39. toolbar = $("<div id='gallery_toolbar'></div>").appendTo(handler);
  40. active = $("<div id='gallery_main'></div>").appendTo(handler);
  41. active.on('click', function() {
  42. close_gallery();
  43. });
  44. $('img.post-image').parent().each(function() {
  45. var thumb = $(this).find('img').attr('src');
  46. var i = $('<img>').appendTo(images);
  47. i.attr('src', thumb);
  48. i.attr('data-galid-th', $(this).attr('data-galid'));
  49. i.on('click', function(e) {
  50. gallery_setimage($(this).attr('data-galid-th'));
  51. });
  52. });
  53. $("<a href='javascript:void(0)'><i class='fa fa-times'></i></div>")
  54. .click(close_gallery).appendTo(toolbar);
  55. $('body').on('keydown.gview', function(e) {
  56. if (e.which == 39 || e.which == 40) { // right or down arrow
  57. gallery_setimage(+1);
  58. e.preventDefault();
  59. }
  60. else if (e.which == 37 || e.which == 38) { // left or up arrow
  61. gallery_setimage(-1);
  62. e.preventDefault();
  63. }
  64. });
  65. handler.fadeIn(400);
  66. };
  67. var gallery_setimage = function(a) {
  68. if (a == +1 || a == -1) {
  69. var meth = (a == -1) ? 'prev' : 'next';
  70. a = $('#gallery_images img.active')[meth]().attr('data-galid-th');
  71. if (!a) return;
  72. }
  73. $('#gallery_images img.active').removeClass('active');
  74. var thumb = $('#gallery_images [data-galid-th="'+a+'"]');
  75. var elem = $('a[data-galid="'+a+'"]');
  76. thumb.addClass('active');
  77. var topscroll = thumb.position().top + images.scrollTop();
  78. topscroll -= images.height() / 2;
  79. topscroll += thumb.height() / 2;
  80. images.animate({'scrollTop': topscroll}, 300);
  81. var img = elem.attr('href');
  82. active.find('img, video').fadeOut(200, function() { $(this).remove(); });
  83. var i;
  84. if (img.match(/player\.php/)) {
  85. img = img.replace(/.*player\.php\?v=|&t=.*/g, '');
  86. }
  87. if (img.match(/\.webm$|\.mp4$|\.ogv$/i)) { // We are handling video nao
  88. i = $('<video>');
  89. i.attr('src', img);
  90. i.attr('autoplay', true);
  91. i.attr('controls', true);
  92. i.appendTo(active);
  93. i.hide();
  94. }
  95. else { // Just a plain image
  96. i = $('<img>');
  97. i.attr('src', img);
  98. i.appendTo(active);
  99. i.hide();
  100. }
  101. // Let's actually preload the next few images
  102. var nextimg = $('#gallery_images active');
  103. for (var j = 0; j < 3; j++) {
  104. nextimg = nextimg.next();
  105. var attr;
  106. if (attr = nextimg.attr('data-gaild-th')) {
  107. var href = $('a[data-galid="'+attr+'"]').attr('href');
  108. if (href.match(/\.webm|\.mp4|\.ogv/i)) { j--; continue; }
  109. if ($('[data-galid-preload="'+attr+'"]').length) continue;
  110. var img = $('<img>').attr('src', href).attr('data-galid-preload', attr).hide().appendTo('body').on('load', function() { $(this).remove(); });
  111. }
  112. else break;
  113. }
  114. i.one('load canplay', function() {
  115. i.css('left', 'calc(50% - '+i.width()+'px / 2)');
  116. i.css('top', 'calc(50% - '+i.height()+'px / 2)');
  117. i.fadeIn(200);
  118. }).on('click', function(e) {
  119. e.stopPropagation();
  120. gallery_setimage(+1);
  121. });
  122. };
  123. var close_gallery = function() {
  124. $('body').css('overflow', 'auto');
  125. gallery_opened = false;
  126. $('body').off('keydown.gview');
  127. handler.fadeOut(400, function() { handler.remove(); });
  128. };
  129. });