Browse Source

Code refactoring to save more bytes

pull/10/head
Viljami S 13 years ago
parent
commit
ac4d676817
  1. 146
      responsiveslides.js
  2. 8
      responsiveslides.min.js

146
responsiveslides.js

@ -1,6 +1,6 @@
/*! ResponsiveSlides.js v1.04. (c) 2011 Viljami Salminen. MIT License. http://responsive-slides.viljamis.com */ /*! ResponsiveSlides.js v1.04. (c) 2011-2012 Viljami Salminen. MIT License. http://responsive-slides.viljamis.com */
(function ($) { (function ($) {
$.fn.responsiveSlides = function (opts) { $.fn.responsiveSlides = function (options) {
// Settings // Settings
var settings = { var settings = {
'speed' : 4000, 'speed' : 4000,
@ -12,12 +12,11 @@
return this.each(function () { return this.each(function () {
var $this = $(this); var $this = $(this);
if (opts) { if (options) {
$.extend(settings, opts); $.extend(settings, options);
} }
var slideshow = function () { var slideshow = function () {
var $slide = $this.find('img'), var $slide = $this.find('img'),
namespace = settings.namespace, namespace = settings.namespace,
activeClass = namespace + '_here', activeClass = namespace + '_here',
@ -29,88 +28,85 @@
visible = { 'position': 'relative', 'float': 'left' }, visible = { 'position': 'relative', 'float': 'left' },
hidden = { 'position': 'absolute', 'float': 'none' }; hidden = { 'position': 'absolute', 'float': 'none' };
// 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) {
this.id = slideClassPrefix + i;
});
$slide.css({
'top': 0,
'left': 0,
'width': '100%',
'height': 'inherit',
'position': 'absolute'
});
$this.css({
'max-width': parseFloat(settings.maxwidth),
'width': '100%',
'overflow': 'hidden',
'position': 'relative'
});
$this.find(':first-child').css(visible);
$this.find($slide + ':gt(0)').hide();
// Auto: true
if (settings.auto === true) {
setInterval(function () {
$this.find(':first-child').fadeOut(fadetime, function () {
$(this).css(hidden);
}).next($slide).fadeIn(fadetime, function () {
$(this).css(visible);
}).end().appendTo($this);
}, parseFloat(settings.speed));
// Auto: false
} else {
tabMarkup = '';
$slide.each(function (i) { $slide.each(function (i) {
var n = i + 1; this.id = slideClassPrefix + i;
tabMarkup +=
'<li>' +
'<a href="#' + slideClassPrefix + n + '"' +
'class="' + slideClassPrefix + n + '">' + n + '</a>' +
'</li>';
}); });
$pagination.append(tabMarkup);
$this.after($pagination).find(':first-child').addClass(visibleClass); $slide.css({
$('.' + slideClassPrefix + '1').parent().addClass(activeClass); 'top': 0,
'left': 0,
$('.' + tabsClass + ' a').each(function (i) { 'width': '100%',
var $el = $(this); 'height': 'inherit',
'position': 'absolute'
});
$el.click(function (e) { $this.css({
e.preventDefault(); 'max-width': parseFloat(settings.maxwidth),
// Prevent clicking if animated 'width': '100%',
if ($('.' + visibleClass + ':animated').length) { 'overflow': 'hidden',
return false; 'position': 'relative'
} })
if (!($el.parent().hasClass(activeClass))) { .find(':first-child').css(visible).end()
$('.' + tabsClass + ' li').removeClass(activeClass); .find($slide + ':gt(0)').hide();
$('.' + visibleClass).stop().fadeOut(fadetime, function () {
$(this).removeClass(visibleClass).css(hidden); // Auto: true
}).end(); if (settings.auto === true) {
$('#' + slideClassPrefix + i).stop().fadeIn(fadetime, function () { setInterval(function () {
$(this).addClass(visibleClass).css(visible); $this.find(':first-child').fadeOut(fadetime, function () {
}).end(); $(this).css(hidden);
$el.parent().addClass(activeClass); }).next($slide).fadeIn(fadetime, function () {
} $(this).css(visible);
}).end().appendTo($this);
}, parseFloat(settings.speed));
// Auto: false
} else {
t = '';
$slide.each(function (i) {
var n = i + 1;
t +=
'<li>' +
'<a href="#' + slideClassPrefix + n + '"' +
'class="' + slideClassPrefix + n + '">' + n + '</a>' +
'</li>';
}); });
}); $pagination.append(t);
$this.after($pagination).find(':first-child').addClass(visibleClass);
$('.' + slideClassPrefix + '1').parent().addClass(activeClass);
$('.' + tabsClass + ' a').each(function (i) {
var $el = $(this);
$el.click(function (e) {
e.preventDefault();
// Prevent clicking if animated
if ($('.' + visibleClass + ':animated').length) {
return false;
}
if (!($el.parent().hasClass(activeClass))) {
$('.' + tabsClass + ' li').removeClass(activeClass);
$('.' + visibleClass).stop().fadeOut(fadetime, function () {
$(this).removeClass(visibleClass).css(hidden);
}).end();
$('#' + slideClassPrefix + i).stop().fadeIn(fadetime, function () {
$(this).addClass(visibleClass).css(visible);
}).end();
$el.parent().addClass(activeClass);
}
});
});
}
} }
}; };
// Fallback to make IE6 support CSS max-width // Fallback to make IE6 support CSS max-width
var widthSupport = function () { var widthSupport = function () {
var maxwidth = parseFloat(settings.maxwidth); var maxwidth = parseFloat(settings.maxwidth);
if (opts && opts.maxwidth) { if (options && options.maxwidth) {
if (typeof document.body.style.maxHeight === 'undefined') { if (typeof document.body.style.maxHeight === 'undefined') {
$this.each(function () { $this.each(function () {
$this.css('width', '100%'); $this.css('width', '100%');

8
responsiveslides.min.js vendored

@ -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-2012 Viljami Salminen. MIT License. http://responsive-slides.viljamis.com */
(function(a){a.fn.responsiveSlides=function(d){var c={speed:4E3,fade:1E3,auto:!0,maxwidth:"none",namespace:"rs"};return this.each(function(){var b=a(this);d&&a.extend(c,d);var g=function(){var a=parseFloat(c.maxwidth);d&&d.maxwidth&&"undefined"===typeof document.body.style.maxHeight&&b.each(function(){b.css("width","100%");b.width()>a?b.css("width",a):b.width()<a&&b.css("width","100%")})};(function(){var f=b.find("img"),e=c.namespace,d=e+"_here",h=e+"_on",i=e+"_s",k=e+"_tabs",e=a('<ul class="'+k+ (function(a){a.fn.responsiveSlides=function(d){var c={speed:4E3,fade:1E3,auto:!0,maxwidth:"none",namespace:"rs"};return this.each(function(){var b=a(this);d&&a.extend(c,d);var g=function(){var a=parseFloat(c.maxwidth);d&&d.maxwidth&&"undefined"===typeof document.body.style.maxHeight&&b.each(function(){b.css("width","100%");b.width()>a?b.css("width",a):b.width()<a&&b.css("width","100%")})};(function(){var f=b.find("img"),e=c.namespace,d=e+"_here",h=e+"_on",i=e+"_s",k=e+"_tabs",e=a('<ul class="'+k+
'" />'),j=parseFloat(c.fade),l={position:"relative","float":"left"},g={position:"absolute","float":"none"};1>=b.find(f).length||(f.each(function(a){this.id=i+a}),f.css({top:0,left:0,width:"100%",height:"inherit",position:"absolute"}),b.css({"max-width":parseFloat(c.maxwidth),width:"100%",overflow:"hidden",position:"relative"}),b.find(":first-child").css(l),b.find(f+":gt(0)").hide(),!0===c.auto?setInterval(function(){b.find(":first-child").fadeOut(j,function(){a(this).css(g)}).next(f).fadeIn(j,function(){a(this).css(l)}).end().appendTo(b)}, '" />'),j=parseFloat(c.fade),l={position:"relative","float":"left"},g={position:"absolute","float":"none"};1<b.find(f).length&&(f.each(function(a){this.id=i+a}),f.css({top:0,left:0,width:"100%",height:"inherit",position:"absolute"}),b.css({"max-width":parseFloat(c.maxwidth),width:"100%",overflow:"hidden",position:"relative"}).find(":first-child").css(l).end().find(f+":gt(0)").hide(),!0===c.auto?setInterval(function(){b.find(":first-child").fadeOut(j,function(){a(this).css(g)}).next(f).fadeIn(j,function(){a(this).css(l)}).end().appendTo(b)},
parseFloat(c.speed)):(tabMarkup="",f.each(function(a){a+=1;tabMarkup+='<li><a href="#'+i+a+'"class="'+i+a+'">'+a+"</a></li>"}),e.append(tabMarkup),b.after(e).find(":first-child").addClass(h),a("."+i+"1").parent().addClass(d),a("."+k+" a").each(function(b){var c=a(this);c.click(function(e){e.preventDefault();if(a("."+h+":animated").length)return!1;c.parent().hasClass(d)||(a("."+k+" li").removeClass(d),a("."+h).stop().fadeOut(j,function(){a(this).removeClass(h).css(g)}).end(),a("#"+i+b).stop().fadeIn(j, parseFloat(c.speed)):(t="",f.each(function(a){a+=1;t+='<li><a href="#'+i+a+'"class="'+i+a+'">'+a+"</a></li>"}),e.append(t),b.after(e).find(":first-child").addClass(h),a("."+i+"1").parent().addClass(d),a("."+k+" a").each(function(b){var c=a(this);c.click(function(e){e.preventDefault();if(a("."+h+":animated").length)return!1;c.parent().hasClass(d)||(a("."+k+" li").removeClass(d),a("."+h).stop().fadeOut(j,function(){a(this).removeClass(h).css(g)}).end(),a("#"+i+b).stop().fadeIn(j,function(){a(this).addClass(h).css(l)}).end(),
function(){a(this).addClass(h).css(l)}).end(),c.parent().addClass(d))})})))})();g();a(window).resize(function(){g()})})}})(jQuery); c.parent().addClass(d))})})))})();g();a(window).resize(function(){g()})})}})(jQuery);
Loading…
Cancel
Save