Browse Source

Fixing most of the bugs

pull/21/head
Viljami S 13 years ago
parent
commit
1ee7b70d7d
  1. 45
      responsiveslides.js

45
responsiveslides.js

@ -3,32 +3,34 @@
$.fn.responsiveSlides = function (options) { $.fn.responsiveSlides = function (options) {
// Merge default settings with optional arguments // Default settings
var settings = $.extend({ var settings = $.extend({
"auto": true, "auto": true,
"fade": 300, "fade": 1000,
"maxwidth": "none", "maxwidth": "none",
"speed": 4000 "speed": 4000
}, options); }, options);
return this.each(function () { return this.each(function () {
// Index, which is used for namespacing // Index which is used for namespacing
i++; i++;
var $this = $(this); var $this = $(this);
var $slide = $this.children(), var index = 0,
$slide = $this.children(),
$img = $("img", this), $img = $("img", this),
index = 0,
length = $slide.size(), length = $slide.size(),
namespace = "rslides" + i, namespace = "rslides",
namespaceIndex = namespace + i,
namespaceIndexClass = namespace + " " + namespaceIndex,
activeClass = namespace + "_here", activeClass = namespace + "_here",
visibleClass = namespace + '_on', visibleClass = namespaceIndex + "_on",
slideClassPrefix = namespace + "_s", slideClassPrefix = namespaceIndex + "_s",
tabsClass = namespaceIndex + "_tabs",
fadetime = parseFloat(settings.fade), fadetime = parseFloat(settings.fade),
tabsClass = namespace + "_tabs", $pagination = $("<ul class=\"" + namespace + "_tabs " + tabsClass + "\" />"),
$pagination = $("<ul class=\"" + tabsClass + "\" />"),
visible = {"float": "left", "position": "relative"}, visible = {"float": "left", "position": "relative"},
hidden = {"float": "none", "position": "absolute"}; hidden = {"float": "none", "position": "absolute"};
@ -59,15 +61,16 @@
this.id = slideClassPrefix + i; this.id = slideClassPrefix + i;
}); });
// Add max-width // Add max-width and classes
$this.css({ $this
"max-width": settings.maxwidth .css("max-width", settings.maxwidth)
}); .addClass(namespaceIndexClass);
// Hide all slides, then show first one // Hide all slides, then show first one
$slide $slide
.hide() .hide()
.eq(0) .eq(0)
.addClass(visibleClass)
.css(visible) .css(visible)
.show(); .show();
@ -103,13 +106,6 @@
$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 currently animated,
// otherwise if someone is using very long fade
// This'll break when changing slide at the same time
if ($('.' + visibleClass + ':animated').length) {
return false;
}
// Get index of clicked tab // Get index of clicked tab
var idx = $tabs.index(this); var idx = $tabs.index(this);
@ -118,6 +114,13 @@
return; return;
} }
// Prevent click/touch if currently animated,
// otherwise if someone is using very long fade
// This'll break when changing a slide at the same time
if ($("." + visibleClass + ":animated").length) {
return false;
}
// Remove active state from old tab and set new one // Remove active state from old tab and set new one
$tabs $tabs
.closest("li") .closest("li")

Loading…
Cancel
Save