var defaultStyles = `
Нажмите, чтобы посмотреть
избранные вами отели
Вы еще не добавили отели в избранное.
Добавьте, чтобы не потерять!
Мы сохранили отели,
которые вы смотрели ранее
После просмотра отеля,
информация о нем сохранится здесь!
`; $('body').append(defaultStyles); /* wishlist start */ /* wishlist global flags */ var isInsertHtml = false; var isInsertShare = false; var isInsertFavoriteBtnHtml = false; var isPopup = false; /* wishlist global flags end */ /* wishlist html for insert */ var HOTEL_ADD_BTN_HTML = `
Отель добавлен в избранное
Смотреть
`; var HOTEL_SHARE_SVG_HTML = ``; var HOTEL_WISHLIST_BTN_CABINET_HTML = `
`; var HOTEL_WISHLIST_TIMER_HTML = `
Добавленные отели
сохраняются в разделе 3 дня
%days%
%DAYS%
%hours%
%HOURS%
%minuts%
%MINUTS%
%seconds%
%SECONDS%
`; /* wishlist html for insert end */ (function () { (function ($, window) { var Plugin, defaults, locales, pluginName; pluginName = 'timer'; locales = { ru: { days: ['день', 'дня', 'дней'], hours: ['час', 'часа', 'часов'], minuts: ['минута', 'минуты', 'минут'], seconds: ['секунда', 'секунды', 'секунд'] }, eng: { days: ['day', 'days', 'days'], hours: ['hour', 'hours', 'hours'], minuts: ['minut', 'minuts', 'minuts'], seconds: ['second', 'seconds', 'seconds'] } }; defaults = { lang: 'ru', updateTime: 1000, onEnd: $.noop }; Plugin = (function () { function Plugin(el, options) { this.el = el; this.$el = $(this.el); $.extend(this, defaults, this.$el.data(), options); if (!this.locale) { this.locale = locales[this.lang]; } this.startDate = new Date(); this.template = this.$el.html(); if (Object.prototype.toString.call(this.endDate) !== '[object Date]') { this.endDate = this.parseDate(this.endDate, this.dateFormat); } this.start(); } Plugin.prototype.parseDate = function (str, format) { var data, now; str = str + ''; str = str.split(/[^\d]/g); format = format + ''; format = format.split(/[^%yMdhms]/g); now = new Date(); data = { y: now.getFullYear(), M: now.getMonth() + 1, d: now.getDate(), h: 0, m: 0, s: 0 }; format.forEach(function (val, index) { var key; key = val.slice(1); return data[key] = str[index]; }); return new Date(data.y, data.M - 1, data.d, data.h, data.m, data.s); }; Plugin.prototype.start = function () { this.interval = setInterval((function (_this) { return function () { return _this.update(); }; })(this), this.updateTime); return this.update(); }; Plugin.prototype.end = function () { clearInterval(this.interval); this.$el.trigger("" + pluginName + ":stop"); return this.onEnd(); }; Plugin.prototype.update = function () { var days, devider, hours, minuts, now, range, seconds; now = new Date(); range = this.endDate - now; if (range <= 0) { this.end(); return; } devider = 1000 * 60 * 60 * 24; days = Math.floor(range / devider); range = range - days * devider; devider = 1000 * 60 * 60; hours = Math.floor(range / devider); range = range - hours * devider; devider = 1000 * 60; minuts = Math.floor(range / devider); range = range - minuts * devider; devider = 1000; seconds = Math.floor(range / devider); return this.render({ days: days, hours: hours, minuts: minuts, seconds: seconds }),this.circle(seconds,60,'seconds'),this.circle(minuts,60,'minuts'),this.circle(hours,24,'hours'),this.circle(days,21,'days'); }; Plugin.prototype.circle = function (key, value, type) { // var progressBarSecond = this.$el.prev().find('.timer__circle-second .timer__circle-path'), // progressBarMinut = this.$el.prev().find('.timer__circle-minut .timer__circle-path'), // progressBarHour = this.$el.prev().find('.timer__circle-hour .timer__circle-path'), // progressBarDay = this.$el.prev().find('.timer__circle-day .timer__circle-path'), // pathAmount = 36, // progressBar, // kcoefficient; // kcoefficient = Math.ceil( pathAmount * key / value ); // if( type == 'seconds'){ // progressBar = progressBarSecond; // } // else if(type == 'minuts'){ // progressBar = progressBarMinut; // } // else if(type == 'hours'){ // progressBar = progressBarHour; // } // else { // progressBar = progressBarDay; // }; // function update_circle(){ // progressBar.addClass('timer__circle-path-active'); // progressBar.each(function(){ // var $bar = $(this), // barIndex = $bar.index(); // if( barIndex < progressBar.length && barIndex >= kcoefficient ){ // $bar.removeClass('timer__circle-path-active'); // } // }); // } // update_circle(); }; Plugin.prototype.render = function (data) { var html; html = this.template; $.each(this.locale, (function (_this) { return function (key, values) { return html = html.replace(new RegExp('%' + key + '%', 'g'),_this.leadingZero(data[key])).replace(new RegExp('%' + key.toUpperCase() + '%', 'g'),_this.spellCount(data[key], values)); }; })(this)); return this.$el.html(html); }; Plugin.prototype.spellCount = function (num, variants) { if ($.isArray(variants)) { if (num % 10 === 1 && num % 100 !== 11) { return variants[0]; } else if (num % 10 >= 2 && num % 10 <= 4 && (num % 100 < 10 || num % 100 >= 20)) { return variants[1]; } else { return variants[2]; } } else { return variants; } }; Plugin.prototype.leadingZero = function (num) { var result = ''; if (num < 10) { num = '0' + num; }; num = num + ''; for (var i = 0; i < num.length; i++) { result += '' + num[i] + ''; }; return result; }; return Plugin; })(); return $.fn[pluginName] = function (options) { return this.each(function () { if (!$.data(this, pluginName)) { return $.data(this, pluginName, new Plugin(this, options)); } }); }; })(jQuery, window); }).call(this); /* wishlist functions */ var sortByHeight = function(a, b) { var a = $(a).attr('data-wishlist-price'); var b = $(b).attr('data-wishlist-price'); console.log(a) console.log(b) return a > b ? 1 : -1; }; function padTo2Digits(num) { return num.toString().padStart(2, '0'); } function formatDate(date) { return [ padTo2Digits(date.getDate()), padTo2Digits(date.getMonth() + 1), date.getFullYear(), ].join('.'); } function byField(field) { return (a, b) => parseInt(a[field]) > parseInt(b[field]) ? 1 : -1; } function getHotelPrice(prices){ var arr1 = prices; var arr2 = []; arr1.each(function(){ var $this = $(this); var $num = $this.text().trim(); var $order = $this.css('order'); var $width = $this.width(); if( $width > 1 && $order < 20 ){ var number= { order : $order, num: $num, }; arr2.push( number ); } }); arr2.sort(byField('order')); var price = ''; for (var i = 0; i < arr2.length; i++){ price += arr2[i].num.toString(); } return price; } function getCurrentHotel(hotelSelector){ var $hotel = $( hotelSelector ); if( $hotel.length ){ var hotelId = $hotel.find('h1[data-hotelid]').data('hotelid') || false; var hotelName = $hotel.find('h1[data-hotelid]').text().trim() || false; var hotelUrl = document.location.href || false; var hotelImg = $hotel.find('.gallery-layout > img').attr('src'); var hotelImgDefault = '//cdn.coral.ru/content/insider/russia/abandoned_cart/default.jpg'; var hotelRating = $hotel.find('h1[data-hotelid]').next().find('.material-icons').length || 0; var hotelAddedDate = new Date(); var hotelDateOfFlight = $('#departureDateRangePickerInput').val() || false; var hotelPrice = 0; var hotelParams = $('[data-module="hoteldetail"]').length ? $('[data-module="hoteldetail"]').attr('data-itemparams') : ''; var hotelLocation = $('.hoteltitlesub .location > span').length ? $('.hoteltitlesub .location > span').text() : ''; hotelAddedDate.setHours(0,0,0,0); /* */ var isHotelPage = $('.hoteldetailpage') || false; if( isHotelPage.length ) { var hasPrice = $('.priceInnerWrap .price .price-big') || false; var $container = $('.noroomavailable .card'); if ( hasPrice.length && !$container.length ) { hotelPrice = getHotelPrice( $('.priceInnerWrap .price .price-big > *') ); } } if( hotelImg.indexOf('/' + hotelId + '/') !== -1 && hotelId ){ hotelImg = hotelImg; } else{ hotelImg = hotelImgDefault; } /* */ var storage = localStorage.getItem("dmfavoritehotels2"); storage = JSON.parse(storage); if( storage && storage.hasOwnProperty('hotels') && storage.hotels.length ){ for ( var i = 0; i < storage.hotels.length; i++ ){ var tempHotel = storage.hotels[i]; var tempPrice = tempHotel.price; var tempParams = tempHotel.hotelParams; var tempId = tempHotel.id; var isExist = 'isExist'; if( tempPrice == hotelPrice && tempParams == hotelParams && tempId == hotelId ){ return isExist } } } /* */ var hotel = { id: hotelId, name: hotelName, url: hotelUrl, img: hotelImg, rating: hotelRating, addedDate: hotelAddedDate, dateOfFlight: hotelDateOfFlight, price: hotelPrice, hotelParams: hotelParams, hotelLocation: hotelLocation, }; return hotel } return null } function addHotel(){ var hotel = getCurrentHotel('.hoteldetailpage'); var storage = localStorage.getItem("dmfavoritehotels2"); if ( hotel != 'isExist' ){ if ( storage ){ storage = JSON.parse(storage); storage.hotels.unshift( hotel ); localStorage.setItem("dmfavoritehotels2", JSON.stringify(storage)); } else{ var currentTimeAsMs = Date.now(); var adjustedTimeAsMs = currentTimeAsMs + (1000 * 60 * 60 * 24 * 3); var firstAddedHotelDateMil = new Date(adjustedTimeAsMs); var dmfavoritehotels2 = { hotels: [], firstAddedHotelDate: firstAddedHotelDateMil, }; dmfavoritehotels2.hotels.unshift( hotel ); localStorage.setItem("dmfavoritehotels2", JSON.stringify(dmfavoritehotels2)); } ym(553380, 'reachGoal', 'favorites1', {hotel: hotel.name}); } } function showAddedMsg(){ var $msg = $('.dm-ins-wish-list__add2__msg'); $msg.addClass('dm-ins-wish-list__add2__msg--show'); } function hideAddedMsg(){ var $msg = $('.dm-ins-wish-list__add2__msg'); $msg.removeClass('dm-ins-wish-list__add2__msg--show'); } function refreshWishlist(){ var storage = JSON.parse(localStorage.getItem("dmfavoritehotels2")); if( storage ){ var cur_date = Date.now(); var end_date = new Date( storage.firstAddedHotelDate ); var end_date2 = end_date.getTime(); } var amountHotels = 0; if ( storage && cur_date < end_date2 ){ var hotels = storage.hotels; var amount = hotels.length || 0; amountHotels = amount; } else{ localStorage.removeItem('dmfavoritehotels2'); } $('.dm-ins-wish-list__add2__amount--2').attr('data-amount', '(' + amountHotels + ')'); $('.ins-dm-panel__wishlist').attr('data-amount', amountHotels ); $('.dm-ins-wish-list__add-amount').attr('data-amount', amountHotels ); if( amountHotels > 0 ){ $('.dm-ins-wish-list__add2__amount--2').closest('.dm-ins-wish-list__add2--cabinet').addClass('dm-ins-wish-list__add2--added'); $('.dm-ins-wish-list__add2--cabinet .dm-ins-wish-list__add2__btn').addClass('js--show-wishlist'); $('.dm-ins-wish-list__add2--istour .dm-ins-wish-list__add2__amount--1').addClass('js--show-wishlist'); $('.dm-ins-wish-list__add2--istour .dm-ins-wish-list__add2__amount--2').addClass('js--show-wishlist'); $('.dm-ins-wish-list__add2--istour .dm-ins-wish-list__add2__icon').addClass('js--show-wishlist'); $('.ins-dm-panel__wishlist').addClass('js--show-wishlist'); $('.shortcut.wish-offers').addClass('active'); } else{ $('.dm-ins-wish-list__add2__amount--2').closest('.dm-ins-wish-list__add2--cabinet').removeClass('dm-ins-wish-list__add2--added'); $('.dm-ins-wish-list__add2--cabinet .dm-ins-wish-list__add2__btn').removeClass('js--show-wishlist'); $('.dm-ins-wish-list__add2--istour .dm-ins-wish-list__add2__amount--1').removeClass('js--show-wishlist'); $('.dm-ins-wish-list__add2--istour .dm-ins-wish-list__add2__amount--2').removeClass('js--show-wishlist'); $('.dm-ins-wish-list__add2--istour .dm-ins-wish-list__add2__icon').removeClass('js--show-wishlist'); $('.ins-dm-panel__wishlist').removeClass('js--show-wishlist'); $('.shortcut.wish-offers').removeClass('active'); } var hotel = getCurrentHotel('.hoteldetailpage'); if (hotel == 'isExist'){ $('.dm-ins-wish-list__add2--istour').addClass('dm-ins-wish-list__add2--added'); $('.dm-ins-wish-list__add2--istour').find('.dm-ins-wish-list__add2__amount--2').addClass('js--add-to-wishlist'); } else{ $('.dm-ins-wish-list__add2--istour').removeClass('dm-ins-wish-list__add2--added'); $('.dm-ins-wish-list__add2--istour').find('.dm-ins-wish-list__add2__amount--2').removeClass('js--add-to-wishlist'); } } function deleteHotel(id, price, params){ var deleteHotelId = id; var deleteHotelPrice = price; var deleteHotelParams = params; var storage = localStorage.getItem("dmfavoritehotels2"); if ( storage && deleteHotelId != 0 && deleteHotelPrice && deleteHotelParams ){ storage = JSON.parse(storage); var hotels = storage.hotels; for (var i = 0; i < hotels.length; i++){ var hotel = hotels[i]; var hotelId = hotel.id; var hotelPrice = hotel.price; var hotelParams = hotel.hotelParams; if( deleteHotelId == hotelId && deleteHotelPrice == hotelPrice && deleteHotelParams == hotelParams ){ hotels.splice( i, 1 ); } } storage.hotels = hotels; localStorage.setItem("dmfavoritehotels2", JSON.stringify(storage)); } } /* wishlist functions end */ function timer(){ var $timer = $('.dm-ins-wish-list__timer'); var storage = JSON.parse(localStorage.getItem("dmfavoritehotels2")); function flTimerEnd(){ $timer.find('div').each(function(){ var $this = $(this), $text = $this.text(); if( $text == '%days%' || $text == '%hours%' || $text == '%minuts%' || $text == '%seconds%' ){ $this.text('00'); } else if( $text == '%DAYS%' ){ $this.text('дней'); } else if( $text == '%HOURS%' ){ $this.text('часов'); } else if( $text == '%MINUTS%' ){ $this.text('мин'); } else if( $text == '%SECONDS%' ){ $this.text('сек'); } }); refreshWishlist(); if (isPopup){ myo.close(); } } function flTimer() { if (storage && storage.hasOwnProperty('firstAddedHotelDate')) { var end_date = new Date( storage.firstAddedHotelDate ); var cur_date = Date.now(); var end_date2 = end_date.getTime(); if (cur_date < end_date2){ $timer.timer({ endDate: end_date, locale: { days: ['день', 'дня', 'дней'], hours: ['час', 'часа', 'часов'], minuts: ['мин', 'мин', 'мин'], seconds: ['сек', 'сек', 'сек'] }, onEnd: function (param) { flTimerEnd(); } }); $timer.removeAttr('data-end-date'); } else{ flTimerEnd(); } } else{ flTimerEnd(); } } flTimer(); } function renderHotels(arr){ var hotelsArr = arr; var hotelsHTML = ''; if( hotelsArr.length ){ hotelsArr.sort(byField('price')); for(var i = 0; i < hotelsArr.length; i++){ var hotel = hotelsArr[i]; var hotelId = hotel.id; var hotelName = hotel.name; var hotelUrl = hotel.url; var hotelImg = hotel.img; var hotelRating = hotel.rating; var hotelPrice = hotel.price || 0; var hotelPricePure = hotel.price || 0; var hotelHTML = ''; var hotelRatingHTML = ''; var hotelParams = hotel.hotelParams; var hotelParamsHTML = ''; var hotelLocation = hotel.hotelLocation; var hotelLocationHTML = ''; if( hotelRating > 0 ){ for( var j = 0; j < hotelRating; j++ ){ hotelRatingHTML += '
 
'; } } else{ hotelRatingHTML = '
Без звёзд
'; } var hotelPriceHTML = ''; if( hotelPrice > 0 ){ hotelPrice = parseInt(hotelPrice).toLocaleString(); hotelPriceHTML = `
от ${hotelPrice} ₽
`; } else{ hotelPriceHTML = `
`; } var hotelParamsArr = hotelParams.split(','); var child = hotelParamsArr[2].trim(); var nights = hotelParamsArr[0].trim(); var adult = hotelParamsArr[1].trim(); var childHTML = ''; if( child != 0 ){ childHTML = `| ${hotelParamsArr[2]} детей`; } if( hotelLocation != '' ){ hotelLocationHTML = `
${hotelLocation}
`; } hotelParamsHTML = `${adult} взрослых ${childHTML} | ${nights} ночей`; hotelHTML = `
${hotelRatingHTML}
${hotelName}
${hotelLocationHTML}
* Цена актуальна на момент добавления в Избранное
${hotelParamsHTML}
${hotelPriceHTML}
* Цена актуальна на момент добавления в Избранное
Удалить
`; hotelsHTML += hotelHTML; } } return hotelsHTML } function showWishlist(){ function showWishlistInn(){ var POPUP_HTML = ''; var HOTELS_HTML = ''; var HOTELS_FULL_HTML = ''; var storage = JSON.parse(localStorage.getItem("dmfavoritehotels2")); var hotelsArr; if( storage.hasOwnProperty('hotels') && storage.hotels.length ){ hotelsArr = storage.hotels; HOTELS_HTML = renderHotels(hotelsArr); HOTELS_FULL_HTML = `

Избранное

`; } POPUP_HTML = HOTELS_FULL_HTML + HOTEL_WISHLIST_TIMER_HTML; myo.open({ clas: 'dm-ins-wish-list__popup', html: POPUP_HTML, beforeOpen: function(){ hideAddedMsg(); isPopup = true; slider(); timer(); }, afterClose: function(){ this.bodyDiv.html(''); isPopup = false; }, afterOpen: function(){ ym(553380,'reachGoal','jivo_custom_favourite'); }, }); } if( typeof window.myo != 'object' && typeof window.myo == 'undefined' ){ $.getScript( "https://cdn.coral.ru/content/insider/russia/libs/popup.txt", function( data, textStatus, jqxhr ) { showWishlistInn(); }); } else{ showWishlistInn(); } }; function sliderOwl(){ if (window.innerWidth <= 768){ var startPosition = 0; var items = $('.dm-ins-wish-list__slider .dm-ins-wish-list__tour'); var dmOwl = $('.dm-ins-wish-list__slider.owl-carousel'); if (items.length > 2){ startPosition = Math.floor(items.length / 2); } dmOwl.owlCarousel({ loop:false, margin: 0, dots: false, nav:true, autoWidth: true, items: 1, center: 1, startPosition: startPosition, navText : ["менее
дорогие ОТЕЛИ", "Более
дорогие ОТЕЛИ"], onInitialized: function(){ }, }); } else{ $('.dm-ins-wish-list__slider.owl-carousel').trigger('destroy.owl.carousel'); } } function slider(){ if( typeof $.fn.owlCarousel != 'function' && typeof $.fn.owlCarousel == 'undefined' && !jQuery().owlCarousel ){ $.getScript( "https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js", function( data, textStatus, jqxhr ) { sliderOwl(); }); } else{ sliderOwl(); } } function ins_wishlist_default(){ if( !isInsertHtml ){ var $elem = $('.sharebtn'); if( $elem.length ){ $elem.closest('.shortcuts').find('>div').append( '
' + HOTEL_ADD_BTN_HTML + '
'); } isInsertHtml = true; } if( !isInsertShare ){ $('.hoteldetailpage .contentheader .shortcuts .sharebtn .shareicon').html( HOTEL_SHARE_SVG_HTML ); isInsertShare = true; } if( !isInsertFavoriteBtnHtml ){ $('.topItem.geolocation').before( HOTEL_WISHLIST_BTN_CABINET_HTML ); $('.profilemenuwrapper').after( HOTEL_WISHLIST_BTN_CABINET_HTML ); isInsertFavoriteBtnHtml = true; } refreshWishlist(); } /* wishlist start */ ins_wishlist_default(); $(document).on('click', '.js--add-to-wishlist', function(e){ e.preventDefault(); var $this = $(this); var $par = $this.closest('.dm-ins-wish-list__add2'); var added = $par.hasClass('dm-ins-wish-list__add2--added'); if( added ){ // $('.js--show-wishlist').trigger('click'); // showAddedMsg(); // showWishlist(); return } else{ $par.addClass('dm-ins-wish-list__add2--added'); showAddedMsg(); addHotel(); } refreshWishlist(); }); $(document).on('click', '.js--show-wishlist', function(e){ e.preventDefault(); showWishlist(); }); $(document).on('click', '.js__delete-from-wishlist', function(e){ e.preventDefault(); var $this = $(this); var $parent = $this.closest('.dm-ins-wish-list__tour'); var deleteId = $this.attr('data-hotel-id'); var deletePrice = $this.attr('data-price'); var deleteParams = $this.attr('data-hotel-params'); var caruselItemParent = $this.closest('.dm-ins-wish-list__slider.owl-carousel'); deleteHotel(deleteId, deletePrice, deleteParams); if (window.innerWidth <= 768){ var caruselItem = $this.closest('.owl-item'); var caruselItems = caruselItemParent.find('.owl-item'); var $index = 0; $index = caruselItems.index(caruselItem); caruselItem.find('.dm-ins-wish-list__tour').addClass('dm-ins-wish-list__tour--detele'); setTimeout(function(){ $('.dm-ins-wish-list__slider.owl-carousel').trigger('remove.owl.carousel', $index).trigger('refresh.owl.carousel'); if( !caruselItemParent.find('.owl-item').length && isPopup == true ){ $('.dm-popover__close').trigger('click'); $('.dm-popup__html').remove(); localStorage.removeItem("dmfavoritehotels2"); } refreshWishlist(); $(window).trigger('resize'); }, 400); } else{ $parent.addClass('dm-ins-wish-list__tour--detele'); setTimeout(function(){ $parent.remove(); if( !caruselItemParent.find('.dm-ins-wish-list__tour').length && isPopup == true ){ $('.dm-popover__close').trigger('click'); $('.dm-popup__html').remove(); localStorage.removeItem("dmfavoritehotels2"); } refreshWishlist(); }, 400); } ym(553380,'reachGoal','jivo_custom_favourite_clearhistory'); }); $(document).on('click', function(e){ if ( !$(e.target).closest('.dm-ins-wish-list__add2__msg, .dm-ins-wish-list__add2').length ) { hideAddedMsg(); }; }); $(window).on('resize', function(){ slider(); }); /* wishlist end */ /* resent start */ var dmPath = document.location.pathname; var dmResentHotelsLimit = 19; /* resent functions */ function refreshResent(){ var storage = JSON.parse(localStorage.getItem("dmresenthotels")); var hasResent = storage ? storage.hasOwnProperty('hotels') : false; var filterHotels = []; if( storage && hasResent ){ var resentHotels = storage.hotels; var cur_date = Date.now(); filterHotels = resentHotels.filter(function(hotel){ if ( hotel ){ var addedDate = new Date( hotel.addedDate ); var currentTimeAsMs = addedDate.getTime(); var compareAddedDate = currentTimeAsMs + (1000 * 60 * 60 * 24 * 3); return compareAddedDate > cur_date } }); } var amountHotels = 0; if ( filterHotels.length > 0 ){ var dmresenthotels = { hotels: [], }; dmresenthotels.hotels = filterHotels ; localStorage.setItem("dmresenthotels", JSON.stringify(dmresenthotels)); var amount = filterHotels.length || 0; amountHotels = amount; } else{ localStorage.removeItem('dmresenthotels'); } $('.ins-dm-panel__resent').attr('data-amount', amountHotels ); if( amountHotels > 0 ){ $('.ins-dm-panel__resent').addClass('js--show-resent'); $('.shortcut.resent-offers').addClass('active'); } else{ $('.ins-dm-panel__resent').removeClass('js--show-resent'); $('.shortcut.resent-offers').removeClass('active'); } } function showResent(){ function showResentInn(){ var POPUP_HTML = ''; var HOTELS_HTML = ''; var HOTELS_FULL_HTML = ''; var storage = JSON.parse(localStorage.getItem("dmresenthotels")); var hotelsArr; if( storage.hasOwnProperty('hotels') && storage.hotels.length ){ hotelsArr = storage.hotels; HOTELS_HTML = renderResentHotels(hotelsArr); HOTELS_FULL_HTML = `

Вы смотрели ранее Очистить историю

`; } POPUP_HTML = HOTELS_FULL_HTML; myo.open({ clas: 'dm-ins-wish-list__popup', html: POPUP_HTML, beforeOpen: function(){ isPopup = true; slider(); }, afterClose: function(){ this.bodyDiv.html(''); isPopup = false; }, afterOpen: function(){ ym(553380,'reachGoal','jivo_custom_viewed'); }, }); } if( typeof window.myo != 'object' && typeof window.myo == 'undefined' ){ $.getScript( "https://cdn.coral.ru/content/insider/russia/libs/popup.txt", function( data, textStatus, jqxhr ) { showResentInn(); refreshWishlist(); }); } else{ showResentInn(); refreshWishlist(); } }; function renderResentHotels(arr){ var hotelsArr = arr; var hotelsHTML = ''; if( hotelsArr.length ){ hotelsArr.sort(byField('price')); for(var i = 0; i < hotelsArr.length; i++){ var hotel = hotelsArr[i]; var hotelId = hotel.id; var hotelName = hotel.name; var hotelUrl = hotel.url; var hotelImg = hotel.img; var hotelRating = hotel.rating; var hotelPrice = hotel.price || 0; var hotelPricePure = hotel.price || 0; var hotelHTML = ''; var hotelRatingHTML = ''; var hotelParams = hotel.hotelParams; var hotelParamsHTML = ''; var hotelDataParams = ''; var hotelPurchaseAmount = hotel.purchaseAmount || 0; var hotelPurchaseAmountHTML = ''; var hotelLocation = hotel.hotelLocation; var hotelLocationHTML = ''; var storage = localStorage.getItem("dmfavoritehotels2"); storage = JSON.parse(storage); var isExist = ''; var isExist2 = ''; if( storage && storage.hasOwnProperty('hotels') && storage.hotels.length ){ for ( var z = 0; z < storage.hotels.length; z++ ){ var tempHotel = storage.hotels[z]; var tempPrice = tempHotel.price; var tempParams = tempHotel.hotelParams; var tempId = tempHotel.id; if( tempPrice == hotelPrice && tempParams == hotelParams && tempId == hotelId ){ isExist = 'dm-ins-wish-list__add--added'; isExist2 = 'js--show-wishlist-from-resent'; } } } if( hotelRating > 0 ){ for( var j = 0; j < hotelRating; j++ ){ hotelRatingHTML += '
 
'; } } else{ hotelRatingHTML = '
Без звёзд
'; } var hotelPriceHTML = ''; if( hotelPrice > 0 ){ hotelPrice = parseInt(hotelPrice).toLocaleString(); hotelPriceHTML = `
от ${hotelPrice} ₽
`; } else{ hotelPriceHTML = `
`; } var hotelParamsArr = hotelParams.split(','); var child = hotelParamsArr[2].trim(); var nights = hotelParamsArr[0].trim(); var adult = hotelParamsArr[1].trim(); var childHTML = ''; if( child != 0 ){ childHTML = `| ${hotelParamsArr[2]} детей`; } hotelParamsHTML = `${adult} взрослых ${childHTML} | ${nights} ночей`; hotelDataParams = ` data-hotelid="${hotelId}" data-hotelname="${hotelName}" data-hotelurl="${hotelUrl}" data-hotelimg="${hotelImg}" data-hotelprice="${hotelPricePure}" data-hotelparams="${hotelParams}" data-hotelrating="${hotelRating}" data-hotellocation="${hotelLocation}"`; hotelPurchaseAmountHTML = plural(hotelPurchaseAmount, ['раз', 'раза', 'раз']); if( hotelLocation != '' ){ hotelLocationHTML = `
${hotelLocation}
`; } hotelHTML = `
этот отель забронировали ${hotelPurchaseAmount} ${hotelPurchaseAmountHTML}
${hotelRatingHTML}
${hotelName}
${hotelLocationHTML}
${hotelParamsHTML}
${hotelPriceHTML}
* Цена актуальна на момент добавления в Избранное
`; hotelsHTML += hotelHTML; } } return hotelsHTML } function getResentHotel(hotel){ if( hotel ){ var storage = localStorage.getItem("dmfavoritehotels2"); storage = JSON.parse(storage); if( storage && storage.hasOwnProperty('hotels') && storage.hotels.length ){ for ( var i = 0; i < storage.hotels.length; i++ ){ var tempHotel = storage.hotels[i]; var tempPrice = tempHotel.price; var tempParams = tempHotel.hotelParams; var tempId = tempHotel.id; var isExist = 'isExist'; if( tempPrice == hotel.price && tempParams == hotel.hotelParams && tempId == hotel.id ){ return isExist } } } /* */ return hotel } return null } function addToWishFromResent(hotel){ var $hotel = getResentHotel(hotel); var storage = localStorage.getItem("dmfavoritehotels2"); if ( $hotel != 'isExist' ){ if ( storage ){ storage = JSON.parse(storage); storage.hotels.unshift( $hotel ); localStorage.setItem("dmfavoritehotels2", JSON.stringify(storage)); } else{ var currentTimeAsMs = Date.now(); var adjustedTimeAsMs = currentTimeAsMs + (1000 * 60 * 60 * 24 * 3); var firstAddedHotelDateMil = new Date(adjustedTimeAsMs); var dmfavoritehotels2 = { hotels: [], firstAddedHotelDate: firstAddedHotelDateMil, }; dmfavoritehotels2.hotels.unshift( $hotel ); localStorage.setItem("dmfavoritehotels2", JSON.stringify(dmfavoritehotels2)); } ym(553380, 'reachGoal', 'favorites1', {hotel: hotel.name}); } } function getCurrentHotelFromPage(hotelSelector){ var $hotel = $( hotelSelector ); if( $hotel.length ){ var hotelId = $hotel.find('h1[data-hotelid]').data('hotelid') || false; var hotelName = $hotel.find('h1[data-hotelid]').text().trim() || false; var hotelUrl = document.location.href || false; var hotelImg = $hotel.find('.gallery-layout > img').attr('src'); var hotelImgDefault = '//cdn.coral.ru/content/insider/russia/abandoned_cart/default.jpg'; var hotelRating = $hotel.find('h1[data-hotelid]').next().find('.material-icons').length || 0; var hotelAddedDate = new Date(); var hotelDateOfFlight = $('#departureDateRangePickerInput').val() || false; var hotelPrice = 0; var hotelParams = $('[data-module="hoteldetail"]').length ? $('[data-module="hoteldetail"]').attr('data-itemparams') : ''; var hotelPurchaseAmount = $('[data-dynamic-attribute="@dailyPurchase"]').length ? $('[data-dynamic-attribute="@dailyPurchase"]').text() : 4; hotelAddedDate.setHours(0,0,0,0); var hotelLocation = $('.hoteltitlesub .location > span').length ? $('.hoteltitlesub .location > span').text() : ''; /* */ var isHotelPage = $('.hoteldetailpage') || false; if( isHotelPage.length ) { var hasPrice = $('.priceInnerWrap .price .price-big') || false; var $container = $('.noroomavailable .card'); if ( hasPrice.length && !$container.length ) { hotelPrice = getHotelPrice( $('.priceInnerWrap .price .price-big > *') ); } } if( hotelImg.indexOf('/' + hotelId + '/') !== -1 && hotelId ){ hotelImg = hotelImg; } else{ hotelImg = hotelImgDefault; } /* */ var storage = localStorage.getItem("dmresenthotels"); storage = JSON.parse(storage); if( storage && storage.hasOwnProperty('hotels') && storage.hotels.length ){ for ( var i = 0; i < storage.hotels.length; i++ ){ var tempHotel = storage.hotels[i]; var tempPrice = tempHotel.price; var tempParams = tempHotel.hotelParams; var tempId = tempHotel.id; var isExist = 'isExist'; if( tempPrice == hotelPrice && tempParams == hotelParams && tempId == hotelId ){ return isExist } } } /* */ var hotel = { id: hotelId, name: hotelName, url: hotelUrl, img: hotelImg, rating: hotelRating, addedDate: hotelAddedDate, dateOfFlight: hotelDateOfFlight, price: hotelPrice, hotelParams: hotelParams, purchaseAmount: hotelPurchaseAmount, hotelLocation: hotelLocation, }; return hotel } return null } function addToResent(){ var hotel = getCurrentHotelFromPage('.hoteldetailpage'); var storage = localStorage.getItem("dmresenthotels"); if ( hotel != 'isExist' ){ if ( storage ){ storage = JSON.parse(storage); var storageLength = storage ? storage.hotels.length : 0; if( dmResentHotelsLimit <= storageLength ){ storage.hotels.length = storage.hotels.length - ( storageLength - dmResentHotelsLimit ); } storage.hotels.unshift( hotel ); localStorage.setItem("dmresenthotels", JSON.stringify(storage)); } else{ var currentTimeAsMs = Date.now(); var adjustedTimeAsMs = currentTimeAsMs + (1000 * 60 * 60 * 24 * 3); var firstAddedHotelDateMil = new Date(adjustedTimeAsMs); var dmresenthotels = { hotels: [], firstAddedHotelDate: firstAddedHotelDateMil, }; dmresenthotels.hotels.unshift( hotel ); localStorage.setItem("dmresenthotels", JSON.stringify(dmresenthotels)); } } }; window.dmAddToResent = function(){ addToResent(); }; function plural(number, titles) { cases = [2, 0, 1, 1, 1, 2]; return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ]; } /* resent functions end */ function ins_resent_default(){ if( dmPath.indexOf("/hotels/")!==-1 || dmPath == '/coral.html' ){ window.dmAddToResent(); } refreshResent(); } /* resent start */ ins_resent_default(); $(document).on('click', '.js--show-resent', function(e){ e.preventDefault(); showResent(); }); $(document).on('click', '.js__add-to-wishlist-from-resent', function(e){ e.preventDefault(); var $this = $(this); var $par = $this.closest('.dm-ins-wish-list__add'); var added = $par.hasClass('dm-ins-wish-list__add--added'); if( added ){ // $('.js--show-wishlist').trigger('click'); return } else{ $par.addClass('dm-ins-wish-list__add--added'); $par.find('.js__add-to-wishlist-from-resent').addClass('js--show-wishlist-from-resent'); var hotelId = $par.data('hotelid'); var hotelName = $par.data('hotelname'); var hotelUrl = $par.data('hotelurl'); var hotelImg = $par.data('hotelimg'); var hotelRating = $par.data('hotelrating'); var hotelAddedDate = false; var hotelDateOfFlight = false; var hotelPrice = $par.data('hotelprice'); var hotelParams = $par.data('hotelparams'); var hotelLocation = $par.data('hotellocation'); var hotel = { id: hotelId, name: hotelName, url: hotelUrl, img: hotelImg, rating: hotelRating, addedDate: hotelAddedDate, dateOfFlight: hotelDateOfFlight, price: hotelPrice, hotelParams: hotelParams, hotelLocation: hotelLocation, } addToWishFromResent(hotel); } refreshResent(); refreshWishlist(); }); $(document).on('click', '.js--show-wishlist-from-resent', function(e){ e.preventDefault(); myo.close(); showWishlist(); }); $(document).on('click','.js--clear-all-resent', function(e){ e.preventDefault(); var $this = $(this); var $parent = $this.closest('.dm-ins-wish-list__tour'); $parent.remove(); localStorage.removeItem("dmresenthotels"); $('.dm-popover__close').trigger('click'); refreshResent(); }) /* resent end */