Skip to content

Instantly share code, notes, and snippets.

@EthanGould
Last active November 21, 2016 15:35
Show Gist options
  • Save EthanGould/0be8cae5ae7aadb54ab5f68fdc948f56 to your computer and use it in GitHub Desktop.
Save EthanGould/0be8cae5ae7aadb54ab5f68fdc948f56 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
(function($) {
var module = {};
module.init = function() {
this.$contentBtn = $('.js-content-btn');
this.$sliderNav = $('.js-slider-nav');
this.$slides = $('.toolbox-slide');
this.$slideCount = $('.js-slide-count');
$('#side-header').remove();
$('#wrapper').css('margin-left', '0');
$('#main .fusion-row').css('max-width', 'none');
this.eventHandlers();
};
module.eventHandlers = function() {
module.$contentBtn.click(module.updateContent);
module.$sliderNav.click(module.moveSlide);
};
module.moveSlide = function() {
$btn = $(this);
var direction = $btn.data('slide');
var curSlide = module.$slides.not(':hidden').index();
var count = curSlide + 1;
// Move slide show forward;
if ( 'right' === direction ) {
if ( curSlide >= 0 && curSlide + 1 < module.$slides.length ) {
module.$slides.hide();
$(module.$slides[curSlide + 1]).fadeIn();
count +=1;
}
// Move slide show backwards;
} else if ( 'left' === direction ) {
console.log(curSlide, direction);
if ( curSlide > 0 ) {
module.$slides.hide();
$(module.$slides[curSlide - 1]).fadeIn();
count--;
}
}
// Update slide count;
module.$slideCount.text(count);
};
module.updateContent = function() {
var $btn = $(this);
var msgId = $btn.data('btn'); // get message ID
var msg = $('.js-content-msg[data-list-id="' + msgId + '"]'); //find selected message
$('.js-content-msg').hide();
msg.fadeIn(); //show the message text
// if on a phone, scroll user up to the content
// area once they click a new "solution" button
if ( $(window).width() < 768 ) {
msg[0].scrollIntoView(true);
// account for fixed header
var scrolledY = window.scrollY;
if(scrolledY){
window.scroll(0, scrolledY - 200);
}
}
// reset currently active btn
var $currentBtn = $('.js-content-btn.active');
var defaultImage = $currentBtn.css('backgroundImage').replace('Selected', 'Default');
$currentBtn.css('backgroundImage', defaultImage).removeClass('active')
var selectedBackground = $btn.css('backgroundImage').replace('Default', 'Selected');
$btn.css('backgroundImage', selectedBackground).addClass('active');
};
$(document).ready(function() {
module.init();
});
}(jQuery));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment