/* Библиотека функций javaScript */ var utils={};utils.debounce=function(n,t,u){var e;return function(){var a=this,i=arguments,o=function(){e=null,u||n.apply(a,i)},r=u&&!e;clearTimeout(e),e=setTimeout(o,t||200),r&&n.apply(a,i)}}; function debounce(func, wait, immediate) { var timeout; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; }; function throttle(fn, threshold, scope) { threshold || (threshold = 250); var last, deferTimer; return function () { var context = scope || this; var now = +new Date, args = arguments; if (last && now < last + threshold) { // hold on to it clearTimeout(deferTimer); deferTimer = setTimeout(function () { last = now; fn.apply(context, args); }, threshold); } else { last = now; fn.apply(context, args); } }; } function rollOverimage( imgID, imgSRC ) { if (document.getElementById) { imageEl = document.getElementById( imgID ); imageEl.src = imgSRC; } } /** * @param Date/string birthday */ function calculateAge(birthday) { var now = new Date; if(!(birthday instanceof Date)) { birthday = new Date(birthday); } var getDay = function(x) { return x.getMonth() * 100 + x.getDate(); } return now.getFullYear() - birthday.getFullYear() - (getDay(now) < getDay(birthday) ? 1 : 0); } document.addEventListener('DOMContentLoaded', function(){ setTimeout(function () { if(jQuery.fancybox) { jQuery("a.services-compare").fancybox({href: "//www.behappy2day.com/lang/services-comparison/eng.htm?v=011113-1",type: "ajax", width: 1250, height: 500, helpers: {overlay: { locked: false } } }); } if('qtip' in jQuery) { jQuery('.tooltip-html').each( function() { var el = jQuery(this); jQuery(this).qtip({ content: { text: jQuery( el.attr("href") || el.attr("data-tooltip-html") ), button: true }, style: { classes: 'qtip-ow-yellow' }, position: { my: el.attr('data-tooltip-position-my'), at: el.attr('data-tooltip-position-at'), adjust: { x: parseInt(el.attr('data-tooltip-position-adjust-x')) || 0, y: parseInt(el.attr('data-tooltip-position-adjust-y')) || 0 } }, show: { delay: 500 }, hide: { event: 'unfocus' } }).on('click', function() { return false; }); } ); } jQuery('a.open-new-window') .on('click', function(e) { e.preventDefault(); window.open(this.href, 'bh_popup_' + (Math.random()), "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes,width=1280,height=1024"); }); jQuery('a.toggle-block') .on('click', function(e) { e.preventDefault(); $(this.getAttribute('href')).toggle(); }); if(window.clc !== 0) { jQuery('.manage-favorites') .not('.manage-favorites-bound') .addClass('manage-favorites-bound') //.attr('href', 'javascript:void(0);') .on('click', function(e) { e.preventDefault(); var el = jQuery(this); var icon = el.find('.icon'); var lady_id = parseInt(el.data('person-id')) - 10000; if(clc in window && window.clc == 0) { window.location.href = "girls_info.php?i=" + lady_id; return; } var path = 'favorite.php?'; var state = !icon.hasClass('inactive'); if(!state) { path += 'add=' + lady_id; } else { path += 'delete=' + lady_id; } jQuery.ajax({ url: path, success: function() { state ? icon.addClass('inactive') : icon.removeClass('inactive'); }, error: function() { alert('An error has occurred. Please try again later'); } }); }); } $('.js-one-time-form').on('submit', function() { if($(this).data('validator')) { return false; } if( this.hasAttribute('data-submitted') ) { return false; } this.setAttribute('data-submitted', 1); this.submit(); return false; }); var my_account_menu = $('#my-account-menu'); var my_account_menu_trigger = $('#my-account-menu-trigger'); if(my_account_menu.length) { $(document).on('mouseup', function(e) { if( !my_account_menu.is(e.target) && !my_account_menu.has(e.target).length && !my_account_menu_trigger.is(e.target) && !my_account_menu_trigger.has(e.target).length ) { my_account_menu.removeClass('my-account-menu--shown'); } }); } }, 2000); }); /** * @param options * form HTMLFormElement * messages сообщения на случай ошибок * rules правила для полей, см Vex * bool please_do - Добавить Please, если сообщение только одно */ function GenericValidatedForm(options) { $(options.form).validate({ ignore: "input[type='text']:hidden", invalidHandler: function(form, validator) { var errors = validator.numberOfInvalids(); if (errors) { var ul = document.createElement('ul'), li; for(var i=0; i < validator.errorList.length; i++) { li = document.createElement('li'); li.innerHTML = validator.errorList[i].message; ul.appendChild(li); } /*if(options.please_do && validator.errorList.length == 1) { ul.childNodes[0].innerHTML = 'Please ' + ul.childNodes[0].innerHTML.toLowerCase(); }*/ vex.dialog.alert({ message: '
Please correct the following before proceeding:
' + ul.outerHTML, callback: function() { if(validator.errorList[0]) { validator.errorList[0].element.focus(); } } }) } }, errorPlacement: function(error, element) { return true; }, highlight: function(element, errorClass) { return true; }, rules: options.rules, messages: options.messages, focusInvalid: false, submitHandler: function(form) { if( form.hasAttribute('data-submitting') ) { return false; } var valid = $(form).valid(); if(!valid) { return false; } form.setAttribute('data-submitting', 1); form.submit(); } }); options.form.removeAttribute('novalidate'); } if('validator' in $) { // Метод регулярного выражения для валидатора $.validator.addMethod( "regex", function(value, element, regexp) { if (regexp.constructor != RegExp) regexp = new RegExp(regexp); else if (regexp.global) regexp.lastIndex = 0; return this.optional(element) || regexp.test(value); }, "Please check your input." ); // Метод возраста для валидатора $.validator.addMethod( "min_age", function(value, element, params) { return this.optional(element) || calculateAge(value) >= params; }, "Please check your input." ); } $.fn.preventFormEnterSubmit = function() { this.on('keypress', function(e) { if(document.activeElement.tagName === 'TEXTAREA') { return; } var key = e.originalEvent.charCode || e.originalEvent.keyCode || 0; if (key == 13) { e.preventDefault(); } }); };