PageSourceSearch

https://www.nnva.gov/Assets/Scripts/Shared.js

js nnva.gov collected 2026-10-01 11:30:43 UTC 8,051 bytes, 254 lines download raw bytes

1/// <reference path="../../Common/Controls/jquery-ui-1.14.2/jquery-ui.js" />
2if (!window.Core) {
3	window.Core = new CoreNamespace();
4}
5
6function AJAX(url, type, json, callBack, showLoadingMessage, contentType, forceCallBack, suppressErrorMessage) {
7	contentType = contentType || 'application/x-www-form-urlencoded; charset=UTF-8';
8	showLoadingMessage = showLoadingMessage == null ? true : showLoadingMessage;
9	forceCallBack = forceCallBack == null ? false : forceCallBack;
10	if (typeof (suppressErrorMessage) === 'undefined') suppressErrorMessage = false;
11	$.ajax({
12		url: url,
13		type: type,
14		contentType: contentType,
15		data: json,
16		success: function (response) {
17			if (response.ErrorMessage && !forceCallBack) {
18				if (response.ErrorMessage.indexOf('You do not have permission to perform this action.') != -1 && !isUserLoggedIn()) { // 079B4F43 
19					alert('You are not logged in. Please login to continue.');
20					location.href = '/myaccount?from=url&url=' + window.location.pathname;
21				} else {
22					alert(response.ErrorMessage);
23				}
24			}
25			else if (response.RedirectURL && !forceCallBack)
26				window.location.href = response.RedirectURL;
27			else if (callBack)
28				callBack(response);
29		},
30		beforeSend: function () {
31			if (showLoadingMessage) {
32				ajaxPostBackStart('Loading');
33			}
34		},
35		complete: function () {
36			if (showLoadingMessage) {
37				ajaxPostBackEnd();
38			}
39		},
40		error: function (xhr, textStatus, exception) {
41			if (!suppressErrorMessage) {
42				alert('Error: ' + xhr.statusText + '\nStatus: ' + xhr.status);
43			}
44		}
45	});
46}
47
48function isUserLoggedIn() {
49	var result = true; // if there is an error lets not show the login message.
50	$.ajaxSetup({ async: false, ignoreEditor: true });
51	$.post('/Utility/IsUserLoggedIn', function (data) {
52		result = data;
53	});
54	$.ajaxSetup({ async: true, ignoreEditor: false });
55	return result;
56}
57
58///Method to pause a javascript execution for x seconds, works like sleep(). VB
59function sleep(seconds) {
60	var max_sec = new Date().getTime();
61	while (new Date() < max_sec + seconds * 1000) { }
62	return true;
63}
64
65if (!String.prototype.format) {
66	String.prototype.format = function () {
67		var args = arguments;
68		return this.replace(/{(\d+)}/g, function (match, number) {
69			return typeof args[number] != 'undefined'
70				? args[number]
71				: match
72				;
73		});
74	};
75}
76
77if (!String.prototype.isNullOrWhiteSpace) {
78	String.prototype.isNullOrWhiteSpace = function () {
79		return this == null || this.trim() == '';
80	};
81}
82
83function isValidMoney(value) {
84	var isValid = false;
85	if (value && value != '')
86		isValid = /^\$?\s*\d+(,\d{3})*(\.\d{1,2})?$/.test(value);
87	return isValid;
88};
89
90if (typeof String.prototype.startsWith != 'function') {
91	String.prototype.startsWith = function (str) {
92		return this.slice(0, str.length) == str;
93	};
94}
95
96String.prototype.format = String.prototype.f = function () {
97	var s = this,
98		i = arguments.length;
99
100	while (i--) {
101		s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
102	}
103	return s;
104};
105
106//Creates a javascript namespace, if one already exists, just returns that namespace.
107function createNamespace(namespaceString) {
108	var parts = namespaceString.split('.'),
109		parent = window,
110		currentPart = '',
111		nsLength = parts.length;
112
113	for (var i = 0, length = nsLength; i < length; i++) {
114		currentPart = parts[i];
115		parent[currentPart] = parent[currentPart] || {};
116		parent = parent[currentPart];
117	}
118	return parent;
119}
120$(function () {
121
122	// Ensures a dependency exists. If it doesn't acquire it.
123	function ensure(dependencyExists, dependencyUrl, onceItExistsCallback) {
124		if (dependencyExists) {
125			onceItExistsCallback();
126			return;
127		}
128		$.getScript(dependencyUrl, onceItExistsCallback);
129	}
130
131	var ajaxControlToolkit = window.AjaxControlToolkit;
132	// This is hack override in order to fix problems with Ajax Toolkit Drag and Drop in newer browsers. It substitutes in jQuery Draggable if it is available.
133	// A more proper fix is ideal, but extremely expensive as it would require replacing over a hundred instances of invocations of the old modal.
134	// There isn't a clean way to integrate in the new modal system. JE
135	// https://system.netsuite.com/app/crm/support/issuedb/issue.nl?id=3809568&l=T
136	if (ajaxControlToolkit && ajaxControlToolkit.ModalPopupBehavior) {
137		ajaxControlToolkit.ModalPopupBehavior.prototype._attachPopup = function () {
138			/// <summary>
139			/// Attach the event handlers for the popup
140			/// </summary>
141
142			if (this._DropShadow && !this._dropShadowBehavior) {
143				this._dropShadowBehavior = $create(ajaxControlToolkit.DropShadowBehavior, {}, null, null, this._popupElement);
144			}
145
146			var _this = this;
147			// Drag and Drop Replacement. Acquire any dependencies on the fly.
148			ensure($.ui, "/Common/Controls/jquery-ui-1.14.2/jquery-ui.min.js", function () {
149				$("#" + _this._PopupControlID).draggable({ handle: '#' + _this._PopupDragHandleControlID });
150				$("#" + _this._PopupDragHandleControlID).css('cursor', 'move');
151			});
152
153			$addHandler(window, 'resize', this._resizeHandler);
154			$addHandler(window, 'scroll', this._scrollHandler);
155			this._windowHandlersAttached = true;
156		}
157	}
158});
159
160String.prototype.replaceAll = function (search, replacement) {
161	var target = this;
162	return target.replace(new RegExp(search, 'g'), replacement);
163};
164
165function executeViewMapPostClickActions($element) {
166	//Hide the view map element post click(to avoid clicking repeatedly)
167	$element.hide('fast');
168
169	//Collect analytics around map clicks
170	var url = '/CollectGoogleMapClicks/Execute';
171	var moduleId = $element.data('moduleid');
172	$.ajax({
173		url: url,
174		type: 'POST',
175		data: {
176			url: window.location.href,
177			moduleId: moduleId
178		},
179		success: function (json) {
180			//send data to telemetry
181			appInsights.trackEvent("googlemapclicked", json);
182		},
183		error: function (xhr, textStatus, exception) {
184			alert("Error: " + xhr.statusText + "\nStatus: " + xhr.status);
185		}
186	});
187}
188
189function importModal(options) {
190	if (window.ImportModalInstance === undefined) {
191		var script = document.createElement("script");
192		script.onload = function () {
193			window.ImportModalInstance.init(options);
194		};
195		script.src = "/Assets/Scripts/ImportModal.js";
196		document.head.appendChild(script);
197	}
198	else
199		window.ImportModalInstance.init(options);
200}
201
202function exportModal(options) {
203	if (window.ExportModalInstance === undefined) {
204		var script = document.createElement("script");
205		script.onload = function () {
206			window.ExportModalInstance.init(options);
207		};
208		script.src = "/Assets/Scripts/ExportModal.js";
209		document.head.appendChild(script);
210	}
211	else
212		window.ExportModalInstance.init(options);
213}
214
215document.addEventListener("DOMContentLoaded", function () {
216	var modal = document.querySelector(".importModal");
217	if (modal !== null) {
218		try {
219			if (!modal.classList.contains("processed")) {
220				var options = modal.dataset.importconfig;
221				if (options) {
222					modal.addEventListener("click",
223						function (e) {
224							e.preventDefault();
225							importModal(JSON.parse(options));
226						});
227					//Avoid further processing if the event gets triggered multiple times during page load
228					modal.classList.add("processed");
229				}
230			}
231		} catch (err) {
232			console.error("Unable to initialize import modal");
233		}
234	}
235	var modalExport = document.querySelector(".exportModal");
236	if (modalExport !== null) {
237		try {
238			if (!modalExport.classList.contains("processed")) {
239				var options = modalExport.dataset.exportconfig;
240				if (options) {
241					modalExport.addEventListener("click",
242						function (e) {
243							e.preventDefault();
244							exportModal(JSON.parse(options));
245						});
246					//Avoid further processing if the event gets triggered multiple times during page load
247					modalExport.classList.add("processed");
248				}
249			}
250		} catch (err) {
251			console.error("Unable to initialize export modal");
252		}
253	}
254});

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.