Browse files

Update jquery.blueberry.js

  • Loading branch information...
1 parent 2278fd2 commit 1b161b6b355f6b2440b3534f7da4f8499cc4f533 @ShaunSpringer committed Mar 26, 2012
Showing with 39 additions and 16 deletions.
  1. +39 −16 jquery.blueberry.js
View
55 jquery.blueberry.js
@@ -32,18 +32,20 @@
hoverpause: false,
pager: true,
nav: true, //reserved
- keynav: true
+ keynav: true,
+ captions: false
}
var options = $.extend(defaults, options);
return this.each(function() {
var o = options;
var obj = $(this);
- //store the slide and pager li
+ //store the slide, pager li, and captions li
var slides = $('.slides li', obj);
var pager = $('.pager li', obj);
-
+ var captions = $('.captions li', obj);
+
//set initial current and next slide index values
var current = 0;
var next = current+1;
@@ -60,7 +62,6 @@
//hide all slides, fade in the first, add active class to first slide
slides.hide().eq(current).fadeIn(o.duration).addClass('active');
-
//build pager if it doesn't already exist and if enabled
if(pager.length) {
pager.eq(current).addClass('active');
@@ -85,6 +86,22 @@
return false;
});
}
+
+ //build our captions box if it doesnt exist
+ if (o.captions)
+ {
+ if(captions.length) {
+ captions.eq(current).addClass('active');
+ } else if(o.captions){
+ obj.append('<ul class="captions"></ul>');
+ slides.each(function(index) {
+ var caption = slides.eq(index).attr('caption');
+ $('.captions', obj).append('<li><span>'+caption+'</span></li>');
+ });
+ captions = $('.captions li', obj);
+ captions.eq(current).addClass('active');
+ }
+ }
//primary function to change slides
var rotate = function(){
@@ -104,6 +121,12 @@
pager.eq(current).removeClass('active')
.end().eq(next).addClass('active');
}
+
+ //update captions to reflect slide change
+ if(captions){
+ captions.eq(current).removeClass('active')
+ .end().eq(next).addClass('active');
+ }
//update current and next vars to reflect slide change
//set next as first slide if current is the last
@@ -144,33 +167,33 @@
//bind setsize function to window resize event
$(window).resize(function(){
setsize();
- });
-
+ });
+
- //Add keyboard navigation
+ //Add keyboard navigation
if(o.keynav){
- $(document).keyup(function(e){
+ $(document).keyup(function(e){
- switch (e.which) {
+ switch (e.which) {
- case 39: case 32: //right arrow & space
+ case 39: case 32: //right arrow & space
- clearTimeout(obj.play);
+ clearTimeout(obj.play);
- rotate();
+ rotate();
- break;
+ break;
case 37: // left arrow
clearTimeout(obj.play);
next = current - 1;
- rotate();
+ rotate();
break;
- }
+ }
});
}
@@ -179,4 +202,4 @@
});
}
});
-})(jQuery);
+})(jQuery);

1 comment on commit 1b161b6

@ShaunSpringer

Added support for captions

Please sign in to comment.