HOST_CORE = 'https://cc.planeta.turtella.ru'; $(document).ready(function() { $('body') .on('click', '[qId] [aId]', question.sendAnswer) .on('click', '#feedbacks .thanx_bnt', comment.like) .on('change', '.userPlaceVotes input[name=userVote]', vote.changed) .on('click', '.commentForm input[type=button]', comment.add) .on('focus', '#feedbacks .is-invalid', comment.clearValidation) .on('click', 'a[m]', weather.changeMonth) .on('click', 'a[action=loadMoreComments]', comment.load) if (typeof ymaps !== 'undefined') ymaps.ready(map.init); /*--- TYPEAHEAD - JUST SIMPLY STUPID EMULATION --- */ var links = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('n'), queryTokenizer: Bloodhound.tokenizers.whitespace, remote: { url: '/ajax/typeahead', prepare: function (query, settings) { settings.type = "POST"; settings.contentType = "application/json; charset=UTF-8"; settings.data = query; return settings; }, } }); $('.typeahead').typeahead( { minLength: 3, highlight: true }, { display: function(d){return d.n}, source: links, limit: 7, templates: { suggestion: Handlebars.compile ( '
{{n}}
' ), footer: Handlebars.compile ( '' ), empty: Handlebars.compile ( '' ) } }).bind('typeahead:select', function(evt, item) { location.href=item.u; }) $('body').on('click', '.taLink', function() { var href = this.href; $('.typeahead').blur().val(''); location.href = href; return false; }); $('body') .on('click', '.searchSubmit', function() { $("form[action='/search']").submit(); }) .on('submit', "form[action='/search']", function(evt) { if ($(this).serialize().length<=2) { $(this).find('.typeahead').focus(); evt.preventDefault(); } else { var q=$(this).serialize().substring(2); $(this).find('.typeahead').blur().val(''); window.location='/search?q='+q; evt.preventDefault(); } }) /*--- EOD: TYPEAHEAD EMULATION --- */ }); weather = { changeMonth: function() { $('a[m]').removeClass('active'); $(this).addClass('active'); var m = $(this).attr('m'); var el = $(this).closest('.weather'); var lat = el.attr('lat'); var lng = el.attr('lng'); var z = el.attr('z'); $('.weatherMap').attr('src','https://pogoda.turtella.ru/i/planet/map/?m='+m+'#avg,m'+m+','+lat+','+lng+','+z); } } comment = { load: function() { var lastComment = $('[userComment]:last'); var lastCommentId = lastComment.attr('userComment'); var placeId = $('#feedbacks').attr('pId'); $.ajax({ url: '/ajax/loadUserComments', data: {placeId: placeId, lastCommentId: lastCommentId}, type: 'POST', async: true, success: function (obj) { $('#feedbacks .newCommentsWrp').replaceWith(obj); } }); }, add: function() { var valid = true; var pointsEl = $('.commentForm [name=points]'); var userNameEl = $('.commentForm [name=userName]'); var userLocationEl = $('.commentForm [name=userLocation]'); var commentTitleEl = $('.commentForm [name=commentTitle]'); var commentTextEl = $('.commentForm [name=commentText]'); var pointsVal = 1*pointsEl.val(); var userNameVal = userNameEl.val(); var userLocationVal = userLocationEl.val(); var commentTitleVal = commentTitleEl.val(); var commentTextVal = commentTextEl.val(); if (pointsVal<1 || pointsVal>5) { pointsEl.addClass('is-invalid'); valid = false; } if (userNameVal.length<3) { userNameEl.addClass('is-invalid'); valid = false; } if (commentTitleVal.length<3) { commentTitleEl.addClass('is-invalid'); valid = false; } if (commentTextVal.length<3) { commentTextEl.addClass('is-invalid'); valid = false; } // submit var placeId = $('#feedbacks').attr('pId'); if (valid) { $.ajax({ url: '/ajax/savePlaceComment', data: {placeId: placeId, points: pointsVal, userName: userNameVal, userLocation: userLocationVal, commentTitle: commentTitleVal, commentText: commentTextVal}, type: 'POST', async: true, success: function (obj) { $('#feedbacks .feedback_form_wrp').replaceWith(obj); } }); } }, clearValidation: function() { $(this).removeClass('is-invalid'); }, like: function() { var commentId = $(this).closest('[userComment]').attr('userComment'); $.ajax({ url: '/ajax/likeComment', data: {commentId: commentId}, type: 'POST', async: true, success: function (obj) { var o = JSON.parse(obj); $('[userComment='+o.commentId+'] .commentFooter').html('Благодарим Вас за голосование!'); $('[userComment='+o.commentId+'] .likes_cnt').html(''+o.likeCount+''); } }); } } question = { sendAnswer: function() { var answer = $(this).attr('aId'); var question = $(this).closest('[qId]').attr('qId'); var placeId = $('#feedbacks').attr('pId'); $.ajax({ url: '/ajax/questionAnswered', data: {placeId: placeId, question: question, answer: answer}, type: 'POST', async: true, success: function (obj) { $('.feedback_experience form').html(obj); } }); } } vote = { changed: function() { $('#feedbacks .preVote').hide(); $('#feedbacks .postVote').show(); var placeId = $('#feedbacks').attr('pId'); var points = $(this).val(); $.ajax({ url: '/ajax/voteForPlace', data: {placeId: placeId, points: points}, type: 'POST', async: true, success: function (obj) { var o = JSON.parse(obj); $('#feedbacks .feedback_rates .starz').html(''); $('#feedbacks .feedback_rates .users_rate_val').html(o.avg); $('#feedbacks .feedback_rates .reviews_descr').html('('+o.reviewsDesc+')'); $('#feedbacks .feedback_rates .percent1').attr('style', 'background:#ededed linear-gradient(to right,rgb(255,102,0)'+o.p1+'%,rgba(255,255,255,0)'+o.p1+'%,rgba(255,255,255,0)101%,rgb(4,120,21)101%);'); $('#feedbacks .feedback_rates .percent2').attr('style', 'background:#ededed linear-gradient(to right,rgb(255,102,0)'+o.p2+'%,rgba(255,255,255,0)'+o.p2+'%,rgba(255,255,255,0)101%,rgb(4,120,21)101%);'); $('#feedbacks .feedback_rates .percent3').attr('style', 'background:#ededed linear-gradient(to right,rgb(255,102,0)'+o.p3+'%,rgba(255,255,255,0)'+o.p3+'%,rgba(255,255,255,0)101%,rgb(4,120,21)101%);'); $('#feedbacks .feedback_rates .percent4').attr('style', 'background:#ededed linear-gradient(to right,rgb(255,102,0)'+o.p4+'%,rgba(255,255,255,0)'+o.p4+'%,rgba(255,255,255,0)101%,rgb(4,120,21)101%);'); $('#feedbacks .feedback_rates .percent5').attr('style', 'background:#ededed linear-gradient(to right,rgb(255,102,0)'+o.p5+'%,rgba(255,255,255,0)'+o.p5+'%,rgba(255,255,255,0)101%,rgb(4,120,21)101%);'); $('#feedbacks .feedback_rates .percent1Txt').html(o.p1+'%'); $('#feedbacks .feedback_rates .percent2Txt').html(o.p2+'%'); $('#feedbacks .feedback_rates .percent3Txt').html(o.p3+'%'); $('#feedbacks .feedback_rates .percent4Txt').html(o.p4+'%'); $('#feedbacks .feedback_rates .percent5Txt').html(o.p5+'%'); } }); } } map = { map: {}, init: function() { if ($('#map').length) { var center = [$('#mapPanel').attr('lat'), $('#mapPanel').attr('lng')]; map.map = new ymaps.Map( // The ID of the DOM element that the map will be added to. 'mapPanel', // Map parameters. { // Geographical coordinates of the center of the displayed map. center: center, // Scale. zoom: $('#mapPanel').attr('zoom'), controls: ['searchControl','typeSelector','zoomControl'] }, { // Searching for organizations. searchControlProvider: 'yandex#search' } ); map.map.behaviors.disable('scrollZoom'); if ($('#mapPanel').attr('showPin')=='true') { map.map.geoObjects.add(new ymaps.Placemark(center, {}, { iconLayout: 'default#image', iconImageHref: HOST_CORE+'/i/placeholder.svg', iconImageSize: [20, 30], iconImageOffset: [-10, -15] })); } } } };