Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(window, $) {
- 'use strict';
- // Document -------------------------------------------------------------------
- $(document).ready(function () {
- console.log('## Document ready');
- // VARS -------------------------------------------------------------------
- //
- var elementPosition = $('.subnav').offset();
- var source = getParameterByName('src');
- var email = getParameterByName('emailAddress');
- var tel = getParameterByName('tel');
- // ACTIONS ----------------------------------------------------------------
- //
- $(window).on('scroll', windowScrollHandler);
- $('.subnav .js-scroll').on('click', subnavClickHandler);
- console.log(source);
- console.log(email);
- console.log(tel);
- storeLocallySource(source);
- storeLocallyEmail(email);
- storeLocallyTel(tel);
- dynamicNavigation();
- });
- //
- // FUNCTIONS --------------------------------------------------------------
- //
- function windowScrollHandler() {
- if($(window).scrollTop() > 331){
- $('.subnav').css('position','fixed').css('top','0');
- } else {
- $('.subnav').css('position','initial');
- }
- }
- function subnavClickHandler(e) {
- e.preventDefault();
- $(document).off('scroll');
- $(this).parent().siblings().removeClass('active');
- $(this).parent().addClass('active');
- var target = this.hash,
- menu = target;
- var $target = $(target);
- console.log(this.hash);
- $('html, body').stop().animate({
- 'scrollTop': $target.offset().top+2
- }, 500, 'swing', function () {
- window.location.hash = target;
- $(document).on('scroll', onScroll);
- });
- }
- function onScroll(event){
- var scrollPosition = $(document).scrollTop();
- $('.sub-nav .js-scroll').each(function () {
- var currentLink = $(this);
- var refElement = $(currentLink.attr('href'));
- if (refElement.position().top <= scrollPosition && refElement.position().top + refElement.height() > scrollPosition) {
- $('.sub-navigation ul li').removeClass('active');
- currentLink.addClass('active');
- }
- else{
- currentLink.removeClass('active');
- }
- });
- }
- // GET Parameter from URL
- function getParameterByName(name, url) {
- if (!url) {
- url = window.location.href;
- }
- name = name.replace(/[\[\]]/g, '\\$&%');
- var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
- results = regex.exec(url);
- if (!results) return null;
- if (!results[2]) return null;
- return decodeURIComponent(results[2].replace(/\+/g, ' '));
- }
- // STORE src parameter in LocalStorage
- function storeLocallySource(source) {
- if (source !== null && source !== '') {
- if(source === 'default' || source === 'efficacy' || source === 'safety' || source === 'practicalities' || source === 'all' ) {
- localStorage.setItem('source', source);
- }
- }
- }
- // STORE email parameter in LocalStorage
- function storeLocallyEmail(email) {
- if (email !== null && email !== '') {
- if (email === '{!User.Email}') {
- localStorage.setItem('email', 'janssen@jacbe.jnj.com');
- } else{
- localStorage.setItem('email', email);
- }
- }
- }
- // STORE tel parameter in LocalStorage
- function storeLocallyTel(tel) {
- if (tel !== null && tel !== '') {
- if (tel ==='{!User.MobilePhone}') {
- localStorage.setItem('tel', '0800 93 377');
- } else{
- localStorage.setItem('tel', tel);
- }
- }
- }
- function dynamicNavigation() {
- var source = localStorage.getItem('source');
- var email = localStorage.getItem('email');
- var tel = localStorage.getItem('tel');
- var $emailTarget = $('#dyn-email');
- var $telTarget = $('#dyn-tel');
- var $emailTarget2 = $('#dyn-email-2');
- var $telTarget2 = $('#dyn-tel-2');
- $emailTarget.text(email);
- $telTarget.text(tel);
- $emailTarget2.text(email);
- $telTarget2.text(tel);
- $emailTarget.attr('href',"mailto:" + email);
- $emailTarget2.attr('href',"mailto:" + email);
- switch (source) {
- case 'efficacy':
- $('#navigation li').addClass('show');
- $('#navigation li:nth-child(5)').addClass('border-left');
- $('#navigation li:nth-child(3)').addClass('no-border-left');
- $('#navigation li:nth-child(4)').removeClass('show');
- $('#navigation li:last-child').addClass('show');
- $('#navigation ul').addClass('intro-nav');
- break;
- case 'safety':
- $('#navigation li').addClass('show');
- $('#navigation li:last-child').removeClass('show');
- $('#navigation li:nth-child(3)').addClass('no-border-left');
- $('#navigation li:nth-child(5)').addClass('no-border-left');
- $('#navigation ul').addClass('intro-nav');
- break;
- case 'practicalities':
- $('#navigation li').addClass('show');
- $('#navigation li:nth-child(5)').addClass('border-left');
- $('#navigation li:nth-child(2)').removeClass('no-border-left');
- $('#navigation li:nth-child(3)').removeClass('show');
- $('#navigation li:nth-child(4)').removeClass('show');
- $('#navigation li:last-child').removeClass('show');
- break;
- case 'all':
- $('#navigation li').addClass('show');
- $('#navigation li').removeClass('no-border-left');
- $('#navigation li').removeClass('border-left');
- $('#navigation ul').addClass('all-nav');
- $('#navigation li:last-child').removeClass('show');
- break;
- case 'default':
- $('#navigation li').addClass('show');
- $('#navigation li:nth-child(4)').removeClass('show');
- $('#navigation li:nth-child(5)').removeClass('show');
- $('#navigation li:nth-child(6)').removeClass('show');
- $('#navigation li:last-child').removeClass('show');
- $('#navigation ul').addClass('intro-nav');
- break;
- default:
- console.log('default');
- $('#navigation li').addClass('show');
- $('#navigation li:nth-child(3)').removeClass('show');
- $('#navigation li:nth-child(4)').removeClass('show');
- $('#navigation li:nth-child(5)').removeClass('show');
- $('#navigation li:last-child').removeClass('show');
- $('#navigation ul').addClass('intro-nav');
- break;
- }
- }
- }(window, $));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement