PageSourceSearch

https://www.stadtradio-goettingen.de/++resource++zms_/jquery/plugin/jquery.plugin.zmi_highlight.js

js stadtradio-goettingen.de collected 2026-10-02 05:42:52 UTC 2,538 bytes, 93 lines download raw bytes

1// ############################################################################
2// ### Highlight
3// ############################################################################
4
5/**
6 * Scroll to given element.
7 * 
8 * @see http://radio.javaranch.com/pascarello/2005/01/09/1105293729000.html
9 */
10function zmiScrollToElement(theElement) {
11	var selectedPosX = 0;
12	var selectedPosY = 0;
13	while(theElement != null){
14		selectedPosX += theElement.offsetLeft;
15		selectedPosY += theElement.offsetTop;
16		theElement = theElement.offsetParent;
17	}
18	window.scrollTo(selectedPosX,selectedPosY);
19}
20
21// escape by Colin Snover
22// Note: if you don't care for (), you can remove it..
23RegExp.escape = function(text) {
24	return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
25}
26
27/**
28 * Highlight all occurences of given text.
29 * 
30 * @see http://stackoverflow.com/questions/3241169/highlight-search-terms-select-only-leaf-nodes
31 */
32function htmlReplace($context, exp, newvalue) {
33	newvalue = newvalue.replace(/class="(.*?)"/i,'class="$1 nohighlight"');
34	var regexp = new RegExp(exp, "gi");
35	$('*',$context)
36		.andSelf()
37		.contents()
38		.filter(function(){
39			// nodyType=3 (Text) Represents textual content in an element or attribute
40			return this.nodeType === 3;
41		})
42		.filter(function(){
43			// Only match when contains 'simple string' anywhere in the text
44			return this.nodeValue.match(regexp);
45		})
46		.each(function(i, el){
47			// Do something with this.nodeValue
48			if ($(el).parents(".nohighlight,a,button,input").length==0) {
49				var data = el.data;
50				if (data = data.replace(regexp, newvalue)) {
51					var wrapper = $("<span>").html(data);
52					$(el).before(wrapper.contents()).remove();
53				}
54			}
55		});
56}
57
58/**
59 * Init highlight.
60 */
61function zmiInitHighlight(s) {
62	var $context = $("body");
63	var newvalue = '<span class=\"highlight\">$1</span>';
64	var raw = s.split(" ");
65	var text1st = null;
66	for (var i = 0; i < raw.length; i++) {
67		var text = raw[i].basicTrim();
68		if (text.length > 0) {
69			if (text1st == null) {
70				text1st = text;
71			}
72			htmlReplace( $context, "("+text+")", newvalue);
73		}
74	}
75	if (text1st!=null) {
76		var spans_highlight = $('span.highlight');
77		if ( spans_highlight.length>0) {
78			zmiScrollToElement(spans_highlight[0]);
79		}
80	}
81}
82
83
84$(function() {
85	try {
86		zmiInitHighlight(zmiParams[zmiParams['ZMS_HIGHLIGHT']]);
87	}
88	catch (e) {
89		// do nothing
90	}
91});
92
93// ############################################################################

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.