123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- (function ($) {
- $.fn.extend({
- flexslider: function(options) {
-
- var defaults = {
- animation: "fade",
- slideshow: true,
- slideshowSpeed: 7000,
- animationDuration: 500,
- directionNav: true,
- controlNav: true,
- keyboardNav: true,
- touchSwipe: true,
- prevText: "Previous",
- nextText: "Next",
- randomize: false,
- slideToStart: 0,
- pauseOnAction: true,
- pauseOnHover: false,
- controlsContainer: "",
- manualControls: ""
- }
-
-
- var options = $.extend(defaults, options),
- slider = this,
- container = $('.slides', slider),
- slides = $('.slides li', slider),
- length = slides.length;
- ANIMATING = false,
- currentSlide = options.slideToStart;
-
-
-
-
- if (options.randomize && length > 1) {
- slides.sort(function() { return (Math.round(Math.random())-0.5); });
- container.empty().append(slides);
- }
-
-
-
-
- if (options.animation.toLowerCase() == "slide" && length > 1) {
- slider.css({"overflow": "hidden"});
-
- container.append(slides.filter(':first').clone().addClass('clone')).prepend(slides.filter(':last').clone().addClass('clone'));
- container.width(((length + 2) * slider.width()) + 2000);
-
-
- var newSlides = $('.slides li', slider);
- setTimeout(function() {
- newSlides.width(slider.width()).css({"float": "left"}).show();
- }, 100);
- container.css({"marginLeft": (-1 * (currentSlide + 1))* slider.width() + "px"});
-
- } else {
- slides.hide().eq(currentSlide).fadeIn(400);
- }
-
-
-
- function flexAnimate(target) {
- if (!ANIMATING) {
- ANIMATING = true;
- if (options.animation.toLowerCase() == "slide") {
- if (currentSlide == 0 && target == length - 1) {
- container.animate({"marginLeft": "0px"}, options.animationDuration, function(){
- container.css({"marginLeft": (-1 * length) * slides.filter(':first').width() + "px"});
- ANIMATING = false;
- currentSlide = target;
- });
- } else if (currentSlide == length - 1 && target == 0) {
- container.animate({"marginLeft": (-1 * (length + 1)) * slides.filter(':first').width() + "px"}, options.animationDuration, function(){
- container.css({"marginLeft": -1 * slides.filter(':first').width() + "px"});
- ANIMATING = false;
- currentSlide = target;
- });
- } else {
- container.animate({"marginLeft": (-1 * (target + 1)) * slides.filter(':first').width() + "px"}, options.animationDuration, function(){
- ANIMATING = false;
- currentSlide = target;
- });
- }
- } else if (options.animation.toLowerCase() == "show") {
-
- slides.eq(currentSlide).hide();
- slides.eq(target).show();
- ANIMATING = false;
- currentSlide = target;
-
- } else {
- slider.css({"minHeight": slides.eq(currentSlide).height()});
- slides.eq(currentSlide).fadeOut(options.animationDuration, function() {
- slides.eq(target).fadeIn(options.animationDuration, function() {
- ANIMATING = false;
- currentSlide = target;
- });
- slider.css({"minHeight": "inherit"});
- });
- }
- }
- }
-
-
-
-
- if (options.controlNav && length > 1) {
- if (options.manualControls != "" && $(options.manualControls).length > 0) {
- var controlNav = $(options.manualControls);
- } else {
- var controlNav = $('<ol class="flex-control-nav"></ol>');
- var j = 1;
- for (var i = 0; i < length; i++) {
- controlNav.append('<li><a>' + j + '</a></li>');
- j++;
- }
-
-
- if (options.controlsContainer != "" && $(options.controlsContainer).length > 0) {
- $(options.controlsContainer).append(controlNav);
- } else {
- slider.append(controlNav);
- }
-
- controlNav = $('.flex-control-nav li a');
- }
-
- controlNav.eq(currentSlide).addClass('active');
- controlNav.click(function(event) {
- event.preventDefault();
-
- if ($(this).hasClass('active') || ANIMATING) {
- return;
- } else {
- controlNav.removeClass('active');
- $(this).addClass('active');
-
- var selected = controlNav.index($(this));
- flexAnimate(selected);
- if (options.pauseOnAction) {
- clearInterval(animatedSlides);
- }
- }
- });
- }
-
-
-
-
- if (options.directionNav && length > 1) {
-
- if (options.controlsContainer != "" && $(options.controlsContainer).length > 0) {
- $(options.controlsContainer).append($('<ul class="flex-direction-nav"><li><a class="prev" href="#">' + options.prevText + '</a></li><li><a class="next" href="#">' + options.nextText + '</a></li></ul>'));
- } else {
- slider.append($('<ul class="flex-direction-nav"><li><a class="prev" href="#">' + options.prevText + '</a></li><li><a class="next" href="#">' + options.nextText + '</a></li></ul>'));
- }
-
- $('.flex-direction-nav li a').click(function(event) {
- event.preventDefault();
- if (ANIMATING) {
- return;
- } else {
-
- if ($(this).hasClass('next')) {
- var target = (currentSlide == length - 1) ? 0 : currentSlide + 1;
- } else {
- var target = (currentSlide == 0) ? length - 1 : currentSlide - 1;
- }
-
- if (options.controlNav) {
- controlNav.removeClass('active');
- controlNav.eq(target).addClass('active');
- }
-
- flexAnimate(target);
- if (options.pauseOnAction) {
- clearInterval(animatedSlides);
- }
- }
- });
- }
-
-
-
- if (options.keyboardNav && length > 1) {
- $(document).keyup(function(event) {
- if (ANIMATING) {
- return;
- } else if (event.keyCode != 39 && event.keyCode != 37){
- return;
- } else {
-
- if (event.keyCode == 39) {
- var target = (currentSlide == length - 1) ? 0 : currentSlide + 1;
- } else if (event.keyCode == 37){
- var target = (currentSlide == 0) ? length - 1 : currentSlide - 1;
- }
-
- if (options.controlNav) {
- controlNav.removeClass('active');
- controlNav.eq(target).addClass('active');
- }
-
- flexAnimate(target);
- if (options.pauseOnAction) {
- clearInterval(animatedSlides);
- }
- }
- });
- }
-
-
-
-
- if (options.slideshow && length > 1) {
- var animatedSlides;
-
- function animateSlides() {
- if (ANIMATING) {
- return;
- } else {
- var target = (currentSlide == length - 1) ? 0 : currentSlide + 1;
-
- if (options.controlNav) {
- controlNav.removeClass('active');
- controlNav.eq(target).addClass('active');
- }
-
- flexAnimate(target);
- }
- }
-
-
- if (options.pauseOnHover) {
- slider.hover(function() {
- clearInterval(animatedSlides);
- }, function() {
- animatedSlides = setInterval(animateSlides, options.slideshowSpeed);
- });
- }
-
-
- if (length > 1) {
- animatedSlides = setInterval(animateSlides, options.slideshowSpeed);
- }
- }
-
-
-
-
- if (options.touchSwipe && 'ontouchstart' in document.documentElement && length > 1) {
- slider.each(function() {
- var startX,
- min_move_x = 20;
- isMoving = false;
-
- function cancelTouch() {
- this.removeEventListener('touchmove', onTouchMove);
- startX = null;
- isMoving = false;
- }
- function onTouchMove(e) {
- if (isMoving) {
- var x = e.touches[0].pageX,
- dx = startX - x;
-
- if(Math.abs(dx) >= min_move_x) {
- cancelTouch();
- if(dx > 0) {
- var target = (currentSlide == length - 1) ? 0 : currentSlide + 1;
- }
- else {
- var target = (currentSlide == 0) ? length - 1 : currentSlide - 1;
- }
-
- if (options.controlNav) {
- controlNav.removeClass('active');
- controlNav.eq(target).addClass('active');
- }
-
- flexAnimate(target);
- if (options.pauseOnAction) {
- clearInterval(animatedSlides);
- }
- }
- }
- }
- function onTouchStart(e) {
- if (e.touches.length == 1) {
- startX = e.touches[0].pageX;
- isMoving = true;
- this.addEventListener('touchmove', onTouchMove, false);
- }
- }
- if ('ontouchstart' in document.documentElement) {
- this.addEventListener('touchstart', onTouchStart, false);
- }
- });
- }
-
-
-
-
- if (options.animation.toLowerCase() == "slide" && length > 1) {
- var sliderTimer;
- $(window).resize(function(){
- newSlides.width(slider.width());
-
- container.width(((length + 2) * slider.width()) + 2000);
-
-
- clearTimeout(sliderTimer);
- sliderTimer = setTimeout(function(){
- flexAnimate(currentSlide);
- }, 300);
- });
- }
-
- }
- });
-
- })(jQuery);
|