Advertisement
Guest User

Untitled

a guest
Apr 21st, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.45 KB | None | 0 0
  1. <?php
  2.     header('content-type: application/x-javascript');
  3.     define('WP_USE_THEMES', false);
  4.     require_once((dirname(dirname(dirname(dirname(dirname( __FILE__ ) ) )))).'/wp-config.php');
  5. ?>
  6.  
  7. <?php
  8.     $fpg_page_speed = get_option('fpg_page_speed');
  9.     $post_autoscroll = get_option('fpg_autoscroll');
  10.     $post_scroll_interval = get_option('fpg_scroll_interval');
  11.     $fpg_rollover = get_option('fpg_rollover');
  12. ?>
  13.  
  14. var FeaturedPostsLib = this.FeaturedPostsLib || {};
  15. FeaturedPostsLib.fpg = FeaturedPostsLib.fpg || {};
  16.  
  17. (function($j) {
  18.     var animationLocked = new Array(); // Lock object for animations
  19.     var autoscrollInterval = new Array();
  20.  
  21.     /** Initialize jQuery based animations */
  22.     FeaturedPostsLib.fpg.init = function()
  23.     {
  24.         // hide all pages on first entry in featured posts list
  25.         $j('.fpg-wrapper').each(function() {
  26.            $j(this).children('.fpg-page').slice(1).find('.fpg-item').css(
  27.                {'margin-top':'3px','opacity':0.0});
  28.         });
  29.  
  30.         // initialize the scroll buttons and autoscroll
  31.         initAutoscroll();
  32.         initScrollButtons();
  33.         initPips();
  34.  
  35.         // release animation locks
  36.         for (var i=1; i<=animationLocked.length; i++)
  37.         {
  38.             animationLocked[i-1] = false;
  39.         }
  40.     };
  41.  
  42.  
  43.     /** Add click event handlers to scroll buttons */
  44.     function initScrollButtons()
  45.     {
  46.         $j('.fpg-arrow-right').each(function(index) {
  47.             $j(this).click(function() {
  48.                 if (animationLocked[index] == false)
  49.                 {
  50.                     FeaturedPostsLib.fpg.fpgScrollPages(this, 'right', index);
  51.                 }
  52.                 clearInterval(autoscrollInterval[index]);
  53.             });
  54.         });
  55.  
  56.         $j('.fpg-arrow-left').each(function(index) {
  57.             $j(this).click(function() {
  58.                 if (animationLocked[index] == false)
  59.                 {
  60.                     FeaturedPostsLib.fpg.fpgScrollPages(this, 'left', index);
  61.                 }
  62.                 clearInterval(autoscrollInterval[index]);
  63.             });
  64.         });
  65.     }
  66.  
  67.  
  68.     function initPips()
  69.     {
  70.         $j('.fpg-arrow-wrapper').each(function(index) {
  71.             $j(this).children('.fpg-arrow-pip').click(function() {
  72.                 if (animationLocked[index] == false)
  73.                 {
  74.                     fpgScrollToPage(this, index);
  75.                 }
  76.                 clearInterval(autoscrollInterval[index]);
  77.             });
  78.         });
  79.     }
  80.  
  81.  
  82.     function initAutoscroll()
  83.     {
  84.        
  85.         $j('.fpg-wrapper').each(function(index) {
  86.             animationLocked[index] = true;
  87.  
  88.             if (1 == <?php echo $post_autoscroll ?>)
  89.             {
  90.                 var callback =
  91.                     "FeaturedPostsLib.fpg.fpgScrollPages(jQuery('.fpg-wrapper').slice(" +
  92.                     index + "," + (index + 1) + ").find('.fpg-arrow-right'), 'right', " + index + ")";
  93.                 autoscrollInterval[index] = setInterval(
  94.                     callback, <?php echo $post_scroll_interval ?>);
  95.             }
  96.         });
  97.    
  98.     }
  99.  
  100.  
  101.     function fpgScrollToPage(slideButton, index)
  102.     {
  103.         if (!($j(slideButton).hasClass('fpg-selected-pip')))
  104.         {
  105.             // lock animations
  106.             animationLocked[index] = true;
  107.  
  108.             // get the currently displayed element(s)
  109.             var currentItem = $j(slideButton).parent().siblings('.fpg-page:visible');
  110.  
  111.             // get the next item to display
  112.             var nextItemIndex = parseInt($j(slideButton).text());
  113.            
  114.             var nextItem = $j(slideButton).parent().siblings('.fpg-page').eq(nextItemIndex-1);
  115.  
  116.             fpgSetSelectedPip(nextItem);
  117.             fpgAnimate(nextItem, currentItem, 'right', index);
  118.         }
  119.     }
  120.  
  121.  
  122.     FeaturedPostsLib.fpg.fpgScrollPages = function(button, dir, index)
  123.     {
  124.         if (animationLocked[index] != true)
  125.         {
  126.             // lock animations
  127.             animationLocked[index] = true;
  128.  
  129.             // get the currently displayed element(s)
  130.             var currentItem = $j(button).parent().siblings('.fpg-page:visible');
  131.  
  132.             var nextItem;
  133.          
  134.             if (dir == 'right')
  135.             {
  136.                 nextItem = currentItem.next('.fpg-page');
  137.             }
  138.             else if (dir == 'left')
  139.             {
  140.                 nextItem = currentItem.prev('.fpg-page');
  141.             }
  142.  
  143.             if (nextItem.length > 0)
  144.             {
  145.                 fpgSetSelectedPip(nextItem);
  146.                 fpgAnimate(nextItem, currentItem, dir, index);
  147.             }
  148.             else if (1 == <?php echo $fpg_rollover ?>)
  149.             {
  150.                 if (dir == 'right')
  151.                 {
  152.                     nextItem = currentItem.siblings('.fpg-page').first();
  153.                 }
  154.                 else if (dir == 'left')
  155.                 {
  156.                     nextItem = currentItem.siblings('.fpg-page').last();
  157.                 }
  158.  
  159.                 fpgSetSelectedPip(nextItem);
  160.                 fpgAnimate(nextItem, currentItem, dir, index);
  161.             }
  162.             else
  163.             {
  164.                 animationLocked[index] = false;
  165.             }
  166.         }
  167.     };
  168.  
  169.  
  170.     function fpgSetSelectedPip(toShow)
  171.     {
  172.         // Remove class from current slide
  173.         $j(toShow).siblings('.fpg-arrow-wrapper').children('.fpg-selected-pip').removeClass('fpg-selected-pip');
  174.  
  175.         // Get the index of the next item to be displayed
  176.         var nextSlideIndex = $j(toShow).index();
  177.  
  178.         $j(toShow).siblings('.fpg-arrow-wrapper').children('.fpg-arrow-pip').eq(nextSlideIndex).addClass('fpg-selected-pip');
  179.     }
  180.  
  181.  
  182.     function fpgAnimate(toShow, toHide, dir, index)
  183.     {
  184.         // fade out items on currently shown page
  185.         var itemToHide;
  186.         if (dir == 'right')
  187.         {
  188.             itemToHide = $j(toHide).children().children('.fpg-item.fpg-first-col');
  189.         }
  190.         else
  191.         {
  192.             itemToHide = $j(toHide).children().children('.fpg-item').last();
  193.         }
  194.        
  195.  
  196.         fpgFadeOutItems(itemToHide, dir, function() {
  197.             toHide.css('display','none');
  198.             toShow.css('display','');
  199.  
  200.             var itemToShow;
  201.             if (dir == 'right')
  202.             {
  203.                 itemToShow = $j(toShow).children().children('.fpg-item.fpg-first-col');
  204.             }
  205.             else
  206.             {
  207.                 itemToShow = $j(toShow).children().children('.fpg-item').last();
  208.             }
  209.  
  210.             fpgFadeInItems(itemToShow, dir, function() {
  211.                 animationLocked[index] = false;
  212.             });
  213.         });
  214.     }
  215.  
  216.  
  217.     function fpgFadeOutItems(itemToHide, dir, callback)
  218.     {
  219.         var itemCount = itemToHide.length;
  220.         $j(itemToHide).animate({ 'opacity': 1.0,
  221.                                  'margin-top': '0' },
  222.             <?php echo $fpg_page_speed; ?>, 'linear', function() {
  223.                 if (--itemCount <= 0)
  224.                 {
  225.                     var nextItem;
  226.                     if (dir == 'right')
  227.                     {
  228.                         nextItem = $j(itemToHide).next('.fpg-item');
  229.                     }
  230.                     else
  231.                     {
  232.                         nextItem = $j(itemToHide).prev('.fpg-item');
  233.                     }
  234.  
  235.                     if (nextItem.length > 0)
  236.                         fpgFadeOutItems(nextItem, dir, callback);
  237.                     else
  238.                         callback();
  239.                 }
  240.             }
  241.         );
  242.     }
  243.  
  244.  
  245.     function fpgFadeInItems(itemToShow, dir, callback)
  246.     {
  247.         var itemCount = itemToShow.length;
  248.         $j(itemToShow).animate({ 'opacity': 1.0,
  249.                                  'margin-top': '0' },
  250.             <?php echo $fpg_page_speed; ?>, 'linear', function() {
  251.                 if (--itemCount <= 0)
  252.                 {
  253.                     var nextItem;
  254.                     if (dir == 'right')
  255.                     {
  256.                         nextItem = $j(itemToShow).next('.fpg-item');
  257.                     }
  258.                     else
  259.                     {
  260.                         nextItem = $j(itemToShow).prev('.fpg-item');
  261.                     }
  262.  
  263.                     if (nextItem.length >0 )
  264.                         fpgFadeInItems(nextItem, dir, callback);
  265.                     else
  266.                         callback();
  267.                 }
  268.             }
  269.         );
  270.     }
  271.    
  272. }(jQuery))
  273.  
  274. jQuery(document).ready(FeaturedPostsLib.fpg.init);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement