forked from arielsalminen/ResponsiveSlides.js
/
responsiveslides.js
132 lines (119 loc) · 4.23 KB
/
responsiveslides.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*! ResponsiveSlides.js v1.04. (c) 2011-2012 Viljami Salminen. MIT License. http://responsive-slides.viljamis.com */
(function ($) {
$.fn.responsiveSlides = function (options) {
// Settings
var settings = {
'speed' : 4000,
'fade' : 1000,
'auto' : true,
'maxwidth' : 'none',
'namespace' : 'rs'
};
return this.each(function () {
var $this = $(this);
if (options) {
$.extend(settings, options);
}
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' };
// Only run if there's more than one slide
if ($this.find($slide).length > 1) {
$slide.each(function (i) {
this.id = slideClassPrefix + i;
});
$slide.css({
'top': 0,
'left': 0,
'width': '100%',
'height': 'inherit',
'position': 'absolute'
});
$this.css({
'max-width': parseFloat(settings.maxwidth),
'width': '100%',
'overflow': 'hidden',
'position': 'relative'
})
.find(':first-child').css(visible).end()
.find($slide + ':gt(0)').hide();
// 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);
}, parseFloat(settings.speed));
// Auto: false
} else {
t = '';
$slide.each(function (i) {
var n = i + 1;
t +=
'<li>' +
'<a href="#' + slideClassPrefix + n + '"' +
'class="' + slideClassPrefix + n + '">' + n + '</a>' +
'</li>';
});
$pagination.append(t);
$this.after($pagination).find(':first-child').addClass(visibleClass);
$('.' + slideClassPrefix + '1').parent().addClass(activeClass);
$('.' + tabsClass + ' a').each(function (i) {
var $el = $(this);
$el.click(function (e) {
e.preventDefault();
// Prevent clicking if animated
if ($('.' + visibleClass + ':animated').length) {
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);
}
});
});
}
}
};
// Fallback to make IE6 support CSS max-width
var widthSupport = function () {
var maxwidth = parseFloat(settings.maxwidth);
if (options && options.maxwidth) {
if (typeof document.body.style.maxHeight === 'undefined') {
$this.each(function () {
$this.css('width', '100%');
if ($this.width() > maxwidth) {
$this.css('width', maxwidth);
} else if ($this.width() < maxwidth) {
$this.css('width', '100%');
}
});
}
}
};
// Call once
slideshow();
widthSupport();
// Call on resize
$(window).resize(function () {
widthSupport();
});
});
};
})(jQuery);