Browse Source

Version 1.3

rewrite v1.3
Viljami S 13 years ago
parent
commit
c2927cc2cc
  1. 94
      responsiveslides.js
  2. 12
      responsiveslides.min.js

94
responsiveslides.js

@ -1,33 +1,11 @@
/*! ResponsiveSlides.js v1.25
/*! ResponsiveSlides.js v1.3
* http://responsiveslides.com
*
* Copyright (c) 2011-2012 @viljamis
* Available under the MIT license
*/
/* ResponsiveSlides.js is a tiny jQuery plugin that creates a responsive
* slideshow using images inside <ul>. It works with wide range of browsers
* including all IE versions from IE6 and up. It also adds css max-width
* support for IE6 and other browsers that don't natively support it. Only
* dependency is jQuery (1.4 and up) and that all the images are same size.
*
* Features:
* - Fully responsive
* - Under 1kb minified and gzipped
* - Simple markup using unordered lists
* - Settings for transition and timeout durations
* - Multiple slideshows supported
* - Automatic and manual fade
* - Works in all major desktop and mobile browsers
* - Captions and other html-elements supported inside slides
* - Separate pagination and next/prev controls
* - Possibility to choose where the controls append to
* - Images can be wrapped inside links
* - Optional 'before' and 'after' callbacks
*
*/
/*jslint browser: true, sloppy: true, vars: true, plusplus: true, maxerr: 50, indent: 2 */
/*jslint browser: true, sloppy: true, vars: true, plusplus: true, indent: 2 */
(function ($, window, i) {
$.fn.responsiveSlides = function (options) {
@ -39,6 +17,9 @@
"timeout": 4000, // Integer: Time between slide transitions, in milliseconds
"pager": false, // Boolean: Show pager, true or false
"nav": false, // Boolean: Show navigation, true or false
"random": false, // Boolean: Randomize the order of the slides, true or false
"pause": false, // Boolean: Pause on hover, true or false
"pauseControls": false, // Boolean: Pause when hovering controls, true or false
"prevText": "Previous", // String: Text for the "previous" button
"nextText": "Next", // String: Text for the "next" button
"maxwidth": "", // Integer: Max-width of the slideshow, in pixels
@ -104,6 +85,16 @@
});
};
// Random order
if (settings.random) {
$slide.sort(function () {
return (Math.round(Math.random()) - 0.5);
});
$this
.empty()
.append($slide);
}
// Add ID's to each slide
$slide.each(function (i) {
this.id = slideClassPrefix + i;
@ -126,8 +117,13 @@
// Only run if there's more than one slide
if ($slide.size() > 1) {
// Make sure the timeout is at least 100ms longer than the fade
if (settings.timeout < settings.speed + 100) {
return;
}
// Pager
if (settings.pager === true) {
if (settings.pager) {
var tabMarkup = [];
$slide.each(function (i) {
var n = i + 1;
@ -158,14 +154,14 @@
}
// Auto cycle
if (settings.auto === true) {
if (settings.auto) {
startCycle = function () {
rotate = setInterval(function () {
var idx = index + 1 < length ? index + 1 : 0;
// Remove active state and set new if pager = "true"
if (settings.pager === true) {
// Remove active state and set new if pager is set
if (settings.pager) {
selectTab(idx);
}
@ -179,7 +175,7 @@
// Restarting cycle
restartCycle = function () {
if (settings.auto === true) {
if (settings.auto) {
// Stop
clearInterval(rotate);
// Restart
@ -187,11 +183,23 @@
}
};
// Pause on hover
if (settings.pause) {
$this.hover(function () {
clearInterval(rotate);
}, function () {
restartCycle();
});
}
// Pager click event handler
if (settings.pager === true) {
if (settings.pager) {
$tabs.bind("click", function (e) {
e.preventDefault();
if (!settings.pauseControls) {
restartCycle();
}
// Get index of clicked tab
var idx = $tabs.index(this);
@ -210,10 +218,19 @@
.eq(0)
.closest("li")
.addClass(activeClass);
// Pause when hovering pager
if (settings.pauseControls) {
$tabs.hover(function () {
clearInterval(rotate);
}, function () {
restartCycle();
});
}
}
// Navigation
if (settings.nav === true) {
if (settings.nav) {
var navMarkup =
"<a href='#' class='" + navClass + " prev'>" + settings.prevText + "</a>" +
"<a href='#' class='" + navClass + " next'>" + settings.nextText + "</a>";
@ -244,18 +261,29 @@
// Go to slide
slideTo($(this)[0] === $prev[0] ? prevIdx : nextIdx);
if (settings.pager === true) {
if (settings.pager) {
selectTab($(this)[0] === $prev[0] ? prevIdx : nextIdx);
}
if (!settings.pauseControls) {
restartCycle();
}
});
// Pause when hovering navigation
if (settings.pauseControls) {
$trigger.hover(function () {
clearInterval(rotate);
}, function () {
restartCycle();
});
}
}
}
// Max-width fallback
if (typeof document.body.style.maxWidth === "undefined" && options && options.maxwidth) {
if (typeof document.body.style.maxWidth === "undefined" && options.maxwidth) {
var widthSupport = function () {
$this.css("width", "100%");
if ($this.width() > maxw) {

12
responsiveslides.min.js vendored

@ -1,6 +1,6 @@
/*! http://responsiveslides.com v1.25 by @viljamis */
(function(b,C,u){b.fn.responsiveSlides=function(e){var c=b.extend({auto:!0,speed:1E3,timeout:4E3,pager:!1,nav:!1,prevText:"Previous",nextText:"Next",maxwidth:"",controls:"",namespace:"rslides"},e);return this.each(function(){u++;var d=b(this),l,o,p,v,m,k=0,f=d.children(),w=f.size(),x=parseFloat(c.speed),q=parseFloat(c.maxwidth),g=c.namespace,h=g+u,i=g+"_nav "+h+"_nav",r=g+"_here",j=h+"_on",y=h+"_s",n=b("<ul class='"+g+"_tabs "+h+"_tabs' />"),z={"float":"left",position:"relative"},D={"float":"none",
position:"absolute"},s=function(a){d.trigger(g+"-before");f.stop().fadeOut(x,function(){b(this).removeClass(j).css(D)}).eq(a).fadeIn(x,function(){b(this).addClass(j).css(z).trigger(g+"-after");k=a})};f.each(function(a){this.id=y+a});d.addClass(g+" "+h);e&&e.maxwidth&&d.css("max-width",q);f.hide().eq(0).addClass(j).css(z).show();if(1<f.size()){if(!0===c.pager){var t=[];f.each(function(a){a+=1;t+="<li><a href='#' class='"+y+a+"'>"+a+"</a></li>"});n.append(t);m=n.find("a");e.controls?b(c.controls).append(n):
d.after(n);l=function(a){m.closest("li").removeClass(r).eq(a).addClass(r)}}!0===c.auto&&(o=function(){v=setInterval(function(){var a=k+1<w?k+1:0;!0===c.pager&&l(a);s(a)},parseFloat(c.timeout))},o());p=function(){if(c.auto===true){clearInterval(v);o()}};!0===c.pager&&m.bind("click",function(a){a.preventDefault();p();a=m.index(this);if(!(k===a||b("."+j+":animated").length)){l(a);s(a)}}).eq(0).closest("li").addClass(r);if(!0===c.nav){i="<a href='#' class='"+i+" prev'>"+c.prevText+"</a><a href='#' class='"+
i+" next'>"+c.nextText+"</a>";e.controls?b(c.controls).append(i):d.after(i);var i=b("."+h+"_nav"),A=b("."+h+"_nav.prev");i.bind("click",function(a){a.preventDefault();if(!b("."+j+":animated").length){var d=f.index(b("."+j)),a=d-1,d=d+1<w?k+1:0;s(b(this)[0]===A[0]?a:d);c.pager===true&&l(b(this)[0]===A[0]?a:d);p()}})}}if("undefined"===typeof document.body.style.maxWidth&&e&&e.maxwidth){var B=function(){d.css("width","100%");d.width()>q&&d.css("width",q)};B();b(C).bind("resize",function(){B()})}})}})(jQuery,
this,0);
/*! http://responsiveslides.com v1.3 by @viljamis */
(function(d,C,v){d.fn.responsiveSlides=function(i){var b=d.extend({auto:!0,speed:1E3,timeout:4E3,pager:!1,nav:!1,random:!1,pause:!1,pauseControls:!1,prevText:"Previous",nextText:"Next",maxwidth:"",controls:"",namespace:"rslides"},i);return this.each(function(){v++;var c=d(this),o,q,j,l,m,n=0,e=c.children(),w=e.size(),x=parseFloat(b.speed),r=parseFloat(b.maxwidth),g=b.namespace,h=g+v,f=g+"_nav "+h+"_nav",s=g+"_here",k=h+"_on",y=h+"_s",p=d("<ul class='"+g+"_tabs "+h+"_tabs' />"),z={"float":"left",position:"relative"},
D={"float":"none",position:"absolute"},t=function(a){c.trigger(g+"-before");e.stop().fadeOut(x,function(){d(this).removeClass(k).css(D)}).eq(a).fadeIn(x,function(){d(this).addClass(k).css(z).trigger(g+"-after");n=a})};b.random&&(e.sort(function(){return Math.round(Math.random())-0.5}),c.empty().append(e));e.each(function(a){this.id=y+a});c.addClass(g+" "+h);i&&i.maxwidth&&c.css("max-width",r);e.hide().eq(0).addClass(k).css(z).show();if(1<e.size()){if(b.timeout<b.speed+100)return;if(b.pager){var u=
[];e.each(function(a){a=a+1;u=u+("<li><a href='#' class='"+y+a+"'>"+a+"</a></li>")});p.append(u);m=p.find("a");i.controls?d(b.controls).append(p):c.after(p);o=function(a){m.closest("li").removeClass(s).eq(a).addClass(s)}}b.auto&&(q=function(){l=setInterval(function(){var a=n+1<w?n+1:0;b.pager&&o(a);t(a)},parseFloat(b.timeout))},q());j=function(){if(b.auto){clearInterval(l);q()}};b.pause&&c.hover(function(){clearInterval(l)},function(){j()});b.pager&&(m.bind("click",function(a){a.preventDefault();
b.pauseControls||j();a=m.index(this);if(!(n===a||d("."+k+":animated").length)){o(a);t(a)}}).eq(0).closest("li").addClass(s),b.pauseControls&&m.hover(function(){clearInterval(l)},function(){j()}));if(b.nav){f="<a href='#' class='"+f+" prev'>"+b.prevText+"</a><a href='#' class='"+f+" next'>"+b.nextText+"</a>";i.controls?d(b.controls).append(f):c.after(f);var f=d("."+h+"_nav"),A=d("."+h+"_nav.prev");f.bind("click",function(a){a.preventDefault();if(!d("."+k+":animated").length){var c=e.index(d("."+k)),
a=c-1,c=c+1<w?n+1:0;t(d(this)[0]===A[0]?a:c);b.pager&&o(d(this)[0]===A[0]?a:c);b.pauseControls||j()}});b.pauseControls&&f.hover(function(){clearInterval(l)},function(){j()})}}if("undefined"===typeof document.body.style.maxWidth&&i.maxwidth){var B=function(){c.css("width","100%");c.width()>r&&c.css("width",r)};B();d(C).bind("resize",function(){B()})}})}})(jQuery,this,0);
Loading…
Cancel
Save