Browse Source

Moves local variables to top + other optimization

pull/32/merge
Viljami S 13 years ago
parent
commit
bda5523122
  1. 103
      responsiveslides.js
  2. 8
      responsiveslides.min.js

103
responsiveslides.js

@ -12,7 +12,7 @@
"prev": "Previous", // String: Text for the "previous" button
"next": "Next", // String: Text for the "next" button
"maxwidth": "none", // Integer: Max-width of the slideshow, in pixels
"controls": "", // Selector: Where all controls should be appended to, default is after the <ul>
"controls": "", // Selector: Where controls should be appended to, default is after the <ul>
"namespace": "rslides" // String: change the default namespace used
}, options);
@ -21,9 +21,17 @@
// Index for namespacing
i++;
var $this = $(this);
var $this = $(this),
var index = 0,
// Local variables
selectTab,
startCycle,
restartCycle,
rotate,
$tabs,
// Helpers
index = 0,
$slide = $this.children(),
length = $slide.size(),
fadetime = parseFloat(settings.speed),
@ -38,34 +46,33 @@
activeClass = namespace + "_here",
visibleClass = namespaceIdx + "_on",
slideClassPrefix = namespaceIdx + "_s",
tabsClass = namespaceIdx + "_tabs",
// Pager
$pager = $("<ul class='" + namespace + "_tabs " + tabsClass + "' />"),
$pager = $("<ul class='" + namespace + "_tabs " + namespaceIdx + "_tabs' />"),
// Styles for visible and hidden slides
visible = {"float": "left", "position": "relative"},
hidden = {"float": "none", "position": "absolute"};
// Fading animation
var slideTo = function (idx) {
$this.trigger(namespace + "-before");
$slide
.stop()
.fadeOut(fadetime, function () {
$(this)
.removeClass(visibleClass)
.css(hidden);
})
.eq(idx)
.fadeIn(fadetime, function () {
$(this)
.addClass(visibleClass)
.css(visible)
.trigger(namespace + "-after");
index = idx;
});
};
hidden = {"float": "none", "position": "absolute"},
// Fading animation
slideTo = function (idx) {
$this.trigger(namespace + "-before");
$slide
.stop()
.fadeOut(fadetime, function () {
$(this)
.removeClass(visibleClass)
.css(hidden);
})
.eq(idx)
.fadeIn(fadetime, function () {
$(this)
.addClass(visibleClass)
.css(visible)
.trigger(namespace + "-after");
index = idx;
});
};
// Only run if there's more than one slide
if ($slide.size() > 1) {
@ -80,7 +87,7 @@
.css("max-width", settings.maxwidth)
.addClass(namespaceIdxClass);
// Hide all slides, then show first one + add visible class
// Hide all slides, then show first one
$slide
.hide()
.eq(0)
@ -100,7 +107,7 @@
});
$pager.append(tabMarkup);
var $tabs = $pager.find("a");
$tabs = $pager.find("a");
// Inject pager
if (options.controls) {
@ -110,7 +117,7 @@
}
// Select pager item
var selectTab = function (idx) {
selectTab = function (idx) {
$tabs
.closest("li")
.removeClass(activeClass)
@ -121,7 +128,6 @@
// Auto cycle
if (settings.auto === true) {
var startCycle, rotate;
startCycle = function () {
rotate = setInterval(function () {
@ -141,7 +147,7 @@
}
// Restarting cycle
var restartCycle = function () {
restartCycle = function () {
if (settings.auto === true) {
// Stop
clearInterval(rotate);
@ -150,25 +156,17 @@
}
};
// Prevent clicking if currently animated
var preventClick = function (event) {
if ($("." + visibleClass + ":animated").length) {
event.preventDefault();
}
};
// Pager click event handler
if (settings.pager === true) {
$tabs.on("click", function (event) {
event.preventDefault();
preventClick();
$tabs.bind("click", function (e) {
e.preventDefault();
restartCycle();
// Get index of clicked tab
var idx = $tabs.index(this);
// Break if element is already active
if (index === idx) {
// Break if element is already active or currently animated
if (index === idx || $("." + visibleClass + ":animated").length) {
return;
}
@ -199,13 +197,16 @@
}
var $trigger = $("." + namespaceIdx + "_nav"),
$prev = $("." + namespaceIdx + "_nav.prev"),
$next = $("." + namespaceIdx + "_nav.next");
$prev = $("." + namespaceIdx + "_nav.prev");
// Click event handler
$trigger.on("click", function (event) {
event.preventDefault();
preventClick();
$trigger.bind("click", function (e) {
e.preventDefault();
// Prevent clicking if currently animated
if ($("." + visibleClass + ":animated").length) {
return;
}
// Determine where to slide
var idx = $slide.index($("." + visibleClass)),
@ -226,14 +227,14 @@
if (typeof document.body.style.maxWidth === "undefined" && options && options.maxwidth) {
var widthSupport = function () {
$this.css("width", "100%");
if ($this.width() > settings.maxwidth) {
$this.css("width", settings.maxwidth);
if ($this.width() > parseFloat(settings.maxwidth)) {
$this.css("width", parseFloat(settings.maxwidth));
}
};
// Init fallback
widthSupport();
$(window).on("resize", function () {
$(window).bind("resize", function () {
widthSupport();
});
}

8
responsiveslides.min.js vendored

@ -1,5 +1,5 @@
/*! http://responsive-slides.viljamis.com v1.23 by @viljamis */
(function(c,D,s){c.fn.responsiveSlides=function(i){var b=c.extend({auto:!0,speed:1E3,timeout:4E3,pager:!1,nav:!1,prev:"Previous",next:"Next",maxwidth:"none",controls:"",namespace:"rslides"},i);return this.each(function(){s++;var d=c(this),j=0,f=d.children(),t=f.size(),u=parseFloat(b.speed),g=b.namespace,e=g+s,h=g+" "+e,v=g+"_nav "+e+"_nav",m=g+"_here",k=e+"_on",w=e+"_s",l=c("<ul class='"+g+"_tabs "+(e+"_tabs")+"' />"),x={"float":"left",position:"relative"},E={"float":"none",position:"absolute"},n=
function(a){d.trigger(g+"-before");f.stop().fadeOut(u,function(){c(this).removeClass(k).css(E)}).eq(a).fadeIn(u,function(){c(this).addClass(k).css(x).trigger(g+"-after");j=a})};if(1<f.size()){f.each(function(a){this.id=w+a});d.css("max-width",b.maxwidth).addClass(h);f.hide().eq(0).addClass(k).css(x).show();if(!0===b.pager){var o=[];f.each(function(a){a+=1;o+="<li><a href='#' class='"+w+a+"'>"+a+"</a></li>"});l.append(o);var p=l.find("a");i.controls?c(b.controls).append(l):d.after(l);var q=function(a){p.closest("li").removeClass(m).eq(a).addClass(m)}}if(!0===
b.auto){var r,y;r=function(){y=setInterval(function(){var a=j+1<t?j+1:0;!0===b.pager&&q(a);n(a)},parseFloat(b.timeout))};r()}var z=function(){!0===b.auto&&(clearInterval(y),r())},A=function(a){c("."+k+":animated").length&&a.preventDefault()};!0===b.pager&&p.on("click",function(a){a.preventDefault();A();z();a=p.index(this);j!==a&&(q(a),n(a))}).eq(0).closest("li").addClass(m)}if(!0===b.nav){h="<a href='#' class='"+v+" prev'>"+b.prev+"</a><a href='#' class='"+v+" next'>"+b.next+"</a>";i.controls?c(b.controls).append(h):
d.after(h);var h=c("."+e+"_nav"),B=c("."+e+"_nav.prev");c("."+e+"_nav.next");h.on("click",function(a){a.preventDefault();A();var d=f.index(c("."+k)),a=d-1,d=d+1<t?j+1:0;n(c(this)===B?a:d);!0===b.pager&&q(c(this)===B?a:d);z()})}if("undefined"===typeof document.body.style.maxWidth&&i&&i.maxwidth){var C=function(){d.css("width","100%");d.width()>b.maxwidth&&d.css("width",b.maxwidth)};C();c(D).on("resize",function(){C()})}})}})(jQuery,this,0);
(function(c,C,t){c.fn.responsiveSlides=function(j){var b=c.extend({auto:!0,speed:1E3,timeout:4E3,pager:!1,nav:!1,prev:"Previous",next:"Next",maxwidth:"none",controls:"",namespace:"rslides"},j);return this.each(function(){t++;var d=c(this),l,o,p,u,m,k=0,e=d.children(),v=e.size(),w=parseFloat(b.speed),f=b.namespace,g=f+t,h=f+" "+g,x=f+"_nav "+g+"_nav",q=f+"_here",i=g+"_on",y=g+"_s",n=c("<ul class='"+f+"_tabs "+g+"_tabs' />"),z={"float":"left",position:"relative"},D={"float":"none",position:"absolute"},
r=function(a){d.trigger(f+"-before");e.stop().fadeOut(w,function(){c(this).removeClass(i).css(D)}).eq(a).fadeIn(w,function(){c(this).addClass(i).css(z).trigger(f+"-after");k=a})};if(1<e.size()){e.each(function(a){this.id=y+a});d.css("max-width",b.maxwidth).addClass(h);e.hide().eq(0).addClass(i).css(z).show();if(!0===b.pager){var s=[];e.each(function(a){a+=1;s+="<li><a href='#' class='"+y+a+"'>"+a+"</a></li>"});n.append(s);m=n.find("a");j.controls?c(b.controls).append(n):d.after(n);l=function(a){m.closest("li").removeClass(q).eq(a).addClass(q)}}!0===
b.auto&&(o=function(){u=setInterval(function(){var a=k+1<v?k+1:0;!0===b.pager&&l(a);r(a)},parseFloat(b.timeout))},o());p=function(){if(b.auto===true){clearInterval(u);o()}};!0===b.pager&&m.bind("click",function(a){a.preventDefault();p();a=m.index(this);if(!(k===a||c("."+i+":animated").length)){l(a);r(a)}}).eq(0).closest("li").addClass(q)}if(!0===b.nav){h="<a href='#' class='"+x+" prev'>"+b.prev+"</a><a href='#' class='"+x+" next'>"+b.next+"</a>";j.controls?c(b.controls).append(h):d.after(h);var h=
c("."+g+"_nav"),A=c("."+g+"_nav.prev");h.bind("click",function(a){a.preventDefault();if(!c("."+i+":animated").length){var d=e.index(c("."+i)),a=d-1,d=d+1<v?k+1:0;r(c(this)===A?a:d);!0===b.pager&&l(c(this)===A?a:d);p()}})}if("undefined"===typeof document.body.style.maxWidth&&j&&j.maxwidth){var B=function(){d.css("width","100%");d.width()>parseFloat(b.maxwidth)&&d.css("width",parseFloat(b.maxwidth))};B();c(C).bind("resize",function(){B()})}})}})(jQuery,this,0);
Loading…
Cancel
Save