PageSourceSearch

https://langleyessex.net/js/rrmsb_lib.js

js langleyessex.net collected 2026-10-04 02:11:09 UTC 13,387 bytes, 270 lines download raw bytes

1/*
2##### rrmsb_lib.js, installed by ###Mod Settings Blocks, by Robin Richmond
3
4**** Revisions
514.0.4.4d 24 Mar 2024
6* Added function rrmsbShowPopupHint that mods will use to show popup messages
7### See the Inner Mod Menus documentation in the mod's subfolder.
8*/
9//////////////////////////////////////////////////
10/// document.ready function
11$(function () {
12	var numMods = $('.rrimmMenu').length;
13	if (!numMods || (rrconfig['MSB-IMMLocation'] != 'innermenu' && rrconfig['MSB-IMMLocation'] != "footer"))
14		return; //**********************no menus to see or don't show menus => Early exit
15
16	//Put the various Inner Mod Menus in an array that can be sorted by modname
17	var menuArray1 = Array(); //primary mods
18	var menuArray2 = Array(); //secondary mods
19	$('.rrimmMenu').each (function() {
20		if (numMods<6 || !Number($(this).attr('secondary')))
21			menuArray1.push($(this).html());
22		else menuArray2.push($(this).html());
23		$(this).remove();
24	});
25	//Add each menu to an HTML string
26	var html = '';
27	var modCount1 = menuArray1.length;
28	menuArray1.sort();
29	for (i=0; i<modCount1; i++)
30		html += menuArray1[i];
31	var modCount2 = menuArray2.length
32	if (modCount2) {
33		html += "<b><a href='#' class='more rrimmlink' onclick='rrimmMoreClick(event);'>" + rrconfig['rrimm-moremods'] + "</a></b>";
34		html += "<b><a href='#' class='more rrimmlink' onclick='rrimmMoreClick(event);' style='display:none;'>" + rrconfig['rrimm-fewermods'] + "</a></b>";
35		html += "<div class='more' style='display:none;'>";
36		menuArray2.sort();
37		for (i=0; i<modCount2; i++)
38			html += menuArray2[i];
39		html += "</div>";
40	}
41	//Add the InnerModMenu wrapper to the appropriate Inner menu.
42	//Figure out the ID of this program's Inner menu.
43	var rrimmMenuID,rrimmAdminNote, labelButton;
44	if (rrconfig['MSB-IMMLocation'] == "innermenu") {
45		if ($('#adm-innermenu').length) { //Admin program
46			rrimmMenuID = '#adm-innermenu';
47			rrimmAdminNote = '';
48		} else { //End-user program
49			rrimmMenuID = '#pub-innermenu';
50			rrimmAdminNote = rrconfig['rrim-onlyadmins'];
51		}
52		labelClass = "lightlink";
53	} else { // (rrconfig['MSB-IMMLocation'] == "footer")
54		if ($('#rrImmFooterAdmin').length) { //Admin program
55			rrimmMenuID = '#rrImmFooterAdmin';
56			rrimmAdminNote = '';
57		} else { //End-user program
58			rrimmMenuID = '#rrImmFooterPublic';
59			rrimmAdminNote = rrconfig['rrimm-onlyadmins'];
60		}
61		labelClass = "snlink"; 
62	} // end IF location 
63
64	//Build a wrapper around the Inner Mod Menu html, and add it to the Inner Menu
65	var wrapHtml = "<div id='rrimmMenu'>"
66	+ "<a href='#' onclick='return false;' class='" + labelClass + "' "
67	+ "title='" + rrimmAdminNote + "'>" + rrconfig['InnermenuLabel'] + "</a>\n"
68	+ "<div id='rrimmDrop' class='slidedown'>"
69	+ "<img src='img/tng_close.gif' class='rrimmMenuX' border='0' alt=''>"
70	+ "</div></div>";
71
72	//Add the menu structure to the appropriate div
73	$(rrimmMenuID).append(wrapHtml);
74	//Add the InnerModMenu contents to the wrapper inside the menu structure
75	$('#rrimmDrop').append(html);
76
77	//Define the height of the InnerModMenu, based on the count of lines (<br> tags) in the content.
78	var rrNumLines = html.split('<br>').length;
79
80	//If there is a map at the top of the content div, it will hide the exposed IMM, so it will
81	//need to be moved out of the way. These variables will be used to figure out how much the
82	//map's width needs to be reduced to move it out of the way.
83	//If OSM Is installed, an pverlay div with id='osmmapsat' also needs to be shifted via
84	//its css right attribute.
85	//Unfortunately, the map div might not yet have been created when this document ready
86	//function executes, so these values have to be calculated the first time that the
87	//IMM click handler runs.
88	var rrMapWidthState = true; //Toggle; true=the map is in its original state
89	var rrIMMFirstTime = true;
90	var rrNewMapWidth = 0;
91	var rrOldOverlayRight = 0;
92	var rrNewOverlayRight = 0;
93//////////////////////////////////////////////////
94	//Click event for any part of the Inner Mod Menu that toggles its display, and,
95	//IF there is a map that needs to be moved, move it, too.
96	//When the menu is open, its 'X' does not need to explictly clicked to close the menu;
97	//the X is simply part of the menu div.
98	$('#rrimmMenu').click(function () {
99		$('#rrimmDrop').slideToggle(200); //Toggle the menu. That was easy.
100		//Move the map and a possible overlay. Not quite so easy
101		//If a map needs to be moved, mods will add a dummy div with class='rrimmMap'.
102		if ($('.rrimmMap').length) {
103			// Calculate the shift values if this is the first execution of this click handler.
104			if (rrIMMFirstTime) {
105				rrIMMFirstTime = false;
106				rrNewMapWidth = (parseInt($('#map').css('width')) -
107					parseInt($('#rrimmDrop').css('width')) - 20) +'px';
108				if ($('#osmmapsat').length) {
109					rrOldOverlayRight = $('#osmmapsat').css('right');
110					rrNewOverlayRight = (parseInt(rrOldOverlayRight) +
111						parseInt($('#rrimmDrop').css('width')) + 20) +'px';
112				}
113			}
114			//Move the map divs
115			if (rrMapWidthState) {
116				$('#map').css('width',rrNewMapWidth);
117				if ($('#osmmapsat').length)
118					$('#osmmapsat').css('right',rrNewOverlayRight);
119			} else { //Restore map
120				$('#map').css('width','100%');
121				if ($('#osmmapsat').length)
122					$('#osmmapsat').css('right',rrOldOverlayRight);
123			}
124			rrMapWidthState = !rrMapWidthState
125		} //end if there is a div that tells us to fiddle with the map
126		return false;
127	}); //end Inner Mod Menu click function
128}); //end document.ready function
129
130//////////////////////////////////////////////////
131//Function that acts on a "more" or "fewer" link that controls the length (the number of visible
132//mods) of an IMM. The intent is to to avoid dropping down a confusingly long IMM by focusing on
133// the most significant mods. If there are a sufficient number of mods in a page's IMM and some 
134//of them have arbitrariy labeled themselves as "secondary". The user can choose whether to add
135//the secondary mods. Mods that specify an IMM on a given page but don't do very much to a page
136//can arbitrarily label themseves as secondary.
137function rrimmMoreClick(event) {
138	$('.more').toggle();
139	event.stopPropagation();
140	return false;
141} //end function rrimmMoreClick
142
143//////////////////////////////////////////////////
144//Onclick event handler to open a TNG Wiki page as a popup. It acts on:
145//- The mod name and "W" icon that serve as the mod's heading within an IMM.
146//- An identical heading in each MSB.
147//- An IMM's "Mods Options" entry in which case the menu entry specifies the HTML anchor for
148//  the "Mod Options" section within the wiki article.
149function rrimmOpenWikiPage(article, anchor='') {
150	if (anchor) anchor="#"+anchor;
151	newwindow = window.open('https://tng.lythgoes.net/wiki/index.php?title='+article+anchor, 'wikiwindow', 'height=600, width=780, top=50, left=100, resizable=yes, scrollbars=yes, status=yes');
152	newwindow.focus();
153	return false;
154} //end function rrInnerMenuOpenWikiPage
155
156//////////////////////////////////////////////////
157//Handles an IMM "change mod options" link. Pops up a window that contains the Admin General Settings
158//form and opens the mod's MSB, but no other subsections of the form or other MSBs.
159// Arguments:
160//- configprogram - deprecated. All MSBs are not in admin_genconfig.php
161//- subform - deprecated. All MSB's are now in the "Mod Settings Blocks" subform. It takes on
162//          the constant value "robin13", which is the element ID of the entire "Mod Settings Blocks"
163//          subform within admin_genconfig.php, to which the Mods Settings Blocks mod has added
164//          a document.ready function that opens the specified subform, and, potentially a
165//          specified MSB 
166//- modid - Identifies the MSB to be opened. It is a variant of the mod name, in all-lower-case,
167//          and without spaces. It is passed to admin_genconfig.php, which will open the
168//          specified MSB.. If it is missing, the entire "Mod Settings Blocks" subform 
169//          within the General Settings form is opened.
170//The editor is invoked as a popup page.
171function rrimmOpenConfigPage(configprogram, subform='', modid='') {
172	if (configprogram.indexOf('.php') == -1)
173		configprogram += '.php';
174	if (!subform) {
175		if (configprogram == 'admin_genconfig.php') subform = 'robin13';
176		else if (configprogram == 'admin_pedconfig.php') subform = 'robin13';
177	}
178	newwindow = window.open(configprogram+"?mod="+modid+'&rrmsbPopup=1', 'optionswindow', 'height=600, width=780, top=50, left=100, resizable=yes, scrollbars=yes, status=yes');
179	newwindow.focus();
180	return false;
181} //end function rrimmOpenConfigPage
182
183//////////////////////////////////////////////////
184//Onclick handler for an Inner Mod Menu "What has changed" link that specfies an arbitrary URL.
185//This function does not need to know the mod name, because it can't do anything with it.
186function rrimmOpenOtherPage(configprogram) {
187	newwindow = window.open(configprogram, 'otherwindow', 'height=600, width=780, top=50, left=100, resizable=yes, scrollbars=yes, status=yes');
188	newwindow.focus();
189	return false;
190} //end function rrimmOpenOtherPage
191
192//////////////////////////////////////////////////
193//Onclick handler for an Inner Mod Menu "What has changed" link that specifies the ID of an HTML
194//block within the page.  It loads the contents of that block into a TNG Litbox within the page.
195//Arguments:
196// element - an identfier that is used as the prefix for three HTML elements (within the page)
197//           whose ID suffixes indicate they contain the Litbox heading, body text, or footer
198// width, height - optional arguments that specify the Litbox's size.
199function rrimmPopupElement(modname, element, width, height) {
200	if (element.substring(0,1) != '#')
201		element = '#' + element;
202	var content = "<div class='rrimmLitBox'>" + $(element).html() + "</div>";
203	var title = 'Changes made by '+modname;
204	if (!width) width=500;
205	if (!height) height=500;
206	new LITBox(content,{type:'alert', width:width, height:height, overlay:false, title:title});
207	return false;
208} //end function rrimmPopupElement
209
210//////////////////////////////////////////////////
211//Onclick handler for the Inner Mod Menu "What has changed" link. It opens a TNG Litbox
212//(within the page) that contains text specified within that page.
213function rrInnerModPopupText(modname, content, width, height) {
214	var content = "<div class='rrimmLitBox'>" + content + "</div>";
215	var title = 'Changes made by '+modname;
216	if (!width) width=500;
217	if (!height) height=500;
218	new LITBox(content,{type:'alert', width:width, height:height, overlay:false, title:title});
219	return false;
220} //end function rrInnerModPopupText
221
222//////////////////////////////////////////////////
223//Onclick handler for the Inner Mod Menu "What has changed" link It loads an arbitrary
224//URL in a pop up window.
225function rrimmPopupElement(modname, element, width, height) {
226	if (element.substring(0,1) != '#')
227		element = '#' + element;
228	var content = "<div class='rrimmLitBox'>" + $(element).html() + "</div>";
229	var title = 'Changes made by '+modname;
230	if (!width) width=500;
231	if (!height) height=500;
232	new LITBox(content,{type:'alert', width:width, height:height, overlay:false, title:title});
233	return false;
234} //end function rrimmPopupElement
235
236//////////////////////////////////////////////////////////
237//Function to pop up a hint when a specific info button is clicked.
238//The hint text, title, and dimensionsof the popup box are stored in hidden divs.
239//This is a utility function that will be used by several mods. For it to work:
240// 1. Mod Settings Blocks must define a div with the ID "rrfootnote" that contains
241//    footnote text on the order of "This box can be moved out of the way..."
242// 2. A mod must define 3 elements with these specified IDs
243//    a) {hintname}title - 1 line of text for the popup box's title bar
244//    b) {hintname}hint - The html code to be displayed in the popup box
245//    c) {hintname}box - "{width},{height}" of the popup box
246//   In most cases, the contents of those boxes will be defined as language strings.
247//    where hintname must be unique within the TNG page, but not across all pages and mods.
248function rrmsbShowPopupHint(hintname, width=0, height=0) {
249	//Make sure that the title, hint, and footer HTML elements have values
250	if (!$('#rr'+hintname+'Title').length ||
251		($('#rr'+hintname+'Title').length && !$('#rr'+hintname+'Title').html().length))
252		$('#rr'+hintname+'Title').html("Hint for '"+hintname+"'");
253	if (!$('#rr'+hintname+'Hint').length ||
254		($('#rr'+hintname+'Hint').length && !$('#rr'+hintname+'Hint').html().length))
255		$('#rr'+hintname+'Hint').html("No help message identified as '"+hintname+"' found!");
256
257	var title = $('#rr'+hintname+'Title').html();
258	var content = "<div class='rrlitboxHint'>" + $('#rr'+hintname+'Hint').html();
259	var footer = $('#rrlitboxFootnote').length ? $('#rrlitboxFootnote').html()
260    : "This help message window can be dragged out of the way and left on the screen as long as you need it.";
261	content += "<footer>" + footer + "</footer></div>\n";
262
263	if (!$('#rr'+hintname+'Dims').length) $('#rr'+hintname+'Dims').text = width +","+height;
264	var boxDims = $('#rr'+hintname+'Dims').html().split(',');
265	mywidth = boxDims[0] ? boxDims[0] : (width ? width : 450)
266	myheight = boxDims[1] ? boxDims[1] : (height ? height : 450)
267	new LITBox(content,{type:'alert', width:mywidth, height:myheight, overlay:false, title:title});
268	return false;
269} //End function rrmsbShowPopupHint
270

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.