PageSourceSearch

https://legimonaco.mc/libs/lib-md/explorer.js

js legimonaco.mc collected 2026-10-02 07:50:34 UTC 4,084 bytes, 101 lines download raw bytes

1window.explorer = {
2	fContentPath : "bod:",
3	fStackPath : "des:nav.stack",
4	fHeaderPath : "ide:siteHeader",
5	fListeners : {scrollPage:[]},
6	init:function() {
7		try{
8
9			// Content scrolling management
10			this.fContent = scPaLib.findNode(this.fContentPath);
11			if (this.fContent){
12				const vScroller = this.fContentPath === "bod:" ? window : this.fContent;
13				if (this.fContentPath === "bod:") this.fContent.style.position = "relative";
14				vScroller.addEventListener("scroll", function(pEvt){
15					explorer.fScrollPos = null;
16					if (typeof pEvt.target != "undefined" && pEvt.target.scrollTop) explorer.fScrollPos = pEvt.target.scrollTop;
17					else if (typeof document.scrollingElement != "undefined" && document.scrollingElement.scrollTop) explorer.fScrollPos = document.scrollingElement.scrollTop;
18					else explorer.fScrollPos = document.documentElement.scrollTop;
19					if (!explorer.fScrollTicking){
20						window.requestAnimationFrame(function() {
21							explorer.fireEvent("scrollPage");
22							explorer.fScrollTicking = false;
23						});
24					}
25					explorer.fScrollTicking = true;
26				});
27			}
28	
29			// Init page scrolling
30			this.fHeader = scPaLib.findNode(this.fHeaderPath);
31			this.fStack = scPaLib.findNode(this.fStackPath);
32			this.registerListener("scrollPage", function(){
33				const vBody = document.body,
34					vArticleHeader = sc$("articleHeader"),
35					vScrollValue = explorer.fHeader.offsetHeight + explorer.fStack.offsetHeight;
36				let vArticleHeaderHeight = 0;
37				if (vArticleHeader) vArticleHeaderHeight = vArticleHeader.offsetHeight;
38				if ( explorer.fScrollPos > vScrollValue && !vBody.fPageScrolled) {
39					sc$("main").style.marginTop = (vScrollValue + vArticleHeaderHeight) + "px";
40					explorer.switchClass(vBody, "page_scrolled_no", "page_scrolled_yes", true);
41					vBody.fPageScrolled = true;
42				}
43				if ( explorer.fScrollPos < vScrollValue && vBody.fPageScrolled) {
44					sc$("main").style.marginTop = "";
45					explorer.switchClass(vBody, "page_scrolled_yes", "page_scrolled_no");
46					vBody.fPageScrolled = false;
47				}
48			});
49		} catch(e){console.error("ERROR explorer.init : "+e)}
50	},
51
52	/* explorer.registerListener : registers a given function to a given template event */
53	registerListener : function(pListener, pFunc){
54		if (this.fListeners[pListener]) this.fListeners[pListener].push(pFunc);
55		else console.error("ERROR - explorer.registerListener - non-existent listener : " + pListener);
56	},
57
58	/* explorer.fireEvent : fire a given template event */
59	fireEvent : function(pListener, pParam){
60		if (this.fListeners[pListener]) {
61			for (let i=0; i< this.fListeners[pListener].length; i++) {
62				try{
63					this.fListeners[pListener][i](pParam);
64				} catch(e){console.error("ERROR - explorer.fireEvent("+pListener+") : " + e)}
65			}
66		}
67		else console.error("ERROR - explorer.fireEvent - non-existent listener : " + pListener);
68	},
69
70	switchClass : function(pNode, pClassOld, pClassNew, pAddIfAbsent, pMatchExact) {
71		const vAddIfAbsent = typeof pAddIfAbsent == "undefined" ? false : pAddIfAbsent;
72		const vMatchExact = typeof pMatchExact == "undefined" ? true : pMatchExact;
73		const vClassName = pNode.className;
74		const vReg = new RegExp("\\b" + pClassNew + "\\b");
75		if (vMatchExact && vClassName.match(vReg)) return;
76		let vClassFound = false;
77		if (pClassOld && pClassOld !== "") {
78			if (vClassName.indexOf(pClassOld)===-1){
79				if (!vAddIfAbsent) return;
80				else if (pClassNew && pClassNew !== "") pNode.className = vClassName + " " + pClassNew;
81			} else {
82				const vCurrentClasses = vClassName.split(" ");
83				const vNewClasses = [];
84				let i = 0;
85				const n = vCurrentClasses.length;
86				for (; i < n; i++) {
87					const vCurrentClass = vCurrentClasses[i];
88					if (vMatchExact && vCurrentClass !== pClassOld || !vMatchExact && vCurrentClass.indexOf(pClassOld) !== 0) {
89						vNewClasses.push(vCurrentClasses[i]);
90					} else {
91						if (pClassNew && pClassNew !== "") vNewClasses.push(pClassNew);
92						vClassFound = true;
93					}
94				}
95				pNode.className = vNewClasses.join(" ");
96			}
97		}
98		return vClassFound;
99	}
100}
101explorer.init();

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.