1 changed files with 163 additions and 157 deletions
@ -1,157 +1,163 @@ |
|||||||
/*! ResponsiveSlides.js v1.07. (c) 2011 Viljami Salminen. MIT License. http://responsive-slides.viljamis.com */ |
/*! ResponsiveSlides.js v1.10. Authors & copyright (c) 2011-2012 Viljami Salminen & Bastian Gutschke. MIT License. http://responsive-slides.viljamis.com */ |
||||||
(function($, window, i) { |
(function ($, window, i) { |
||||||
|
|
||||||
$.fn.responsiveSlides = function( options ) { |
$.fn.responsiveSlides = function (options) { |
||||||
|
|
||||||
// Merge default settings with optional arguments
|
// Merge default settings with optional arguments
|
||||||
var settings = $.extend({ |
var settings = $.extend({ |
||||||
"auto": true, |
"auto": true, |
||||||
"fade": 1000, |
"fade": 1000, |
||||||
"maxwidth": "none", |
"maxwidth": "none", |
||||||
"speed": 4000 |
"speed": 4000 |
||||||
}, options); |
}, options); |
||||||
|
|
||||||
return this.each( function () { |
return this.each(function () { |
||||||
|
|
||||||
// increment i, which is used for namespacing
|
// Index, which is used for namespacing
|
||||||
i++; |
i++; |
||||||
|
|
||||||
// save handle for the slideshow
|
var $this = $(this); |
||||||
var $this = $( this ); |
|
||||||
|
var $slide = $this.children(), |
||||||
var $slide = $this.children(), |
$img = $("img", this), |
||||||
$img = $( "img", this ), |
index = 0, |
||||||
|
length = $slide.size(), |
||||||
namespace = "rslides" + i, |
namespace = "rslides" + i, |
||||||
|
activeClass = namespace + "_here", |
||||||
activeClass = namespace + "_here", |
visibleClass = namespace + '_on', |
||||||
slideClassPrefix = namespace + "_s", |
slideClassPrefix = namespace + "_s", |
||||||
|
tabsClass = namespace + "_tabs", |
||||||
tabsClass = namespace + "_tabs", |
$pagination = $("<ul class=\"" + tabsClass + "\" />"), |
||||||
$pagination = $( "<ul class=\"" + tabsClass + "\" />" ), |
visible = {"float": "left", "position": "relative"}, |
||||||
|
hidden = {"float": "none", "position": "absolute"}; |
||||||
visible = {"float": "left", "position": "relative"}, |
|
||||||
hidden = {"float": "none", "position": "absolute"}, |
// Fading animation
|
||||||
|
var slideTo = function (idx) { |
||||||
// start index and number of slides
|
|
||||||
index = 0, |
$slide |
||||||
length = $slide.size(); |
.stop() |
||||||
|
.fadeOut(settings.fade, function () { |
||||||
// animations
|
$(this) |
||||||
var slideTo = function( idx ) { |
.removeClass(visibleClass) |
||||||
|
.css(hidden); |
||||||
$slide |
}) |
||||||
.stop() |
.eq(idx) |
||||||
.fadeOut( settings.fade, function() { |
.fadeIn(settings.fade, function () { |
||||||
$( this ).css( hidden ); |
$(this) |
||||||
}) |
.addClass(visibleClass) |
||||||
.eq( idx ) |
.css(visible); |
||||||
.fadeIn( settings.fade, function() { |
index = idx; |
||||||
$( this ).css( visible ); |
}); |
||||||
index = idx; |
}; |
||||||
}); |
|
||||||
}; |
// Only run if there's more than one slide
|
||||||
|
if ($slide.size() > 1) { |
||||||
// Only run if there's more than one slide
|
|
||||||
if ( $slide.size() > 1 ) { |
// Add ID's to each slide
|
||||||
|
$slide.each(function (i) { |
||||||
// add ids to each slide
|
this.id = slideClassPrefix + i; |
||||||
$slide.each( function ( i ) { |
}); |
||||||
this.id = slideClassPrefix + i; |
|
||||||
}); |
// Add max-width
|
||||||
|
$this.css({ |
||||||
// add css to the slideshow
|
"max-width": settings.maxwidth |
||||||
$this.css({ |
}); |
||||||
"max-width": settings.maxwidth |
|
||||||
}); |
// Hide all slides, then show first one
|
||||||
|
$slide |
||||||
// hide all slides, then show first one
|
.hide() |
||||||
$slide |
.eq(0) |
||||||
.hide() |
.css(visible) |
||||||
.eq( 0 ) |
.show(); |
||||||
.css( visible ) |
|
||||||
.show(); |
// Auto: true
|
||||||
|
if (settings.auto === true) { |
||||||
// Auto: true
|
|
||||||
if ( settings.auto === true ) { |
// Rotate slides automatically
|
||||||
|
setInterval(function () { |
||||||
// rotate slides automatically
|
var idx = index + 1 < length ? index + 1 : 0; |
||||||
setInterval( function () { |
slideTo(idx); |
||||||
var idx = index + 1 < length ? index + 1 : 0; |
}, settings.speed); |
||||||
slideTo( idx ); |
|
||||||
}, settings.speed ); |
} |
||||||
|
|
||||||
} |
// Auto: false
|
||||||
// Auto: false
|
else { |
||||||
else { |
|
||||||
|
// Build pagination
|
||||||
// build pagination
|
var tabMarkup = [] |
||||||
var tabMarkup = []; |
$slide.each(function (i) { |
||||||
$slide.each( function( i ) { |
var n = i + 1; |
||||||
var n = i + 1; |
|
||||||
|
tabMarkup.push("<li>"); |
||||||
tabMarkup.push( "<li>" ); |
tabMarkup.push("<a href=\"#" + slideClassPrefix + n + "\" "); |
||||||
tabMarkup.push( "<a href=\"#" + slideClassPrefix + n + "\" " ); |
tabMarkup.push("class=\"" + slideClassPrefix + n + "\">" + n + "</a>"); |
||||||
tabMarkup.push( "class=\"" + slideClassPrefix + n + "\">" + n + "</a>" ); |
tabMarkup.push("</li>"); |
||||||
tabMarkup.push( "</li>" ); |
}); |
||||||
}); |
$pagination.append(tabMarkup.join("")); |
||||||
$pagination.append( tabMarkup.join("") ); |
|
||||||
|
var $tabs = $pagination.find("a"); |
||||||
var $tabs = $pagination.find( "a" ); |
|
||||||
|
// Click/touch event handler
|
||||||
// add click/touch event handler and set first tab active
|
$tabs.on("ontouchstart" in window ? "touchstart" : "click", function (e) { |
||||||
$tabs.on( "ontouchstart" in window ? "touchstart" : "click", function( e ) { |
e.preventDefault(); |
||||||
e.preventDefault(); |
|
||||||
|
// Prevent click/touch if animated
|
||||||
// get index of clicked tab
|
if ($('.' + visibleClass + ':animated').length) { |
||||||
var idx = $tabs.index( this ); |
return false; |
||||||
|
} |
||||||
// break here if element is already active
|
|
||||||
if( index === idx ) { |
// Get index of clicked tab
|
||||||
return; |
var idx = $tabs.index(this); |
||||||
} |
|
||||||
|
// Break if element is already active
|
||||||
// remove active state from old tab and set new one
|
if (index === idx) { |
||||||
$tabs |
return; |
||||||
.closest( "li" ) |
} |
||||||
.removeClass( activeClass ) |
|
||||||
.eq( idx ) |
// Remove active state from old tab and set new one
|
||||||
.addClass( activeClass ); |
$tabs |
||||||
|
.closest("li") |
||||||
// do the animation
|
.removeClass(activeClass) |
||||||
slideTo( idx ); |
.eq(idx) |
||||||
}) |
.addClass(activeClass); |
||||||
.eq( 0 ) |
|
||||||
.closest( "li" ) |
// Do the animation
|
||||||
.addClass( activeClass ); |
slideTo(idx); |
||||||
|
}) |
||||||
// inject pagination
|
.eq(0) |
||||||
$this.after( $pagination ); |
.closest("li") |
||||||
} |
.addClass(activeClass); |
||||||
} |
|
||||||
|
// Inject pagination
|
||||||
|
$this.after($pagination); |
||||||
// only add fallback if maxwidth isn't supported and maxwidth is set
|
} |
||||||
if ( typeof document.body.style.maxWidth === "undefined" && options && options.maxwidth ) { |
} |
||||||
|
|
||||||
// Fallback to make IE6 support CSS max-width
|
// Add fallback if CSS max-width isn't supported and maxwidth is set
|
||||||
var widthSupport = function() { |
if (typeof document.body.style.maxWidth === "undefined" && options && options.maxwidth) { |
||||||
|
|
||||||
$this.css( "width", "100%" ); |
var widthSupport = function () { |
||||||
|
|
||||||
if ( $this.width() > settings.maxwidth ) { |
$this.css("width", "100%"); |
||||||
$this.css( "width", settings.maxwidth ); |
|
||||||
} |
if ($this.width() > settings.maxwidth) { |
||||||
}; |
$this.css("width", settings.maxwidth); |
||||||
widthSupport(); |
} |
||||||
// bind on window resize
|
}; |
||||||
$( window ).on( "resize", function () { |
|
||||||
widthSupport(); |
// Init fallback
|
||||||
}); |
widthSupport(); |
||||||
|
|
||||||
} |
// + Bind on window resize
|
||||||
|
$(window).on("resize", function () { |
||||||
}); |
widthSupport(); |
||||||
}; |
}); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
})(jQuery, this, 0); |
})(jQuery, this, 0); |
Loading…
Reference in new issue