You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.3 KiB

/*! ResponsiveSlides.js v1.01. (c) 2011 Viljami Salminen. MIT License. http://responsive-slides.viljamis.com */
13 years ago
(function ($) {
13 years ago
$.fn.responsiveSlides = function (options) {
13 years ago
// Settings
var settings = {
'speed' : 4000,
'fade' : 1000,
'auto' : true,
'maxwidth' : 'none',
13 years ago
'namespace' : 'responsiveSlides'
13 years ago
};
return this.each(function () {
var $this = $(this);
if (options) {
$.extend(settings, options);
}
var slideshow = function () {
var $slide = $this.find('img'),
// just for minification:
namespace = settings.namespace,
maxwidth = parseFloat(settings.maxwidth),
fade = parseFloat(settings.fade),
$pagination = $('<ul class="' + namespace + '_tabs"/>'),
visible = {
'position': 'relative',
'float': 'left'
},
hidden = {
'position': 'absolute',
'float': 'none'
};
// Don't run if there's only one slide
if ($this.find($slide).length <= 1) {
return;
}
$slide.each(function (i) {
this.id = namespace + '_slide' + i;
13 years ago
});
$slide.css({
'top': 0,
'left': 0,
'width': '100%',
'height': 'inherit',
'position': 'absolute'
13 years ago
});
$this.find(':first-child').addClass(namespace + '_visible').css(visible);
13 years ago
$this.css({
'max-width': parseFloat(settings.maxwidth),
'width': '100%',
'overflow': 'hidden',
'position': 'relative'
13 years ago
});
$this.find($slide + ':gt(0)').hide();
13 years ago
// Auto: true
if (settings.auto === true) {
setInterval(function () {
$this.find(':first-child').fadeOut(fade, function () {
$(this).css(hidden);
}).next($slide).fadeIn(fade, function () {
$(this).css(visible);
}).addClass(namespace + '_visible').end().appendTo($this).removeClass(namespace + '_visible');
13 years ago
}, parseFloat(settings.speed));
// Auto: false
} else {
$slide.each(function (i) {
var whichSlide = i + 1,
tabMarkup =
'<li>' +
'<a href="#' + namespace + '_slide' + whichSlide + '"' +
'class="' + namespace + '_slide' + whichSlide + '">' + whichSlide + '</a>' +
13 years ago
'</li>'
;
$pagination.append(tabMarkup);
});
13 years ago
$this.after($pagination);
$('.' + namespace + '_slide1').parent().addClass(namespace + '_active');
$('.' + namespace + '_tabs a').each(function (i) {
13 years ago
var $el = $(this);
$el.click(function (e) {
e.preventDefault();
// Prevent clicking if animated
if ($('.' + namespace + '_visible:animated').length) {
13 years ago
return false;
}
if (!($el.parent().hasClass(namespace + '_active'))) {
$('.' + namespace + '_tabs li').removeClass(namespace + '_active');
13 years ago
$('.' + namespace + '_visible').stop()
.fadeOut(fade, function () {
$(this).removeClass(namespace + '_visible').css(hidden);
13 years ago
}).end();
$('#' + namespace + '_slide' + i).stop()
.fadeIn(fade, function () {
$(this).addClass(namespace + '_visible').css(visible);
13 years ago
}).end();
$el.parent().addClass(namespace + '_active');
13 years ago
}
});
});
}
};
// Fallback to make IE6 support CSS max-width
var widthSupport = function () {
if (options.maxwidth) {
if (typeof document.body.style.maxHeight === 'undefined' || typeof document.body.style.minHeight === 'undefined') {
13 years ago
$this.each(function () {
$this.css('width', '100%');
if ($this.width() > maxwidth) {
$this.css('width', maxwidth);
} else if ($this.width() < maxwidth) {
13 years ago
$this.css('width', '100%');
}
});
}
}
};
// Call once
slideshow();
widthSupport();
// Call on resize
$(window).resize(function () {
widthSupport();
});
});
};
})(jQuery);