PageSourceSearch

https://www.casn.ca/WebResource.axd?d=Bdx__JkQr3_zQGGJuFvhK_rZndXG…YHNaFs_2Q6rsL86GWTFk41&t=638985533620000000

js casn.ca collected 2026-09-24 10:18:46 UTC 22,645 bytes, 674 lines download raw bytes

1/*#<![CDATA[*/
2//-For version 6.0.0
3
4/*
5* The following is Copyright 2007-2015 Keyoti Inc.
6*/
7		
8var sew_queryTB;
9var sew_menuShiftX=0;
10var sew_menuShiftY=0;
11
12function sew_item_selected(li, options){
13	if(options.sew_runSearchOnSelect)
14	    eval(options.sew_searchPostback);
15	else
16	    sew_queryTB.focus();
17		//document.getElementById(options.sew_searchButtonID).click();
18}
19		
20
21function sew_formatItem(row, i, num, li) {
22    return "<span class='sew_suggestion'>" + row[0].replace(/</g, "&lt;").replace(/>/g, "&gt;") + "</span><span class='sew_results'>" + (row[1] != "-1" && typeof (row[1]) != 'undefined' ? row[1] : "") + "</span>";
23}
24KSQ(document).ready(function(){
25for(var i=0; i<sew_configs.length; i++){
26
27
28	KSQ("#"+sew_configs[i].sew_queryTextBoxID).autocomplete(
29	sew_configs[i].sew_appPath+"Keyoti.SearchEngine.Web.CallBackHandler.ashx",
30
31	{
32	delay:50,
33	minChars:1,
34	matchSubset:0,
35	matchContains:1,
36	cacheLength:1,
37	formatItem:sew_formatItem,
38	autoFill:false,
39	onItemSelect:sew_item_selected,
40		//##NOCRUNCH
41	extraParams: { "cl": "SBAC", "id": sew_configs[i].sew_indexDirectory, "tl": sew_configs[i].sew_showNumberOfResults, "n": sew_configs[i].sew_numberOfSuggestions, "p": (sew_configs[i].sew_autoCompleteQueryLoadPlugin ? "1" : "0"), "s": sew_configs[i].sew_source, "hd": sew_configs[i].sew_hideNoResulters },
42		//##ENDNOCRUNCH
43	sew_searchButtonID:sew_configs[i].sew_searchButtonID,
44	sew_runSearchOnSelect:sew_configs[i].sew_runSearchOnSelect,
45	sew_searchPostback:sew_configs[i].sew_searchPostback
46	}
47	);
48	sew_queryTB = KSQ("#"+sew_configs[i].sew_queryTextBoxID)[0];
49	if(sew_queryTB!=null)sew_copyComputedStyle(KSQ._styleRule('.sew_suggestion'), sew_queryTB);
50	if(sew_queryTB!=null)sew_copyComputedStyle(KSQ._styleRule('.sew_results'), sew_queryTB, "nocolor");
51}
52});
53
54KSQ.autocomplete = function(input, options) {
55    // Create a link to self
56    var me = this;
57
58    // Create KSQ object for input element
59    var $input = KSQ(input).attr("autocomplete", "off");
60
61    // Apply inputClass if necessary
62    if (options.inputClass) $input.addClass(options.inputClass);
63
64    // Create results
65    var results = document.createElement("div");
66    // Create KSQ object for results
67    var $results = KSQ(results);
68    $results.hide().addClass(options.resultsClass).css("position", "absolute");
69    if (options.width > 0) $results.css("width", options.width);
70
71    // Add to body element
72    KSQ("body").append(results);
73
74    input.autocompleter = me;
75
76    var timeout = null;
77    var prev = "";
78    var active = -1;
79    var cache = {};
80    var keyb = false;
81    var hasFocus = false;
82    var lastKeyPressCode = null;
83
84    // flush cache
85    function flushCache() {
86        cache = {};
87        cache.data = {};
88        cache.length = 0;
89    };
90
91    // flush cache
92    flushCache();
93
94    // if there is a data array supplied
95    if (options.data != null) {
96        var sFirstChar = "", stMatchSets = {}, row = [];
97
98        // no url was specified, we need to adjust the cache length to make sure it fits the local data store
99        if (typeof options.url != "string") options.cacheLength = 1;
100
101        // loop through the array and create a lookup structure
102        for (var i = 0; i < options.data.length; i++) {
103            // if row is a string, make an array otherwise just reference the array
104            row = ((typeof options.data[i] == "string") ? [options.data[i]] : options.data[i]);
105
106            // if the length is zero, don't add to list
107            if (row[0].length > 0) {
108                // get the first character
109                sFirstChar = row[0].substring(0, 1).toLowerCase();
110                // if no lookup array for this character exists, look it up now
111                if (!stMatchSets[sFirstChar]) stMatchSets[sFirstChar] = [];
112                // if the match is a string
113                stMatchSets[sFirstChar].push(row);
114            }
115        }
116
117        // add the data items to the cache
118        for (var k in stMatchSets) {
119            // increase the cache size
120            options.cacheLength++;
121            // add to the cache
122            addToCache(k, stMatchSets[k]);
123        }
124    }
125
126    $input
127	.keydown(function(e) {
128	    // track last key pressed
129	    lastKeyPressCode = e.keyCode;
130	    switch (e.keyCode) {
131	        case 38: // up
132	            e.preventDefault();
133	            moveSelect(-1);
134	            break;
135	        case 40: // down
136	            e.preventDefault();
137	            moveSelect(1);
138	            break;
139	        case 9:  // tab
140	        case 13: // return
141	            if (selectCurrent()) {
142	                // make sure to blur off the current field
143	                $input.get(0).blur();
144	                e.preventDefault();
145	            }
146	            break;
147	        default:
148	            active = -1;
149	            if (timeout) clearTimeout(timeout);
150	            timeout = setTimeout(function() { onChange(); }, options.delay);
151	            break;
152	    }
153	})
154	.focus(function() {
155	    // track whether the field has focus, we shouldn't process any results if the field no longer has focus
156	    hasFocus = true;
157	})
158	.blur(function() {
159	    // track whether the field has focus
160	    hasFocus = false;
161	    hideResults();
162	});
163
164    hideResultsNow();
165
166    function onChange() {
167        // ignore if the following keys are pressed: [del] [shift] [capslock]
168        if (lastKeyPressCode == 46 || (lastKeyPressCode > 8 && lastKeyPressCode < 32)) return $results.hide();
169        var v = $input.val();
170        if (v == prev) return;
171        prev = v;
172        if (v.length >= options.minChars) {
173            $input.addClass(options.loadingClass);
174            requestData(v);
175        } else {
176            $input.removeClass(options.loadingClass);
177            $results.hide();
178        }
179    };
180
181    function moveSelect(step) {
182
183        var lis = KSQ("li", results);
184        if (!lis) return;
185
186        active += step;
187
188        if (active < 0) {
189            active = 0;
190        } else if (active >= lis.size()) {
191            active = lis.size() - 1;
192        }
193
194        lis.removeClass("sew_ac_over");
195
196        if (lis[active])
197            KSQ(lis[active]).addClass("sew_ac_over");
198
199        //jim fill when cursor selecting
200        $input.val(KSQ(lis[active])[0].selectValue);
201
202        // Weird behaviour in IE
203        // if (lis[active] && lis[active].scrollIntoView) {
204        // 	lis[active].scrollIntoView(false);
205        // }
206
207    };
208
209    function selectCurrent() {
210        var li = KSQ("li.sew_ac_over", results)[0];
211        if (!li) {
212            var $li = KSQ("li", results);
213            if (options.selectOnly) {
214                if ($li.length == 1) li = $li[0];
215            } else if (options.selectFirst) {
216                li = $li[0];
217            }
218        }
219        if (li) {
220            selectItem(li);
221            return true;
222        } else {
223            return false;
224        }
225    };
226
227    function selectItem(li) {
228        if (!li) {
229            li = document.createElement("li");
230            li.extra = [];
231            li.selectValue = "";
232        }
233        var v = KSQ.trim(li.selectValue ? li.selectValue : li.innerHTML);
234        input.lastSelected = v;
235        prev = v;
236        $results.html("");
237        $input.val(v);
238        hideResultsNow();
239        if (options.onItemSelect) setTimeout(function() { options.onItemSelect(li, options) }, 1);
240    };
241
242    // selects a portion of the input string
243    function createSelection(start, end) {
244        // get a reference to the input element
245        var field = $input.get(0);
246        if (field.createTextRange) {
247            var selRange = field.createTextRange();
248            selRange.collapse(true);
249            selRange.moveStart("character", start);
250            selRange.moveEnd("character", end);
251            selRange.select();
252        } else if (field.setSelectionRange) {
253            field.setSelectionRange(start, end);
254        } else {
255            if (field.selectionStart) {
256                field.selectionStart = start;
257                field.selectionEnd = end;
258            }
259        }
260        field.focus();
261    };
262
263    // fills in the input box w/the first match (assumed to be the best match)
264    function autoFill(sValue) {
265        // if the last user key pressed was backspace, don't autofill
266        if (lastKeyPressCode != 8) {
267            // fill in the value (keep the case the user has typed)
268            $input.val($input.val() + sValue.substring(prev.length));
269            // select the portion of the value not typed by the user (so the next character will erase)
270            createSelection(prev.length, sValue.length);
271        }
272    };
273
274    function showResults() {
275        // get the position of the input field right now (in case the DOM is shifted)
276        var pos = findPos(input);
277        // either use the specified width, or autocalculate based on form element
278        var iWidth = (options.width > 0) ? options.width : $input.width();
279        // reposition
280        $results.css({
281            width: parseInt(iWidth) + "px",
282            top: (pos.y + input.offsetHeight + sew_menuShiftY) + "px",
283            left: pos.x + sew_menuShiftX + "px"
284        }).show();
285    };
286
287    function hideResults() {
288        if (timeout) clearTimeout(timeout);
289        timeout = setTimeout(hideResultsNow, 200);
290    };
291
292    function hideResultsNow() {
293        if (typeof (sew_autocomplete_nohide) != 'undefined') return;
294        if (timeout) clearTimeout(timeout);
295        $input.removeClass(options.loadingClass);
296        if ($results.is(":visible")) {
297            $results.hide();
298        }
299        if (options.mustMatch) {
300            var v = $input.val();
301            if (v != input.lastSelected) {
302                selectItem(null);
303            }
304        }
305    };
306
307    function receiveData(q, data) {
308        if (data) {
309            $input.removeClass(options.loadingClass);
310            results.innerHTML = "";
311
312            // if the field no longer has focus or if there are no matches, do not display the drop down
313            if (!hasFocus || data.length == 0) return hideResultsNow();
314
315            if (KSQ.browser && KSQ.browser.msie) {
316                // we put a styled iframe behind the calendar so HTML SELECT elements don't show through
317                $results.append(document.createElement('iframe'));
318            }
319            results.appendChild(dataToDom(data));
320            // autofill in the complete box w/the first match as long as the user hasn't entered in more data
321            if (options.autoFill && ($input.val().toLowerCase() == q.toLowerCase())) autoFill(data[0][0]);
322            showResults();
323        } else {
324            hideResultsNow();
325        }
326    };
327
328    function parseData(data) {
329        if (!data) return null;
330        var parsed = [];
331
332        var rows = data.split(options.lineSeparator);
333
334        for (var i = 0; i < rows.length; i++) {
335            var row = KSQ.trim(rows[i]);
336            if (row.indexOf("~Exception/") > -1) {
337                var message = row.substring("~Exception/".length);
338                onError("An exception occurred on the server: " + message);
339            } else {
340
341                if (row) {
342                    /*
343                    parsed[parsed.length] = row.split(options.cellSeparator);
344                    parsed[parsed.length-1][0] = parsed[parsed.length-1][0].replace(/\\\|/g,"|");
345                    */
346                    parsed[parsed.length] = lastSplit(row, options.cellSeparator);
347                }
348            }
349        }
350        return parsed;
351    };
352
353    function lastSplit(row, separator) {
354        //splits once, at the last instance of separator
355        var p = row.lastIndexOf(separator);
356        if (p == -1) return [row];
357        else return [row.substring(0, p), row.substring(p + 1)];
358    }
359
360    function dataToDom(data) {
361        var ul = document.createElement("ul");
362        var num = data.length;
363
364        // limited results to a max number
365        if ((options.maxItemsToShow > 0) && (options.maxItemsToShow < num)) num = options.maxItemsToShow;
366
367        for (var i = 0; i < num; i++) {
368            var row = data[i];
369            if (!row) continue;
370            var li = document.createElement("li");
371            if (options.formatItem) {
372                li.innerHTML = options.formatItem(row, i, num, li);
373                li.selectValue = row[0];
374            } else {
375                li.innerHTML = row[0];
376                li.selectValue = row[0];
377            }
378            var extra = null;
379            if (row.length > 1) {
380                extra = [];
381                for (var j = 1; j < row.length; j++) {
382                    extra[extra.length] = row[j];
383                }
384            }
385            li.extra = extra;
386            ul.appendChild(li);
387            KSQ(li).hover(
388				function() { KSQ("li", ul).removeClass("sew_ac_over"); KSQ(this).addClass("sew_ac_over"); active = KSQ("li", ul).indexOf(KSQ(this).get(0)); },
389				function() { KSQ(this).removeClass("sew_ac_over"); }
390			).click(function(e) { e.preventDefault(); e.stopPropagation(); selectItem(this) });
391        }
392        return ul;
393    };
394
395    var requestTimeout = null;
396
397    function requestData(q) {
398        if (!options.matchCase) q = q.toLowerCase();
399        //JIM, no caching		var data = options.cacheLength ? loadFromCache(q) : null;
400        var data = null;
401        // receive the cached data
402        if (data) {
403            receiveData(q, data);
404            // if an AJAX url has been supplied, try loading the data now
405        } else if ((typeof options.url == "string") && (options.url.length > 0)) {
406            if (requestTimeout != null)
407                clearTimeout(requestTimeout);
408            requestTimeout = setTimeout(onTimeout, 10000);
409            KSQ.get(makeUrl(q), function(data) {
410                clearTimeout(requestTimeout);
411                data = parseData(data);
412                if (typeof sew_OnAutoCompleteSuggestionsGenerated == 'function') sew_OnAutoCompleteSuggestionsGenerated(q, data);
413                addToCache(q, data);
414                receiveData(q, data);
415            });
416            // if there's been no data found, remove the loading class
417        } else {
418            $input.removeClass(options.loadingClass);
419        }
420    };
421
422    function onTimeout() {
423        onError("Sorry the server didn't respond to the AJAX request from SearchUnit, please email [email protected] for help, likely you need to get WCF working (for .NET 4) or the WebAPI controller in our assembly wasn't loaded (for .NET 5+).");
424    };
425
426    function onError(message) {
427        if (!sew_failSilent)
428            alert(message);
429    };
430
431    function makeUrl(q) {
432        var url = options.url + "?q=" + encodeURI(q);
433        for (var i in options.extraParams) {
434            url += "&" + i + "=" + encodeURI(options.extraParams[i]);
435        }
436        return url + "&nocache=" + Math.floor(Math.random() * 99999);//without nocache it seems the browser will cache server responses
437    };
438
439    function loadFromCache(q) {
440        if (!q) return null;
441        if (cache.data[q]) return cache.data[q];
442        if (options.matchSubset) {
443            for (var i = q.length - 1; i >= options.minChars; i--) {
444                var qs = q.substr(0, i);
445                var c = cache.data[qs];
446                if (c) {
447                    var csub = [];
448                    for (var j = 0; j < c.length; j++) {
449                        var x = c[j];
450                        var x0 = x[0];
451                        if (matchSubset(x0, q)) {
452                            csub[csub.length] = x;
453                        }
454                    }
455                    return csub;
456                }
457            }
458        }
459        return null;
460    };
461
462    function matchSubset(s, sub) {
463        if (!options.matchCase) s = s.toLowerCase();
464        var i = s.indexOf(sub);
465        if (i == -1) return false;
466        return i == 0 || options.matchContains;
467    };
468
469    this.flushCache = function() {
470        flushCache();
471    };
472
473    this.setExtraParams = function(p) {
474        options.extraParams = p;
475    };
476
477    this.findValue = function() {
478        var q = $input.val();
479
480        if (!options.matchCase) q = q.toLowerCase();
481        var data = options.cacheLength ? loadFromCache(q) : null;
482        if (data) {
483            findValueCallback(q, data);
484        } else if ((typeof options.url == "string") && (options.url.length > 0)) {
485            KSQ.get(makeUrl(q), function(data) {
486                data = parseData(data);
487                addToCache(q, data);
488                findValueCallback(q, data);
489            });
490        } else {
491            // no matches
492            findValueCallback(q, null);
493        }
494    };
495
496    function findValueCallback(q, data) {
497        if (data) $input.removeClass(options.loadingClass);
498
499        var num = (data) ? data.length : 0;
500        var li = null;
501
502        for (var i = 0; i < num; i++) {
503            var row = data[i];
504
505            if (row[0].toLowerCase() == q.toLowerCase()) {
506                li = document.createElement("li");
507                if (options.formatItem) {
508                    li.innerHTML = options.formatItem(row, i, num, li);
509                    li.selectValue = row[0];
510                } else {
511                    li.innerHTML = row[0];
512                    li.selectValue = row[0];
513                }
514                var extra = null;
515                if (row.length > 1) {
516                    extra = [];
517                    for (var j = 1; j < row.length; j++) {
518                        extra[extra.length] = row[j];
519                    }
520                }
521                li.extra = extra;
522            }
523        }
524
525        if (options.onFindValue) setTimeout(function() { options.onFindValue(li) }, 1);
526    }
527
528    function addToCache(q, data) {
529        if (!data || !q || !options.cacheLength) return;
530        if (!cache.length || cache.length > options.cacheLength) {
531            flushCache();
532            cache.length++;
533        } else if (!cache[q]) {
534            cache.length++;
535        }
536        cache.data[q] = data;
537    };
538
539    function findPos(obj) {
540        var curleft = obj.offsetLeft || 0;
541        var curtop = obj.offsetTop || 0;
542        while (obj = obj.offsetParent) {
543            curleft += obj.offsetLeft;
544            curtop += obj.offsetTop;
545        }
546        return { x: curleft, y: curtop };
547    }
548};
549
550KSQ.fn.autocomplete = function(url, options, data) {
551	// Make sure options exists
552	options = options || {};
553	// Set url as option
554	options.url = url;
555	// set some bulk local data
556	options.data = ((typeof data == "object") && (data.constructor == Array)) ? data : null;
557
558	// Set default values for required options
559	options.inputClass = options.inputClass || "ac_input";
560	options.resultsClass = options.resultsClass || "sew_ac_results";
561	options.lineSeparator = options.lineSeparator || "\n";
562	options.cellSeparator = options.cellSeparator || "|";
563	options.minChars = options.minChars || 1;
564	options.delay = options.delay || 400;
565	options.matchCase = options.matchCase || 0;
566	options.matchSubset = options.matchSubset || 1;
567	options.matchContains = options.matchContains || 0;
568	options.cacheLength = options.cacheLength || 1;
569	options.mustMatch = options.mustMatch || 0;
570	options.extraParams = options.extraParams || {};
571	options.loadingClass = options.loadingClass || "sew_ac_loading";
572	options.selectFirst = options.selectFirst || false;
573	options.selectOnly = options.selectOnly || false;
574	options.maxItemsToShow = options.maxItemsToShow || -1;
575	options.autoFill = options.autoFill || false;
576	options.width = parseInt(options.width, 10) || 0;
577
578	this.each(function() {
579		var input = this;
580		new KSQ.autocomplete(input, options);
581	});
582
583	// Don't break the chain
584	return this;
585};
586
587KSQ.fn.autocompleteArray = function(data, options) {
588	return this.autocomplete(null, options, data);
589};
590
591KSQ.fn.indexOf = function(e){
592	for( var i=0; i<this.length; i++ ){
593		if( this[i] == e ) return i;
594	}
595	return -1;
596};
597
598
599//--------------------------------------
600
601
602
603  KSQ._styleRule = function (selector, options){
604    options = KSQ.extend ({type: 'text/css', media: 'all'}, options);
605    var sheet = KSQ._styleRule.sheets[options.media];
606    if (!sheet){
607      var style = KSQ(document.createElement('style')).attr(options).appendTo('head')[0];
608      if (style.styleSheet){
609        // IE
610        KSQ._styleRule.sheets[options.media] = sheet = style.styleSheet;
611      }else if (style.sheet){
612        // Firefox
613        KSQ._styleRule.sheets[options.media] = sheet = style.sheet;
614        sheet.rules = []; // lets us use the same rules array
615      }
616    }
617    if(sheet.rules){
618    if (sheet.rules [selector]) return KSQ(sheet.rules [selector]);
619    if (sheet.cssRules){
620      // Firefox
621      sheet.insertRule(selector+' {}',sheet.cssRules.length);
622      return KSQ(sheet.rules[selector] = sheet.cssRules[sheet.cssRules.length-1]);
623    }else{
624      // IE
625      sheet.addRule(selector, null);
626      return KSQ(sheet.rules[selector] = sheet.rules[sheet.rules.length-1]);
627    }  
628    }    
629  };
630  KSQ._styleRule.sheets = []; 
631
632//copies style from sEl to tEl
633function sew_copyComputedStyle(tEl, sEl, opt){
634	var col;
635	
636	if (sEl.currentStyle) 
637		col = sEl.currentStyle;
638	else if (document.defaultView && document.defaultView.getComputedStyle)
639		col = document.defaultView.getComputedStyle(sEl, null);
640	else{
641	
642		return;
643	}
644	for(sp in col)
645	
646		try{
647		    if (sp.indexOf("font") > -1 || sp.indexOf("text") > -1 || (sp == "color" && opt != 'nocolor')) {
648
649		        var v = sew_getStyleProperty(sEl, sp);
650
651		        if (sp == "color" && sew_OC[sEl.id] != null) v = sew_OC[sEl.id];
652				if(typeof(v)!='undefined' && v!='' )
653					tEl.css(sp, v);
654		}
655				
656		} catch (ex){
657		
658		}
659}
660
661
662function sew_getStyleProperty(obj, IEStyleProp) 
663{ 
664
665	if (obj.currentStyle) {//IE 
666		return obj.currentStyle[IEStyleProp]; 
667	}else if (document.defaultView.getComputedStyle) {//W3C 
668		return document.defaultView.getComputedStyle(obj, null)[IEStyleProp];//.getPropertyValue(CSSStyleProp); 
669	}else{
670		return null; 
671	}
672}
673
674/* ]]> */

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.