From 19e7e25e3b50dcb621fea842589db38cd393a74c Mon Sep 17 00:00:00 2001 From: BTMPL Date: Thu, 14 Mar 2013 10:41:38 +0100 Subject: [PATCH 1/2] New features - added option to skipp by given number of images/frames - added option to block looping on the edges - while looping is disabled prev/next elements will have css class disabled set on them while inactive --- simple.carousel.js | 75 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 11 deletions(-) diff --git a/simple.carousel.js b/simple.carousel.js index 05badd2..09e36e5 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 @@ -21,7 +25,9 @@ $.fn.simplecarousel = function( params ) { items: 0, slidespeed: 600, visible: 1, - pagination: false + jump: 1, + pagination: false, + noloop: false }; var config = $.extend(defaults, params); @@ -58,22 +64,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 +176,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 +194,4 @@ $.fn.simplecarousel = function( params ) { slide('next'); }, config.auto); } -})(jQuery); \ No newline at end of file +})(jQuery); From 644e699fc45c870c918525a43d2a7725601ba5a1 Mon Sep 17 00:00:00 2001 From: BTMPL Date: Thu, 14 Mar 2013 10:43:04 +0100 Subject: [PATCH 2/2] Updated default values Updated default values for nolooping and visible params --- simple.carousel.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/simple.carousel.js b/simple.carousel.js index 09e36e5..f1be68f 100644 --- a/simple.carousel.js +++ b/simple.carousel.js @@ -24,10 +24,12 @@ $.fn.simplecarousel = function( params ) { current: 0, items: 0, slidespeed: 600, - visible: 1, - jump: 1, + visible: 4, + // nuber of frames that prev/next should skip + jump: 4, pagination: false, - noloop: false + // enable / disable looping on ends + noloop: true }; var config = $.extend(defaults, params);