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.

137 lines
4.1 KiB

/*! ResponsiveSlides.js v1.03. (c) 2011 Viljami Salminen. MIT License. http://responsive-slides.viljamis.com */
13 years ago
(function ($) {
$.fn.responsiveSlides = function (opts) {
13 years ago
// Settings
var settings = {
'speed' : 4000,
'fade' : 1000,
'auto' : true,
'maxwidth' : 'none',
'namespace' : 'rs'
13 years ago
};
return this.each(function () {
var $this = $(this);
if (opts) {
$.extend(settings, opts);
13 years ago
}
var slideshow = function () {
var $slide = $this.find('img'),
namespace = settings.namespace,
activeClass = namespace + '_here',
visibleClass = namespace + '_on',
slideClassPrefix = namespace + '_s',
tabsClass = namespace + '_tabs',
$pagination = $('<ul class="' + tabsClass + '" />'),
fadetime = parseFloat(settings.fade),
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 = slideClassPrefix + i;
13 years ago
});
$slide.css({
'top': 0,
'left': 0,
'width': '100%',
'height': 'inherit',
'position': 'absolute'
13 years ago
});
$this.css({
'max-width': parseFloat(settings.maxwidth),
'width': '100%',
'overflow': 'hidden',
'position': 'relative'
13 years ago
});
$this.find(':first-child').css(visible);
$this.find($slide + ':gt(0)').hide();
13 years ago
// Auto: true
if (settings.auto === true) {
setInterval(function () {
$this.find(':first-child').fadeOut(fadetime, function () {
$(this).css(hidden);
}).next($slide).fadeIn(fadetime, function () {
$(this).css(visible);
}).end().appendTo($this);
13 years ago
}, parseFloat(settings.speed));
// Auto: false
} else {
tabMarkup = '';
$slide.each(function (i) {
var n = i + 1;
tabMarkup += [
13 years ago
'<li>',
'<a href="#' + slideClassPrefix + n + '"',
'class="' + slideClassPrefix + n + '">' + n + '</a>',
13 years ago
'</li>'
].join('');
});
$pagination.append(tabMarkup);
13 years ago
$this.after($pagination).find(':first-child').addClass(visibleClass);
$('.' + slideClassPrefix + '1').parent().addClass(activeClass);
$('.' + tabsClass + ' a').each(function (i) {
13 years ago
var $el = $(this);
$el.click(function (e) {
e.preventDefault();
// Prevent clicking if animated
if ($('.' + visibleClass + ':animated').length) {
13 years ago
return false;
}
if (!($el.parent().hasClass(activeClass))) {
$('.' + tabsClass + ' li').removeClass(activeClass);
$('.' + visibleClass).stop().fadeOut(fadetime, function () {
$(this).removeClass(visibleClass).css(hidden);
}).end();
$('#' + slideClassPrefix + i).stop().fadeIn(fadetime, function () {
$(this).addClass(visibleClass).css(visible);
}).end();
$el.parent().addClass(activeClass);
13 years ago
}
});
});
}
};
// Fallback to make IE6 support CSS max-width
var widthSupport = function () {
var maxwidth = parseFloat(settings.maxwidth);
if (opts.maxwidth) {
if (typeof document.body.style.maxHeight === '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);