Skip to content

Commit

Permalink
Fixes #347 - Carousel refinement (pt. 2)
Browse files Browse the repository at this point in the history
Carousel refinement in part with repo of oregon-digital-set-content
  • Loading branch information
David McCallum committed Aug 22, 2014
1 parent 91fd595 commit 37acbf1
Show file tree
Hide file tree
Showing 3 changed files with 291 additions and 31 deletions.
7 changes: 4 additions & 3 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
//= require jquery.ui.draggable
//= require jquery.ui.effect.all
//
// Adding bootstrap for carousel
//= require bootstrap-carousel
// Adding bootstrap for dropdown - is this used?
//= require bootstrap-dropdown
//
// Required by Blacklight
Expand All @@ -45,4 +44,6 @@
//= require bookreader/jquery.bt.min
//= require bookreader/BookReader
//

// Adding blueberry for carousel
//= require jquery.blueberry.js
//
132 changes: 104 additions & 28 deletions app/assets/stylesheets/theme.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ $highlight-bg: #1FA1BF;

$color: #144651;
$highlight-color: #ffffff;
$linkColor: #0f959a;//#1C88A4;
$linkColorHover: lighten($linkColor, 10%);

$font-stack: Gudea, Helvetica, Verdana, sans-serif;

Expand Down Expand Up @@ -613,42 +615,116 @@ ul.sidenav {
margin-left: 20px;
}

.carousel-inner {
text-align: center;

.carousel-indicators {
position: static;
float: none;
margin: 3px auto;
display: inline-block;
/*
* jQuery Blueberry Slider v0.4 BETA
* http://marktyrrell.com/labs/blueberry/
*
* Copyright (C) 2011, Mark Tyrrell <me@marktyrrell.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

.blueberry {
margin: 0 auto;

figure, ul {
margin: 0;
}

figcaption {
margin-top: .2rem;
}

.slides {
display: block;
position: relative;
overflow: hidden;

li {
border: 1px solid #ccc;
}
position: absolute;
top: 0;
left: 0;

li.active {
background-color: #ccc;
figure {
width: 100%;
max-width: none;
}

figcaption {
position: absolute;
background: white;
background: rgba(245,245,245,0.85);
padding: 10px 20px;
opacity: 1;
width: 90%;
bottom: 0;
}

&.active {
display: block;
position: relative;
}
}
}

.crop li figure {
width: auto;
}
.carousel-caption {
text-align: left;

a {
color: #ffffff;
.pager {
height: 40px;
text-align: center;

li {
display: inline-block;

a, a span {
display: block;
height: 10px;
width: 10px;
}

a {
padding: 18px 8px;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
border: 0;
width: .30em;
background-color: transparent;
}

a span {
overflow: hidden;
background: $linkColor;
text-indent: -9999px;
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
border-radius: 12px;
}

&.active a span {
background: transparent;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
border: 1px solid #aaa;
height: 8px;
width: 8px;
}
}
}
}
.carousel-control {
font-size: 80px;
line-height: 38px;
color: #fff !important;
top: 45%;
left: 0;
border: 0;
background: #c3c3c3;
}

.carousel-control.right {
right: 0;
}
183 changes: 183 additions & 0 deletions vendor/assets/javascripts/jquery.blueberry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* jQuery Blueberry Slider v0.4 BETA
* http://marktyrrell.com/labs/blueberry/
*
* Copyright (C) 2011, Mark Tyrrell <me@marktyrrell.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

(function($){
$.fn.extend({
blueberry: function(options) {

//default values for plugin options
var defaults = {
interval: 5000,
duration: 500,
lineheight: 1,
height: 'auto', //reserved
hoverpause: false,
pager: true,
nav: true, //reserved
keynav: true
}
var options = $.extend(defaults, options);

return this.each(function() {
var o = options;
var obj = $(this);

//store the slide and pager li
var slides = $('.slides li', obj);
var pager = $('.pager li', obj);

//set initial current and next slide index values
var current = 0;
var next = current+1;

//get height and width of initial slide image and calculate size ratio
var imgHeight = slides.eq(current).find('img').height();
var imgWidth = slides.eq(current).find('img').width();
var imgRatio = imgWidth/imgHeight;

//define vars for setsize function
var sliderWidth = 0;
var cropHeight = 0;

//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');
} else if(o.pager){
obj.append('<ul class="pager"></ul>');
slides.each(function(index) {
$('.pager', obj).append('<li><a href="#"><span>'+index+'</span></a></li>')
});
pager = $('.pager li', obj);
pager.eq(current).addClass('active');
}

//rotate to selected slide on pager click
if(pager){
$('a', pager).click(function() {
//stop the timer
clearTimeout(obj.play);
//set the slide index based on pager index
next = $(this).parent().index();
//rotate the slides
rotate();
return false;
});
}

//primary function to change slides
var rotate = function(){
//fade out current slide and remove active class,
//fade in next slide and add active class
slides.eq(current).fadeOut(o.duration).removeClass('active')
.end().eq(next).fadeIn(o.duration).addClass('active').queue(function(){
//add rotateTimer function to end of animation queue
//this prevents animation buildup caused by requestAnimationFrame
//rotateTimer starts a timer for the next rotate
rotateTimer();
$(this).dequeue()
});

//update pager to reflect slide change
if(pager){
pager.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
current = next;
next = current >= slides.length-1 ? 0 : current+1;
};
//create a timer to control slide rotation interval
var rotateTimer = function(){
obj.play = setTimeout(function(){
//trigger slide rotate function at end of timer
rotate();
clearTimeout(obj.play);
}, o.interval);
};
//start the timer for the first time
rotateTimer();

//pause the slider on hover
//disabled by default due to bug
if(o.hoverpause){
slides.hover(function(){
//stop the timer in mousein
clearTimeout(obj.play);
}, function(){
//start the timer on mouseout
rotateTimer();
});
}

//calculate and set height based on image width/height ratio and specified line height
var setsize = function(){
sliderWidth = $('.slides', obj).width();
cropHeight = Math.floor(((sliderWidth/imgRatio)/o.lineheight))*o.lineheight;

$('.slides', obj).css({height: cropHeight});
};
setsize();

//bind setsize function to window resize event
$(window).resize(function(){
setsize();
});



//Add keyboard navigation

if(o.keynav){
$(document).keyup(function(e){

switch (e.which) {

case 39: case 32: //right arrow & space

clearTimeout(obj.play);

rotate();

break;


case 37: // left arrow
clearTimeout(obj.play);
next = current - 1;
rotate();

break;
}

});
}


});
}
});
})(jQuery);

0 comments on commit 37acbf1

Please sign in to comment.