Advertisement
urosevic

Site 2 SlideShow

Feb 22nd, 2014
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 5.11 KB | None | 0 0
  1. /**
  2.   * Save as Bookmark
  3.   * Works on:
  4.   * * fishki.net
  5.   * * dofiga.net (gallery + table 20141227)
  6.   * * ibkas.info (dead)
  7.   * * urod.ru
  8.   * * vasi.net
  9.   * * thechive.com
  10.   * * englishrussia.com
  11.   * * daypic.ru (20141227)
  12.   */
  13. javascript: jQuery(document).ready(function($) {
  14.     var width = jQuery(window).width() - 100;
  15.     var height = jQuery(window).height() - 50;
  16.     var heighthalf = height / 2;
  17.  
  18.     $('head').append('<style type="text/css">body {overflow:hidden;} #preload { width:1px; height:1px; overflow: hidden; z-index: 0; } #fsshcnt {position: absolute; top: 0; right: 0; float: right; font-size: 36px; line-height: 36px; font-weight: bold; color: #333; padding: 5px; font-family: sans-serif; } #fsshow { position: fixed; top: 0; left: 0; width: 100%; height: 100%; display: block; background: #000; z-index: 9999; text-align: center; } #fsslide { width:' + width + 'px; height: ' + height + 'px; line-height: ' + height + 'px; margin-left: auto; margin-right: auto; margin-top: -' + heighthalf + 'px; top: 50%; position: relative; text-align: center; } #fsslide img { max-width: ' + width + 'px; max-height: ' + height + 'px; height: 100%; vertical-align: middle; border: 0; box-shadow: 0 0 50px rgba(255,255,255,0.1); } #fsslide .title {width: 100%; height: 100%; line-height: ' + height + 'px; font-size: 96px; font-weight: bold; }</style>');
  19.  
  20.     $('body').append('<div id="preload"></div><div id="fsshow"><div id="fsslide"><div class="title">Slideshow Comming...</div></div><div id="fsshcnt">0</div></div>');
  21.  
  22.     /* get all images for gallery */
  23.     var path = '.post_body img[src^="images/news/"][src*="/tn_"][src$=".jpg"]'; /* fishki */
  24.     path = path + ',.gallery .picture-holder img'; /* dofiga.net */
  25.     path = path + ',#dofiga .post_body table a[onclick="click()"] img[itemprop="image"]'; /* tiles on dofiga.net */
  26.     /* path = path + ',a[href*="ibkas.info"] img[src*="uploads"]'; */ /* ibkas.info (dead) */
  27.     path = path + ',img[src*="urod.ru/uploads"]'; /* urod.ru */
  28.     path = path + ',img[src*="vasi.net/uploads/podbor"]'; /* vasi.net */
  29.     path = path + ',.gallery-item img[src*="thechive.files.wordpress.com"]'; /* chive */
  30.     path = path + ',.post_pic_p img[src*="media.englishrussia.com/newpictures"]'; /* englishrussia */
  31.     path = path + ',a[href*="attachment"] img[src*="/wp-content/uploads/"]'; /* daypic.ru */
  32.     var imgs_arr = $(path);
  33.  
  34.     /* count total images */
  35.     var current_img_total = imgs_arr.length;
  36.     var current_img = 0;
  37.  
  38.     /* get slide function */
  39.     function get_img_src(this_img) {
  40.         this_img_src = this_img.src;
  41.         this_img_src = this_img_src.replace("tn_", "");
  42.         this_img_src = this_img_src.replace(/\?w\=[0-9]+\&h=[0-9]+/g, "");
  43.         return this_img_src;
  44.     }
  45.  
  46.     function set_slide(this_img) {
  47.         this_img_src = get_img_src(this_img);
  48.         $('#fsslide').html('<img src="' + this_img_src + '" />');
  49.         $('#fsshcnt').html((current_img + 1) + '/' + current_img_total);
  50.     }
  51.  
  52.     function preload_slide(this_img) {
  53.         this_img_src = get_img_src(this_img);
  54.         $('#preload').html(this_img_src);
  55.     }
  56.     set_slide(imgs_arr.get(current_img));
  57.  
  58.     /* prev/next */
  59.     function prevSlide() {
  60.         current_img--;
  61.         if (current_img < 0) {
  62.             current_img = (current_img_total - 1);
  63.             $('#fsslide').html('<div class="title">No More Images</div>');
  64.             $('#fsshcnt').html("");
  65.             current_img++;
  66.             preload_slide(imgs_arr.get(current_img));
  67.         } else {
  68.             set_slide(imgs_arr.get(current_img));
  69.             preload_slide(imgs_arr.get(current_img - 1));
  70.         }
  71.     }
  72.  
  73.     function nextSlide() {
  74.         current_img++;
  75.         if (current_img > (current_img_total - 1)) {
  76.             current_img = 0;
  77.             $('#fsslide').html('<div class="title">No More Images</div>');
  78.             $('#fsshcnt').html("");
  79.             current_img--;
  80.             preload_slide(imgs_arr.get(current_img));
  81.         } else {
  82.             set_slide(imgs_arr.get(current_img));
  83.             preload_slide(imgs_arr.get(current_img + 1));
  84.         }
  85.     }
  86.  
  87.     /* detect keys */
  88.     $(document).keydown(function(e) {
  89.         /* if fsshow visible, scroll */
  90.         if ($('#fsshow').css('display') == 'block') {
  91.             if (e.keyCode == 37) {
  92.                 prevSlide();
  93.             } else if (e.keyCode == 39) {
  94.                 nextSlide();
  95.             } else if (e.keyCode == 27) {
  96.                 $('#fsshow').toggle();
  97.                 $('body').css('overflow', 'visible');
  98.             }
  99.         } else {
  100.             /* fsshow not displayed, show on escape */
  101.             if (e.keyCode == 27) {
  102.                 $('#fsshow').toggle();
  103.                 $('body').css('overflow', 'hidden');
  104.             }
  105.         }
  106.     });
  107.  
  108.     /* detect whell */
  109.     $(document).bind('mousewheel', function(e) {
  110.         /* only when show is visible */
  111.         if ($('#fsshow').css('display') == 'block') {
  112.             if (e.originalEvent.wheelDelta / 120 > 0) {
  113.                 prevSlide();
  114.             } else {
  115.                 nextSlide();
  116.             }
  117.         }
  118.     });
  119. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement