PageSourceSearch

https://mypridenet.springfield.edu/js/jquery-alerts/jquery.alerts.js

js springfield.edu collected 2026-09-24 09:21:51 UTC 9,147 bytes, 265 lines download raw bytes

1// jQuery Alert Dialogs Plugin
2//
3// Version 1.1
4//
5// Cory S.N. LaViska
6// A Beautiful Site (http://abeautifulsite.net/)
7// 14 May 2009
8//
9// Visit http://abeautifulsite.net/notebook/87 for more information
10//
11// Usage:
12//		jAlert( message, [title, callback] )
13//		jConfirm( message, [title, callback] )
14//		jPrompt( message, [value, title, callback] )
15// 
16// History:
17//
18//		1.00 - Released (29 December 2008)
19//
20//		1.01 - Fixed bug where unbinding would destroy all resize events
21//
22// License:
23// 
24// This plugin is dual-licensed under the GNU General Public License and the MIT License and
25// is copyright 2008 A Beautiful Site, LLC. 
26//
27(function($) {
28	
29	$.alerts = {
30		
31		// These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time
32		
33		verticalOffset: -75,                // vertical offset of the dialog from center screen, in pixels
34		horizontalOffset: 0,                // horizontal offset of the dialog from center screen, in pixels/
35		repositionOnResize: true,           // re-centers the dialog on window resize
36		overlayOpacity: .01,                // transparency level of overlay
37		overlayColor: '#FFF',               // base color of overlay
38		draggable: true,                    // make the dialogs draggable (requires UI Draggables plugin)
39		okButton: ' OK ',         			// text for the OK button
40		cancelButton: ' Cancel ', 			// text for the Cancel button
41		dialogClass: null,                  // if specified, this class will be applied to all dialogs
42		
43		// Public methods
44		
45		alert: function(message, title, callback, focusOnClose) {
46			if( title == null ) title = 'Alert';
47			$.alerts._show(title, message, null, 'alert', function(result) {
48				if( callback ) callback(result);
49			}, focusOnClose);
50		},
51		
52		confirm: function(message, title, callback, focusOnClose) {
53			if( title == null ) title = 'Confirm';
54			$.alerts._show(title, message, null, 'confirm', function(result) {
55				if( result && callback ) callback(result);
56			}, focusOnClose);
57		},
58			
59		prompt: function(message, value, title, callback, focusOnClose) {
60			if( title == null ) title = 'Prompt';
61			$.alerts._show(title, message, value, 'prompt', function(result) {
62				if( callback ) callback(result);
63			}, focusOnClose);
64		},
65		
66		// Private methods
67		
68		_show: function(title, msg, value, type, callback, focusOnClose) {
69			let pathToElementToFocusOnClose = focusOnClose;
70			if (!pathToElementToFocusOnClose) {
71				if (window.event && window.event.target) {
72					let selector = getElementSelector(window.event.target);
73					if ($(selector).length > 0) {
74						pathToElementToFocusOnClose = selector;
75					}
76				}
77			}
78
79			$.alerts._hide();
80			$.alerts._overlay('show');
81			
82			var appendTo = "body";
83			if( $("#primary-modal").is(':visible') ) { appendTo = "#primary-modal" };
84
85			$(appendTo).append(
86			  '<div id="popup_container">' +
87			    '<h1 id="popup_title"></h1>' +
88			    '<div id="popup_content">' +
89			      '<div id="popup_message"></div>' +
90				'</div>' +
91			  '</div>');
92			
93			if( $.alerts.dialogClass ) $("#popup_container").addClass($.alerts.dialogClass);
94			
95			// IE6 Fix
96			//var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; 
97			var pos = 'fixed'; 
98			
99			$("#popup_container").css({
100				position: pos,
101				zIndex: 999999,
102				padding: 0,
103				margin: 0
104			});
105			
106			$("#popup_title").text(title);
107			$("#popup_content").addClass(type);
108			$("#popup_message").text(msg);
109			$("#popup_message").html( $("#popup_message").text().replace(/\n/g, '<br />') );
110			
111			$("#popup_container").css({
112				minWidth: $("#popup_container").outerWidth(),
113				maxWidth: $("#popup_container").outerWidth()
114			});
115			
116			$.alerts._reposition();
117			$.alerts._maintainPosition(true);
118			
119			switch( type ) {
120				case 'alert':
121					$("#popup_message").after('<div id="popup_panel"><input class="btn btn-cg--user" type="button" value="' + $.alerts.okButton + '" id="popup_ok" /></div>');
122					$("#popup_ok").click( function() {
123						$.alerts._hide();
124						callback(true);
125					});
126					$("#popup_ok").focus().keypress( function(e) {
127						if( e.keyCode == 13 || e.keyCode == 27 ) $("#popup_ok").trigger('click');
128					});
129				break;
130				case 'confirm':
131					$("#popup_message").after('<div id="popup_panel"><input class="btn btn-cg--user" type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input class="btn btn-grey" type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
132					$("#popup_ok").click( function() {
133						$.alerts._hide();
134						if( callback ) callback(true);
135					});
136					$("#popup_cancel").click( function() {
137						$.alerts._hide();
138						if( callback ) callback(false);
139					});
140					$("#popup_ok").focus();
141					$("#popup_ok").keypress( function(e) {
142						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
143						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
144					});
145					$("#popup_cancel").keypress( function(e) {
146						if( e.keyCode == 13 ) $("#popup_cancel").trigger('click');
147						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
148					});
149				break;
150				case 'prompt':
151					$("#popup_message").append('<br /><input class="form-control" type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input class="btn btn-cg--user" type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input class="btn btn-grey" type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
152					// Accessibility: ensure the prompt input has an accessible name.
153					$("#popup_prompt").attr("aria-label", getSafeAriaLabelTextTrim(msg));
154					//$("#popup_prompt").width( $("#popup_message").width() );
155					$("#popup_ok").click( function() {
156						var val = $("#popup_prompt").val();
157						$.alerts._hide();
158						if( callback ) callback( val );
159					});
160					$("#popup_cancel").click( function() {
161						$.alerts._hide();
162						if( callback ) callback( null );
163					});
164					$("#popup_prompt, #popup_ok").keypress( function(e) {
165						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
166						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
167					});
168					$("#popup_cancel").keypress( function(e) {
169						if( e.keyCode == 13 ) $("#popup_cancel").trigger('click');
170						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
171					});
172					if( value ) $("#popup_prompt").val(value);
173					$("#popup_prompt").focus().select();
174				break;
175			}
176
177			initPopupAccessibility('popup_container', pathToElementToFocusOnClose);
178
179			// Make draggable
180			if( $.alerts.draggable ) {
181				try {
182					$("#popup_container").draggable({ handle: $("#popup_title") });
183					$("#popup_title").css({ cursor: 'move' });
184				} catch(e) { /* requires jQuery UI draggables */ }
185			}
186		},
187		
188		_hide: function() {
189			terminatePopupAccessibility('popup_container');
190			$("#popup_container").remove();
191			$.alerts._overlay('hide');
192			$.alerts._maintainPosition(false);
193		},
194		
195		_overlay: function(status) {
196			switch( status ) {
197				case 'show':
198					$.alerts._overlay('hide');
199
200					var appendTo = "body";
201					if( $("#primary-modal").is(':visible') ) { appendTo = "#primary-modal" };
202
203					$(appendTo).append('<div id="popup_overlay"></div>');
204					$("#popup_overlay").css({
205						position: 'absolute',
206						zIndex: 999998,
207						top: '0px',
208						left: '0px',
209						width: '100%',
210						height: $(document).height(),
211						background: $.alerts.overlayColor,
212						opacity: $.alerts.overlayOpacity
213					});
214				break;
215				case 'hide':
216					$("#popup_overlay").remove();
217				break;
218			}
219		},
220		
221		_reposition: function() {
222			var top = (($(window).height() / 2) - ($("#popup_container").outerHeight() / 2)) + $.alerts.verticalOffset;
223			var left = (($(window).width() / 2) - ($("#popup_container").outerWidth() / 2)) + $.alerts.horizontalOffset;
224			if( top < 0 ) top = 0;
225			if( left < 0 ) left = 0;
226			
227			// IE6 fix
228			//if( $.browser.msie && parseInt($.browser.version) <= 6 ) top = top + $(window).scrollTop();
229			
230			$("#popup_container").css({
231				top: top + 'px',
232				left: left + 'px'
233			});
234			$("#popup_overlay").height( $(document).height() );
235		},
236		
237		_maintainPosition: function(status) {
238			if( $.alerts.repositionOnResize ) {
239				switch(status) {
240					case true:
241						$(window).bind('resize', $.alerts._reposition);
242					break;
243					case false:
244						$(window).unbind('resize', $.alerts._reposition);
245					break;
246				}
247			}
248		}
249		
250	}
251	
252	// Shortuct functions
253	jAlert = function(message, title, callback, focusOnClose) {
254		$.alerts.alert(message, title, callback, focusOnClose);
255	}
256	
257	jConfirm = function(message, title, callback, focusOnClose) {
258		$.alerts.confirm(message, title, callback, focusOnClose);
259	};
260		
261	jPrompt = function(message, value, title, callback, focusOnClose) {
262		$.alerts.prompt(message, value, title, callback, focusOnClose);
263	};
264	
265})(jQuery);

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.