1//Primpogoda custom JS 2$(document).ready(function(e) { 3 4 window.yaContextCb=window.yaContextCb||[]; 5 //document.addEventListener('scroll', initYandexRtb, {passive: true, once: true}); 6 initYandexRtb(); 7 8 // Clear wrong cookie 9 resetCookiesByName('fav_list'); 10 resetCookiesByName('mycity'); 11 resetCookiesByName('mycity_obj'); 12 resetCookiesByName('prefered_type'); 13 resetCookiesByName('fav_list_prev'); 14 //console.log('cookie should be cleaned here'); 15 16 17 //Load AJAX components 18 19 //User Place 20 var ctime = new Date(); 21 var place = $.cookie("mycity"); 22 var place_obj = ($.cookie("mycity_obj")) ? JSON.parse($.cookie("mycity_obj")) : false; 23 24 if (place && place_obj && place_obj.regionId) { 25 $('#mycity-container').html("<a href='" + place_obj.url+ "'>" + place + "</a>"); 26 $('#mycity-mobile').html("<a href='" + place_obj.url+ "'>" + place + "</a>"); 27 $('input[name="city"]').val(place); 28 29 if($('#weather-panel-container')) { 30 var wpc = $('#weather-panel-container'); 31 wpc.load('/internal/weather_panel/?place=' + place); 32 } 33 if($('#text-forecast')) { 34 var tf = $('#text-forecast'); 35 tf.load('/internal/text_forecast/?place=' + place); 36 console.log('text forecast - /internal/text_forecast/?place=' + place); 37 } 38 if ($('#weather-drop-down-menu')) { 39 $('#weather-drop-down-menu').load('/internal/mycitydropdown/?place=' + place); 40 } 41 loadStormAlerts(place_obj.regionId); 42 } 43 else { 44 $('#mycity-container').load('/internal/mycity/?' + ctime.getTime(), function() { 45 place = $('#mycity-container a').text(); 46 47 // Set cookie 48 var cityLink = $('#mycity-container a'); 49 setCityCookie(cityLink); 50 51 $('input[name="city"]').val(place); 52 53 if($('#weather-panel-container')) { 54 var wpc = $('#weather-panel-container'); 55 wpc.load('/internal/weather_panel/?place=' + place); 56 } 57 if($('#text-forecast')) { 58 var tf = $('#text-forecast'); 59 tf.load('/internal/text_forecast/?place=' + place); 60 console.log('text forecast - /internal/text_forecast/?place=' + place); 61 } 62 if ($('#weather-drop-down-menu')) { 63 $('#weather-drop-down-menu').load('/internal/mycitydropdown/?place=' + place); 64 } 65 66 $('.mycity-name').each(function () { 67 $(this).text(place); 68 }); 69 70 $('#my_city_input').val(place); 71 72 loadStormAlerts(place_obj.regionId); 73 }); 74 } 75 76 77 var timer; 78 $(window).scroll(function() { 79 if(timer) { 80 window.clearTimeout(timer); 81 } 82 83 timer = window.setTimeout(function() { 84 var isMobile = (window.location.host.substring(0,2) == 'm.'); 85 // ÐÑполнÑÑÑ Ð´Ð»Ñ desktop 86 if (!isMobile) { 87 // ÐоказÑваем погодное Ð¼ÐµÐ½Ñ Ð½Ð° ÑÑÑаниÑÐ°Ñ Ð¿Ð¾Ð³Ð¾Ð´Ñ Ð¿Ñи ÑкÑолле вниз 88 if ($('#scroller-anchor').length) { 89 var isElementInView = isScrolledIntoView($('#scroller-anchor'), false); 90 91 if (isElementInView) { 92 $('.fixed-tabs').slideUp(); 93 } 94 else { 95 $('.fixed-tabs').slideDown() 96 } 97 } 98 99 // СкÑÑваÑÑ ÑекламнÑе блоки, еÑли они не в поле зÑÐµÐ½Ð¸Ñ 100 var adBlocks = $('.ad'); 101 if (adBlocks.length) { 102 $.each( adBlocks, function( key, value ) { 103 var isElementTopInView = isScrolledIntoView($(this), 'top'); 104 var isElementBottomInView = isScrolledIntoView($(this), 'bottom'); 105 if (isElementTopInView || isElementBottomInView) { 106 $(this).children('div').show(); 107 } else { 108 // Ðадаем ÑикÑиÑованнÑÑ Ð²ÑÑоÑÑ ÑекламнÑм блокам, пеÑед Ñем как ÑкÑÑÑÑ Ð¸Ñ 109 adBlockHeight = $(this).children('div').css('height'); 110 if (adBlockHeight != '0px') { 111 $(this).css('height', adBlockHeight); 112 } 113 $(this).children('div').hide(); 114 } 115 }); 116 } 117 118 } 119 120 // ÐеÑконеÑÐ½Ð°Ñ Ð»ÐµÐ½Ñа новоÑÑей 121 var infiniteNewsContainer = getInfiniteNewsContainer(); 122 if (infiniteNewsContainer.data('news-feed-id')) { 123 loadInfiniteNews(); 124 125 // Change url string to url of current news item in document view 126 $('.news-detail').each( function (n) { 127 if ( isScrolledIntoView(this, 'center') ) { 128 if (window.location.pathname != this.dataset.url) { 129 history.pushState({}, null, this.dataset.url); 130 } 131 } 132 }); 133 } 134 }, 100); 135 }); 136 137 //User Favorites 138 var sum; 139 if ($.cookie("fav_list")) { 140 var fav_list = JSON.parse($.cookie("fav_list")); 141 sum = new Array(); 142 $.each(fav_list, function(key, value){ 143 sum.push(value.pid); 144 }); 145 sum = sum.sort(); 146 sum = sum.join(); 147 } 148 $('#favorites-container').hide(); 149 $('#favorites-container').load('/internal/favorites/?' + sum, function() {FavoritesInit(
149); $('#favorites-container').slideDown(); }); 150 $('#favorites-container-mobile').load('/internal/favorites_mobile/?' + sum, function() {FavoritesInit(); $('#favorites-container-mobile').slideDown();}); 151 152 var timestamp = Math.floor(Date.now() / 1000 / 300); 153 154 //Full City list 155 $('#city_list_full .tabs-content.ajax').load('/internal/city_list_full/'); 156 157 //News lists 158 $('.news-list.ajax').each(function() { 159 $(this).load($(this).attr('data-source').replace('{limit}', $(this).attr('data-limit') + '&' + timestamp)); 160 }); 161 $('.news-headliner.ajax').each(function() { 162 $(this).load($(this).attr('data-source').replace('{limit}', $(this).attr('data-limit') + '&' + timestamp)); 163 }); 164 165 //Footer Menu 166 $('.footer .bottom-menu').load($('.footer .bottom-menu').eq(0).attr('data-source')); 167 168 169 $('.weather-sponsor.ajax').each(function() { 170 $(this).load($(this).attr('data-source')+ '&' + timestamp, function() { 171 getWeatherSponsorMap(); 172 $('.fotorama').fotorama(); // СÑаÑÑÑÐµÑ ÑкÑÐ¸Ð¿Ñ Ð³Ð°Ð»ÐµÑеи поÑле подгÑÑзки ajax, должен вÑзÑваÑÑÑÑ Ð¿Ð¾Ñле полÑÑÐµÐ½Ð¸Ñ ÐºÐ°ÑÑÑ 173 }); 174 }); 175 getWeatherSponsorMap(); 176 177 178 /* PAGE HEADER - Smaller topbar while scroll */ 179 var leftMenuOffsetTop, leftMenuWidth; 180 181 if($('.left-menu:visible').length > 0) { 182 leftMenuOffsetTop = $('.left-menu:visible').eq(0).offset().top; 183 leftMenuWidth = $('.left-menu:visible').eq(0).width(); 184 185 $('.left-menu li[data-id="' + $('.left-menu:visible').eq(0).attr('data-active-id') + '"]').addClass('active'); 186 } 187 188 $(window).scroll(function(e) { 189 190 if($(window).scrollTop() > $('.page-top').height()) { 191 $('.top-bar-section .left li').addClass('smaller'); 192 $('.top-bar .title-area').addClass('show-logo'); 193 } 194 else { 195 $('.top-bar-section .left li').removeClass('smaller'); 196 $('.top-bar .title-area').removeClass('show-logo'); 197 } 198 199 if($('.left-menu:visible').length > 0) { 200 if($(window).scrollTop() > leftMenuOffsetTop - 48) { 201 $('.left-menu:visible').addClass('fix'); 202 $('.left-menu:visible').css('width', leftMenuWidth); 203 } 204 else { 205 $('.left-menu:visible').removeClass('fix'); 206 $('.left-menu:visible').css('width', 'auto'); 207 } 208 } 209 210 if($('.stick-to-top').length > 0) 211 { 212 $('.stick-to-top').each(function() { 213 214 var marginTop = 0; 215 var offsetTop = $(this).offset().top; 216 217 if($(this).attr('data-offset-top')) 218 offsetTop = $(this).attr('data-offset-top'); 219 220 if($(this).attr('data-margin-top')) 221 marginTop = $(this).attr('data-margin-top'); 222 223 if($(window).scrollTop() > offsetTop - marginTop) { 224 if(!$(this).attr('data-offset-top')) 225 $(this).attr('data-offset-top', $(this).offset().top); 226 227 $(this).css('width', $(this).width()); 228 $(this).addClass('fix'); 229 $(this).css('top', marginTop + 'px'); 230 } else { 231 $(this).removeClass('fix'); 232 $(this).css('width', 'auto'); 233 } 234 235 }); 236 } 237 238 }); 239 240 $('.top-bar').find('.left li:first a').html('<i class="fa fa-home fa-fw"></i>'); 241 242 243 /* NEWS */ 244 //ЧиÑÑим новоÑÑи Ð¾Ñ Ð½ÐµÐ²Ð¸Ð´Ð¸Ð¼ÑÑ Ð¸ повÑоÑов 245 $('.news-list li:hidden').remove(); 246 247 /* ARTICLES */ 248 //ЧиÑÑим ÑÑаÑÑи Ð¾Ñ Ð¿Ð¾Ð²ÑоÑÑÑÑÐ¸Ñ ÑÑ Ð·Ð°Ð³Ð¾Ð»Ð¾Ð²ÐºÐ¾Ð² 249 if ($('body.inner').length > 0) { 250 if ($('.inner h1').text() == $('.inner h2').text()) { 251 $('.inner h2').text($('.inner h2').attr('data-parent')); 252 } 253 } 254 255 /* SEARCH */ 256 //Autocomplete 257 var once = false; 258 var q; 259 var i = 0; 260 261 262 $('.autocomplete').blur(function(e) { 263 264 }); 265 266 267 $('.autocomplete').click(function(e) { 268 269 var ac = $(this); 270 var drop = $('#' + $(this).data('dropdown')); 271 if($(this).val().length <= 0) { 272 drop.addClass('hide'); 273 } 274 275 if(!drop.hasClass("data-loaded")) { 276 drop.load("/internal/city_list/ #list a", function() { 277 drop.addClass("data-loaded"); 278 279 drop.find('a').each(function(index, element) { 280 $(this).attr('data-query', $(this).text().toLowerCase()); 281 $(this).attr('data-query-lat', autoKeyboardLang($(this).text().toLowerCase())); 282 }); 283 }); 284 } 285 286 /* 287 $('form').submit(function(e) { 288 e.preventDefault(); 289 }); 290 //*/ 291 292 //ÐÑедоÑвÑаÑаем пеÑÐµÑ Ð¾Ð´ по ÑÑÑлке 293 if ($(this).hasClass('prevent-jump')) { 294 drop.find('a').click(function(e) { 295 e.preventDefault(); 296 ac.val($(this).text()); 297 drop.hide(); 298 return false;
299 }); 300 } 301 else { 302 drop.find('a').click(function(e) { 303 return true; 304 }); 305 } 306 }); 307 308 $('.autocomplete').keyup(function(e) { 309 e.preventDefault(); 310 311 var q = $(this).val().toLowerCase(); 312 $(this).data('dropdown', 'keywords'); 313 314 var drop = $('#' + $(this).data('dropdown')); 315 316 if (!drop.hasClass("data-loaded")) 317 return false; 318 319 320 if (q.length > 0) { 321 $(this).click(); 322 if(!drop.hasClass('open')) 323 $(this).click(); 324 325 switch(e.key) { 326 case "Enter": 327 if(drop.find('a.active').length > 0) { 328 $(this).val(drop.find('a.active').text()); 329 if(!$(this).hasClass('prevent-jump')) { 330 location.href = drop.find('a.active').attr('href'); 331 } 332 } 333 break; 334 335 case "Up": 336 i = (i > 0) ? i - 1 : i; 337 338 drop.find('a:visible').removeClass('active'); 339 drop.find('a:visible').eq(i).addClass('active'); 340 $(this).val(drop.find('a.active').text()); 341 342 break; 343 344 case "Down": 345 i = (i < drop.find('a:visible').length) ? i + 1 : i; 346 347 drop.find('a:visible').removeClass('active'); 348 drop.find('a:visible').eq(i).addClass('active'); 349 $(this).val(drop.find('a.active').text()); 350 351 break; 352 353 default: 354 i = 0; 355 356 drop.find('a').hide(); 357 drop.find('a').removeClass('active'); 358 if (drop.find('a').filter('[data-query^="' + q +'"], [data-query-lat^="' + q +'"]').length > 0) { 359 drop.find('a').filter('[data-query^="' + q +'"], [data-query-lat^="' + q +'"]').show(); 360 drop.find('a:visible').eq(i).addClass('active'); 361 } 362 363 if(drop.find('a').filter('[data-query^="' + q +'"], [data-query-lat^="' + q +'"]').length > 0) { 364 drop.removeClass('hide'); 365 var offset = $(this).offset(); 366 drop.css('left', offset.left + 'px'); 367 } 368 else { 369 drop.addClass('hide'); 370 } 371 } 372 } 373 else { 374 drop.hide(); 375 } 376 }); 377 378 //Filter some list by text input 379 $($('.filter').data('target')).find('li').each(function(index, element) { 380 var t = $(this).find('a').text().toLowerCase(); 381 $(this).attr('data-query', t); 382 $(this).attr('data-query-lat', autoKeyboardLang(t)); 383 }); 384 385 $('.filter').keyup(function(e) { 386 e.preventDefault(); 387 388 var q = $(this).val().toLowerCase(); 389 var drop = $($(this).data('target')); 390 391 if (q.length > 0 || !drop.hasClass("data-loaded")) { 392 393 var exclude = $($(this).data('exclude')); 394 var selection = drop.find('li[data-query*="' + q +'"], li[data-query-lat*="' + q +'"]'); 395 396 drop.find('li').hide(); 397 selection.each(function(index, element) { 398 $(this).show(); 399 }); 400 401 } else { 402 drop.find('li').show(); 403 } 404 }); 405 406 //Select city and write cookies 407 $("#select-city").submit(function( event ) { 408 var cityLink = $('#keywords a.active'); 409 setCityCookie(cityLink); 410 }); 411 412 //PREFERED 413 $('.prefered[data-type!=""]').removeClass('hide'); 414 415 $('.prefered[data-type!=""]').each(function(index, element) { 416 if($(this).attr('data-type') == $.cookie("prefered_type")) { 417 $(this).addClass('active'); 418 } 419 }); 420 421 $('.prefered[data-type!=""]').click(function(e) { 422 e.preventDefault(); 423 424 $.cookie("prefered_type", $(this).attr('data-type'), { expires: 360, path: '/', domain: '.primpogoda.ru' }); 425 $(this).addClass('active'); 426 }); 427 428 // FAVORITES 429 if('.favorites') 430 FavoritesInit(); 431 432 $(".favstar").click(function(e) { 433 e.preventDefault(); 434 435 if(!$(this).hasClass('active')) { 436 AddFavorite($(this).data('pid'), $(this).data('title'), $(this).attr('href'), true); 437 $(this).addClass('active'); 438 $('.favorites [data-predefined]').fadeOut(); 439 $(this).parent().find('small').fadeOut(); 440 } 441 else { 442 RemoveFavorite($(this).data('pid'), $(this).data('title')); 443 $('.favorites').find('a[data-pid=' + $(this).data('pid')+ ']').parent().fadeOut(); 444 $(this).removeClass('active'); 445 $(this).parent().find('small').fadeIn(); 446 $('.favorites [data-predefined]').fadeIn(); 447 } 448 }); 449 450 //RemoveSessionCookies(); 451 452 /* Making Clearing gallery work fine */ 453 $('.clearing-thumbs li > a').click(function(e) { 454 $('.visible-img').find('img').eq(0).attr('src', $(this).attr('href')); 455 $('.visible-img').find('img').eq(0).hide(); 456 $('.visible-img').find('img').eq(0).fadeIn(); 457 }); 458 459 //Load weather widgets for divs 460 LoadCitiesWidgetAjax(); 461 462 // Add Copyright to copied text 463 $('.news-detail').on('copy', function addLink() { 464 var body_element = document.getElementsByTagName('body')[0]; 465 var selection; 466 selection = window.getSelection(); 467 var pagelink = "<br /><br />
467 ЧиÑаÑÑ Ð´Ð°Ð»ÐµÐµ: <a href='"+document.location.href+"'>"+document.location.href+"</a><br />Copyright © ÐÑимпогода"; // change this if you want 468 var copytext = selection + pagelink; 469 var newdiv = document.createElement('div'); 470 newdiv.style.position='absolute'; 471 newdiv.style.left='-99999px'; 472 body_element.appendChild(newdiv); 473 newdiv.innerHTML = copytext; 474 selection.selectAllChildren(newdiv); 475 window.setTimeout(function() { 476 body_element.removeChild(newdiv); 477 },0); 478 }); 479 480 // Ajax загÑÑзка ÑпÑÑниковÑÑ Ñнимков Ð´Ð»Ñ ÑÑÑаниÑÑ /info/sat 481 var youtbeSat = $('.ajax.youtbeSat'); 482 if (youtbeSat.length) { 483 youtbeSat.html('<div class="text-center"><i class="fa fa-spinner fa-spin fa-lg grey semi-transparent"></i></div>'); 484 youtbeSat.load('/internal/sat_images_video?' + Date.now()); 485 } 486 487 var sealineEmptySlots = new Array(); 488 window.addEventListener('message', function (message) { 489 490 //reload google Ad slot if SeaLine don't show ad 491 if (message.data.bus == 'sealine' && message.data.event == 'noBannerLoad') { 492 $('iframe').each(function (index) { 493 if (this.contentWindow == message.source) { 494 var adSlotId = $(this).parent().parent().attr('id'); 495 for (var key in googleTagSlots) { 496 if (googleTagSlots[key].getSlotElementId() == adSlotId) { 497 console.log('SeaLine ad is empty, refresh slot - ' + adSlotId); 498 if (sealineEmptySlots.indexOf(adSlotId) == -1) { 499 googletag.pubads().refresh([googleTagSlots[key]]); 500 sealineEmptySlots.push(adSlotId); 501 } 502 } 503 } 504 } 505 }); 506 } 507 508 }); 509 510 var getInfiniteNewsContainer = (function () { 511 var newsContainer = $('#infinite-news-container'); 512 return function () { 513 return newsContainer; 514 } 515 })(); 516 517 var loadInfiniteNews = (function () { 518 var newsContainer = getInfiniteNewsContainer(); 519 520 if ($(newsContainer).length) { 521 isFeedValid = newsContainer.data('news-feed-id') ? true : false; 522 var pageNumber = 0; 523 var newsFeedId = newsContainer.attr('data-news-feed-id'); 524 var firstNewsItem = $('.news-detail').first(); 525 526 if (isFeedValid) {
527 var spinner = $('<div class="news-load-spinner text-center"></div>').append($('<i class="fa fa-spinner fa-spin fa-lg grey semi-transparent font-3x" style="line-height: 2em;"></i>')); 528 newsContainer.append(spinner); 529 } 530 531 return function () { 532 if (isFeedValid) { 533 var lastNewsItem = newsContainer.find('.news-detail').last(); 534 if (isScrolledIntoView(firstNewsItem, 'bottom') || isScrolledIntoView(lastNewsItem, 'top') || isScrolledIntoView(newsContainer, 'bottom')) 535 { 536 $.get('/internal/ajax_news', { 537 // mmmm: Date.now(), 538 p: pageNumber, 539 per_page: 3, 540 // feed_id: 23015 541 // feed_id: 31374 542 feed_id: newsFeedId 543 }) 544 .done(function (data) { 545 var result = $('<div/>').html(data) 546 var news = $(result).find('.news-container'); 547 548 if (news.length) { 549 spinner.show(); 550 551 news.each(function () { 552 // var $dfpAd = $(this).find('.bober') 553 // var horizontalDesktopSizes = ['fluid', [728,90], [730,150], [730,200], [750,200], [650,150], [600,150], [480,320], [450, 255], [468,60], [336,280], [300,250], [250,250], [300,75], [300,50]]; //[[730,150],[728,90],[600,150],[468,60]]; 554 // fillElementWithAd($dfpAd, '/136837651/forecastA3', horizontalDesktopSizes); 555 556 // hide main news from list 557 $(this).find('.news-detail[data-url="' + firstNewsItem.data('url') + '"]').addClass('hide'); 558 559 spinner.before(this); 560 }); 561 } 562 else { 563 spinner.hide(); 564 } 565 566 567 }) 568 .fail(function () { 569 spinner.hide(); 570 }); 571 572 pageNumber++; 573 } 574 } 575 } 576 } else { 577 return function () { 578 // console.log('now container for infinite news'); 579 } 580 } 581 })(); 582 583}); 584/************************************ $(document).ready() **********************************************/ 585 586 587 588 589 590 591 592function getIsMobile() { 593 var isMobile = (window.location.host.substring(0,2) == 'm.'); 594 return isMobile; 595} 596 597//Initiate favorites 598function FavoritesInit() { 599 if($(".favorites").height() < 50) { 600 $(".favorites").removeClass('multiline'); 601 } 602 603 $(".favorites .edit").click(function(e) { 604 e.preventDefault(); 605 $('.favorites .remove').fadeToggle(); 606 $('.favorites').addClass('multiline'); 607 }); 608 609 $(".edit-favorites-mobile").unbind("click").click(function(e) { 610 e.preventDefault(); 611 $('.favorites .remove').fadeToggle(); 612 $('.favorites').addClass('multiline'); 613 }); 614 615 616 $(".favorites .remove").click(function(e) { 617 e.preventDefault(); 618 619 RemoveFavorite($(this).parent().attr('data-pid'), $(this).parent().attr('data-name')); 620 621 $(this).parent().parent().fadeOut(); 622 }); 623 624 if ($('.favorites').find('a[data-pid=' + $(".favstar").eq(0).data('pid')+ ']').length > 0) { 625 $(".favstar").addClass('active'); 626 $(".favstar").parent().find('small').fadeOut(); 627 } 628 else { 629 $(".favstar").parent().find('small').fadeIn(); 630 } 631 632 $('.favorites .tabs a').click(function (event) { 633 if ($(this).find('span').is(":visible")) { 634 console.log('x visible'); 635 event.preventDefault(); 636 } 637 }); 638} 639 640/* 641 // 1 April, April Fools' joke 642 function AprilFoolJoke() { 643 var img = $('a.logo img'); 644 if (img.length) { 645 var today = new Date(); 646 var aprilFirst = new Date(today.getFullYear() + '-04-01'); 647 today = today.getFullYear()+ '-' + today.getMonth() + '-' + today.getDate(); 648 aprilFirst = aprilFirst.getFullYear()+ '-' + aprilFirst.getMonth() + '-' + aprilFirst.getDate(); 649 //console.log(today + ' - ' + aprilFirst); 650 651 if (today === aprilFirst) { 652 //console.log('found img'); 653 //console.log(img.attr('src')); 654 var src = img.attr('src').replace("logo.svg", "logo_april_fool.svg"); 655 //console.log(src); 656 img.attr('src', src); 657 } 658 } 659 } 660 AprilFoolJoke(); 661//*/ 662 663function setCityCookie(cityLink) { 664 var cityData = cityLink; 665 cityName = cityData.text(); 666 cityId = cityData.attr("data-id"); 667 cityUrl = cityData.attr("href"); 668 regionId = cityData.attr("data-region-id"); 669 670 var json = {'url': cityUrl, 'title': cityName, 'pid': cityId, 'regionId': regionId }; 671 var mycity_obj = JSON.stringify(json); 672 var date = new Date(); 673 var currTime = date.getTime(); 674 675 $.cookie("mycity", cityName, { 676 expires : 360, 677 path : '/', 678 domain : '.primpogoda.ru' 679 }); 680 $.cookie("mycity_obj", mycity_obj, { 681 expires : 360, 682 path : '/', 683 domain : '.primpogoda.ru' 684 }); 685} 686 687function loadStormAlerts(regionId) { 688 $('#storm-alerts').load('/storm_alerts?regionId=' + regionId + '&' + Date.now()); 689} 690 691// Add place to favorite 692function AddFavorite(cityname, title, url, setActive) { 693 //CopyCookieToSession("fav_list", "fav_list_prev"); 694 695 $.fav_list = new Array(); 696 if($.cookie("fav_list")) { 697 $.fav_list = JSON.parse($.cookie("fav_list")); 698 var isExist = false;
699 $.each($.fav_list, function(key, value) { 700 if (cityname == value.pid) isExist = true; 701 }); 702 if (isExist) return false; 703 } 704 setActive = (setActive) ? 'active': ''; 705 706 newitem = '<dd class="' + setActive + '"><a data-title="' + title + '" data-pid="' + cityname + '" href="' + url + '" >' + title + ' <span class="remove" href="#">| Ã</span></a></dd>'; 707 if (getIsMobile()) { 708 newitem = '<div class="' + setActive + '"><a data-title="' + title + '" data-pid="' + cityname + '" href="' + url + '" >' + title + ' <span class="remove" href="#">| Ã</span></a></div>'; 709 } 710 711 $('.favorites').removeClass('hide'); 712 $('.favorites .tabs').append(newitem); 713 714 $.fav_list.push({ pid: cityname, title: title, url: url}); 715 716 $.cookie("fav_list", JSON.stringify($.fav_list), { expires: 360, path: '/', domain: '.primpogoda.ru' }); 717 718 return true; 719} 720 721// Delete place from favorite 722function RemoveFavorite(pid, title) { 723 //CopyCookieToSession("fav_list", "fav_list_prev"); 724 725 if($.cookie("fav_list") == 'undefined' || $.cookie("fav_list") == '') 726 return false; 727 728 $.fav_list = JSON.parse($.cookie("fav_list")); 729 var del_key = -1; 730 $.each($.fav_list, function(key, value) { 731 if (value.pid == pid) del_key = key; 732 }); 733 if (del_key != -1) $.fav_list.splice(del_key, 1); 734 735 $.cookie("fav_list", JSON.stringify($.fav_list), { expires: 360, path: '/', domain: '.primpogoda.ru' }); 736} 737 738function CopyCookieToSession(source, target) { 739 if ( $.cookie(source) != null ) {
740 $.cookie(target, $.cookie(source), { path: '/', domain: '.primpogoda.ru' }); 741 } 742} 743 744function RemoveSessionCookies() { 745 if ($(".footer[class*=timestamp]").length > 0) 746 $.removeCookie('fav_list_prev'); 747} 748 749/** 750* Add caption to "fotorama" img gallary from img title 751* 752*/ 753function FotoramaTitle() { 754 var imgs = $('.fotorama img'); 755 $(imgs).each(function(index) { 756 var title = $(this).attr('title'); 757 $(this).attr('data-caption', title); 758 }); 759} 760FotoramaTitle(); 761 762/** 763* Ajax load weather widget by city name 764* 765*/ 766function LoadCitiesWidgetAjax() { 767 var cites = $('.load-weather-widget-by-name'); 768 if (cites.length) { 769 cites.each(function () { 770 cityName = $(this).text(); 771 if ($(this).attr('data-city')) { 772 cityName = $(this).attr('data-city'); 773 } 774 if (cityName) { 775 $(this).html('<div class="text-center"><i class="fa fa-spinner fa-spin fa-lg grey semi-transparent"></i></div>'); 776 //$(this).text('Ðогода загÑÑжаеÑÑÑ...'); 777 $(this).css('min-height','250px'); 778 //console.log('City name - '+cityName); 779 $(this).load('/weather_widget/?place=' + cityName); 780 } 781 else { 782 $(this).text('Ðе ÑдалоÑÑ Ð·Ð°Ð³ÑÑзиÑÑ Ð¿Ð¾Ð³Ð¾Ð´Ñ.'); 783 } 784 }); 785 } 786} 787 788// ÐзменÑÐµÑ Ð»Ð¾Ð³Ð¾Ñип на пÑаздники 789function changeLogoForHolidays() { 790 791 var logoBlock = $('.row.holiday'); 792 if (logoBlock.length) { 793 //console.log('hello'); 794 var today = new Date(); 795 todayStr = today.getFullYear()+ '-' + today.getMonth() + '-' + today.getDate(); 796 797 // ÐовÑй год 798 if ((today >= (new Date(today.getFullYear() + '-12-30 00:00')) && today <= (new Date(today.getFullYear() + '-12-31 23:59'))) || todayStr === (today.getFullYear()+'-01-01')) 799 $(logoBlock).addClass('newyear'); 800 // ÐÐµÐ½Ñ Ð·Ð°ÑиÑника оÑеÑеÑÑва 801 if (today >= (new Date(today.getFullYear() + '-02-22 00:00')) && today <= (new Date(today.getFullYear() + '-02-24 00:00'))) 802 $(logoBlock).addClass('feb23'); 803 // ÐенÑкий Ð´ÐµÐ½Ñ 804 if (today >= (new Date(today.getFullYear() + '-03-07 00:00')) && today <= (new Date(today.getFullYear() + '-03-09 00:00'))) 805 $(logoBlock).addClass('march8'); 806 // ÐÐµÐ½Ñ Ð¼ÐµÑеоÑолога 807 if (today >= (new Date(today.getFullYear() + '-03-22 00:00')) && today <= (new Date(today.getFullYear() + '-03-24 00:00'))) 808 $(logoBlock).addClass('wmo-day'); 809 // ÐÐµÐ½Ñ Ð´ÑÑака 810 if (today >= (new Date(today.getFullYear() + '-04-01 00:00')) && today <= (new Date(today.getFullYear() + '-04-02 00:00'))) 811 $(logoBlock).addClass('april1'); 812 // ÐÐµÐ½Ñ ÐºÐ¾ÑмонавÑики 813 if (today >= (new Date(today.getFullYear() + '-04-12 00:00')) && today <= (new Date(today.getFullYear() + '-04-13 00:00'))) 814 $(logoBlock).addClass('april12'); 815 // ÐÐµÐ½Ñ ÑÑÑда 816 if (today >= (new Date(today.getFullYear() + '-04-29 00:00')) && today <= (new Date(today.getFullYear() + '-05-02 00:00'))) 817 $(logoBlock).addClass('may1'); 818 // ÐÐµÐ½Ñ Ð¿Ð¾Ð±ÐµÐ´Ñ 819 if (today >= (new Date(today.getFullYear() + '-05-08 00:00')) && today <= (new Date(today.getFullYear() + '-05-10 00:00'))) 820 $(logoBlock).addClass('may9'); 821 // ÐеÑÑкий Ð´ÐµÐ½Ñ 822 if (today >= (new Date(today.getFullYear() + '-06-01 00:00')) && today <= (new Date(today.getFullYear() + '-06-02 00:00'))) 823 $(logoBlock).addClass('june1'); 824 825 // ÐаÑлениÑа 826 if ((today >= new Date('2019-03-04 00:00') && today <= new Date('2019-03-11 00:00')) 827 || (today >= new Date('2020-02-24 00:00') && today <= new Date('2020-03-02 00:00')) 828 || (today >= new Date('2021-03-08 00:00') && today <= new Date('2021-03-14 00:00')) 829 || (today >= new Date('2022-02-28 00:00') && today <= new Date('2022-03-06 00:00')) 830 ) { 831 $(logoBlock).addClass('maslenitsa'); 832 } 833 } 834} 835changeLogoForHolidays(); 836 837function resetCookiesByName(name) { 838 var namedCookie = $.cookie(name); 839 840 // Cookie Ð´Ð»Ñ m.primpogoda.ru можно ÑдалиÑÑ ÑолÑко Ñ Ñамого m-домена. 841 if (window.location.hostname === 'm.primpogoda.ru') { 842 $.cookie(name, '', { 843 expires: -1, 844 path: '/', 845 domain: 'm.primpogoda.ru' 846 }); 847 } 848 849 $.cookie(name, '', { 850 expires: -1, 851 path: '/', 852 domain: 'primpogoda.ru' 853 }); 854 855 $.cookie(name, '', { 856 expires: -1, 857 path: '/', 858 domain: '.primpogoda.ru' 859 }); 860 861 // Удаление host-only cookie ÑекÑÑего домена. 862 $.removeCookie(name, { 863 path: '/' 864 }); 865 866 if (namedCookie) { 867 $.cookie(name, namedCookie, { 868 expires: 360, 869 path: '/', 870 domain: '.primpogoda.ru' 871 }); 872 } 873 } 874 875 876function isScrolledIntoView(elem, side) { 877 if ($(elem).length) { 878 var docViewTop = $(window).scrollTop() + $('.sticky.topbar-bg').height() - $('.content-header .tabs.compact').height() / 3; 879 var docViewBottom = docViewTop + $(window).height(); 880 var docViewHeight = $(window).height(); 881 882 var elemTop = $(elem).offset().top; 883 var elemBottom = elemTop + $(elem).height(); 884 var elemHeight = $(elem).height(); 885
886 if (side == 'top') { 887 return ((elemTop <= docViewBottom) && (elemTop >= docViewTop)); 888 } 889 if (side == 'bottom') { 890 return ((elemBottom <= docViewBottom) && (elemBottom >= docViewTop)); 891 } 892 if (side == 'center') { 893 var totalHeight = Math.max(elemBottom, docViewBottom) - Math.min(elemTop, docViewTop); 894 var docViewComp = totalHeight - docViewHeight; 895 var elemIn = elemHeight - docViewComp; 896 var elemPercentOfView = Math.round(100 / (docViewHeight / elemIn)); 897 898 return elemPercentOfView > 50 899 } 900 901 return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop)); 902 } 903 return false; 904} 905 906// Weather sponsor 907function getWeatherSponsorMap() { 908 var sponsorMap = $('.weather-sponsor .map img'); 909 var sponsorLink = $('.weather-sponsor .map a'); 910 if (sponsorMap.length) { 911 var mapImg = $('.weather-sponsor .map img'); 912 var lat = mapImg.attr('data-lat'); 913 var lon = mapImg.attr('data-lon'); 914 var mapAddress = mapImg.attr('data-map-address'); 915 var address = 'ÐладивоÑÑок'; 916 917 if (lat && lon) { 918 address = lat + ',' + lon; 919 } else if (mapAddress) { 920 address = mapAddress; 921 } 922 923 address = encodeURIComponent(address); 924 var url = 'https://maps.googleapis.com/maps/api/staticmap?center='+address+'&zoom=9&size=250x223&maptype=roadmap&markers=size:mid%7Ccolor:red%7Clabel:C%7C'+a
924ddress+'&key=AIzaSyDOtj6txoYeyZctV5ADGbVl2BQF39y2i1o'; 925 $(sponsorMap).attr('src', url); 926 $(sponsorLink).attr('href', 'https://www.google.ru/maps/place/' + address) 927 } 928} 929 930function autoKeyboardLang(str) 931{ 932 var s = [ 933 "й","Ñ","Ñ","к","е","н","г","Ñ","Ñ","з","Ñ ","Ñ", 934 "Ñ","Ñ","в","а","п","Ñ","о","л","д","ж","Ñ", 935 "Ñ","Ñ","Ñ","м","и","Ñ","Ñ","б","Ñ" 936 ]; 937 938 var r = [ 939 "q","w","e","r","t","y","u","i","o","p","\\[","\\]", 940 "a","s","d","f","g","h","j","k","l",";","'", 941 "z","x","c","v","b","n","m",",","\\." 942 ]; 943 944 for (var i = 0; i < s.length; i++) 945 { 946 var reg = new RegExp(s[i], 'mig'); 947 str = str.replace(reg, function (a) { 948 return a == a.toLowerCase() ? r[i] : r[i].toUpperCase(); 949 }); 950 } 951 952 return str; 953} 954 955/** 956 * Activates Yandex.RTB 957 */ 958function initYandexRtb() { 959 console.log('Yandex.RTB load start'); 960 961 loadScript('https://yandex.ru/ads/system/context.js', function () { 962 963 console.log('Yandex.RTB loaded'); 964 //console.log(window.yaContextCb); 965 966 var prefix = 'yandex_rtb_'; 967 var popupRendered = false; 968 $('[id*=' + prefix + ']:visible').each(function(index) { 969 var element = $(this)[0]; 970 var adType = element.getAttribute('data-type'); 971 var adPlatform = element.getAttribute('data-platform'); 972 973 if(element.id.replace(prefix, '') == 'R-A-1573335-20') 974 adType = 'feed'; 975 976 setTimeout(function() { 977 window.yaContextCb.push(()=>{ 978 Ya.Context.AdvManager.render({ 979 renderTo: element.id, 980 blockId: element.id.replace(prefix, ''), 981 type: adType, 982 onRender: (data) => { console.log('Primary ad: ' + data.product); } 983 }, () => { 984 // код вÑзова Ñвоей ÑÐµÐºÐ»Ð°Ð¼Ñ Ð² блоке 985 var backupAdId = element.getAttribute('data-backup-ad'); 986 987 if(backupAdId) { 988 if(backupAdId.startsWith("adfox")) { 989 Ya.adfoxCode.create({ 990 ownerId: 399977, 991 containerId: element.id, 992 params: { 993 pp: element.getAttribute('data-pp'), 994 ps: element.getAttribute('data-ps'), 995 p2: element.getAttribute('data-p2') 996 } 997 }); 998 } else { 999 window.yaContextCb.push(()=>{ 1000 Ya.Context.AdvManager.render({ 1001 renderTo: element.id, 1002 blockId: backupAdId.replace(prefix, ''), 1003 onRender: (data) => { console.log('Backup: ' + data.product); } 1004 }) 1005 }) 1006 } 1007 } 1008 }); 1009 }); 1010 console.log('Ad slot ' + index + ' ' + element.parentElement.getAttribute('data-title') + ' inited: ' + element.id); 1011 }, 100 * index); 1012 1013 1014 }); 1015 1016 initAdFox(); 1017 1018 }, document.body, 0); 1019} 1020 1021/** 1022 * Activates AdFox 1023 */ 1024function initAdFox() { 1025 console.log('AdFox load start'); 1026 1027 var prefix = 'adfox_'; 1028 var popupRendered = false; 1029 $('[id*=' + prefix + ']:visible').each(function(index) { 1030 var element = $(this)[0]; 1031 var adType = element.getAttribute('data-type'); 1032 var adPlatform = element.getAttribute('data-platform'); 1033 1034 var pp = element.getAttribute('data-pp'); 1035 var ps = element.getAttribute('data-ps'); 1036 var p2 = element.getAttribute('data-p2'); 1037 1038 setTimeout(function() { 1039 window.yaContextCb.push(()=>{ 1040 Ya.adfoxCode.create({ 1041 ownerId: 399977,
1042 containerId: element.id, 1043 params: { 1044 pp: pp, 1045 ps: ps, 1046 p2: p2 1047 } 1048 }); 1049 }); 1050 console.log('Ad slot ' + index + ' ' + element.parentElement.getAttribute('data-title') + ' inited: ' + element.id); 1051 }, 10 * index); 1052 }); 1053} 1054 1055function loadScript(url, callback, location, delay = 0) { 1056 setTimeout(function() { 1057 const tag = document.createElement('script'); 1058 tag.onload = callback; 1059 //tag.onreadystatechange = callback; 1060 tag.src = url; 1061 tag.async = true; 1062 tag.crossorigin = "anonymous"; 1063 1064 location.appendChild(tag); 1065 }, delay); 1066}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.