PageSourceSearch

https://www.nmc.edu/files/js/message.js

js nmc.edu collected 2026-10-01 11:50:24 UTC 5,182 bytes, 166 lines download raw bytes

1if(typeof addLoadEvent == "function")
2    addLoadEvent(loadMessage);
3else
4	window.onload = loadMessage;
5
6function loadMessage()
7{
8	var httpRequest = new XMLHttpRequest();
9	httpRequest.onreadystatechange = function()
10	{
11		if(httpRequest.readyState == 4 && httpRequest.status != 200)
12		{
13			//alert("Unable to load data.");
14		}
15		else if(httpRequest.readyState == 4)
16		{
17            if(httpRequest.responseXML)
18			    processMessageXML(httpRequest.responseXML.firstChild);
19		}
20	};
21	httpRequest.open("GET", "/files/xml/messages.xml" + "?cacheBuster=" + (Math.round(new Date().getTime() / 10000)), true);
22	httpRequest.send(null);
23}
24
25function processMessageXML(messageXML)
26{
27	var page = window.location.pathname;
28	if(page.substring(page.length - 1) == "/")
29		page += "index.html";
30	if(page.substring(0, 10) == "/textonly/")
31		page = page.substring(9);
32	
33	for(var i = 0; i < messageXML.childNodes.length; i++)
34	{
35		if(messageXML.childNodes[i].nodeName == "message")
36		{
37			var showMessage = false;
38			var data = {
39				name: "",
40				global: "",
41				content: "",
42				pages: new Array()
43			};
44
45			for(var j = 0; j < messageXML.childNodes[i].childNodes.length; j++)
46			{
47				if(messageXML.childNodes[i].childNodes[j].nodeName == "global" && messageXML.childNodes[i].childNodes[j].firstChild && messageXML.childNodes[i].childNodes[j].firstChild.nodeValue == "Yes")
48				{
49					showMessage = true;
50					break;
51				}
52				if(messageXML.childNodes[i].childNodes[j].nodeName == "pages")
53				{
54					for(var k = 0; k < messageXML.childNodes[i].childNodes[j].childNodes.length; k++)
55					{
56						if(messageXML.childNodes[i].childNodes[j].childNodes[k].firstChild && (messageXML.childNodes[i].childNodes[j].childNodes[k].firstChild.nodeValue == page || messageXML.childNodes[i].childNodes[j].childNodes[k].firstChild.nodeValue == "/textonly" + page))
57						{
58							showMessage = true;
59							break;
60						}
61					}
62				}
63			}
64			if(showMessage)
65			{
66				for(var j = 0; j < messageXML.childNodes[i].childNodes.length; j++)
67				{
68					if(messageXML.childNodes[i].childNodes[j].nodeName == "content")
69					{
70						var node = document.createElement("div");
71						if(copyXmlToHtml(messageXML.childNodes[i].childNodes[j], node))
72							document.getElementById("message").appendChild(node);
73					}
74				}
75			}
76		}
77	}
78}
79
80function copyXmlToHtml(xmlElement, htmlElement)
81{
82	var ieIgnoredAttributes = [ "style", "onclick", "onblur", "name", "type", "checked", "for" ];
83	var copiedElements = 0;
84	for(var i = 0; i < xmlElement.childNodes.length; i++)
85	{
86		switch(xmlElement.childNodes[i].nodeType)
87		{
88			case 3:
89				var textNode = document.createTextNode(xmlElement.childNodes[i].nodeValue.toString());
90				if(textNode.length)
91				{
92					htmlElement.appendChild(textNode);
93					copiedElements++;
94				}
95				break;
96			case 1:
97				var node = document.createElement(xmlElement.childNodes[i].nodeName);
98				for(var j = 0; j < xmlElement.childNodes[i].attributes.length; j++)
99				{
100					if(isIE())
101					{
102						if(xmlElement.childNodes[i].attributes[j].name.toLowerCase() == "style")
103							node.style.setAttribute("cssText", xmlElement.childNodes[i].attributes[j].value);
104						else if(!in_array(xmlElement.childNodes[i].attributes[j].name.toLowerCase, ieIgnoredAttributes))
105							node.setAttribute(getIEAttributeReplacement(xmlElement.childNodes[i].attributes[j].name.toLowerCase()), xmlElement.childNodes[i].attributes[j].value);
106					}
107					else
108					{
109						node.setAttribute(xmlElement.childNodes[i].attributes[j].name, xmlElement.childNodes[i].attributes[j].value);
110					}
111				}
112				copiedElements += copyXmlToHtml(xmlElement.childNodes[i], node);
113				htmlElement.appendChild(node);
114				break;
115		}
116	}
117	return copiedElements;
118}
119
120function isIE()
121{
122	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
123}
124
125function getIEAttributeReplacement(attrib)
126{
127	switch(attrib)
128	{
129		case "acceptcharset": return "acceptCharset";
130		case "accesskey": return "accessKey";
131		case "allowtransparency": return "allowTransparency";
132		case "bgcolor": return "bgColor";
133		case "cellpadding": return "cellPadding";
134		case "cellspacing": return "cellSpacing";
135		case "class": return "className";
136		case "colspan": return "colSpan";
137		case "defaultchecked": return "defaultChecked";
138		case "defaultselected": return "defaultSelected";
139		case "defaultvalue": return "defaultValue";
140		case "frameborder": return "frameBorder";
141		case "hspace": return "hSpace";
142		case "longdesc": return "longDesc";
143		case "maxlength": return "maxLength";
144		case "marginwidth": return "marginWidth";
145		case "marginheight": return "marginHeight";
146		case "noresize": return "noResize";
147		case "noshade": return "noShade";
148		case "readonly": return "readOnly";
149		case "rowspan": return "rowSpan";
150		case "tabindex": return "tabIndex";
151		case "valign": return "vAlign";
152		case "vspace": return "vSpace";
153	}
154	return attrib;
155}
156
157function in_array(needle, haystack)
158{
159	var key = ""; 
160	for(key in haystack)
161	{
162		if(haystack[key] == needle)
163			return true;
164	}
165	return false;
166}

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.