/* * Локальный JS, версия 4.5 * Зависимости: jQuery, jQueryUI, libhack, bxSlider, AutoResize, dotdotdot */ (function(){ /* Список действий */ var toDo = { // На всех страницах '.*':[ // настроить вывод ошибок function(){ DEBUG = 1; noConsoleNoErrors(); interceptErrors('behaviour.js'); }, // костыль - удалить мусор из пейджера function() { replaceDomByTable([{ target:'.divPager', search:' ', replacement:'' }]); }, // табы function() { // баг в jQuery UI tabs var hrefBase = location.protocol + '//' + location.host + location.pathname + location.search; $('.tabs > ul > li > a').each(function() { $(this).attr('href', hrefBase + $(this).attr('href')); }); $('.tabs').tabs(); }, // многоточия function() { $("figcaption").dotdotdot({wrap:'word', fallbackToLetter:true}); }, // оценки function() { createNormalGrades(); createCommentsGrades('.binary_grade'); }, // расширенный поиск function() { $('header .search .more').on('click', function(event){ event.preventDefault(); $(event.target).parent('form').find('.advanced').toggle(); }); $('[name="city"]').on('change', function(event){ if (event.target.value === '257') { $('[name="moscow_metro"]').parents('li').show(); } else { $('[name="moscow_metro"]').parents('li').hide(); } }); $( ".slider" ).each(function(i,e){ e = $(e); var fromInput = e.parents('form').find('.slider_from'); var toInput = e.parents('form').find('.slider_to'); var from = parseInt(fromInput.val()); var to = parseInt(toInput.val()); e.slider({range:true, min:0, max:3000, values:[from, to], slide:(function(fromI, toI){ return function(event, ui) { fromInput.val(ui.values[0]); toInput.val(ui.values[1]); if (ui.values[1] === 3000) toInput.val(10000); } })(fromInput, toInput)}); if (to === 3000) toInput.val(10000); }); }, // еще материалов function() { $('.listing [href="#"].more, .box [href="#"].more').on('click', function(event){ event.preventDefault(); $(event.target).parent('.box, .listing').addClass('processing').find('[data-request-url]').updateContents({callback:function(container){ container.parent('.box, .listing').removeClass('processing'); container.find('figcaption').dotdotdot({wrap:'word', fallbackToLetter:true}); }}); }); }, // обновление капчи function() { $('#captcha, img.captcha').on('click', function(event){ event.target.src='xajax.php?rnd_image&' + Math.random(); }); } ], // На страницах с параметром less или с #!watch '([?]less\\b)|(#!watch)':[ // все в лесс function(){ LESSerate('main.css', '../less/main.less', '../lib/less-1.4.1.min.js'); } ], // На главной '[/]osoboebludo.com[/]*(#!watch|[#?].*)*$': [ // включить карусель function() { $('.bxslider').bxSlider({ slideWidth:626, useCSS:false, slideSelector:'li', adaptiveHeight:true, prevText:'', nextText:'' }); } ], // В листинге /restaurants/ '\\w+[:][/][/]\\w+[.]\\w+[/]restaurants[/]*(#!watch|[#?].*)*$': [ // карта ресторанов function() { var list = []; $('.restaurants > ul > li').each(function(i,e){ e = $(e); var name = e.find('h4').text(); var address = e.find('.city').text() + ', ' + e.find('.address').text(); var message = e.find('.address_instructions').text(); if (address !== '') list.push({name:name, address:address, message:message}); }); mapFromList(list); } ], // На конечных страницах '\\w+[:][/][/]\\w+[.]\\w+[/]\\w+[/]\\w+[/]?.*': [ // костыль - убрать метку реклама если реклама === 'Нет' function() { $('.advert').filter(function(){ return $(this).html().match('Нет'); }).text(''); }, // авторесайз textarea function(){ $('textarea').autoResize(); } ], // На конечных страницах /restaurants/ '\\w+[:][/][/]\\w+[.]\\w+[/]restaurants[/]\\w+[/]?.*': [ // костыль - добавить id в ссылки на меню, блоги, новости, рецензии function() { var id = $('.jsData .id').text(); $('.restaurants_menu.box h3 a, .restaurants_blog.box h3 a, .restaurants_news.box h3 a, .restaurants_reviews.box h3 a').each(function(i,e){ e.href = e.href.replace(/ID/, id); }); }, // заменить "Комментарии" на "Отзывы" function() { $('.comments h3 span').html('Отзывы'); }, // костыль - переместить блок контактов из листинга на место, кроме страницы контактной формы function() { /[/]contact[/]?/.test(document.location.pathname) || $('[role="main"] aside').prepend($('.jsData .contacts.box')); }, // включить фотогалерею function() { $('.photogallery .viewport .pager_item, .photogallery .bx-pager .viewport_item').remove(); $('.photogallery .bx-pager a').each(function(i,e){ $(e).attr('data-slide-index', i); }); $('.photogallery .viewport').bxSlider({ slideWidth:636, useCSS:false, slideSelector:'li', controls:false, pagerCustom: '.photogallery .bx-pager' }); $('.photogallery .scrollHelper').perfectScrollbar({wheelSpeed:40, wheelPropagation:false, suppressScrollY:true, useBothWheelAxes:true}); }, // меню ресторана гармошкой function() { $('.accordion').accordion({ collapsible:true, heightStyle:'content' }); }, // костыль - удалить скобки в счетчиках комментариев в меню ресторана function() { $('.comment_count').each(function(i,e){ e.innerHTML = e.innerHTML.replace(/[)(]/g, '') }); }, // костыль - переписать заголовок function() { var element = $('.table_booking.box h3'); element.html( element.html().replace(/N/, $('.jsData .name').text()) ); } ], // На странице /register/ '\\w+[:][/][/]\\w+[.]\\w+[/]register[/]*?.*': [ // обновление капчи по щелчку function(){ $('img.captcha').on('click', function(event){ event.target.src='/xajax.php?rnd_image&' + Math.random(); }); }, // соглашение function() { $('.consent [type="checkbox"]').consent(); } ], // На странице /subscribe/ '\\w+[:][/][/]\\w+[.]\\w+[/]subscribe[/]*?.*': [ // подписка на пресс-релизы function(){ $('[name="press_subscribe_form"]').submit(function(event){ event.preventDefault(); x_item_form('press_subscribe'); }); } ], // В личном кабинете '[/]profile[/]':[ // постнавигация function(){ postNavigation({ add:'/index.php?app=front&xml=content&structure=items&show=form&mod=', list:'index.php?app=front&xml=content&structure=items&show=listing&mod=' }); } ], // В личных сообщениях '\\w+[:][/][/]\\w+[.]\\w+[/]profile[/][?]messages.*':[ // костыль - убрать лишний заголовок function() { $('#AJAX_MAIN > h1:first-child').remove(); } ], // На страницах с блоком .contacts.box 'return $(".contacts.box").length !== 0':[ // статичная карта "схема проезда" function() { $('.contacts.box').each(function(i,e) { e = $(e); var address = e.find('.city').text() + ', ' + e.find('.address').text(); var url_ = 'http://geocode-maps.yandex.ru/1.x/?results=1&format=json&geocode=' + address ; url_ = 'http://osoboebludo.com/proxy.php?url=' + url_; var jq_got_ = $.ajax( {url: url_, dataType: 'json', success: function(data) { var position = data.response.GeoObjectCollection.featureMember[0].GeoObject.Point.pos.replace(' ' , ','); e.find('.route img').attr('src' , 'http://static-maps.yandex.ru/1.x/?size=112,112&z=13&l=map&pt=' + position + ',pm2orgm'); } } ); }); }, // модальное окно "схема проезда" с интерактивной картой function() { $('.contacts.box').each(function(i,e){ e = $(e); e.find('.route').on('click', function(event){ var dimensions_ = {width:$(window).width()*0.75 , height:$(window).height()*0.75 , modal:true , dialogClass:'no-close' }; event.preventDefault(); $('#dialog').html('
'); $('#dialog').dialog(dimensions_); $('#dialog').on('dialogclose', function(event, ui) { $(event.target).html(''); }); $('.ui-widget-overlay').on('click', function() { $('#dialog').dialog('close'); }); var a = [{ name: e.find('.name').text(), address: e.find('.address_city').text() + ', ' + e.find('.address').text(), message: e.find('.address_instructions').text() }]; //var ss=1; mapFromList( a ); }); }); }, // модальное окно "резервация столика" с формой function() { $('.contacts.box').each(function(i,e){ e = $(e); var showBookingForm = function(event){ $('#dialog') .html(e.find('.table_booking.box').clone().attr('id', 'table_booking').find('form').attr('id', 'table_booking_form').end()) .dialog({width:$(window).width()*0.75, modal:true, closeText:'×'}) .on('dialogclose', function(event, ui){ $(event.target).html(''); }); // $('[name="table_booking_form"]').submit(function(event){ // event.preventDefault() // x_item_form('table_booking'); // $('#table_booking').on('DOMSubtreeModified', function(event){ // if (! event.target.closing) { // $('#dialog').delay(4000, 'dialogClosing').queue('dialogClosing', function(){ $(this).dialog('close'); }).dequeue('dialogClosing'); // } // event.target.closing = 'yes'; // }); // }); // закрытие окна $('.ui-widget-overlay').on('click', function() { $('#dialog').dialog('close'); }); //$('#dialog .consent [type="checkbox"]').consent(); } e.find('button.table_booking').on('click', showBookingForm); if (location.hash === '#book_table') showBookingForm(); }); } ] }; /* Локальные функции */ (function($){ // переключать кнопку отправки формы по чекбоксу ("принять соглашение") $.fn.consent = function() { return this.each(function(i,e){ $(e).on('change', function(event){ var button = $(event.target).parents('form').find('[type="submit"]')[0]; if (event.target.checked) { button.disabled = 0; } else { button.disabled = 1; } }); }); } })(jQuery); /* Начало работы */ execFunctionsByTable(toDo); })();