Skip to content

Commit

Permalink
Removed a console log message from the stopAutoPlay method and cleane…
Browse files Browse the repository at this point in the history
…d up whitespace and tabs
  • Loading branch information
sebnitu committed Mar 13, 2012
1 parent e3097f3 commit 27575a3
Showing 1 changed file with 70 additions and 71 deletions.
141 changes: 70 additions & 71 deletions jquery.quovolver.js
Expand Up @@ -7,58 +7,58 @@
*/ */
(function($) { (function($) {
$.fn.quovolver = function(options) { $.fn.quovolver = function(options) {

// Extend our default options with those provided. // Extend our default options with those provided.
var opts = $.extend({}, $.fn.quovolver.defaults, options); var opts = $.extend({}, $.fn.quovolver.defaults, options);

// This allows for multiple instances of this plugin in the same document // This allows for multiple instances of this plugin in the same document
return this.each(function () { return this.each(function () {

// Save our object // Save our object
var $this = $(this); var $this = $(this);

// Build element specific options // Build element specific options
// This lets me access options with this syntax: o.optionName // This lets me access options with this syntax: o.optionName
var o = $.meta ? $.extend({}, opts, $this.data()) : opts; var o = $.meta ? $.extend({}, opts, $this.data()) : opts;

// Initial styles and markup // Initial styles and markup
$this.addClass('quovolve') $this.addClass('quovolve')
.css({ 'position' : 'relative' }) .css({ 'position' : 'relative' })
.wrap('<div class="quovolve-box"></div>'); .wrap('<div class="quovolve-box"></div>');

if( o.children ) { if( o.children ) {
var groupMethod = 'find'; var groupMethod = 'find';
} else { } else {
var groupMethod = 'children'; var groupMethod = 'children';
} }

// Initialize element specific variables // Initialize element specific variables
var $box = $this.parent('.quovolve-box'), var $box = $this.parent('.quovolve-box'),
$items = $this[groupMethod](o.children), $items = $this[groupMethod](o.children),
$active = 1, $active = 1,
$total = $items.length; $total = $items.length;

// Hide all except the first // Hide all except the first
$items.hide().filter(':first').show(); $items.hide().filter(':first').show();

// Call build navigation function // Call build navigation function
if ( o.navPrev || o.navNext || o.navNum || o.navText ) { if ( o.navPrev || o.navNext || o.navNum || o.navText ) {
o.navEnabled = true; o.navEnabled = true;
var $nav = buildNav(); var $nav = buildNav();
} else { } else {
o.navEnabled = false; o.navEnabled = false;
} }

// Call equal heights function // Call equal heights function
if (o.equalHeight) { if (o.equalHeight) {
equalHeight( $items ); equalHeight( $items );
// Recalculate equal heights on window resize // Recalculate equal heights on window resize
$(window).resize(function() { $(window).resize(function() {
equalHeight( $items ); equalHeight( $items );
$this.css('height', $($items[$active -1]).outerHeight() ); $this.css('height', $($items[$active -1]).outerHeight() );
}); });
} }

// Auto play interface // Auto play interface
if (o.autoPlay) { if (o.autoPlay) {
var $playID = autoPlay(); var $playID = autoPlay();
Expand All @@ -68,42 +68,42 @@
var $playID = pauseAutoPlay($playID); var $playID = pauseAutoPlay($playID);
} }
} }

// Go To function // Go To function
function gotoItem(itemNumber) { function gotoItem(itemNumber) {

// Check if stuff is already being animated and kill the script if it is // Check if stuff is already being animated and kill the script if it is
if( $items.is(':animated') || $this.is(':animated') ) return false; if( $items.is(':animated') || $this.is(':animated') ) return false;
// If the container has been hidden, kill the script // If the container has been hidden, kill the script
// This prevents the script from bugging out if something hides the revolving // This prevents the script from bugging out if something hides the revolving
// object from another script (tabs for example) // object from another script (tabs for example)
if( $box.is(':hidden') ) return false; if( $box.is(':hidden') ) return false;

// Don't let itemNumber go above or below possible options // Don't let itemNumber go above or below possible options
if ( itemNumber < 1 ) { if ( itemNumber < 1 ) {
itemNumber = $total; itemNumber = $total;
} else if ( itemNumber > $total ) { } else if ( itemNumber > $total ) {
itemNumber = 1; itemNumber = 1;
} }

// Create the data object to pass to our transition method // Create the data object to pass to our transition method
var gotoData = { var gotoData = {
current : $( $items[$active -1] ), // Save currently active item current : $( $items[$active -1] ), // Save currently active item
upcoming : $( $items[itemNumber - 1] ), // Save upcoming item upcoming : $( $items[itemNumber - 1] ), // Save upcoming item
} }

// Save current and upcoming hights and outer heights // Save current and upcoming hights and outer heights
gotoData.currentHeight = getHiddenProperty(gotoData.current), gotoData.currentHeight = getHiddenProperty(gotoData.current),
gotoData.upcomingHeight = getHiddenProperty(gotoData.upcoming), gotoData.upcomingHeight = getHiddenProperty(gotoData.upcoming),
gotoData.currentOuterHeight = getHiddenProperty(gotoData.current, 'outerHeight'), gotoData.currentOuterHeight = getHiddenProperty(gotoData.current, 'outerHeight'),
gotoData.upcomingOuterHeight = getHiddenProperty(gotoData.upcoming, 'outerHeight') gotoData.upcomingOuterHeight = getHiddenProperty(gotoData.upcoming, 'outerHeight')

// Save current and upcoming widths and outer widths // Save current and upcoming widths and outer widths
gotoData.currentWidth = getHiddenProperty(gotoData.current, 'width'), gotoData.currentWidth = getHiddenProperty(gotoData.current, 'width'),
gotoData.upcomingWidth = getHiddenProperty(gotoData.upcoming, 'width'), gotoData.upcomingWidth = getHiddenProperty(gotoData.upcoming, 'width'),
gotoData.currentOuterWidth = getHiddenProperty(gotoData.current, 'outerWidth'), gotoData.currentOuterWidth = getHiddenProperty(gotoData.current, 'outerWidth'),
gotoData.upcomingOuterWidth = getHiddenProperty(gotoData.upcoming, 'outerWidth') gotoData.upcomingOuterWidth = getHiddenProperty(gotoData.upcoming, 'outerWidth')

// Transition method // Transition method
if (o.transition != 'basic' && if (o.transition != 'basic' &&
typeof o.transition == 'string' && typeof o.transition == 'string' &&
Expand All @@ -114,18 +114,18 @@
// Default transition method // Default transition method
basic(gotoData); basic(gotoData);
} }

// Update active item // Update active item
$active = itemNumber; $active = itemNumber;

// Update navigation // Update navigation
updateNavNum($nav); updateNavNum($nav);
updateNavText($nav); updateNavText($nav);

// Disable default behavior // Disable default behavior
return false; return false;
} }

// Build navigation // Build navigation
function buildNav() { function buildNav() {
// Check the position of the nav and insert container // Check the position of the nav and insert container
Expand All @@ -145,7 +145,7 @@
console.log('Error', 'That custom selector did not return an element.'); console.log('Error', 'That custom selector did not return an element.');
} }
} }

// Previous and next navigation // Previous and next navigation
if ( o.navPrev ) { if ( o.navPrev ) {
nav.append('<span class="nav-prev"><a href="#">' + o.navPrevText + '</a></span>'); nav.append('<span class="nav-prev"><a href="#">' + o.navPrevText + '</a></span>');
Expand All @@ -168,15 +168,15 @@
nav.append('<span class="nav-text"></span>'); nav.append('<span class="nav-text"></span>');
updateNavText(nav); updateNavText(nav);
} }

return nav; return nav;
} }

// Get height of a hidden element // Get height of a hidden element
function getHiddenProperty(item, property) { function getHiddenProperty(item, property) {
// Default method // Default method
if (!property) property = 'height'; if (!property) property = 'height';

// Check if item was hidden // Check if item was hidden
if ( $(this).is(':hidden') ) { if ( $(this).is(':hidden') ) {
// Reveal the hidden item but not to the user // Reveal the hidden item but not to the user
Expand All @@ -185,7 +185,7 @@


// Get the requested property // Get the requested property
value = item[property](); value = item[property]();

// Check if item was hidden // Check if item was hidden
if ( $(this).is(':hidden') ) { if ( $(this).is(':hidden') ) {
// Return the originally hidden item to it's original state // Return the originally hidden item to it's original state
Expand All @@ -194,7 +194,7 @@
// Return the height // Return the height
return value; return value;
} }

// Equal Column Heights // Equal Column Heights
function equalHeight(group) { function equalHeight(group) {
var tallest = 0; var tallest = 0;
Expand All @@ -211,7 +211,7 @@
}); });
group.height(tallest); group.height(tallest);
} }

// Update numbered navigation // Update numbered navigation
function updateNavNum(nav) { function updateNavNum(nav) {
if (o.navEnabled) { if (o.navEnabled) {
Expand All @@ -222,24 +222,24 @@
.addClass('active'); .addClass('active');
} }
} }

// Update navigation description // Update navigation description
function updateNavText(nav) { function updateNavText(nav) {
if (o.navEnabled) { if (o.navEnabled) {
var content = o.navTextContent.replace('@a', $active).replace('@b', $total); var content = o.navTextContent.replace('@a', $active).replace('@b', $total);
nav.find('.nav-text').text(content); nav.find('.nav-text').text(content);
} }
} }

// Start auto play // Start auto play
function autoPlay() { function autoPlay() {
$box.addClass('play'); $box.addClass('play');
intervalID = setInterval(function() { intervalID = setInterval(function() {
gotoItem( $active + 1 ); gotoItem( $active + 1 );
}, o.autoPlaySpeed); }, o.autoPlaySpeed);
return intervalID; return intervalID;
} }

// Pause auto play // Pause auto play
function pauseAutoPlay(intervalID) { function pauseAutoPlay(intervalID) {
if ( o.stopAutoPlay !== true ) { if ( o.stopAutoPlay !== true ) {
Expand All @@ -254,17 +254,16 @@
return intervalID; return intervalID;
} }
} }

// Stop auto play // Stop auto play
function stopAutoPlay(intervalID) { function stopAutoPlay(intervalID) {
$box.hover(function() { $box.hover(function() {
$box.addClass('stop').removeClass('play'); $box.addClass('stop').removeClass('play');
clearInterval(intervalID); clearInterval(intervalID);
console.log('stop auto play');
}, function() {}); }, function() {});
return intervalID; return intervalID;
} }

// Transition Effects // Transition Effects
// Basic (default) Just swaps out items with no animation // Basic (default) Just swaps out items with no animation
function basic(data) { function basic(data) {
Expand All @@ -275,13 +274,13 @@
$this.css('height', 'auto'); $this.css('height', 'auto');
} }
} }

// Fade animation // Fade animation
function fade(data) { function fade(data) {

// Set container to current item's height // Set container to current item's height
$this.height(data.currentOuterHeight); $this.height(data.currentOuterHeight);

// Fade out the current container // Fade out the current container
data.current.fadeOut(o.transitionSpeed, function() { data.current.fadeOut(o.transitionSpeed, function() {
// Resize container to upcming item's height // Resize container to upcming item's height
Expand All @@ -295,55 +294,55 @@
}); });
}); });
}); });

} }

