Skip to content

Instantly share code, notes, and snippets.

@shwoodard
Created May 16, 2009 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shwoodard/112791 to your computer and use it in GitHub Desktop.
Save shwoodard/112791 to your computer and use it in GitHub Desktop.
$.currActive;
$.imageCount;
$.fn.preCacheImageFromThumb = function () {
return $(this).each(function () {
var img = new Image();
img.src = $(this).attr('href');
});
};
$.removeCurrActive = function () {
if ($.currActive) {
$.currActive.find('.staging_thumb-numb-indicator').removeClass('active');
$.currActive = null;
}
};
$.setCurrActive = function (currActive) {
$.removeCurrActive();
$.currActive = $(currActive);
$.currActive.find('.staging_thumb-numb-indicator').addClass('active');
$('#staging_main-image').attr('src', $.currActive.attr('href'));
};
$(document).ready(function () {
$.imageCount = $('.staging_thumb-link').length;
$.currActive = $('.staging_thumb-numb-indicator.active').closest('a');
$('.staging_thumb-link').preCacheImageFromThumb().click(function (evt) {
evt.preventDefault();
$.setCurrActive(this);
});
$('.staging_secondary-photo-nav').click(function(evt) {
evt.preventDefault();
var currIndex = parseInt($.currActive.attr('id').substr("staging_thumb-link-".length), 10);
var delta = parseInt($(this).attr('rel'), 10);
var nextIndex = (currIndex + ($.imageCount + delta)) % $.imageCount;
console.log(nextIndex);
$.setCurrActive($("#staging_thumb-link-" + nextIndex));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment