PageSourceSearch

https://web.hcaoa.org/External/WCControls/v12/JQuery/jquery.alerts/1.1/jquery.alerts.js

js hcaoa.org collected 2026-09-25 04:25:39 UTC 8,963 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// Website: http://abeautifulsite.net/blog/2008/12/jquery-alert-dialogs/
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		yesButton: ' Yes ',         // text for the Yes button
42		noButton: ' No ',         // text for the No button
43		dialogClass: null,                  // if specified, this class will be applied to all dialogs
44		
45		// Public methods
46		
47		alert: function(message, title, callback) {
48			if( title == null ) title = 'Alert';
49			$.alerts._show(title, message, null, 'alert', function(result) {
50				if( callback ) callback(result);
51			});
52		},
53		
54		confirm: function(message, title, callback) {
55			if( title == null ) title = 'Confirm';
56			$.alerts._show(title, message, null, 'confirm', function(result) {
57				if( callback ) callback(result);
58			});
59		},
60			
61		prompt: function(message, value, title, callback) {
62			if( title == null ) title = 'Prompt';
63			$.alerts._show(title, message, value, 'prompt', function(result) {
64				if( callback ) callback(result);
65			});
66		},
67
68		yesno: function (message, title, callback) {
69		    if (title == null) title = 'Confirm';
70		    $.alerts._show(title, message, null, 'yesno', function (result) {
71		        if (callback) callback(result);
72		    });
73		},
74		
75		// Private methods
76		
77		_show: function(title, msg, value, type, callback) {
78			
79			$.alerts._hide();
80			$.alerts._overlay('show');
81			
82			$("BODY").append(
83			  '<div id="popup_container">' +
84			    '<h1 id="popup_title"></h1>' +
85			    '<div id="popup_content">' +
86			      '<div id="popup_message"></div>' +
87				'</div>' +
88			  '</div>');
89			
90			if( $.alerts.dialogClass ) $("#popup_container").addClass($.alerts.dialogClass);
91			
92			// IE6 Fix
93			// OLD var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; 
94			var pos = 'fixed';
95
96			$("#popup_container").css({
97				position: pos,
98				zIndex: 99999,
99				padding: 0,
100				margin: 0
101			});
102			
103			$("#popup_title").text(title);
104			$("#popup_content").addClass(type);
105			$("#popup_message").text(msg);
106			$("#popup_message").html( $("#popup_message").text().replace(/\n/g, '<br />') );
107			
108			$("#popup_container").css({
109				minWidth: $("#popup_container").outerWidth(),
110				maxWidth: $("#popup_container").outerWidth()
111			});
112			
113			$.alerts._reposition();
114			$.alerts._maintainPosition(true);
115			
116			switch( type ) {
117				case 'alert':
118					$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /></div>');
119					$("#popup_ok").click( function() {
120						$.alerts._hide();
121						callback(true);
122					});
123					$("#popup_ok").focus().keypress( function(e) {
124						if( e.keyCode == 13 || e.keyCode == 27 ) $("#popup_ok").trigger('click');
125					});
126				break;
127				case 'confirm':
128					$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
129					$("#popup_ok").click( function() {
130						$.alerts._hide();
131						if( callback ) callback(true);
132					});
133					$("#popup_cancel").click( function() {
134						$.alerts._hide();
135						if( callback ) callback(false);
136					});
137					$("#popup_ok").focus();
138					$("#popup_ok, #popup_cancel").keypress( function(e) {
139						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
140						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
141					});
142					break;
143			    case 'yesno':
144			        $("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.yesButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.noButton + '" id="popup_cancel" /></div>');
145			        $("#popup_ok").click(function () {
146			            $.alerts._hide();
147			            if (callback) callback(true);
148			        });
149			        $("#popup_cancel").click(function () {
150			            $.alerts._hide();
151			            if (callback) callback(false);
152			        });
153			        $("#popup_ok").focus();
154			        $("#popup_ok, #popup_cancel").keypress(function (e) {
155			            if (e.keyCode == 13) $("#popup_ok").trigger('click');
156			            if (e.keyCode == 27) $("#popup_cancel").trigger('click');
157			        });
158			        break;
159				case 'prompt':
160					$("#popup_message").append('<br /><input type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
161					$("#popup_prompt").width( $("#popup_message").width() );
162					$("#popup_ok").click( function() {
163						var val = $("#popup_prompt").val();
164						$.alerts._hide();
165						if( callback ) callback( val );
166					});
167					$("#popup_cancel").click( function() {
168						$.alerts._hide();
169						if( callback ) callback( null );
170					});
171					$("#popup_prompt, #popup_ok, #popup_cancel").keypress( function(e) {
172						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
173						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
174					});
175					if( value ) $("#popup_prompt").val(value);
176					$("#popup_prompt").focus().select();
177				break;
178			}
179			
180			// Make draggable
181			if( $.alerts.draggable ) {
182				try {
183					$("#popup_container").draggable({ handle: $("#popup_title") });
184					$("#popup_title").css({ cursor: 'move' });
185				} catch(e) { /* requires jQuery UI draggables */ }
186			}
187		},
188		
189		_hide: function() {
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					$("BODY").append('<div id="popup_overlay"></div>');
200					$("#popup_overlay").css({
201						position: 'absolute',
202						zIndex: 99998,
203						top: '0px',
204						left: '0px',
205						width: '100%',
206						height: $(document).height(),
207						background: $.alerts.overlayColor,
208						opacity: $.alerts.overlayOpacity
209					});
210				break;
211				case 'hide':
212					$("#popup_overlay").remove();
213				break;
214			}
215		},
216		
217		_reposition: function() {
218			var top = (($(window).height() / 2) - ($("#popup_container").outerHeight() / 2)) + $.alerts.verticalOffset;
219			var left = (($(window).width() / 2) - ($("#popup_container").outerWidth() / 2)) + $.alerts.horizontalOffset;
220			if( top < 0 ) top = 0;
221			if( left < 0 ) left = 0;
222			
223			// IE6 fix
224			// OLD if( $.browser.msie && parseInt($.browser.version) <= 6 ) top = top + $(window).scrollTop();
225			
226			$("#popup_container").css({
227				top: top + 'px',
228				left: left + 'px'
229			});
230			$("#popup_overlay").height( $(document).height() );
231		},
232		
233		_maintainPosition: function(status) {
234			if( $.alerts.repositionOnResize ) {
235				switch(status) {
236					case true:
237						$(window).bind('resize', $.alerts._reposition);
238					break;
239					case false:
240						$(window).unbind('resize', $.alerts._reposition);
241					break;
242				}
243			}
244		}
245		
246	}
247	
248	// Shortuct functions
249	jAlert = function(message, title, callback) {
250		$.alerts.alert(message, title, callback);
251	}
252	
253	jConfirm = function(message, title, callback) {
254		$.alerts.confirm(message, title, callback);
255	};
256		
257	jPrompt = function(message, value, title, callback) {
258		$.alerts.prompt(message, value, title, callback);
259	};
260
261	jYesNo = function (message, title, callback) {
262	    $.alerts.yesno(message, title, callback);
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.