Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1.  
  2. var pickEvent = {
  3. // Declare variables
  4. config: {
  5. peopleContainer: $('.event-solo-team'),
  6. peopleDiv: $('.event-solo-team div'),
  7. soloDiv: $('.event-solo-team .solo'),
  8. distanceContainer: $('.event-distances-all'),
  9. distanceDiv: $('.event-distance'),
  10. timeContainer: $('.event-times'),
  11. timeDiv: $('.event-time'),
  12. timeItem: $('.event-time label'),
  13. speedDiv: $('.event-speed'),
  14. speedItem: $('.event-speed div'),
  15. priceContainer: $('.event_prices-all'),
  16. priceDiv: $('.event-prices'),
  17. priceName: $('.event-prices-names'),
  18. navLink: $('a[href*=#]:not([href=#])')
  19. },
  20. init: function() {
  21.  
  22. // Setup solo active
  23. pickEvent.config.soloDiv.addClass('active');
  24.  
  25. // Function starts
  26. pickEvent.pickTeam();
  27. pickEvent.pickDistance();
  28. pickEvent.pickTime();
  29. pickEvent.pickSpeed();
  30. pickEvent.goToSection();
  31. pickEvent.disableTime();
  32.  
  33. // Display first price
  34. pickEvent.config.priceDiv.first().show();
  35. pickEvent.config.priceName.first().show();
  36. },
  37. pickTeam: function(){
  38. pickEvent.config.peopleDiv.on('click', function(){
  39.  
  40. // Reset all sections
  41. pickEvent.resetAll();
  42.  
  43. // Set active trail
  44. $(this).addClass('active');
  45. $(this).find('input[type=radio]').attr('checked', true);
  46.  
  47. // Hide 2.5k if user pick team
  48. var hideIt = pickEvent.config.distanceContainer.find('div[data-dist="2.5"]');
  49. $(this).data('team') === 'team' ? hideIt.hide() : hideIt.show();
  50.  
  51. // Align distance items
  52. var total = pickEvent.config.distanceDiv.filter(':visible').size();
  53. pickEvent.config.distanceContainer.addClass('total-' + total);
  54.  
  55. // Scrolling to div
  56. pickEvent.scrollTo(pickEvent.config.distanceContainer);
  57.  
  58. // Display corrent price name
  59. var team = $(this).data('team');
  60. pickEvent.config.priceName.hide();
  61. pickEvent.config.priceName.filter(function(index) {
  62. return $(this).data('team') == team;
  63. }).show();
  64. });
  65. },
  66. pickDistance: function() {
  67. // Hide divs
  68. pickEvent.config.timeContainer.hide();
  69. pickEvent.config.timeDiv.hide();
  70. pickEvent.config.priceDiv.hide();
  71. pickEvent.config.priceName.hide();
  72.  
  73. // Select distance
  74. pickEvent.config.distanceDiv.on('click', function(){
  75.  
  76. // Display start time
  77. pickEvent.config.timeContainer.slideDown('slow');
  78.  
  79. // Set active trail
  80. pickEvent.config.distanceDiv.removeClass('active');
  81. $(this).addClass('active');
  82.  
  83. // Display matched time slots
  84. var team = pickEvent.config.peopleContainer.find('.active').data('team');
  85. var dist = $(this).data('dist');
  86.  
  87. pickEvent.config.timeDiv.hide();
  88. pickEvent.config.timeDiv.filter(function(index) {
  89. return $(this).data('dist') == dist
  90. && $(this).data('team') == team;
  91. }).show();
  92.  
  93. pickEvent.config.priceDiv.hide();
  94. pickEvent.config.priceDiv.filter(function(index) {
  95. return $(this).data('dist') == dist
  96. && $(this).data('team') == team;
  97. }).show();
  98.  
  99. // Change radio name for solo & relay
  100. pickEvent.config.peopleContainer.find('input').attr('name', 'solo_relay[' + dist +']');
  101.  
  102. // Scrolling to div
  103. pickEvent.scrollTo(pickEvent.config.timeContainer);
  104.  
  105. });
  106. },
  107. pickTime: function() {
  108. pickEvent.config.timeItem.filter('.live').on('click', function(){
  109. pickEvent.config.timeItem.removeClass('active');
  110. $(this).addClass('active');
  111.  
  112. // Update activity id
  113. var activityId = $(this).attr('for');
  114. $('#activity_id').val(activityId);
  115.  
  116. // Scrolling to div
  117. pickEvent.scrollTo(pickEvent.config.speedDiv);
  118. });
  119. },
  120. pickSpeed: function() {
  121. pickEvent.config.speedItem.on('click', function(){
  122.  
  123. // Scrolling to div
  124. pickEvent.scrollTo(pickEvent.config.priceContainer);
  125. });
  126. },
  127. /*
  128. * Reset all checkboxs on page except first section
  129. */
  130. resetAll: function() {
  131. pickEvent.config.timeContainer.slideUp('slow');
  132. pickEvent.config.timeDiv.hide();
  133. pickEvent.config.distanceContainer.removeClass('total-2 total-3');
  134. $('.active').removeClass('active');
  135. $('input[type=radio]').attr('checked', false);
  136. },
  137. /*
  138. * Scroll to div
  139. */
  140. scrollTo: function(point) {
  141. $('html, body').stop().animate({
  142. scrollTop: point.offset().top - 52
  143. }, 1000);
  144. },
  145. /*
  146. * Nav hot link smooth scrolling
  147. */
  148. goToSection: function(){
  149. pickEvent.config.navLink.on('click', function(){
  150. var target = $(this).attr('href').substr(1);
  151. pickEvent.scrollTo($('a[name="' + target + '"]'));
  152. });
  153. },
  154. /*
  155. * Disable full time slot
  156. */
  157. disableTime: function(){
  158. $('.full').prev('input[type="radio"]').prop("disabled", true);
  159. }
  160. }
  161.  
  162. pickEvent.init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement