PageSourceSearch

https://winslow-schools.com/apps-shared/encms/page_editor/compatibility_manager.js?acn=256948

js winslow-schools.com collected 2026-09-25 05:25:25 UTC 7,326 bytes, 251 lines download raw bytes

1function ENCMSCompatibilityManager(editableDiv, imageGallery, docsDiv, compParams) {
2	this.editableDiv = editableDiv;
3	this.compParams = compParams;
4	this.imageGallery = imageGallery;
5	this.docsDiv = docsDiv;
6	this.isMobileSite = (this.compParams.get("isMobileSite") == "true");
7	this.icons = new Map([
8		[null, "file"]
9		,["pdf", "pdf"]
10		,["doc", "doc"]
11		,["docx", "doc"]
12		,["xls", "xls"]
13		,["xlsx", "xls"]
14		,["ppt", "ppt"]
15		,["pptx", "ppt"]
16		,["txt", "txt"]
17		,["wav", "wav"]
18		,["mp3", "mp3"]
19		,["wmv", "wmv"]
20		,["mov", "mov"]
21	]);
22	
23	if (this.imageGallery) {
24		this.imageGallery.classList.add("en_unused_images_gallery");
25	}
26	this.docsDiv.classList.add("en_unused_documents_list");
27	this.docsDiv.setAttribute("role", "region");
28	this.docsDiv.setAttribute("aria-label", "Files");
29	
30	this.removeFile = function(path, lastModified) {
31		if (this.imageGallery == null || path == null || path == "") {
32			return;
33		}
34		let imageDiv = this.getImageDivFromGallery(path, lastModified);
35		if (imageDiv != null) {
36			imageDiv.remove();
37		}
38	}
39	
40	this.getImageDivFromGallery = function(path, lastModified) {
41		
42		for (let x = 0; x < this.imageGallery.childNodes.length; x++) {
43			let thisChild = this.imageGallery.childNodes[x];
44			if (thisChild.tagName == "DIV") {
45				let autodirImagePath = thisChild.getAttribute("en-autodir-image-path");
46				if (autodirImagePath != null) {
47					if (lastModified == null) {
48						if (autodirImagePath.startsWith(path + "?")) {
49							return thisChild;
50						}
51					} else {
52						if (autodirImagePath == path + "?rnd=" + lastModified) {
53							return thisChild;
54						}
55					}
56				}
57			}
58		}
59		return null;
60	}
61	
62	this.fileIsInUse = function(path, parentNode) {
63		if (parentNode == null) {
64			parentNode = this.editableDiv;
65		}
66		for (let x = 0; x < parentNode.children.length; x++) {
67			let c = parentNode.children[x];
68			if (c.tagName == "IMG" || c.tagName == "A") {
69				let targetURL =  c.getAttribute(c.tagName == "IMG" ? "src" : "href");
70				if (targetURL == path) {
71					return true;
72				} else if (targetURL && targetURL.substr(0, targetURL.length - 3) == path.substr(0, path.length - 3)
73					&& (targetURL.substr(-3) == "000" || path.substr(-3) == "000")
74				) {
75					return true;
76				}
77			} else if (c.tagName == "OBJECT") {
78				let targetURL =  c.getAttribute("data");
79				if (targetURL == path) {
80					return true;
81				} else if(path && targetURL) {
82					const cleanPathUrl = path.split('?')[0];
83					const cleanTargetUrl = targetURL.split('?')[0];
84					// Compare the cleaned URLs
85					return cleanPathUrl === cleanTargetUrl;
86				}
87			} else {
88				if (c.children != null) {
89					if (this.fileIsInUse(path, c) == true) {
90						return true;
91					}
92				}
93			}
94		}
95		return false;
96	}
97	
98	this.updateDocsList = function(pathList) {
99		if (this.docsDiv == null || pathList == null) {
100			return;
101		}
102		if (this.compParams == null || this.compParams.get("urlDomain") == null) {
103			return;
104		}
105		
106		let list = document.createElement("ul");
107		list.classList.add("fbList");
108
109		for (let x = 0; x < pathList.length; x++) {
110			let thisPath = pathList[x][0];
111			let lastModified = pathList[x][1];
112			let safePath = thisPath + "?rnd=" + lastModified;
113			if (thisPath == null || thisPath == "" || this.fileIsInUse(safePath)) {
114				continue;
115			}
116			let tmp = thisPath.split("/");
117			let filename = tmp[tmp.length - 1];
118			let ext = null;
119			tmp = filename.split(".");
120			if (tmp.length > 0) {
121				ext = tmp[tmp.length - 1];
122			}
123			let item = document.createElement("li");
124			item.style.paddingLeft = "5px";
125			
126			let spanIcon = document.createElement("span");
127			spanIcon.setAttribute("class", "icon icon-" + (this.icons.get(ext) != null ? this.icons.get(ext) : "file"));
128			item.appendChild(spanIcon);
129			
130			let anchor = document.createElement("a");
131			anchor.setAttribute("href", this.compParams.get("urlDomain") + safePath);
132			anchor.setAttribute("target", "_blank");
133			anchor.style.leftMargin = "7px";
134			anchor.innerHTML = this.htmlEncode(decodeURIComponent(filename));
135			item.appendChild(anchor);
136			
137			if (this.compParams.get("showInPopup") == "true") {
138				if (ext == "pdf" || ext == "doc" || ext == "docx" || ext == "xls" || ext == "xlsx" || ext == "ppt" || ext == "pptx") {
139					let img = new Image();
140					img.setAttribute("alt", "Preview " + filename);
141					img.setAttribute("title", "Preview " + filename);
142					img.style.verticalAlign = "middle";
143					img.style.cursor = "pointer";
144					img.style.marginLeft = "4px";
145					img.setAttribute("src", "/apps/pics/zoom.png");
146					let fakeLink = document.createElement("a");
147					fakeLink.href = thisPath;
148					img.setAttribute("onclick", "DocumentViewer.show(`" + fakeLink.href + "`)");
149					item.appendChild(img);
150				}
151			}
152			
153			list.appendChild(item);
154		}
155		
156		if (list.childNodes.length > 0) {
157			let n = document.createElement("div");
158			n.innerHTML = '<b role="heading" aria-level="2">Files:</b>';
159			n.appendChild(list);
160			if (n.innerHTML != docsDiv.innerHTML) {
161				docsDiv.innerHTML = n.innerHTML;
162			}
163			this.docsDiv.style.display = "block";
164		} else {
165			this.docsDiv.style.display = "none";
166		}
167		
168	}
169	
170	this.createImageDiv = function(safePath, altText) {
171		let d = document.createElement("div");
172		d.classList.add("en-unused-image-outer-container")
173		d.setAttribute("en-autodir-image-path", safePath);
174		
175		let d2 = document.createElement("div");
176		d2.classList.add("en-unused-image-inner-container")
177		
178		let i = new Image();
179		i.style.width = this.compParams.get("imageWidth") + "px";
180		i.src = safePath;
181		i.classList.add("en-unused-image", "sub");
182		i.setAttribute("alt", (altText ? altText : this.extractFileName(safePath)));
183		d2.appendChild(i);
184		
185		if (!this.isMobileSite) {
186
187			let a = document.createElement("a");
188			a.style.display = "block";
189			a.style.textAlign = this.compParams.get("textAlign");
190			a.setAttribute("href", "javascript: PhotoViewer.show('" + safePath + "', '', 600);");
191
192			let iMag = new Image();
193			iMag.src = "/apps/pics/enlarge.png";
194			iMag.classList.add("en-unused-image-enlarge-icon");
195			iMag.setAttribute("alt", "Enlarge icon");
196			d2.appendChild(iMag);
197			
198			a.appendChild(d2);
199			d.appendChild(a);
200		} else {
201			d2.style.width = "80%";
202			i.style.width = "100%";
203			d.appendChild(d2);
204		}
205
206		
207		return d;
208	}
209	
210	this.addImage = function(path, lastModified, altText) {
211		if (this.imageGallery == null || path == null || path == "" || lastModified <= 0) {
212			return;
213		}
214		if (this.compParams == null || this.compParams.get("imageWidth") == null) {
215			return;
216		}
217		
218		let safePath = path + "?rnd=" + lastModified;
219		if (this.fileIsInUse(safePath)) {
220			return;
221		}
222
223		let imageDiv = this.getImageDivFromGallery(path);
224		if (imageDiv != null && imageDiv.getAttribute("en-autodir-image-path") == safePath) {
225			return;
226		}
227		
228		let newImageDiv = this.createImageDiv(safePath, altText);
229		
230		if (imageDiv == null) {
231			this.imageGallery.appendChild(newImageDiv);
232		} else {
233			this.imageGallery.replaceChild(newImageDiv, imageDiv);
234		}
235	}
236	
237	this.htmlEncode = function(s) {
238		let el = document.createElement("div");
239		el.innerText = el.textContent = s;
240		return el.innerHTML;
241	}
242
243	this.extractFileName = function(fullPath) {
244		try {
245			let fileNameWithExt = fullPath.split('/').pop();
246			return fileNameWithExt.replace(/\.[^/.]+$/, "");
247		} catch (e) {
248			return "";
249		}
250	}
251}

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.