1// Áåñêîíå÷íàÿ ëåíòà è ñîöèàëüíûå ñåòè 2$(document).ready(function () { 3 let rootTagId = document.querySelector('.category-tag')?.dataset.tag_id ?? null; 4 5 // Ïîñëåäíåìó äîáàâëåííîìó ýëåìåíòó íîâîñòè óñòàíàâëèâàåò ñîöèàëüíûå ñåòè 6 function loadSocial() { 7 let socialList = document.querySelectorAll('[data-social-share]'); 8 let lastSocial = socialList[socialList.length-1]; 9 let oid = lastSocial.dataset.socialShare; 10 let item = document.querySelector(`.news-block[data-oid="${oid}"]`); 11 Ya.share2(lastSocial, { 12 content: { 13 url: item.dataset.url, 14 title: item.dataset.title, 15 description: item.dataset.description, 16 image: item.dataset.image 17 }, 18 theme: { 19 services: 'vkontakte,odnoklassniki,telegram' 20 } 21 }); 22 } 23 24 // Ïîäãðóçêà ñëåäóþùåé íîâîñòè 25 function loadNextNews(lastNews) { 26 $.ajax({ 27 url: "/ajax/news/next/?mode=new", // TODO óáðàòü 28 type: "POST", 29 data: { 30 'form_data[root_oid]': rootOid, 31 'form_data[root_tag_id]': rootTagId, 32 'form_data[last_oid]': lastNews.dataset.oid, 33 'form_data[last_val]': lastNews.dataset.date, 34 }, 35 success: function (resp) { 36 if (resp) { 37 if (resp.split('|')[0] === 'OK') { 38 var nextPage = JSON.parse(resp.replace('OK|', '')); 39 lastNews.insertAdjacentHTML('afterend', nextPage.html); 40 // Ïîëó÷åíèå script adfox èç ñîäåðæèìîãî òåêñòà è äîáàâëåíèå â head äëÿ çàãðóçêè 41 let nextPageTempTag = document.createElement('div'); 42 nextPageTempTag.innerHTML = nextPage.html; 43 let scriptTag = document.createElement('script') 44 scriptTag.innerHTML = nextPageTempTag.querySelector('script.adfox').innerHTML; 45 document.body.appendChild(scriptTag) 46 // Çàãðóçêà ñîö ñåòåé 47 loadSocial() 48 } 49 } 50 }, 51 }); 52 } 53 54 // Ïðè ñêðîëëå ñòðàíèöû óñòàíàâëèâàåò ìåòàäàííûå òåêóùåé íîâîñòè 55 let current_oid = document.querySelector('.news-block').dataset.oid; 56 function updateMetaData(newsList) { 57 for (let item of newsList) { 58 let scroll_middle = window.innerHeight / 2 + window.scrollY; 59 let item_pos_top = $(item).offset().top; 60 let item_pos_bottom = $(item).offset().top + $(item).height(); 61 if (item_pos_top < scroll_middle) { 62 if (item_pos_bottom > scroll_middle) { 63 if (current_oid !== item.dataset.oid) { 64 current_oid = item.dataset.oid; 65 document.title = item.dataset.title; 66 $('meta[name=description]').attr('content', item.dataset.description); 67 $('meta[property="og:title"]').attr('content', item.dataset.title); 68 $('meta[property="og:description"]').attr('content', item.dataset.description); 69 $('meta[property="og:image"]').attr('content', item.dataset.image); 70 $('meta[property="og:url"]').attr('content', item.dataset.image); 71 $('link[rel="image_src"]').attr('href', item.dataset.image); 72 let referer = window.location.href; 73 window.history.replaceState({}, item.dataset.title, '/news/'+item.dataset.oid+'/'); 74 // Îáíîâëåíèå 75 if (typeof ym !== 'undefined') { 76 ym(66399, 'hit', window.location.href, { 77 referer: referer, 78 }); 79 } 80 break; 81 } 82 } 83 } 84 } 85 } 86 87 // Îáðàáîòêà ñêðîëëà äëÿ ïîäãðóçêè ñëåäóþùåé íîâîñòè â áåñêîíå÷íîé ëåíòå 88 let added_oids = []; 89 window.addEventListener('scroll', function () { 90 let newsList = document.querySelectorAll('.news-block'); 91 let lastNews = newsList[newsList.length-1]; 92 93 if ($(lastNews).offset().top + $(lastNews).height() < window.scrollY + 2*window.innerHeight) { 94 if (added_oids.length === 0) { 95 rootOid = lastNews.dataset.oid; 96 } 97 98 if (!added_oids.includes(lastNews.dataset.oid)) { 99 added_oids.push(lastNews.dataset.oid); 100 loadNextNews(lastNews); 101 } 102 } 103 updateMetaData(newsList); 104 }) 105});
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.