Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var pickEvent = {
- // Declare variables
- config: {
- peopleContainer: $('.event-solo-team'),
- peopleDiv: $('.event-solo-team div'),
- soloDiv: $('.event-solo-team .solo'),
- distanceContainer: $('.event-distances-all'),
- distanceDiv: $('.event-distance'),
- timeContainer: $('.event-times'),
- timeDiv: $('.event-time'),
- timeItem: $('.event-time label'),
- speedDiv: $('.event-speed'),
- speedItem: $('.event-speed div'),
- priceContainer: $('.event_prices-all'),
- priceDiv: $('.event-prices'),
- priceName: $('.event-prices-names'),
- navLink: $('a[href*=#]:not([href=#])')
- },
- init: function() {
- // Setup solo active
- pickEvent.config.soloDiv.addClass('active');
- // Function starts
- pickEvent.pickTeam();
- pickEvent.pickDistance();
- pickEvent.pickTime();
- pickEvent.pickSpeed();
- pickEvent.goToSection();
- pickEvent.disableTime();
- // Display first price
- pickEvent.config.priceDiv.first().show();
- pickEvent.config.priceName.first().show();
- },
- pickTeam: function(){
- pickEvent.config.peopleDiv.on('click', function(){
- // Reset all sections
- pickEvent.resetAll();
- // Set active trail
- $(this).addClass('active');
- $(this).find('input[type=radio]').attr('checked', true);
- // Hide 2.5k if user pick team
- var hideIt = pickEvent.config.distanceContainer.find('div[data-dist="2.5"]');
- $(this).data('team') === 'team' ? hideIt.hide() : hideIt.show();
- // Align distance items
- var total = pickEvent.config.distanceDiv.filter(':visible').size();
- pickEvent.config.distanceContainer.addClass('total-' + total);
- // Scrolling to div
- pickEvent.scrollTo(pickEvent.config.distanceContainer);
- // Display corrent price name
- var team = $(this).data('team');
- pickEvent.config.priceName.hide();
- pickEvent.config.priceName.filter(function(index) {
- return $(this).data('team') == team;
- }).show();
- });
- },
- pickDistance: function() {
- // Hide divs
- pickEvent.config.timeContainer.hide();
- pickEvent.config.timeDiv.hide();
- pickEvent.config.priceDiv.hide();
- pickEvent.config.priceName.hide();
- // Select distance
- pickEvent.config.distanceDiv.on('click', function(){
- // Display start time
- pickEvent.config.timeContainer.slideDown('slow');
- // Set active trail
- pickEvent.config.distanceDiv.removeClass('active');
- $(this).addClass('active');
- // Display matched time slots
- var team = pickEvent.config.peopleContainer.find('.active').data('team');
- var dist = $(this).data('dist');
- pickEvent.config.timeDiv.hide();
- pickEvent.config.timeDiv.filter(function(index) {
- return $(this).data('dist') == dist
- && $(this).data('team') == team;
- }).show();
- pickEvent.config.priceDiv.hide();
- pickEvent.config.priceDiv.filter(function(index) {
- return $(this).data('dist') == dist
- && $(this).data('team') == team;
- }).show();
- // Change radio name for solo & relay
- pickEvent.config.peopleContainer.find('input').attr('name', 'solo_relay[' + dist +']');
- // Scrolling to div
- pickEvent.scrollTo(pickEvent.config.timeContainer);
- });
- },
- pickTime: function() {
- pickEvent.config.timeItem.filter('.live').on('click', function(){
- pickEvent.config.timeItem.removeClass('active');
- $(this).addClass('active');
- // Update activity id
- var activityId = $(this).attr('for');
- $('#activity_id').val(activityId);
- // Scrolling to div
- pickEvent.scrollTo(pickEvent.config.speedDiv);
- });
- },
- pickSpeed: function() {
- pickEvent.config.speedItem.on('click', function(){
- // Scrolling to div
- pickEvent.scrollTo(pickEvent.config.priceContainer);
- });
- },
- /*
- * Reset all checkboxs on page except first section
- */
- resetAll: function() {
- pickEvent.config.timeContainer.slideUp('slow');
- pickEvent.config.timeDiv.hide();
- pickEvent.config.distanceContainer.removeClass('total-2 total-3');
- $('.active').removeClass('active');
- $('input[type=radio]').attr('checked', false);
- },
- /*
- * Scroll to div
- */
- scrollTo: function(point) {
- $('html, body').stop().animate({
- scrollTop: point.offset().top - 52
- }, 1000);
- },
- /*
- * Nav hot link smooth scrolling
- */
- goToSection: function(){
- pickEvent.config.navLink.on('click', function(){
- var target = $(this).attr('href').substr(1);
- pickEvent.scrollTo($('a[name="' + target + '"]'));
- });
- },
- /*
- * Disable full time slot
- */
- disableTime: function(){
- $('.full').prev('input[type="radio"]').prop("disabled", true);
- }
- }
- pickEvent.init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement