PageSourceSearch

https://www.cuw.edu/_files/js/find-degree.js?v=1736892786674

js cuw.edu collected 2026-09-24 09:21:48 UTC 4,637 bytes, 137 lines download raw bytes

1/* 
2*************************************************
3*************************************************
4PROGRAM SEARCH
5************************************************* 
6************************************************* 
7*/
8
9var searchProgram = $('#search-program');
10var searchProgramResults = $('#search-program-results');
11var searchProgramInput = $('#search-program-input');
12
13//show & hide filter list
14function toggleList(action) {			
15	//if we're asking for it to be open, and it isn't: open it
16	if( action && searchProgram.find('li').length >= 1 ) {
17		searchProgramResults.collapse('show');
18		searchProgram.addClass('active');
19	}
20	//if we/re asking to close it, and it's open: close it
21	if( !action ) {
22		searchProgramResults.collapse('hide');
23		searchProgram.removeClass('active');
24	}
25}
26
27//when we lose focus
28searchProgram.focusout(function() {
29	setTimeout(function() {
30		if( !searchProgram.find(':focus').length > 0 ) {
31			toggleList(0);
32		}
33	}, 10);
34}).keyup(function(e) {
35	//escape key pressed
36	if( e.keyCode === 27 ) {
37		toggleList(0);
38	}
39});
40
41//navigate filter list with arrows
42searchProgramResults.on('keydown','li a',function(e){
43	var thisBtn = $(this).parent();			
44	//down arrow key, and next button exists 
45	if(e.keyCode === 40 && thisBtn.next()) {
46		e.preventDefault();
47		thisBtn.nextAll('li').first().find('a').focus();
48	}
49	//up arrow key, and previous button exists                        
50	if(e.keyCode === 38 && thisBtn.prev()) {
51		e.preventDefault();
52		thisBtn.prevAll('li').first().find('a').focus();
53	}
54	//up arrow key, and previous button dosn't exist
55	if( ( e.keyCode === 38 && !thisBtn.prev().length ) || e.keyCode === 27 ) {
56		e.preventDefault();
57		searchProgramInput.focus();
58	}
59});
60
61searchProgramInput.on('focus',function(){
62	if( $(window).width() < 1024 ) {
63		$('html, body').animate({
64			scrollTop: (searchProgramInput.offset().top) - 20
65		}, 1000);
66	}
67});
68
69var timeout = null;
70searchProgramInput.on('focus keyup change',function(){
71	toggleList(1);
72}).keydown(function(e) {
73	if( (e.keyCode >= 65 && e.keyCode <= 90) || (e.keyCode >= 48 && e.keyCode <= 57) || e.keyCode === 8 || e.keyCode === 46 || e.keyCode === 229 ) {
74		clearTimeout(timeout);
75		timeout = setTimeout(function () {
76			var query = searchProgramInput.val().replace(/(<([^>]+)>)/ig,"").replace(/\+/g, ' ').replace(/(^\s+|\s+$)/g,'').trim();
77			if( query && query.length >= 2) {
78				searchQuery(query);
79			} else {
80				toggleList(0);
81				searchProgramResults.find('ul').html('');
82			}
83		}, 400);
84	}
85	//if down arrow, tab, or enter, focus on first list item
86	if( (e.keyCode === 40 || e.keyCode === 9 || e.keyCode === 13) && searchProgramResults.find('li').length) {
87		e.preventDefault();
88		searchProgramResults.find('li:first a').focus();
89	}
90});
91
92/* 
93*************************************************
94*************************************************
95SWIFTYPE
96************************************************* 
97************************************************* 
98*/
99
100/* =====================================================
101SEARCH QUERY
102===================================================== */
103function searchQuery(query) {
104	var searchParams = {
105		engine_key: 'qMoD8wmrbkqoBMgEmBjB',
106		q: query,
107		page: 1,
108		spelling: 'retry',
109		fetch_fields: {'page': ['title','url']},
110		filters: {'page':{'page-type':'degree'}},
111		per_page: 20
112	};
113	$.getJSON("//api.swiftype.com/api/v1/public/engines/search.json?callback=?", searchParams).done(function(data) {
114		searchResults(data, query);
115	});
116}
117
118/* =====================================================
119SEARCH RESULTS
120===================================================== */
121function searchResults(data, query) {
122	var resultList = searchProgramResults.find('ul');
123	resultList.find('li').remove();
124	var resultHTML = '';
125	var totalResults = data['info']['page']['total_result_count'];
126	var spellingSug = data['info']['page']['spelling_suggestion'];
127	if( totalResults == 0 ) { //we have nothing to show
128		resultHTML = '<li class="msg" role="status">We don\'t seem to have a program/degree matching that description, <a title="View all of Concordia\'s academic offerings" aria-l
128ive="polite" href="/academics/index.html" target="_blank">but check the full program list</a>.</li>';
129		resultList.append(resultHTML);
130	} else {
131		$.each(data['records']['page'], function(index, result) {		
132			resultHTML = '<li class="result"><a href="' + result['url'] + '" title="Visit program page">' + result['title'] + '</a></li>';
133			resultList.append(resultHTML);
134		});
135	}
136	toggleList(1);
137}

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.