PageSourceSearch

https://www.syfy.es/sites/all/themes/pint_themes/base/js/modules/search_api_page.js?ta8p3z

js syfy.es collected 2026-10-02 06:28:35 UTC 3,081 bytes, 115 lines download raw bytes

1/**
2 * @file search_api_page.js
3 */
4(function($) {
5
6	// View more results - Ajax loads more search results into the search page. 
7	loadMoreSearchResults();
8
9	setupSearchPage();
10
11 	function loadMoreSearchResults() {
12
13 		var $container = $('.search-api-page-results'),
14 			$facetItem = $('.facetapi-facetapi-links .leaf a'),
15 			noResults = '';
16
17 		if ($container.length > 0) {
18 			var $resultsList = $container.find('[data-search="results"]');
19
20 			// If there are no results then don't do anything
21 			if ($resultsList.length === 0) {
22 				return;
23 			}
24
25	 		var $moreBtn = $('[data-search="more"]'),
26	 			$pager = $container.find('.pager'),
27	 			pathName = window.location.pathname,
28	 			nextPageNum = 1;
29	 			totalResults = $('[data-search="total"]').text();
30
31	 		// Hide the default pager
32	 		$pager.hide();
33
34	 		// Find the amount of items shown
35			var itemsShown = $('[data-search="results"] > li').length;
36
37			// Hide the load more button if all the results are shown initially 
38			if (itemsShown == totalResults) {
39		 		$moreBtn.hide();
40		 		// and then exit function
41		 		return;
42			}
43
44			// Find the facet search string if valid
45			var facetSearchString = $pager.find('.pager-item a').attr('href');
46				
47			if (facetSearchString.indexOf('&') > -1) {
48				var index = facetSearchString.indexOf('&');
49				facetSearchString = (facetSearchString.substr(index));
50			}
51
52		 	function moreBtnClicked() {
53		 		// When more button clicked
54		 		$moreBtn.unbind().on('click', function(e) {
55
56		 			var self = $(this),
57		 				loadPagePath = pathName + '?page=' + nextPageNum + facetSearchString + ' [data-search="results"]';
58
59		 			// Change to loading icon
60		 			self.addClass('is-loading');
61
62		 			e.preventDefault();
63
64		 			// Stop if from being clicked
65		 			$moreBtn.unbind();
66
67		 			// Append the new results loaded from the 'next' page
68		 			$resultsList.append($("<div>").load( pathName + '?page=' + nextPageNum + facetSearchString + ' [data-search="results"]', function (a,b) {
69
70		 				// Increase the next page variable
71		 				nextPageNum++;
72
73		 				// Update the amount of items shown
74		 				itemsShown = $('[data-search="results"] > li').length;
75
76		 				// If there are more pages left
77		 				if (itemsShown < totalResults) {
78		 					// Allow click event
79		 					moreBtnClicked();
80		 				// If on the last page
81		 				} else {
82		 					$moreBtn.hide(); 
83		 				}
84
85		 				// Change to loading icon
86		 				self.removeClass('is-loading');
87
88		 			}));
89		 		});
90		 	}
91
92	 		moreBtnClicked();
93 		}
94 	}
95
96 	/**
97	 * Sets up search page functionality
98	 */
99 	function setupSearchPage() {
100 		var path = window.location.pathname,
101 			// get first /<string>/ in the url to check if on search page
102 			page = path.split('/')[1],
103 			searchString;
104 		// If on search page
105 		if (page  == 'search') {
106 			// Get search string if it exists
107 			searchString = (path.split('/').length) > 2 ?  path.split('/')[2] : '';
108 			if (searchString.length > 0) {
109 				// Put search text into search box for UX
110 				$('.searchbox .form-text').val(decodeURIComponent(searchString));
111 			}
112 		}
113	}
114
115})(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.