diff --git a/simple.carousel.js b/simple.carousel.js index 05badd2..f1be68f 100644 --- a/simple.carousel.js +++ b/simple.carousel.js @@ -1,4 +1,8 @@ /** + * Bartosz Szczecinski baphemot@gmail.com + * + * Fork of: + * * Simple Carousel * Copyright (c) 2010 Tobias Zeising, http://www.aditu.de * Licensed under the MIT license @@ -20,8 +24,12 @@ $.fn.simplecarousel = function( params ) { current: 0, items: 0, slidespeed: 600, - visible: 1, - pagination: false + visible: 4, + // nuber of frames that prev/next should skip + jump: 4, + pagination: false, + // enable / disable looping on ends + noloop: true }; var config = $.extend(defaults, params); @@ -58,22 +66,67 @@ $.fn.simplecarousel = function( params ) { $(item).css('float','left'); }); + if(config.noloop == true) { + if(config.current == 0) { + jQuery(config.prev).addClass('disabled'); + } + else { + jQuery(config.prev).removeClass('disabled'); + } + + if(config.current+config.visible == config.items) { + jQuery(config.next).addClass('disabled'); + } + else { + jQuery(config.next).removeClass('disabled'); + } + } + // function for sliding the carousel var slide = function(dir, click) { if(typeof click == "undefined" & config.auto==false) return; - + + if(dir=="next") { - config.current += config.visible; - if(config.current>=config.items) - config.current = 0; + config.current += config.jump; + if(config.noloop == true) { + if(config.current + ((config.visible >= config.jump) ? config.visible - config.jump : config.jump) >= config.items) { + config.current -= config.jump; + } + } + else { + if(config.current>=config.items) + config.current = 0; + } + + } else if(dir=="prev") { - config.current -= config.visible; - if(config.current<0) - config.current = (config.visible==1) ? config.items-1 : config.items-config.visible+(config.visible-(config.items%config.visible)); + config.current -= config.jump; + if(config.current<0) { + if(config.noloop == true) config.current += config.jump; + else config.current = (config.visible==1) ? config.items-1 : config.items-config.visible+(config.visible-(config.items%config.visible)); + } + } else { config.current = dir; } + + if(config.noloop == true) { + if(config.current == 0) { + jQuery(config.prev).addClass('disabled'); + } + else { + jQuery(config.prev).removeClass('disabled'); + } + + if(config.current+config.visible >= config.items) { + jQuery(config.next).addClass('disabled'); + } + else { + jQuery(config.next).removeClass('disabled'); + } + } // set pagination if(config.pagination != false) { @@ -125,13 +178,15 @@ $.fn.simplecarousel = function( params ) { // set event handler for next and prev if(config.next!=false) - config.next.click(function() { + config.next.click(function(e) { + e.preventDefault(); slide('next',true); }); if(config.prev!=false) - config.prev.click(function() { + config.prev.click(function(e) { + e.preventDefault(); slide('prev',true); }); @@ -141,4 +196,4 @@ $.fn.simplecarousel = function( params ) { slide('next'); }, config.auto); } -})(jQuery); \ No newline at end of file +})(jQuery);