PageSourceSearch

https://www.goodnewswi.com/wp-content/plugins/slider-wd/js/jquery.featureCarouselslider.js?ver=1.0.11

js goodnewswi.com collected 2026-10-06 17:34:17 UTC 25,651 bytes, 581 lines download raw bytes

1(function($){
2  $.fn.featureCarouselslider = function (options) {
3    // Adds support for multiple carousels on one page.
4    if (this.length > 1) {
5      this.each(function() {
6        $(this).featureCarouselslider(options);
7      });
8      return this;
9    }
10
11    // override the default options with user defined options
12    options = $.extend({}, $.fn.featureCarouselslider.defaults, options || {});
13
14    /* These are univeral values that are used throughout the plugin. Do not modify them
15     * unless you know what you're doing. Most of them feed off the options
16     * so most customization can be achieved by modifying the options values 
17    */
18    var pluginData = {      
19     
20      containerWidth:       0,
21      containerHeight:      0,
22      largeFeatureWidth:    0,
23      largeFeatureHeight:   0,
24      smallFeatureHeight:   0,
25      smallFeatureWidth:    0,       
26      totalFeatureCount:    $(this).children().first().children().first().children("span").length,
27      featuresContainer:    $(this),
28      featuresArray:        [],
29      containerIDTag:       "." + $(this).attr("id"),
30      timeoutVar:           null,
31      rotationsRemaining:   0,
32      itemsToAnimate:       0,
33      borderWidth:		      0,     
34      autoTime:             0   
35    };
36
37    /**
38     * Function to preload the images in the carousel if desired.
39     * This is not recommended if there are a lot of images in the carousel because
40     * it may take a while. Functionality does not depend on preloading the images 
41     */ 
42    var preload = function(callback) {
43      callback(); 
44    }
45 
46    // Gets the feature container based on the number
47    var getContainer = function(featureNum) {
48      return pluginData.featuresArray[featureNum-1];
49    }
50
51    // get previous feature number
52    var getPreviousNum = function(num) {
53      if ((num - 1) == 0) {
54        return pluginData.totalFeatureCount;
55      } else {
56        return num - 1;
57      }
58    }
59
60    // get next feature number
61    var getNextNum = function(num) {
62      if ((num + 1) > pluginData.totalFeatureCount) {
63        return 1;
64      } else {
65        return num + 1;
66      }
67    }
68
69    /**
70     * Because there are several options the user can set for the width and height
71     * of the feature images, this function is used to determine which options were set
72     * and to set the appropriate dimensions used for a small and large feature	
73     */
74    var setupFeatureDimensions = function() {
75      // Set the height and width of the entire carousel container
76      options.containerWidth = pluginData.featuresContainer.width();
77      options.containerHeight = pluginData.featuresContainer.height();
78    
79      // Grab the first image for reference
80      var $firstFeatureImage = $(pluginData.containerIDTag).find(".wds_slider_car_image" + options.wds_number + ":first");
81 
82      // Large Feature Width
83      if (options.largeFeatureWidth > 1) {
84        pluginData.largeFeatureWidth = options.largeFeatureWidth;
85      }
86	    else if (options.largeFeatureWidth > 0 && options.largeFeatureWidth < 1) {
87        pluginData.largeFeatureWidth = $firstFeatureImage.width() * options.largeFeatureWidth;
88      }
89      else {
90        pluginData.largeFeatureWidth = $firstFeatureImage.outerWidth();
91      }
92      // Large Feature Height
93      if (options.largeFeatureHeight > 1) {
94        pluginData.largeFeatureHeight = options.largeFeatureHeight;
95      }
96      else if (options.largeFeatureHeight > 0 && options.largeFeatureHeight < 1) {
97        pluginData.largeFeatureHeight = $firstFeatureImage.height() * options.largeFeatureHeight;
98      }
99      else {
100        pluginData.largeFeatureHeight = $firstFeatureImage.outerHeight();
101      }
102    }
103
104    /**
105     * Function to take care of setting up various aspects of the carousel,
106     * most importantly the default positions for the features	
107     */
108    var setupCarousel = function() {
109      // Set the total feature count to the amount the user wanted to cutoff
110      if (options.displayCutoff > 0 && options.displayCutoff < pluginData.totalFeatureCount) {
111        pluginData.totalFeatureCount = options.displayCutoff;
112      }
113
114      // Fill in the features array .
115      pluginData.featuresContainer.find(".wds_slider_car_image" + options.wds_number).each(function (index) {
116        if (index < pluginData.totalFeatureCount) {
117          pluginData.featuresArray[index] = $(this);
118        }
119      });
120 
121      // Determine the total border width around the feature if there is one
122      if (pluginData.featuresContainer.find(".wds_slider_car_image" + options.wds_number).first().css("borderLeftWidth") != "medium") {
123        pluginData.borderWidth = parseInt(pluginData.featuresContainer.find(".wds_slider_car_image" + options.wds_number).first().css("borderLeftWidth"))*2;
124      }
125      // Place all the features in a center hidden position to start off
126      pluginData.featuresContainer
127      .find(".wds_slider_car_image" + options.wds_number).each(function () {
128        // Center all the features in the middle and hide them
129        $(this).css({
130          'left': (options.containerWidth / 2) - (options.largeFeatureWidth * options.smallFeaturePar / 2) - (pluginData.borderWidth / 2)- options.parf,           
131          'width': options.largeFeatureWidth * options.smallFeaturePar * options.parametr / 100,
132          'height': options.largeFeatureHeight * options.smallFeaturePar * options.parametr / 100,
133          'top': options.smallFeatureOffset + options.topPadding + options.parf ,
134          'opacity': 0,
135          'filter': 'Alpha(opacity=0)'
136        });
137      })     
138      // set position to relative of captions if displaying below image
139      if (options.captionBelow) {
140        pluginData.featuresContainer.find(".wds_slider_car_image" + options.wds_number).css('position','absolute');
141      }
142
143      // figure out number of items that will rotate each time
144      if (pluginData.totalFeatureCount < options.imagecount) {
145        pluginData.itemsToAnimate = pluginData.totalFeatureCount;  
146      }  else {
147        pluginData.itemsToAnimate = options.imagecount + 2 ;
148      }       
149    }
150
151    /**
152     * Here all the position data is set for the features.
153     * This is an important part of the carousel to keep track of where
154     * each feature within the carousel is	 
155     */
156    var setupFeaturePositions = function() {
157      // give all features a set number that won't change so they remember their
158      // original order 
159      $.each(pluginData.featuresArray, function (i) {
160        $(this).data('setPosition', i + 1);
161      });
162
163      // Go back one - This is done because we call the move function right away, which
164      // shifts everything to the right. So we set the current center back one, so that
165      // it displays in the center when that happens
166      var oneBeforeStarting = getPreviousNum(window["wds_currentCenterNum" +options.wds_number]);
167
168      window["wds_currentCenterNum" +options.wds_number] = oneBeforeStarting;
169
170      // Center feature will be position 1
171      var $centerFeature = getContainer(oneBeforeStarting);
172      $centerFeature.data('position', 1);
173
174      // Everything before that center feature...
175      var $prevFeatures = $centerFeature.prevAll();
176      $prevFeatures.each(function (i) {
177        $(this).data('position', (pluginData.totalFeatureCount - i
177));
178      });
179        
180      // And everything after that center feature...
181      var $nextFeatures = $centerFeature.nextAll();
182      $nextFeatures.each(function (i) {
183        if ($(this).data('setPosition') != undefined) {
184          $(this).data('position',(i + 2));
185        }
186      });
187    }
188
189    /**
190     * This function will set the autoplay for the carousel to
191     * automatically rotate it given the time in the options
192     * pass in TRUE to just clear the timer
193     */
194    var setTimer = function(stop) {
195      return;
196      // clear the timeout var if it exists
197      clearTimeout(pluginData.timeoutVar);
198
199      // set interval for moving if autoplay is set
200      if (!stop && options.autoPlay != 0) {
201        var autoTime = (Math.abs(options.autoPlay) < options.carouselSpeed) ? options.carouselSpeed : Math.abs(options.autoPlay);
202        pluginData.timeoutVar = setTimeout(function () {
203          (options.autoPlay > 0) ? initiateMove(true,1) : initiateMove(false,1);
204        }, autoTime);
205      }
206    }
207 
208    // This is a helper function for the animateFeature function that
209    // will update the positions of all the features based on the direction
210    var rotatePositions = function(direction) {
211      $.each(pluginData.featuresArray, function () {
212        var newPos;
213        if (direction == false) {
214          newPos = getNextNum($(this).data().position);
215        } else {
216          newPos = getPreviousNum($(this).data().position);
217        }
218
219        $(this).data('position',newPos);
220      });
221    }
222
223    /* Animate the given feature to the given location. Valid locations are "left", "right", "center", "hidden".*/
224    var animateFeature = function($feature, direction, onload) {
225      if (typeof onload == "undefined") {
226        var onload = 0;
227      }
228      $feature.find(".wds_slideshow_image_" + options.wds_number).children().each(function() {
229        jQuery(this).hide();
230      });
231      $feature.find(".wds_video_hide" + options.wds_number).each(function() {
232        jQuery(this).show();
233      });
234      var new_width, new_height, new_top, new_left, new_zindex, new_padding, new_fade, new_fade1, new_left1;
235      // Determine the old and new positions of the feature.
236      var oldPosition = $feature.data('position');
237      var newPosition;
238      if (direction == true) {
239        newPosition = getPreviousNum(oldPosition);
240      }
241      else {
242        newPosition = getNextNum(oldPosition);
243      }
244      // Callback for moving out of center pos.
245      if (oldPosition == 1) {
246        options.leavingCenter($feature);
247      }
248      // Caculate new new css values depending on where the feature will be located center.
249      if (newPosition == 1) {
250        new_width = pluginData.largeFeatureWidth;        
251        new_height = pluginData.largeFeatureHeight;
252        new_top =(options.containerHeight / 2 - new_height / 2 );
253        new_zindex = $feature.css("z-index");
254        new_left = (options.containerWidth / 2) - (pluginData.largeFeatureWidth / 2) - (pluginData.borderWidth / 2);
255        new_fade = 1.0;
256        new_fade1 = 100;
257        $feature.find(".wds_slideshow_image_" + options.wds_number).children().each(function() {
258          jQuery(this).show();
259        });
260        $feature.find(".wds_video_hide" + options.wds_number).each(function() {
261          jQuery(this).hide();
262        });
263      }
264      else {
265        // Left.
266        if (newPosition <= pluginData.totalFeatureCount && newPosition > pluginData.totalFeatureCount - options.imagecount / 2 + 1) {
267          new_width = (pluginData.largeFeatureWidth * Math.pow(options.smallFeaturePar, pluginData.totalFeatureCount - newPosition + 1));      
268          new_height = (pluginData.largeFeatureHeight * Math.pow(options.smallFeaturePar, pluginData.totalFeatureCount - newPosition + 1));
269          new_top = (options.containerHeight/ 2  - new_height / 2 ) ;         
270          new_fade = 1;           
271          new_fade1 = 100;          
272          if(options.fit_containerWidth == false && options.smallFeaturePar < 1){
273            new_left = (options.containerWidth / 2 - pluginData.largeFeatureWidth / 2)-(pluginData.largeFeatureWidth * (1 - options.smallFeaturePar) * options.smallFeaturePar * (pluginData.totalFeatureCount - newPosition + 1));             
274          } else if(options.fit_containerWidth == false && options.smallFeaturePar == 1){
275            new_left = (options.containerWidth / 2 - pluginData.largeFeatureWidth / 2)-(pluginData.largeFeatureWidth * ( options.smallFeaturePar) * options.smallFeaturePar * (pluginData.totalFeatureCount - newPosition + 1));             
276          } else {
277              new_left1 = (options.containerWidth / 2 - pluginData.largeFeatureWidth / 2) / (options.imagecount / 2 - 0.5);
278              new_left =  ((options.containerWidth / 2) - (pluginData.largeFeatureWidth / 2) - (pluginData.borderWidth / 2)) - (new_left1 * (pluginData.totalFeatureCount - newPosition+1  ));             
279          }                        
280        }
281        // Right.
282        else if (newPosition >
282= 2 && newPosition <= options.imagecount / 2 + 1) {
283          new_width = (pluginData.largeFeatureWidth * Math.pow(options.smallFeaturePar,newPosition - 1));
284          new_height =( pluginData.largeFeatureHeight * Math.pow(options.smallFeaturePar, newPosition - 1));
285          new_top = ( options.containerHeight / 2 - new_height / 2);
286          new_fade = 1;
287          new_fade1 = 100;
288          if (options.fit_containerWidth == false && options.smallFeaturePar < 1) {
289            new_left = (options.containerWidth / 2 + pluginData.largeFeatureWidth / 2) + (pluginData.largeFeatureWidth * options.smallFeaturePar * (1 - options.smallFeaturePar) * (newPosition - 1)) - new_width;
290          } else if (options.fit_containerWidth == false && options.smallFeaturePar == 1) {
291            new_left = (options.containerWidth / 2 + pluginData.largeFeatureWidth / 2) + (pluginData.largeFeatureWidth * options.smallFeaturePar * (options.smallFeaturePar) * (newPosition - 1)) - new_width;
292          } else {
293            new_left1 = ( (options.containerWidth / 2 -pluginData.largeFeatureWidth / 2)) / (options.imagecount / 2 - 0.5);
294            new_left = (options.containerWidth / 2 + pluginData.largeFeatureWidth / 2) - new_width + (new_left1 * (newPosition - 1));
295          }
296        }
297        // Hidden.
298        else {
299          new_left = (options.containerWidth / 2) - (pluginData.largeFeatureWidth * options.smallFeaturePar / 2) - (pluginData.borderWidth / 2);
300          new_fade = 0;
301          new_fade1 = 0;
302        }
303      }
304      // This code block takes care of hiding the feature information if the feature is leaving the center.
305      if (oldPosition == 1) {
306        // Slide up the story information.
307        $feature.find(".wds_slider_car_image" + options.wds_number).hide();
308      }
309
310      // Animate the feature div to its new location.
311      $feature
312        .animate(
313          {
314            width: new_width,
315            height: new_height,
316            top: new_top,
317            left: new_left,                      
318            opacity: new_fade,
319            filter: new_fade1
320          },
321          onload ? 0 : options.carouselSpeed,
322          options.animationEasing,
323          function () {
324            // Take feature info out of hiding if new position is center
325            if (newPosition == 1) {
326              // need to set the height to auto to accomodate caption if displayed below image
327              if (options.captionBelow)
328               $feature.css('height','auto');
329              // fade in the feature information
330              $feature.find(".wds_slider_car_image" + options.wds_number)
331                .fadeTo("fast",0.85);
332              // callback for moved to center
333              options.movedToCenter($feature);
334            }
335            // decrement the animation queue
336            pluginData.rotationsRemaining = pluginData.rotationsRemaining - 1;
337            // have to change the z-index after the animation is done
338            $feature.css("z-index", new_zindex);
339            // change trackers if using them
340            if (options.trackerIndividual || options.trackerSummation) {
341              // just update the tracker once; once the new center feature has arrived in center
342              if (newPosition == 1) {
343                // figure out what item was just in the center, and what item is now in the center
344                var newCenterItemNum = pluginData.featuresContainer.find(".wds_slider_car_image" + options.wds_number).index($feature) + 1;
345                var oldCenterItemNum;
346                if (direction == false) {
347                  oldCenterItemNum = getNextNum(newCenterItemNum);
348                }
349                else {
350                  oldCenterItemNum = getPreviousNum(newCenterItemNum);
351                }
352              }
353            }
354
355            // did all the the animations finish yet?
356            var divide = pluginData.rotationsRemaining / pluginData.itemsToAnimate;
357            if (divide % 1 == 0) {
358              // Set moving to false.
359              window["wds_currentlyMoving" +options.wds_number]   = false;
360              // Change positions for all items.
361              rotatePositions(direction);
362
363              // Move carousel again if queue is not empty.
364              if (pluginData.rotationsRemaining > 0)
365                move(direction);
366            }
367            // Reset timer and auto rotate again.
368            setTimer(false); 
369          }
370        )
371        .end();
372    }
373
374    /* Move the carousel to the left or to the right. The features that
375     * will move into the four positions are calculated and then animated
376     * rotate to the RIGHT when direction is TRUE and
377     * rotate to the LEFT when direction is FALSE.
378     */
379    var move = function(direction, onload) {
380      // Set the carousel to currently moving
381      window["wds_currentlyMoving" + options.wds_number]  = true;
382      // Obtain the new feature positions based on the direction that the carousel is moving
383      var $newCenter, $newLefts, $newRights, $newHidden, $curNum;
384
385      if (direction == true) {
386        // Shift features to the left
387        $newCenter = getContainer(getNextNum(window["wds_currentCenterNum" +options.wds_number]));
388        $newLefts = [];
389        $curNum = window["wds_currentCenterNum" +options.wds_number];        
390        for (var i = 1; i <= options.imagecount / 2 + 1; ++i) {
391          $newLefts.push(getContainer($curNum));
392          $curNum = getPreviousNum($curNum);
393        }
394        $newRights = [];
395        $curNum = getNextNum(window["wds_currentCenterNum" + options.wds_number]);
396        for (var i = 1; i <= options.imagecount / 2 + 1; ++i) {
397          $curNum = getNextNum($curNum);
398          $newRights.push(getContainer($curNum));
399        }
400        window["wds_currentCenterNum" + options.wds_number] = getNextNum(window["wds_currentCenterNum" + options.wds_number]);
401      }
402      else {
403        $newCenter = getContainer(getPreviousNum(window["wds_currentCenterNum" +options.wds_number]));
404        $newLefts = [];
405        $curNum = getPreviousNum(window["wds_currentCenterNum" +options.wds_number]);        
406        for (var i = 1; i <= options.imagecount / 2 +1; ++i) {
407          $curNum = getPreviousNum($curNum);   
408          $newLefts.push(getContainer($curNum));
409        }
410        $newRights = [];
411        $curNum = window["wds_currentCenterNum" + options.wds_number];
412        for (var i = 1; i <= options.imagecount / 2 + 1; ++i) {
413          $newRights.push(getContainer($curNum));
414          $curNum = getNextNum($curNum);
415        }
416        window["wds_currentCenterNum" +options.wds_number] = getPreviousNum(window["wds_currentCenterNum" + options.wds_number]);
417      }
418      // Animate the features into their new positions.
419      for (i = 0; i < $newLefts.length; i++) {
420        $newLefts[i].css("z-index", $newLefts.length - i + 3);
421        animateFeature($newLefts[i], direction, onload);
422      }
423      $newCenter.css("z-index", Math.max($newLefts.length, $newRights.length) + 4);
424      animateFeature($newCenter, direction, onload);
425      for (i = 0; i < $newRights.length; i++) {
426        $newRights[i].css("z-index", $newRights.length - i + 3);
427        animateFeature($newRights[i], direction, onload);
428      }
429    }
430
431    // This is used to relegate carousel movement throughout the plugin.
432    // It will only initiate a move if the carousel isn't currently moving.
433    // It will set the animation queue to the number of rotations given.
434    var initiateMove = function(direction, rotations, onload) {
435      if (typeof onload == "undefined") {
436        var onload = 0;
437      }
438      if (window["wds_currentlyMoving" +options.wds_number]  == false ){
439        var queue = rotations * pluginData.itemsToAnimate ;
440        pluginData.rotationsRemaining = queue ;      
441        window["wds_set_filmstrip_class_" + options.wds_number]();
442        window["wds_set_dots_class_" + options.wds_number]();
443        move(direction, onload);
444      }
445    }
446
447    // Add event listener to all clicks within the features container
448    // This is done to disable any links that aren't within the center feature
449    $("a", pluginData.containerIDTag).live("click", function (event) {
450      // travel up to the container
451      var $parents = $(this).parentsUntil(pluginData.containerIDTag);
452      // now check each of the feature divs within it
453      $parents.each(function () {
454        var position = $(this).data('position');
455        // if there are more than just feature divs within the container, they will
456        // not have a position and it may come back as undefined. Throw these out
457        if (position != undefined) {
458          // if any of the links on a feature OTHER THAN the center feature were clicked,
459          // initiate a carousel move but then throw the link action away
460          if (position != 1) {
461            if (position == pluginData.totalFeatureCount) {
462              initiateMove(false,1);
463            } else if (position == 2) {
464              initiateMove(true, 1);
465            }
466            event.preventDefault();
467            return false;
468          // if the position WAS the center (i.e. 1), fire callback
469          } else {
470            options.clickedCenter($(this));
471          }
472        }
473      });
474    });
475
476    // Public functions.
477    this.initialize = function () {
478      // Call the preloader and pass in our callback, which is just a slew of function calls
479      // that should only be executed after the images have been loaded
480      preload(function () {
481        setupFeatureDimensions();
482        setupCarousel();
483        if (window["wds_currentlyMoving" +options.wds_number]  == false ) {
484          setupFeaturePositions();
485          initiateMove(true, 1, 1);
486        }
487      }); 
488      return this;
489    };
490
491    this.next = function() {
492      initiateMove(true, 1);
493    }
494    this.prev = function () {
495      initiateMove(false, 1);
496    }
497    this.shift = function (that) {
498      var position = $(that).data('position');
499      if (position == 1) {
500        return;
501      }
502      if (position > pluginData.totalFeatureCount / 2 + 1) {
503        initiateMove(false, pluginData.totalFeatureCount - position + 1);
504        options.carouselSpeed = 400;
505        options.animationEasing;
506      }
507      else {
508        initiateMove(true, position - 1);
509        options.carouselSpeed = 400;
510        options.animationEasing;
511      }
512    }
513    this.pause = function () {
514      options.autoPlay = false;
515      setTimer(true);
516    }
517    this.start = function () {
518      options.autoPlay = options.interval;
519      setTimer(false);
520    }
521    // Initialize the plugin.
522    return this.initialize();
523  };
524
525  $.fn.featureCarouselslider.defaults = {
526    // If zero, take original width and height of image
527    // If between 0 and 1, multiply by original width and height (acts as a percentage)
528    // If greater than one, use as a forced width/height for all of the images
529    largeFeatureWidth :   0,
530    largeFeatureHeight:		0,
531    containerWidth:       0,
532    containerHeight:      0,
533    fit_containerWidth:   0,
534    wds_number:           0,
535    // how much to pad the top of the carousel
536    topPadding:           20,
537    // spacing between the sides of the container
538    sidePadding:          50,
539    // the additional offset to pad the side features from the top of the carousel
540    smallFeatureOffset:		50,
541    //smallFeature parameters
542    smallFeaturePar:      0,
543    // indicates which feature to start the carousel at
544    startingFeature:      1,
545    // speed in milliseconds it takes to rotate the carousel
546    carouselSpeed:        400,
547    // time in milliseconds to set interval to autorotate the carousel
548    // set to zero to disable it, negative to go left
549    autoPlay:             4000,
550    interval:             true,
551    //imagecounts
552    imagecount:           7,
553    // with autoplay enabled, set this option to true to have the carousel pause rotating
554    // when a user hovers over any feature
555    pauseOnHover:         true,
556    // with autoplay enabled, set this option to completely stop the autorotate functionality
557    stopOnHover:          false,
558    // numbered blips can appear and be used to track the currently centered feature, as well as 
559    // allow the user to click a number to move to that feature. Set to false to not process these at all
560    // and true to process and display them//and true to process and display them
561    trackerIndividual:    true,
562    // a summation of the features can also be used to display an "x Of y" style of tracking
563    // this can be combined with the above option as well
564    trackerSummation:     true,
565    // Will only display this many features in the carousel
566    // set to zero to disable
567    displayCutoff:        0,
568    data:                 "",
569    // an easing can be specified for the animation of the carousel
570    animationEasing:      'swing',
571    // display captions below the image instead of on top
572    captionBelow:         false,
573    parf:                 0,
574    // callback function for when a feature has animated to the center
575    movedToCenter:        $.noop,
576    // callback function for when feature left center
577    leavingCenter:        $.noop,
578    // callback function for when center feature was clicked
579    clickedCenter:        $.noop
580  };
581})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.