Permalink
Browse files

Cleaning up a bit

Signed-off-by: Matt McManus <mattmcmanus@gmail.com>
  • Loading branch information...
1 parent 233a677 commit 06e4b867c2a3ce0e08d43feb5adc6a6740c544e0 Mike Nicholaides committed with May 15, 2009
Showing with 37 additions and 29 deletions.
  1. +37 −29 jquery.fadeAble.js
View
@@ -1,4 +1,4 @@
-(function($) {
+;(function($) {
$.fn.fadeAble = function(options) {
var defaults = {
prevId: 'prevButton',
@@ -23,60 +23,68 @@
var container = this;
var containerImage = $(container).children('img');
- $(container).css({'position':'relative','height':$(containerImage).height(),'width':$(containerImage).width()});
+ $(container).css({
+ position: 'relative',
+ height: $(containerImage).height(),
+ width: $(containerImage).width()
+ });
$(options.images).each(function(){
$(container).append('<img style="display:none" src="'+this+'" />');
});
- $(container).children('img').css({'position':'absolute','top':'0','left':'0','z-index':'-1'});
+ $(container).children('img').css({
+ position: 'absolute',
+ top: 0,
+ left: 0,
+ 'z-index': -1
+ });
- options.images = $.merge([$(container).children('img:eq(0)').attr('src')],options.images);
+ //prepend $(img:first).src to array
+ options.images.unshift($(container).children('img:first').attr('src'));
- if (options.controlsShow){
- var controls = ' <span class="button" id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
- controls += ' <span class="button" id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
- $(this).append(controls);
+ if (options.controlsShow) {
+ $(this).append(
+ ' <span class="button" id="'+options.prevId+'">' + \
+ '<a href=\"javascript:void(0);\">'+ \
+ options.prevText +'</a></span> <span class="button" id="'+options.nextId+'">' + \
+ '<a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>'
+ );
- $("#"+options.nextId).click(function(){
- fade("next", container);
- });
- $("#"+options.prevId).click(function(){
- fade("prev", container);
- });
- };
+ $("#"+options.nextId).click(function(){ fade("next", container); });
+ $("#"+options.prevId).click(function(){ fade("prev", container); });
+ }
if (options.loop) {
options.timeout = setTimeout(function(){
fade("next", container);
- },options.pause);
- };
+ }, options.pause);
+ }
});
function fade(direction, container) {
- if (options.timeout) {clearTimeout(options.timeout)};
+ if (options.timeout) {
+ clearTimeout(options.timeout);
+ }
var nextIndex;
if (direction == 'prev') {
nextIndex = ( options.current == 0 ) ? options.images.length-1 : options.current-1;
} else {
nextIndex = ( options.current == options.images.length-1 ) ? 0 : options.current+1;
-
- };
+ }
- $(container).children('img:eq('+nextIndex+')').fadeIn(options.speed);
- $(container).children('img:eq('+options.current+')').fadeOut(options.speed);
+ var imgs = $(container).children('img');
+ children.eq(nextIndex).fadeIn(options.speed);
+ children.eq(options.current).fadeOut(options.speed);
options.current = nextIndex;
if (options.loop) {
options.timeout = setTimeout(function(){
fade("next", container);
- },options.pause);
- };
- };
+ }, options.pause);
+ }
+ }
};
-})(jQuery);
-
-
-
+})(jQuery);

0 comments on commit 06e4b86

Please sign in to comment.