PageSourceSearch

https://phoode.com/js/search-by.js

js phoode.com collected 2026-10-04 22:04:44 UTC 10,561 bytes, 346 lines download raw bytes

1$(document).ready(function () {
2	let ticks = ['$0', '$50', '$100', '$150', '$200'];
3	let pricesToSearch = [0, 50, 100, 150, 200, 201];
4
5	let getFormType = () => {
6		let type = "project";
7		if ($('.switcher-tab input').prop('checked')) {
8			type = "profile";
9		}
10		return type;
11	};
12
13	let submitForm = () => {
14		let type = getFormType();
15		let data = gatherFormData(type);
16		let urls = [];
17		Object.keys(data).forEach((key) => {
18			urls.push(`${key}=${data[key].join(',')}`);
19		});
20		let query = urls.join('&');
21		let action = `${window.searchUrls[type]}?${query}`;
22		$('#filters-form').attr("action", action);
23		window.location = action;
24		return false;
25	};
26
27	let gatherFormData = (type) => {
28		let data = {};
29
30		let title = $(`#search-input-block__input`).val();
31
32		if (title) {
33			data['title'] = [title];
34		}
35
36		let location = $(`#${type}__city-filter`).val();
37
38		if (location) {
39			data['location'] = [location];
40		}
41
42		let rateValues = $(`#${type}__hourly-rate`).slider("values");
43
44		if (rateValues[0] > 0) {
45			data['rateFrom'] = [pricesToSearch[rateValues[0]]];
46		}
47
48		if (rateValues[1] < pricesToSearch.length - 1) {
49			data['rateTo'] = [pricesToSearch[rateValues[1]]];
50		}
51		let fields = $(`.universal-search-filter input[name^="${type}"]:checked`);
52
53		fields.each((i, field) => {
54			let name = $(field).attr('name').replace(/^.*?\[(.*?)\].*$/gi, '$1');
55			let value = $(field).val();
56			if (!data[name]) {
57				data[name] = [];
58			}
59			data[name].push(value);
60		});
61
62		return data;
63	};
64
65	function checkResultsTitles() {
66		$('.results-item').each(function () {
67			if ($(window).width() < 576) {
68				if ($(this).find('.tag-chosen').length > 0) {
69					$(this).find('.result-mobile-title').show();
70					$(this).show();
71				} else {
72					$(this).find('.result-mobile-title').hide();
73					$(this).hide();
74				}
75			}
76		});
77	}
78
79	$('.choosen-tags-actions .clear-btn').click(function () {
80		let context = $(this).closest('.universal-search-insert-tabs').find('.tab-content');
81		context.find('.un-filt-check').removeClass('active');
82		context.find('.tag-chosen').remove();
83		context.find('input').prop('checked', false).change();
84		clearTabs();
85	});
86
87	$('.mobile-tabs-toggler').click(function () {
88		$('.filter-main-part-top').toggleClass('mobile-hidden');
89		$(this).find('i').toggleClass('fa-plus');
90		$(this).find('i').toggleClass('fa-minus');
91	});
92
93	if ($(window).width() < 576) {
94		$('.filter-main-part-top li a').click(function () {
95			$(this).closest('.tabs').find('li').toggleClass('hidden');
96			$(this).closest('li').toggleClass('active').toggleClass('hidden');
97			$('.filter-main-part-bottom').toggleClass('mobile-hidden');
98		});
99	}
100
101	/**
102	 * @param enable
103	 */
104	function priceLocationChecker(enable = true) {
105		if (enable) {
106			$('.search-choosen-tags-container').hide();
107			if ($(window).width() < 1136) {
108				$('.filter-main-part-bottom').css({'min-height': '180px', 'left': '15px'});
109			} else {
110				$('.filter-main-part-bottom').css({'min-height': '180px', 'right': '15px'});
111			}
112		} else {
113			$('.search-choosen-tags-container').show();
114			$('.filter-main-part-bottom').css({'min-height': '450px', 'right': 'unset'});
115		}
116	}
117
118	let clearTabs = () => {
119		$('.tabs-search').find('.tab a').removeClass('active');
120		$('.filter-main-part-bottom').fadeOut();
121		$('.universal-search-results').removeClass('dimmed');
122	};
123
124	let changeTab = (context) => {
125		let element = $(context);
126		element.parents('.tabs-search').find('.tab a').not(element).removeClass('active');
127		element.toggleClass('active');
128		openSearchDrawer(element);
129	};
130
131	let openSearchDrawer = (element) => {
132		let currentContainer = $('.switcher-tab input').prop('checked') ? "#search_bar_profile" : "#search_bar_project";
133		let id = element.attr('href');
134		$(currentContainer + ' .filter-main-part-bottom .tab-content').not(id).hide();
135
136		$('#search_bar_profile, #search_bar_project').removeClass("visible");
137		$(currentContainer).addClass("visible");
138
139		if (element.hasClass('active')) {
140			priceLocationChecker([
141				'#profile__location',
142				'#profile__pricing',
143				'#project__location',
144				'#project__pricing'
145			].indexOf(id) > -1);
146			$(currentContainer + ' .filter-main-part-bottom').fadeIn();
147			$('.universal-search-results').addClass('dimmed');
148		} else {
149			$(currentContainer + ' .filter-main-part-bottom').fadeOut();
150			$('.universal-search-results').removeClass('dimmed');
151		}
152
153		$(currentContainer + ' .filter-main-part-bottom .tab-content' + id).fadeIn();
154	};
155
156	let removeSelectedTag = (field) => {
157		$(field).prop('checked', false).change();
158	};
159
160	let addSelectedTagToSummary = (context) => {
161		let field = context;
162		context = $(context).parent();
163		let categoryText = context.find('p').text();
164		let categoryID = context.find('input').attr("value");
165
166		if (context.find('input').prop('checked')) {
167			// set active
168			context.parent().addClass('active');
169			context.closest('label').prepend('<div class="tag-chosen" data-item-id="' + categoryID + '">' + '<i class="fa fa-times"></i></div>');
170
171			// create element
172			let element = $('<div class="tag-chosen" data-item-id="' + categoryID + '">' +
173				'<i class="fa fa-times"></i>' +
174				'<span>' +
175				categoryText +
176				'</span>' + '</div>')
177				.on("click", () => {
178					removeSelectedTag(field);
179					$("#filters-form").submit();
180				});
181
182			// append to summary container mobile
183			let containerMobile = context.closest('.tab-content').find('.chosen-categories-container');
184			containerMobile.append(element.clone());
185
186			// append to summary container desktop
187			let id = context.closest('.tab-content').attr('id');
188			$(`#${id}-results .inner`).append(element);
189		} else {
190			context.parent().removeClass('active');
191			context.closest('.tab-content').find('[data-item-id="' + categoryID + '"]').closest('.tag-chosen').remove();
192			let id = context.closest('.tab-content').attr('id');
193			$(`#${id}-results .inner`).find('[data-item-id="' + categoryID + '"]').closest('.tag-chosen').remove();
194		}
195	};
196
197	let setTagsAsSelected = function (searchContainer, container) {
198		let el = $(searchContainer + container);
199		let tagsContainer = el.find('.chosen-categories-container').html();
200		$(searchContainer + container + '-results .inner').html(tagsContainer);
201		checkResultsTitles();
202	};
203
204	$('.search-tabs-container .un-filt-check label input').on("change", function (e) {
205		addSelectedTagToSummary(this);
206	}).each(function () {
207		addSelectedTagToSummary(this);
208	});
209
210	let searchContainers = ["#project__", "#profile__"];
211	let containers = ["focus-area", "creative-style", "unique-skills", "media-end-use", "tags"];
212
213	searchContainers.forEach((searchContainer) => {
214		containers.forEach((container) => {
215			let el = $(searchContainer + container);
216			if (el) {
217				let tags = el.find('.chosen-categories-container').html();
218				el.find('.inner').html(tags);
219			}
220		});
221	});
222
223	let setCurrentSearch = (forceToReload = false) => {
224		let checked = $('.switcher-tab input').prop('checked');
225		clearTabs();
226
227		if (checked) {
228			if (window.location.pathname !== window.searchUrls.profile) {
229				window.history.pushState({}, "", window.searchUrls.profile);
230			}
231			// document.title = "Search Phoode Creatives";
232			$('#project-additional-filters').hide();
233			$('.universal-search-filter').addClass('search-profile');
234			$('#search_bar_project').removeClass("visible").fadeOut();
235			$('.search_project_results').hide();
236			$('.search_profile_results').show();
237			$('#search_bar_profile').addClass("visible").fadeIn();
238			$('.search-top-block .nav-menu').fadeOut();
239		} else {
240			if (window.location.pathname !== window.searchUrls.project) {
241				window.history.pushState({}, "", window.searchUrls.project);
242			}
243			// document.title = "Search Phoode Projects";
244			$('#project-additional-filters').show();
245			$('.universal-search-filter').removeClass('search-profile');
246			$('#search_bar_project').addClass("visible").fadeIn();
247			$('#search_bar_profile').removeClass("visible").fadeOut();
248			$('.search_project_results').show();
249			$('.search_profile_results').hide();
250			$('.search-top-block .nav-menu').fadeIn();
251		}
252
253		if (forceToReload) {
254			clearResults();
255			$("#search-results-all, #project-additional-filters").fadeOut();
256			$("#filters-form").submit();
257		}
258	};
259
260	let clearResults = () => {
261		// $('#all-projects-tab').fadeOut();
262	};
263
264	let initializeRateSlider = (context, rateFrom = 0, rateTo = 201) => {
265		context = $(context);
266
267		let rateFromIndex = pricesToSearch.indexOf(rateFrom);
268		let rateToIndex = pricesToSearch.indexOf(rateTo);
269
270		let slider = context.slider({
271			min: 0,
272			max: ticks.length,
273			range: true,
274			values: [Math.max(0, rateFromIndex), Math.min(ticks.length, rateToIndex)],
275			start: function (event) {
276				event.originalEvent.type === "mousedown" && $(this).addClass("ui-slider-mousesliding");
277			},
278			slide: function (element, ui) {
279				if (ui.values[0] === ui.values[1]) {
280					return false;
281				}
282			}
283		});
284
285		$(ticks).each(function (i) {
286			let tick = $('<div class="tick ui-widget-content"></div>').appendTo(slider);
287			tick.css({
288				left: (100 / ticks.length * i) + '%',
289				width: (100 / ticks.length) + '%'
290			});
291		});
292	};
293
294	let checkIfSearchQueryExists = function () {
295		if ($(this).val() !== "") {
296			$('#search-input-block__input-clear').fadeIn();
297		} else {
298			$('#search-input-block__input-clear').fadeOut();
299		}
300	};
301
302	$('.tabs-search .tab a').on('click', function (e) {
303		e.preventDefault();
304		changeTab(this);
305	});
306
307	$('.switcher-tab input').on('change', () => setCurrentSearch(true));
308
309	$('.new-search-tabs-container .search-top-block').on('click', clearTabs);
310
311	$('#search-input-block__input')
312		.change(checkIfSearchQueryExists)
313		.keyup(checkIfSearchQueryExists);
314
315	$("#filters-form").submit(submitForm);
316
317	$('#search-input-block__input-clear').click(function (event) {
318		$('#search-input-block__input').val("").change();
319		const resetResults = $(this).attr("data-search");
320		if (resetResults === "reset") {
321			return true;
322		}
323		event.preventDefault();
324		return false;
325	});
326
327	$(".universal-search-filter .hourly-rate").each((i, element) => {
328		element = $(element);
329		let rateFrom = element.parent().find('[name="rateFrom"]').val();
330		let rateTo = element.parent().find('[name="rateTo"]').val();
331
332		rateFrom = rateFrom ? Number(rateFrom) : 0;
333		rateTo = rateTo ? Number(rateTo) : pricesToSearch[pricesToSearch.length - 1];
334
335		initializeRateSlider(element, rateFrom, rateTo);
336	});
337
338	$(".universal-search-filter .go-button").on("click", (event) => {
339		event.preventDefault();
340		$("#filters-form").submit();
341		return false;
342	});
343
344	checkResultsTitles();
345	setCurrentSearch();
346});

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.