PageSourceSearch

https://st.uralweb.ru/js/novosti/next_autoload.js?2.02

js uralweb.ru collected 2026-09-24 08:26:48 UTC 8,211 bytes, 244 lines download raw bytes

1;
2// -------------------------------
3// js/novosti/nex_autoload.js
4// -------------------------------
5(function( $ ) {
6
7	jQuery.isInViewport = function (el) {
8        if ( el === null ) return false;
9		const rect = el.getBoundingClientRect();
10		let recTop      = parseInt(rect.top);
11		let recLeft     = parseInt(rect.left);
12		let rectBottom  = parseInt(rect.bottom);
13		let rectRight   = parseInt(rect.right);
14		let isInViewport = (
15			recTop >= 0 && recLeft >= 0 &&
16			rectBottom <= (window.innerHeight || document.documentElement.clientHeight) &&
17			rectRight <= (window.innerWidth || document.documentElement.clientWidth)
18		);
19		return isInViewport;
20	}
21
22	function loadNextEventsAuto (obj,nextPage,url,appendObj=null) {
23		$.ajax({
24			type:		'GET',
25	        url:		url,
26	        dataType:	'json',
27	        success: function (resp) {
28				loaded_urls_auto.push(url);
29				history.replaceState(null,null,url);
30	        	appendObj.append(resp.content);
31	        	if ( resp.hasOwnProperty('nextpage') && resp.nextpage !== null && resp.nextpage !== '' ) {
32	        		obj.data('nextpage',resp.nextpage);
33	        	} else {
34	        		obj.remove();
35	        	}
36	        	if ( resp.hasOwnProperty('nexturl') && resp.nexturl !== null && resp.nexturl !== '' ) {
37	        		obj.data('url',resp.nexturl);
38	        	}
39	        }
40	    });
41	}
42	
43	function loadNextResultAuto (obj,nextPage,url) {
44		$.ajax({
45			type:		'GET',
46	        url:		url,
47	        dataType:	'json',
48	        success: function (resp) {
49				loaded_urls_auto.push(url);
50				history.replaceState(null,null,url);
51	        	obj.before(resp.content);
52	        	if ( resp.hasOwnProperty('nextpage') && resp.nextpage !== null && resp.nextpage !== '') {
53	        		obj.data('nextpage',resp.nextpage).attr('data-nextpage',resp.nextpage);
54	        	} else {
55	        		obj.remove();
56	        	}
57	        	if ( resp.hasOwnProperty('nexturl') && resp.nexturl !== null && resp.nexturl !== '' ) {
58	        		obj.data('url',resp.nexturl).attr('data-url',resp.nexturl);
59	        	}
60	        }
61	    });
62	}
63
64	function loadBeforeDayAuto (obj,beforeDay,url) {
65		let nextUrl = url+'?date='+beforeDay;
66		$.ajax({
67			type:		'GET',
68	        url:		nextUrl,
69	        dataType:	'json',
70	        success: function (resp) {
71	        	obj.before(resp.content);
72				history.replaceState(null, null, nextUrl);
73				loaded_urls_auto.push(nextUrl);
74	        	if ( resp.hasOwnProperty('beforeday') && resp.beforeday !== null && resp.beforeday !== '') {
75	        		obj.data('beforeday',resp.beforeday);
76	        	} else {
77	        		obj.remove();
78	        	}
79	        }
80	    });
81	}
82
83	function loadMaterialFeed(newsFeedObj,nextpage,url) {
84		let documentUrl = window.location.origin + window.location.pathname;
85		$.ajax({
86			type:		'GET',
87			url:		url,
88			dataType:	'json',
89			success: function (resp) {
90				if ( resp.hasOwnProperty('documents_list') && resp.documents_list !== undefined ) {
91					let newsFeedContent = tmpl('material-feed',resp);
92					$(newsFeedObj).append(newsFeedContent);
93				}
94				if ( resp.hasOwnProperty('next_page') && resp.next_page !== undefined ) {
95					$(newsFeedObj).data('nextpage',resp.next_page).attr('data-nextpage',resp.next_page);
96				}
97				if ( nextpage > 1 ) {
98					history.replaceState(null, null, documentUrl + '?feed=' + nextpage);
99				}
100			}
101		});
102	}
103	
104	$(window).on('scroll', function() {
105		/* global scrollChecker */
106		let scrollCheckJSObject 	= null;
107		let footTopJQ 					= $('.foot-top');
108		let footerScrollCheckerJQ		= $('.global-scroll-checker');
109		if ( $(footTopJQ).length > 0 ) {
110			scrollCheckJSObject = document.querySelector('.foot-top');
111		}
112		if ( $(footerScrollCheckerJQ).length > 0 ) {
113			scrollCheckJSObject = document.querySelector('.global-scroll-checker');
114		}
115
116		/* auto load materials in material detail */
117		let materialFeedObj 				= $('.material-feed');
118		let materialFeedScrollCheckerJQ 	= $('.material-feed-scroll-checker');
119		if ( $(materialFeedObj).length > 0 && $(materialFeedScrollCheckerJQ).length > 0 ) {
120			let scrollCheckerJS	= $(materialFeedScrollCheckerJQ).get()[0];
121			if ( scrollCheckerJS !== null && $.isInViewport(scrollCheckerJS) ) {
122				let nextPage 	= $(materialFeedObj).data('nextpage');
123				let notId		= $(materialFeedObj).data('notid');
124				let catid		= $(materialFeedObj).data('catid');
125				let url			= $(materialFeedObj).data('url');
126				let params		= [];
127				let urlToLoad;
128				if ( catid !== undefined ) {
129					params.push('catid='+catid);
130				}
131				if ( notId !== undefined ) {
132					params.push('notid='+notId);
133				}
134				if ( nextPage !== undefined ) {
135					params.push('page='+nextPage);
136				}
137				if ( params.length > 0 ) {
138					urlToLoad = url + '?' + params.join('&');
139				} else {
140					urlToLoad = url;
141				}
142				if ( loaded_pages_auto.includes(nextPage) === false ) {
143					loaded_pages_auto.push(nextPage);
144					loadMaterialFeed(materialFeedObj,nextPage,urlToLoad);
145				}
146			}
147		}
148
149		/* auto load news or other auto load like events */
150		let nextResultsJQ = $('#nextresults');
151		if ( $(nextResultsJQ).length > 0 ) {
152			if ( (scrollCheckJSObject !== null && $.isInViewport(scrollCheckJSObject)) || $(footTopJQ).visible() || $(footerScrollCheckerJQ).visible() ) {
153				let nextPage = $(nextResultsJQ).data('nextpage');
154				if ( loaded_pages_auto.includes(nextPage) === false ) {
155					loaded_pages_auto.push(nextPage);
156					let obj 			= $(nextResultsJQ);
157					let url 			= $(nextResultsJQ).data('url');
158					let eventsListJQ 	= $('.events-list');
159					if ( $(eventsListJQ).length > 0 ) {
160						let appendObj 	= $(eventsListJQ);
161						loadNextEventsAuto (obj,nextPage,url,appendObj);
162					} else {
163						loadNextResultAuto (obj,nextPage,url);
164					}
165
166				}
167			}
168		}
169
170		/* auto load news days */
171		let beforeDayJQ	= $('#beforeday');
172		if ( $(beforeDayJQ).length > 0 ) {
173			if ( (scrollCheckJSObject !== null && $.isInViewport(scrollCheckJSObject)) || $(footTopJQ).visible() || $(footerScrollCheckerJQ).visible() ) {
174				let beforeDate = $(beforeDayJQ).data('beforeday');
175				if ( loaded_dates_auto.includes(beforeDate) === false ) {
176					loaded_dates_auto.push(beforeDate);
177					let obj 	= $(beforeDayJQ);
178					let date 	= $(beforeDayJQ).data('beforeday');
179					let url 	= $(beforeDayJQ).data('url');
180					loadBeforeDayAuto (obj,beforeDate,url);
181				}
182			}
183		}
184
185		/* rescroll to top and change url to old loaded */
186		$('[data-separator-current-url]').each(function (){
187			let obj = $(this).get()[0];
188			if ( $.isInViewport(obj) ) {
189				let url 				= $(obj).data('separator-current-url');
190				let current_url	= window.location.pathname + window.location.search;
191				if( loaded_urls_auto.includes(url) && current_url !== url ) {
192					history.replaceState(null,null,url);
193				}
194			}
195		});
196
197		/* rescroll top top in news feed */
198		$('.material-feed .page-separator').each(function (){
199			let obj = $(this).get()[0];
200			if ( $.isInViewport(obj) ) {
201				let page 				= $(obj).data('current-page');
202				let documentUrl  = window.location.pathname;
203				let currentUrl	= window.location.pathname + window.location.search;
204				let targetUrl	= documentUrl;
205				if ( page > 1 ) {
206					targetUrl	= documentUrl + '?feed='+page;
207				}
208				if ( loaded_pages_auto.includes(page) && currentUrl !== targetUrl ) {
209					history.replaceState(null,null,targetUrl);
210				}
211			}
212		});
213
214		/* rescroll top top in news search result */
215		$('.search-results .page-separator').each(function (){
216			let obj = $(this).get()[0];
217			let urlParser 	= new URL(window.location.href);
218			let searchQuery  = urlParser.searchParams.get('query');
219
220			if ( $.isInViewport(obj) ) {
221				let page 				= $(obj).data('current-page');
222				let documentUrl  = window.location.pathname;
223				let currentUrl	= decodeURI(window.location.pathname + window.location.search);
224				let targetUrl	= documentUrl;
225				let queryParams  = [];
226				if ( searchQuery !== null ) {
227					queryParams.push('query=' + searchQuery);
228				}
229				if ( page > 1 ) {
230					queryParams.push('page=' + page);
231				}
232				if ( queryParams.length > 0 ) {
233					targetUrl 	= documentUrl + '?' + queryParams.join('&');
234				} else {
235					targetUrl	= documentUrl;
236				}
237				if ( currentUrl !== targetUrl ) {
238					history.replaceState(null,null,targetUrl);
239				}
240			}
241		});
242
243	});
244}( window.jQuery ));

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.