PageSourceSearch

https://washtheocon.org/wp-content/plugins/wtc-course-database-search/js/script.js?ver=1715730281

js washtheocon.org collected 2026-10-02 10:47:17 UTC 19,242 bytes, 369 lines download raw bytes

1jQuery(document).ready( function($) {
2
3    var getJSONP = function(url, data, callback){
4        $.getJSON(url+"?callback=?", data, callback);
5    };
6
7    var logCallback = function(data){
8        console.log(data);
9    };
10
11    var populateSelect = function(url, selector, defaultText){
12        $(selector).empty();
13        $(selector).append("<option value=''>" + defaultText + "</option>");
14        getJSONP(url, {}, function(data){
15            $.each(data, function(key, item){
16                $(selector).append("<option value='"+item.id+"'>"+item.value+"</option>");
17            });
18        });
19    };
20
21    var populateCheckBoxes = function(url, selector, name){
22        $(selector).empty();
23        getJSONP(url, {}, function(data){
24            $.each(data, function(key, item){
25                $(selector).append("<input type='checkbox' name='"+name+"' value='"+item.id+"'>"+item.value+"</option>");
26            });
27        });
28    };
29
30
31
32
33
34
35
36
37    // define variables
38    var url                         = 'https://courses.washtheocon.org:8443';
39    var items_per_page_default      = 5;
40    var paginate                    = true;
41
42    var footer_copy = [
43        '',
44        '<a href="#!">Return to course search page.</a>',
45        '<a href="#!">Return to All Results</a><br><a href="#!">Return to Course Search Page</a>'
46    ];
47
48    // Cache selectors
49    var $middlewareSearch           = $("#middleware_search");
50    var $middlewareSearchResults    = $("#middleware_search_results");
51    var $middlewareCourseDetails    = $("#middleware_course_details");
52    var $intro                      = $(".intro");
53    var $footer                     = $("#db-search-footer");
54    var $pagination                 = $(".pagination");
55
56    // Populate the form elements with relevant options
57	populateSelect( url + "/middleware/search/semesters/list", "#semester", 'All semesters');
58	populateSelect( url + "/middleware/search/subjectListings/list", "#subjectListing", 'All subjects');
59	populateSelect( url + "/middleware/search/schools/list", "#school", 'All schools');
60	$("#school").change(function(){
61		populateSelect( url + "/middleware/search/schools/" + $("#school").val() + "/campuses", "#campus", 'All locations');
62	});
63	populateSelect( url + "/middleware/search/classTypes/list", "#classType", 'All types');
64	populateSelect( url + "/middleware/search/timesOfDay/list", "#timeOfDay", 'All times');
65	populateCheckBoxes( url + "/middleware/search/daysOfWeek/list", "#dayOfWeek", "daysOfWeek[]");
66
67    // Submit the search. Perform lookout and return results
68	$middlewareSearch.submit( function() {
69
70		var searchData = {
71            semesterId          : $("#semester").val(),
72            campusId            : $("#campus").val(),
73            subjectListingId    : $("#subjectListing").val(),
74            schoolId            : $("#school").val(),
75            classTypeId         : $("#classType").val(),
76            timeOfDayId         : $("#timeOfDay").val(),
77            dayOfWeekIds        : $("input[name='daysOfWeek[]']:checked").map(function(){return this.value;}).get(),
78            faculty             : $("#faculty").val(),
79            description         : $("#description").val(),
80            title               : $("#title").val(),
81		}
82
83		getJSONP( url + "/middleware/search", searchData, function(data) {
84
85		    wtc_step( 1 );
86
87            paginate = true;
88            num_of_pages = Math.ceil(data.length / items_per_page_default);
89
90			$middlewareSearch.fadeOut();
91			$middlewareSearchResults.empty();
92
93            displayResults( 0, $pagination );
94            pagination();
95
96            function displayResults(page_index, jq) {
97
98                if ( ! paginate ) {
99                    items_per_page = 9999;
100                } else {
101                    items_per_page = items_per_page_default;
102                }
103
104                $middlewareSearchResults.fadeOut( function() {
105
106                    var semester, school, subjectListings, title, daysOfWeek, faculty, time, credits;
107
108                    $('html, body').animate( { scrollTop: 0 } );
109
110                    var output = '';
111                    var max_elem = Math.min( ( page_index + 1 ) * items_per_page, data.length );
112                    var newcontent = '';
113
114                    if ( data.length > 0 ) {
115console.log(data);
116                        for ( var i = page_index * items_per_page; i < max_elem; i++ ) {
117                            if ((data[i].semester != null) && (data[i].semester != '')) { semester = data[i].semester; }
117 else { semester = 'Not listed.'; }
118                            if ((data[i].school != null) && (data[i].school != '')) { school = data[i].school; } else { school = 'Not listed.'; }
119                            if ((data[i].subjectListings != null) && (data[i].subjectListings != '')) { subjectListings = data[i].subjectListings; } else { subjectListings = 'Not listed.'; }
120                            if ((data[i].title != null) && (data[i].title != '')) { title = data[i].title; } else { title = 'Not listed.'; }
121                            if ((data[i].daysOfWeek != null) && (data[i].daysOfWeek != '')) { daysOfWeek = data[i].daysOfWeek; } else { daysOfWeek = 'Not listed.'; }
122                            if ((data[i].faculty != null) && (data[i].faculty != '')) { faculty = data[i].faculty; } else { faculty = 'Not listed.'; }
123                            if ((data[i].time != null) && (data[i].time != '')) { time = data[i].time; } else { time = 'Not listed.'; }
124                            if ((data[i].startDate != null) && (data[i].startDate != '')) { startDate = data[i].startDate; } else { startDate = 'Not listed.'; }
125                            if ((data[i].credits != null) && (data[i].credits != '')) { credits = data[i].credits; } else { credits = 'Not listed.'; }
126
127                            output += '<div class="db-result">';
128                                output += '<div class="field semester"><span class="label">Semester:</span> ' + semester + '</div>';
129                                output += '<div class="field school"><span class="label">School:</span> ' + school + '</div>';
130                                output += '<div class="field subject-area"><span class="label">Subject Area:</span> ' + subjectListings + '</div>';
131                                output += '<div class="field course-title"><span class="label">Course Title:</span> <a href="#!/' + i + '" class="course-detail-link">' + title + '</a></div>';
132                                output += '<div class="field days"><span class="label">Days of the Week:</span> ' + daysOfWeek + '</div>';
133                                output += '<div class="field faculty"><span class="label">Faculty:</span> ' + faculty + '</div>';
134                                output += '<div class="field time"><span class="label">Time:</span> ' + time + '</div>';
135                                output += '<div class="field startDate"><span class="label">Start Date:</span> ' + startDate + '</div>';
136                                output += '<div class="field credits"><span class="label">Credits:</span> ' + credits + '</div>';
137                            output += '</div>';
138                        }
139
140                    } else {
141
142                        output += '<div class="db-result">Your search found no results.</div>';
143
144                    }
145
146                    $middlewareSearchResults.empty().html( output ).fadeIn( function() {
147
148                        $('.course-detail-link').bind( 'click', function( event ) {
149
150                            wtc_step( 2, event );
151
152                            // main content fade out/replace/fade in
153                            var detail = data[$(this).attr('href').match(/\d+$/)[0]];
154
155                            var semester = '', school = '', campus = '', subjectListings = '', number = '', title = '', section = '', credits = '',
156                                faculty = '', classType = '', startDate = '', daysOfWeek = '', time = '', description = '', notes = '';
157
158                            if ((detail.semester != null) && (detail.semester != '')) { semester = detail.semester; } else { semester = 'Not listed.'; }
159                            if ((detail.school != null) && (detail.school != '')) { school = detail.school; } else { school = 'Not listed.'; }
160                            if ((detail.campus != null) && (detail.campus != '')) { campus = detail.campus; } else { campus = 'Not listed.'; }
161                            if ((detail.subjectListings != null) && (detail.subjectListings != '')) { subjectListings = detail.subjectListings; } else { subjectListings = 'Not listed.'; }
162                            if ((detail.number != null) && (detail.number != '')) { number = detail.number; } else { number = 'Not listed.'; }
163                            if ((detail.title != null) && (detail.title != '')) { title = detail.title; } else { title = 'Not listed.'; }
164                            if ((detail.section != null) && (detail.section != '')) { section = detail.section; } else { section = 'Not listed.'; }
165                            if ((detail.credits != null) && (detail.credits != '')) { credits = detail.credits; } else { credits = 'Not listed.'; }
166                            if ((detail.faculty != null) && (detail.faculty != '')) { faculty = detail.faculty; } else { faculty = 'Not listed.'; }
167                            if ((detail.classType != null) && (detail.classType != '')) { classType = detail.classType; } else { classType = 'Not listed.'; }
168                            if ((detail.startDate != null) && (detail.startDate != '')) { startDate = detail.startDate; } else { startDate = 'Not listed.'; }
169                            if ((detail.daysOfWeek != null) && (detail.daysOfWeek != '')) { daysOfWeek = detail.daysOfWeek; } else { daysOfWeek = 'Not listed.'; }
170                            if ((detail.time != null) && (detail.time != '')) { time = detail.time; } else { time = 'Not listed.'; }
171                            if ((detail.description != null) && (detail.description != '')) { description = detail.description; } else { description = 'Not listed.'; }
172                            if ((detail.notes != null) && (detail.notes != '')) { notes = detail.notes; } else { notes = 'Not listed.'; }
173
174                            $middlewareSearchResults.fadeOut( function() {
175                                $middlewareCourseDetails
176                                    .append($("<div>").addClass("field semester").html( '<span class="label">
176Semester:</span> ' + semester) )
177                                    .append($("<div>").addClass("field school").html( '<span class="label">School:</span> ' + school) )
178                                    .append($("<div>").addClass("field campus").html( '<span class="label">Campus:</span> ' + campus) )
179                                    .append($("<div>").addClass("field subject-area").html( '<span class="label">Subject Area:</span> ' + subjectListings) )
180                                    .append($("<div>").addClass("field course-number").html( '<span class="label">Course Number:</span> ' + number) )
181                                    .append($("<div>").addClass("field course-title").html( '<span class="label">Course Title:</span> ' + title) )
182                                    .append($("<div>").addClass("field section").html( '<span class="label">Section:</span> ' + section) )
183                                    .append($("<div>").addClass("field credits").html( '<span class="label">Credits:</span> ' + credits) )
184                                    .append($("<div>").addClass("field faculty").html( '<span class="label">Faculty:</span> ' + faculty) )
185                                    .append($("<div>").addClass("field class-type").html( '<span class="label">Class Type:</span> ' + classType) )
186                                    .append($("<div>").addClass("field start-date").html( '<span class="label">Start Date:</span> ' + startDate ) )
187                                    .append($("<div>").addClass("field days").html( '<span class="label">Days of the Week:</span> ' + daysOfWeek) )
188                                    .append($("<div>").addClass("field time").html( '<span class="label">Time:</span> ' + time) )
189                                    .append($("<p>").addClass("field description").html( '<span class="label">Description:</span> ' + description ) )
190                                    .append($("<p>").addClass("field notes").html( '<span class="label">Notes:</span> ' + notes ) );
191                                $middlewareCourseDetails.fadeIn();
192                            });
193                        });
194
195                    });
196                });
197
198                return false;
199            }
200
201            function pagination(currentPage) {
202                // if the currentPage isn't set, assume we're on page 1
203                if ( ! currentPage ) currentPage = 1;
204
205                // Force currentPage to act like a number
206                currentPage = (+currentPage);
207
208                // set the previous and next pages
209                prevPage = currentPage - 1;
210                nextPage = currentPage + 1;
211
212                // Previous button
213                if ( currentPage > -1 ) {
214                    if ( prevPage == 0 ) {
215                        $pagination.html( '<span class="current prev">Prev</span>' );
216                    } else {
217                        $pagination.html( '<a class="prev" href="#' + prevPage + '">Prev</a>' );
218                    }
219                } else {
220                    $pagination.empty();
221                }
222
223                // Paged number buttons
224                if ( num_of_pages > 5 ) {
225                    // If we have more than 5 pages of content, only display links to the pages around currentPage
226
227                    if ( currentPage < 4 ) {
228                        var position = 'start';
229                        var startPage = 1;
230                        var endPage = 5;
231                    } else if ( currentPage > ( num_of_pages - 4 ) ) {
232                        var position = 'end';
233                        var startPage = num_of_pages - 4;
234                        var endPage = num_of_pages;
235                    } else {
236                        var position = 'mid';
237                        var startPage = currentPage - 1;
238                        var endPage = currentPage + 1;
239                    }
240
241                    if ( ( position == 'mid' ) || ( position == 'end' ) ) {
242                        $pagination.append( '<a href="#1">1</a> <span>...</span> ' );
243                    }
244
245                    for ( var i = startPage; i <= endPage; i++ ) {
246                        if ( currentPage == i ) {
247                            $pagination.append( '<span class="current">' + currentPage + '</span>' );
248                        } else {
249                            $pagination.append( '<a href="#' + i + '">' + i + '</a>' );
250                        }
251                    }
252
253                    if ( ( position == 'start' ) || ( position == 'mid' ) ) {
254                        $pagination.append( ' <span>...</span> <a href="#' + num_of_pages + '">' + num_of_pages + '</a>' );
255                    }
256                } else {
257                    for ( var i = 0; i < num_of_pages; i++ ) {
258                        if ( currentPage == ( i + 1 ) ) {
259                            $pagination.append( '<span class="current">' + currentPage + '</span>' );
260                        } else {
261                            $pagination.append( '<a href="#' + ( i + 1 ) + '">' + ( i + 1 ) + '</a>' );
262                        }
263                    }
264                }
265
266                // Next button
267                if ( currentPage > -1 ) {
268                    if ( nextPage > num_of_pages ) {
269                        $pagination.append( '<span class="current next">Next</span>' );
270                    } else {
271                        $pagination.append( '<a class="next" href="#' + nextPage + '">Next</a>' );
272                    }
273
274                    // View all button
275                    $pagination.append( '<a class="view-all" href="#0">View All</a>' );
276                }
277
278                // Bind all the links to an appropriate action
279                $pagination.find('a').unbind('click').bind('click', function(event) {
280                    var startingPage = $(this).attr('href').substring(1);
281                    if ( startingPage == 0 ) {
282                        paginate = false;
283                        displayResults( 0, $pagination );
284                        pagination( -1 );
285                    } else {
286                        displayResults( startingPage - 1, $pagination );
287                        pagination( startingPage );
288                    }
289                });
290            }
291		});
292
293		return false;
294	});
295
296
297    // Perform all the necessary tasks to get to step 1
298    function wtc_step( index, event) {
299
300        if ( ! index ) index = 0;
301
302        $('html, body').animate( { scrollTop: 0 } );
303
304        if ( event ) event.preventDefault();
305
306        // Intro
307        $intro.fadeOut( function() {
308            $intro.eq(index).fadeIn( function() {
309                if ( index == 1 ) {
310                    $(this).find('a').eq(0).unbind('click').bind('click', function( event ) {
311                        wtc_step( 0, event );
312                    });
313                } else if ( index == 2 ) {
314                    $(this).find('a').eq(0).unbind('click').bind('click', function(event) {
315                        wtc_step(1, event);
316                    });
317
318                    $(this).find('a').eq(1).unbind('click').bind('click', function(event) {
319                        wtc_step(0, event);
320                    });
321                }
322            });
323        });
324
325        // Main content
326        if ( index == 0 ) {
327            $middlewareSearchResults.fadeOut();
328            $middlewareCourseDetails.fadeOut();
329            $middlewareSearch.fadeIn();
330
331            if ($pagination.is(":visible")) {
332                $pagination.hide();
333            }
334        } if ( index == 1 ) {
335            $middlewareSearch.fadeOut();
336            $middlewareCourseDetails.fadeOut().empty();
337            $middlewareSearchResults.fadeIn();
338            $pagination.fadeIn();
339        }
340
341        // Footer
342        $footer.fadeOut( function() {
343            $(this).empty().html( footer_copy[index] ).fadeIn( function() {
344                if ( index == 1 ) {
345                    $(this).find('a').eq(0).unbind('click').bind('click', function( event ) {
346                        wtc_step( 0, event );
347                    });
348                } else if ( index == 2 ) {
349                    $(this).find('a').eq(0).unbind('click').bind('click', function( event ) {
350                        wtc_step( 1, event );
351                    });
352
353                    $(this).find('a').eq(1).unbind('click').bind('click', function( event ) {
354                        wtc_step( 0, event );
355                    });
356
357                    $pagination.fadeOut();
358                }
359            });
360        });
361    }
362});
363
364// Clear search form
365function clearDBSearch() {
366    jQuery("#middleware_search").each( function() {
367        this.reset();
368    });
369}

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.