PageSourceSearch

https://wcpl.lib.oh.us/scripts/custom.js

js wcpl.lib.oh.us collected 2026-09-27 10:43:06 UTC 6,532 bytes, 192 lines download raw bytes

1
2document.addEventListener("DOMContentLoaded", () => {
3	"use strict";
4
5	const USE_LEGACY_ENCORE_MAPPING = false;
6
7	const form = document.getElementById("search_encore");
8	if (!form) return;
9
10	const input = document.getElementById("encoreSearchInput");
11	const input_label = document.querySelector('label[for=encoreSearchInput]');
12	const encoreBase = document.getElementById("encoreBase");
13	const websiteBase = document.getElementById("websiteBase");
14
15	const placeholders = {
16		encore: "Search Catalog",
17		website: "Search Library Info & Services",
18		events: "Search Library Calendar",
19	};
20
21	const escapeRegExp = (s) => s.replace(/([.*+?^=!:${}()|[\]/\\])/g, "\\$1");
22
23	const encodeEncoreQuery = (value) => {
24		const term = value.trim();
25
26		if (!USE_LEGACY_ENCORE_MAPPING) {
27			return encodeURIComponent(term);
28		}
29
30		const base64EncodingMap = { "=": "PQ==", "/": "Lw==", "\\": "XA==", "?": "Pw==" };
31		let s = term;
32		for (const ch in base64EncodingMap) {
33			s = s.replace(new RegExp(escapeRegExp(ch), "g"), base64EncodingMap[ch]);
34		}
35		return encodeURIComponent(s);
36	};
37
38	const getSelectedSite = () =>
39		form.querySelector('input[name="searchsite"]:checked')?.value || "encore";
40
41	const updatePlaceholder = () => {
42		let tmp_placeholder = placeholders[getSelectedSite()] || "Search";
43		input.placeholder = tmp_placeholder;
44		input.ariaLabel = tmp_placeholder;
45		input_label.textContent = tmp_placeholder;
46	};
47
48	const buildUrl = (site, term) => {
49		if (site === "website") {
50			const url = new URL(websiteBase.value);
51			url.searchParams.set("q", term);
52			return url.toString();
53		}
54
55		if (site === "events") {
56			const url = new URL("https://events.wclibrary.info/calendar");
57			url.searchParams.set("t", "g");
58			url.searchParams.set("q", term);
59			url.searchParams.set("cid", "-1");
60			url.searchParams.set("cal", "-1");
61			url.searchParams.set("inc", "0");
62			return url.toString();
63		}
64
65		// Default: Encore catalog
66		const url = new URL(encoreBase.value);
67		url.searchParams.set("query", decodeURIComponent(encodeEncoreQuery(term)));
68		// ^ URLSearchParams will encode; we keep encodeEncoreQuery for optional legacy mapping.
69		url.searchParams.set("SearchType", "everything");
70		return url.toString();
71	};
72
73	form.addEventListener("change", (e) => {
74		if (e.target?.matches('input[name="searchsite"]')) {
75			updatePlaceholder();
76			input.setCustomValidity("");
77		}
78	});
79
80	form.addEventListener("submit", (e) => {
81		e.preventDefault();
82
83		const term = (input.value || "").trim();
84		if (!term) {
85			input.setCustomValidity("Please enter a search term.");
86			input.reportValidity();
87			input.focus();
88			return;
89		}
90		input.setCustomValidity("");
91
92		const site = getSelectedSite();
93		const destination = buildUrl(site, term);
94
95		window.open(destination, "_blank", "noopener,noreferrer");
96		input.value = "";
97	});
98
99	updatePlaceholder();
100});
101
102
103$(document).ready(function () {
104	"use strict";
105	// updated 11-8-2017 to rewrite .hover deprecated so use mouseenter and mouseleave //
106	$("#navi li").has("ul").on("mouseenter", function () {
107		$(this).addClass("current").children("ul").fadeIn('3000');
108	}, function () {
109		$(this).removeClass("current").children("ul").stop(true, true).fadeOut('3000');
110	});
111
112
113
114	$("<select />").appendTo("#navi");
115
116	$("<option />", { "selected": "selected", "value": "", "text": "Navigation Menu" }).appendTo("#navi select");
117
118	$("#navi ul li a").each(function () {
119		var el = $(this);
120		$("<option />", {
121			"value": el.attr("href"),
122			"text": el.text()
123		}).appendTo("#navi select");
124	});
125
126	$("#navi select").on('change', function () {    // updated 11-8-2017 to rewrite .change(function () shorthand is deprecated //
127		window.location = $(this).find("option:selected").val();
128	});
129	//// End navigation motions ////
130
131	//// grey scaling function ////
132	$(".bti").on("mouseenter", function () {    // updated 11-8-2017 to rewrite .hover deprecated so use mouseenter and mouseleave //
133		$(this).find(".featured-images").fadeTo(500, 0.4);
134	}, function () {
135		$(this).find(".featured-images").fadeTo(500, 1);
136	});
137
138	$(".latestthree").on("mouseenter", function () {    // updated 11-8-2017 to rewrite .hover deprecated so use mouseenter and mouseleave // 
139		$(this).find(".title").fadeTo(500, 0.4);
140		$(this).find(".latestthreeimage").fadeTo(500, 0.4);
141	}, function () {
142		$(this).find(".title").fadeTo(500, 1);
143		$(this).find(".latestthreeimage").fadeTo(500, 1);
144	});
145	//// End grey scaling function ////
146
147	//// Start Scroll Top Function //// 
148	$(window).on('scroll', function () {  //replaced .bind with .on 4-17-2015  //
149		if ($(this).scrollTop() > 200) {
150			$("#scrolltab").fadeIn('3000');
151		}
152		if ($(this).scrollTop() < 199) {
153			$("#scrolltab").fadeOut('3000');
154		}
155	});
156
157	$('#scrolltab').on('click', function () {  // replaced .live with .on 4-17-2015 //
158		$("html, body").animate({ scrollTop: 0 }, 'slow');
159	});
160	//// End Scroll Top Function ////
161
162	//// Start Tabs Function ////
163	$('.tab').on('click', function () {   // updated 11-8-2017 to rewrite .click(function () shorthand which is deprecated //
164		$('.tabs_container > .tabs > li.active').removeClass('active');
165		$(this).parent().slideDown('slow').addClass('active');
166		$('.tabs_container > .tab_contents_container > div.tab_contents_active').slideUp('slow').removeClass('tab_contents_active');
167
168		$(this.rel).slideDown('slow').addClass('tab_contents_active');
169	});
170	//// End Tabs Function ////
171
172	//// Start Toggle Function ////
173	$(".togglewrap .togglecontent").hide();
174	$('.togglewrap .toggletitle.active').addClass('active').next().show();
175	$(".togglewrap .toggletitle").on('click', function () {		// updated 11-8-2017 to rewrite .click(function shorthand which is deprecated //
176		$(this).toggleClass("active").next().slideToggle("fast");
177		return false;
178	});
179	//// End Toggle Function ////
180
181	//// Start Accordian Function ////
182	$('.accordionwrap .accordioncontent').hide();
183	$('.accordionwrap .accordiontitle:first-child').addClass('active').next().show();
184	$('.accordionwrap .accordiontitle').on('click', function () {	// updated 11-8-2017 to rewrite .click(function shorthand which is deprecated //
185		if ($(this).next().is(':hidden')) {
186			$(this).parent().find(".accordiontitle").removeClass('active').next().slideUp('fast');
187			$(this).toggleClass('active').next().slideDown('fast');
188		}
189		return false;
190	});
191	//// End Accordian Function ////
192});

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.