Browse Source

Small refactoring

pull/21/head
Viljami S 13 years ago
parent
commit
35073affd5
  1. 28
      responsiveslides.js

28
responsiveslides.js

@ -18,26 +18,31 @@
var $this = $(this); var $this = $(this);
var startCycle, rotate;
var index = 0, var index = 0,
$slide = $this.children(), $slide = $this.children(),
length = $slide.size(), length = $slide.size(),
fadetime = parseFloat(settings.fade),
// Namespacing
namespace = "rslides", namespace = "rslides",
namespaceIndex = namespace + i, namespaceIndex = namespace + i,
// Classes
namespaceIndexClass = namespace + " " + namespaceIndex, namespaceIndexClass = namespace + " " + namespaceIndex,
activeClass = namespace + "_here", activeClass = namespace + "_here",
visibleClass = namespaceIndex + "_on", visibleClass = namespaceIndex + "_on",
slideClassPrefix = namespaceIndex + "_s", slideClassPrefix = namespaceIndex + "_s",
tabsClass = namespaceIndex + "_tabs", tabsClass = namespaceIndex + "_tabs",
fadetime = parseFloat(settings.fade),
// Pagination
$pagination = $("<ul class=\"" + namespace + "_tabs " + tabsClass + "\" />"), $pagination = $("<ul class=\"" + namespace + "_tabs " + tabsClass + "\" />"),
// Styles for visible and hidden slides
visible = {"float": "left", "position": "relative"}, visible = {"float": "left", "position": "relative"},
hidden = {"float": "none", "position": "absolute"}; hidden = {"float": "none", "position": "absolute"};
// Fading animation // Fading animation
var slideTo = function (idx) { var slideTo = function (idx) {
$slide $slide
.stop() .stop()
.fadeOut(fadetime, function () { .fadeOut(fadetime, function () {
@ -67,7 +72,9 @@
.css("max-width", settings.maxwidth) .css("max-width", settings.maxwidth)
.addClass(namespaceIndexClass); .addClass(namespaceIndexClass);
// Hide all slides, then show first one // Hide all slides, then show first one + add visible
// class for that one. Later we are using that same
// class to check if it's currently :animated
$slide $slide
.hide() .hide()
.eq(0) .eq(0)
@ -96,6 +103,8 @@
// Auto rotation // Auto rotation
if (settings.auto === true) { if (settings.auto === true) {
var startCycle, rotate;
// Rotate slides automatically // Rotate slides automatically
startCycle = function () { startCycle = function () {
rotate = setInterval(function () { rotate = setInterval(function () {
@ -124,11 +133,10 @@
$tabs.on("ontouchstart" in window ? "touchstart" : "click", function (e) { $tabs.on("ontouchstart" in window ? "touchstart" : "click", function (e) {
e.preventDefault(); e.preventDefault();
// Stop auto rotation
clearInterval(rotate);
// ...Restart it
if (settings.auto === true) { if (settings.auto === true) {
// Stop auto rotation
clearInterval(rotate);
// ...Restart it
startCycle(); startCycle();
} }
@ -164,7 +172,7 @@
} }
// Add fallback if CSS max-width isn't supported and maxwidth is set // Add fallback if max-width isn't supported and settings "maxwidth" is set
if (typeof document.body.style.maxWidth === "undefined" && options && options.maxwidth) { if (typeof document.body.style.maxWidth === "undefined" && options && options.maxwidth) {
var widthSupport = function () { var widthSupport = function () {

Loading…
Cancel
Save