$(document).ready(function () { landing = { init: function () { this.createEvents(); var $screen = $('.section:first'); this.updateByScreen($screen); }, createEvents: function () { var self = this; $('#fullpage').fullpage({ onLeave: function (lastIndex, newIndex) { var screen = $('div.section')[newIndex - 1]; var $screen = $('#' + screen.id); if ($screen.length) { self.updateByScreen($screen); } } }); }, updateByScreen: function ($screen) { if (!$screen.length) { return; } var currentBackgroundColor = this.getCurrentBackgroundColor($screen); var menuItem = $screen.attr('data-main-menu-item'); this.updateBodyBackground(currentBackgroundColor); this.updateColorsFixedItems(currentBackgroundColor); this.setSelectedItemInMainMenu(menuItem); this.updateArrowLink($screen); }, getCurrentBackgroundColor: function ($screen) { var classes = $screen.prop("classList"); var result; $.each(classes, function (i, className) { var match = className.match('^([a-z]+)\-background$'); if (match) { result = match.pop(); return false; } }); return result; }, updateBodyBackground: function (backgroundColor) { var $body = $('body'); $body.attr('class', ''); $body.addClass(backgroundColor + '-background'); }, updateColorsFixedItems: function (backgroundColor) { var $logo = $('#logo'); var $menu = $('#menu'); var $billing = $('#billing'); var $arrow = $('#arrow'); setTimeout(function () { $logo.attr('class', ''); $menu.attr('class', ''); $billing.attr('class', ''); $arrow.attr('class', ''); switch (backgroundColor) { case 'green': $logo.addClass('logo-white'); $menu.addClass('menu-white'); $billing.addClass('billing-white'); $arrow.addClass('arrow-white'); break; case 'white': default: $logo.addClass('logo-green'); $menu.addClass('menu-black-green'); $billing.addClass('billing-black'); $arrow.addClass('arrow-green'); break; } }, 700 / 2); }, setSelectedItemInMainMenu: function (menuItem) { var $menu = $('#menu'); var $menuItem = $('#menu-item-' + menuItem); if (!$menuItem.length) { $menuItem = $menu.find('a:first'); } if ($menuItem.length) { var $menuItemLi = $menuItem.parent('li'); var menuItemWidth = $menuItemLi.outerWidth(); var menuLeft = $menu.position().left; var menuItemLeft = $menuItemLi.position().left; var $activeElement = $menu.find('.active'); $activeElement.css('width', menuItemWidth + 11); $activeElement.css('left', menuItemLeft - menuLeft - 5); } }, updateArrowLink: function ($currentScreen) { var $arrow = $('#arrow'); var $nextScreen = $currentScreen.next(); if (!$nextScreen.length) { $arrow.hide(); $nextScreen = $('.section:first'); } else { $arrow.show(); } var anchor = $nextScreen.attr('data-anchor'); $arrow.html($('').attr('href', '#' + anchor)); }, moveProjectForm: function () { var url = $('#move-project-url').val(); var stat = $('#move-project-stat').val(); var description = $('#move-project-description').val(); var email = $('#move-project-email').val(); var send = true; if (!url.length) { send = false; alert('Пожалуйста, укажите URL вашего сайта'); } if (!stat.length) { send = false; alert('Пожалуйста, укажите среднесуточную посещаемость вашего сайта'); } if (!email.length) { send = false; alert('Пожалуйста, укажите ваше E-Mail'); } if (send) { var ajaxUrl = '/move-project-form'; var data = { url: url, stat: stat, description: description, email: email }; $.appPost(ajaxUrl, data, function (response) { if (response.status) { $('#move-project-form-wrapper').hide(); $('#move-project-message-wrapper').show(); } if (response.message) { alert(response.message); } }, true); } }, contactForm: function () { var email = $('#contact-email').val(); var message = $('#contact-message').val(); var send = true; if (!email.length) { send = false; alert('Пожалуйста, укажите ваше E-Mail'); } if (send) { var ajaxUrl = '/contact-form'; var data = { message: message, email: email }; $.appPost(ajaxUrl, data, function (response) { if (response.status) { $('#contact-form-wrapper').hide(); $('#contact-message-wrapper').show(); } if (response.message) { alert(response.message); } }, true); } } }; landing.init(); });