// Bind to the forward and back buttons // Bind to the forward and back buttons
$('.nav-prev a').click(function () { $('.nav-prev a').click(function () {
return gotoItem( $active - 1 ); return gotoItem( $active - 1 );
}); });
$('.nav-next a').click(function () { $('.nav-next a').click(function () {
return gotoItem( $active + 1 ); return gotoItem( $active + 1 );
}); });

// Bind the numbered navigation buttons // Bind the numbered navigation buttons
$('.nav-numbers a').click(function() { $('.nav-numbers a').click(function() {
return gotoItem( $(this).text() ); return gotoItem( $(this).text() );
}); });

// Create a public interface to move to a specific item // Create a public interface to move to a specific item
$(this).bind('goto', function (event, item) { $(this).bind('goto', function (event, item) {
gotoItem( item ); gotoItem( item );
}); });

}); // @end of return this.each() }); // @end of return this.each()


}; };


$.fn.quovolver.defaults = { $.fn.quovolver.defaults = {

children : '', // If selector is provided, we will use the find method to get the group of items children : '', // If selector is provided, we will use the find method to get the group of items

transition : 'fade', // The style of the transition transition : 'fade', // The style of the transition
transitionSpeed : 300, // This is the speed that each animation will take, not the entire transition transitionSpeed : 300, // This is the speed that each animation will take, not the entire transition

autoPlay : true, // Toggle auto rotate autoPlay : true, // Toggle auto rotate
autoPlaySpeed : 6000, // Duration before each transition autoPlaySpeed : 6000, // Duration before each transition
pauseOnHover : true, // Should the auto rotate pause on hover pauseOnHover : true, // Should the auto rotate pause on hover
stopOnHover : false, // Should the auto rotate stop on hover (and not continue after hover) stopOnHover : false, // Should the auto rotate stop on hover (and not continue after hover)
equalHeight : true, // Should every item have equal heights equalHeight : true, // Should every item have equal heights

navPosition : 'above', // above, below, both, custom (must provide custom selector for placement) navPosition : 'above', // above, below, both, custom (must provide custom selector for placement)
navPositionCustom : '', // selector of custom element navPositionCustom : '', // selector of custom element

navPrev : false, // Toggle "previous" button navPrev : false, // Toggle "previous" button
navNext : false, // Toggle "next" button navNext : false, // Toggle "next" button
navNum : false, // Toggle numbered navigation navNum : false, // Toggle numbered navigation
navText : false, // Toggle navigation description (e.g. display current item # and total item #) navText : false, // Toggle navigation description (e.g. display current item # and total item #)

navPrevText : 'Prev', // Text for the "previous" button navPrevText : 'Prev', // Text for the "previous" button
navNextText : 'Next', // Text for the "next" button navNextText : 'Next', // Text for the "next" button
navTextContent : '@a / @b' // @a will be replaced with current and @b with total navTextContent : '@a / @b' // @a will be replaced with current and @b with total

}; };
})(jQuery); })(jQuery);

0 comments on commit 27575a3

Please sign in to comment.