Browse Source

some more minification optimization; two comments of possibly nonsensible code.

pull/7/head
Tuomas Salo 13 years ago
parent
commit
022ab13abd
  1. 56
      responsiveslides.js

56
responsiveslides.js

@ -1,5 +1,5 @@
/*! ResponsiveSlides.js v1.04. (c) 2011 Viljami Salminen. MIT License. http://responsive-slides.viljamis.com */ /*! ResponsiveSlides.js v1.04. (c) 2011 Viljami Salminen. MIT License. http://responsive-slides.viljamis.com */
(function ($) { (function ($, window) {
$.fn.responsiveSlides = function (opts) { $.fn.responsiveSlides = function (opts) {
// Settings // Settings
@ -9,7 +9,8 @@
'auto' : true, 'auto' : true,
'maxwidth' : 'none', 'maxwidth' : 'none',
'namespace' : 'rs' 'namespace' : 'rs'
}; },
parseF = parseFloat; /* for minification */
return this.each(function () { return this.each(function () {
@ -19,8 +20,6 @@
$.extend(settings, opts); $.extend(settings, opts);
} }
var slideshow = function () {
var $slide = $this.find('img'), var $slide = $this.find('img'),
hasTouch = 'ontouchstart' in window, hasTouch = 'ontouchstart' in window,
startEvent = hasTouch ? 'touchstart' : 'mousedown', startEvent = hasTouch ? 'touchstart' : 'mousedown',
@ -29,15 +28,14 @@
visibleClass = namespace + '_on', visibleClass = namespace + '_on',
slideClassPrefix = namespace + '_s', slideClassPrefix = namespace + '_s',
tabsClass = namespace + '_tabs', tabsClass = namespace + '_tabs',
$pagination = $('<ul class="' + tabsClass + '" />'), $pagination = $('<ul class="' + tabsClass + '"/>'),
fadetime = parseFloat(settings.fade), fadetime = parseF(settings.fade),
visible = { 'position': 'relative', 'float': 'left' }, visible = { 'position': 'relative', 'float': 'left' },
hidden = { 'position': 'absolute', 'float': 'none' }; hidden = { 'position': 'absolute', 'float': 'none' },
maxW = parseF(settings.maxwidth);
// Don't run if there's only one slide // Only run if there's more than one slide
if ($this.find($slide).length <= 1) { if ($this.find($slide).length > 1) {
return;
}
$slide.each(function (i) { $slide.each(function (i) {
this.id = slideClassPrefix + i; this.id = slideClassPrefix + i;
@ -52,24 +50,24 @@
}); });
$this.css({ $this.css({
'max-width': parseFloat(settings.maxwidth), 'max-width': maxW,
'width': '100%', 'width': '100%',
'overflow': 'hidden', 'overflow': 'hidden',
'position': 'relative' 'position': 'relative'
}); });
$this.find(':first-child').css(visible); $this.find(":first-child").css(visible);
$this.find($slide + ':gt(0)').hide(); $this.find($slide + ':gt(0)').hide(); // <-- this makes no sense, since the selector becomes "[object Object]:gt(0)"
// Auto: true // Auto: true
if (settings.auto === true) { if (settings.auto === true) {
setInterval(function () { setInterval(function () {
$this.find(':first-child').fadeOut(fadetime, function () { $this.find(":first-child").fadeOut(fadetime, function () {
$(this).css(hidden); $(this).css(hidden);
}).next($slide).fadeIn(fadetime, function () { }).next($slide).fadeIn(fadetime, function () {
$(this).css(visible); $(this).css(visible);
}).end().appendTo($this); }).end().appendTo($this);
}, parseFloat(settings.speed)); }, parseF(settings.speed));
// Auto: false // Auto: false
} else { } else {
@ -87,7 +85,7 @@
$pagination.append(tabMarkup); $pagination.append(tabMarkup);
$this.after($pagination).find(':first-child').addClass(visibleClass); $this.after($pagination).find(":first-child").addClass(visibleClass);
$('.' + slideClassPrefix + '1').parent().addClass(activeClass); $('.' + slideClassPrefix + '1').parent().addClass(activeClass);
$('.' + tabsClass + ' a').each(function (i) { $('.' + tabsClass + ' a').each(function (i) {
@ -120,33 +118,27 @@
}); });
} }
}
};
// Fallback to make IE6 support CSS max-width // Fallback to make IE6 support CSS max-width
var widthSupport = function () { if (typeof document.body.style.maxHeight === 'undefined') {
function widthSupport() {
var maxwidth = parseFloat(settings.maxwidth);
if (opts && opts.maxwidth) { if (opts && opts.maxwidth) {
if (typeof document.body.style.maxHeight === 'undefined') {
$this.each(function () { $this.each(function () {
$this.css('width', '100%'); $this.css('width', '100%');
if ($this.width() > maxwidth) { if ($this.width() > maxW) {
$this.css('width', maxwidth); $this.css('width', maxW);
} else if ($this.width() < maxwidth) { } else if ($this.width() < maxW) {
$this.css('width', '100%'); $this.css('width', '100%'); // <-- really necessary to do this twice?
} }
}); });
} }
} }
};
// Call once // Call once
slideshow();
widthSupport(); widthSupport();
// Call on resize // Call on resize
@ -154,6 +146,8 @@
widthSupport(); widthSupport();
}); });
}
}); });
}; };
})(jQuery); })(jQuery, this);
Loading…
Cancel
Save