Created
May 13, 2010 19:54
-
-
Save davehimself/400378 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
var $container = null; | |
var $previous = null; | |
var config = {} | |
$.fn.AddressSlider = function(options) { | |
settings = { | |
pidData: pidData, | |
showCallback: null, | |
hideCallback: null, | |
animationDuration: 500, | |
isCTA: false, | |
alignRight: 0, | |
leftBound: 0 | |
} | |
config = $.extend({}, settings, options) | |
this.each(function() { | |
var context = { | |
container: this, | |
pidData: config.pidData | |
} | |
$(this).find('a:last').bind('click', context, $.fn.AddressSlider.show); | |
$('.address-xbutton').click($.fn.AddressSlider.hide); | |
}); | |
return this | |
} | |
$.fn.AddressSlider.show = function(evt) { | |
evt.preventDefault(); | |
$container = $(evt.data.container); | |
var pidData = evt.data.pidData; | |
if ($previous != null) { | |
$.fn.AddressSlider.hide(); | |
} | |
$previous = $container; | |
if (pidData) { | |
var $a = $(evt.target).parent(); | |
if ($a) { | |
var pid = $a.attr('href').match(/\?id=(\d+)/).pop(); | |
$('#scKey').val(pidData[pid].scKey); | |
if (typeof(pidData[pid].spId) != 'undefined' | |
&& typeof(pidData[pid].keyword) != 'undefined') | |
{ | |
$('#spId').val(pidData[pid].spId); | |
$('#keyword').val(pidData[pid].keyword); | |
} else { | |
$('#packageID').val(pidData[pid].packageId); | |
$('#scpId').val(pidData[pid].scpId); | |
} | |
} | |
} | |
if (config.isCTA == true) { | |
console.log('isCTA'); | |
$('body').addClass('ctaLogin').removeClass('gridLogin'); | |
} else { | |
console.log('no cta'); | |
$('body').addClass('gridLogin').removeClass('ctaLogin'); | |
$container.fadeTo(config.animationDuration, 0, function() { | |
$('.login-box').css({ | |
'position': 'absolute', | |
'left' : config.leftBound | |
}); | |
}); | |
} | |
$('#login-box').css({ | |
'top' : $container.offset().top, | |
'height' : $container.height(), | |
'display' : 'block', | |
'left' : 0, | |
'overflow': 'hidden' | |
}).fadeTo(config.animationDuration, 1, function() { | |
if (!$.support.opacity) { | |
$('#login-box').get(0).style.removeAttribute('filter'); | |
} | |
$('#login-box').show(0, function() { | |
$('.login-box').css({ 'visibility': 'visible' }).animate({ | |
'left': config.leftMargin | |
}, config.animationDuration); | |
}); | |
}); | |
if (config.showCallback != null) { | |
config.showCallback.call(evt, $container, $previous); | |
} | |
} | |
$.fn.AddressSlider.hide = function(evt) { | |
jQuery('#login-box').hide(config.animationDuration); | |
$previous.addClass('visible').fadeTo(config.animationDuration, 1); | |
if (config.isCTA == true) { | |
console.log('hiding cta'); | |
if ($previous != null) { | |
$previous.find('.features').toggleClass('visible'); | |
$previous.find('.specials').toggleClass('visible'); | |
} | |
} else { | |
console.log('hiding not cta'); | |
if ($previous != null) { | |
$previous.toggleClass('visible').fadeTo(config.animationDuration, 1); | |
} | |
} | |
if (config.hideCallback != null) { | |
config.hideCallback.call(evt, $container, $previous); | |
} | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment