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: 'ã¯ã', // text for the OK button 40 cancelButton: 'ããã', // 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) { 46 if( title == null ) title = 'Alert'; 47 $.alerts._show(title, message, null, 'alert', function(result) { 48 if( callback ) callback(result); 49 }); 50 }, 51 52 confirm: function(message, title, okButton, cancelButton, callback) { 53 if( title == null ) title = 'Confirm'; 54 if (okButton != ""){ 55 $.alerts.okButton = okButton; 56 $.alerts.cancelButton = cancelButton; 57 } 58 $.alerts._show(title, message, null, 'confirm', function(result) { 59 if( callback ) callback(result); 60 }); 61 }, 62 63 prompt: function(message, value, title, callback) { 64 if( title == null ) title = 'Prompt'; 65 $.alerts._show(title, message, value, 'prompt', function(result) { 66 if( callback ) callback(result); 67 }); 68 }, 69 70 // Private methods 71 72 _show: function(title, msg, value, type, callback) { 73 74 $.alerts._hide(); 75 $.alerts._overlay('show'); 76 77 $("BODY").append( 78 '<div id="popup_container">' + 79 '<h1 id="popup_title"></h1>' + 80 '<div id="popup_content">' + 81 '<div id="popup_message"></div>' + 82 '</div>' + 83 '</div>'); 84 85 if( $.alerts.dialogClass ) $("#popup_container").addClass($.alerts.dialogClass); 86 87 // IE6 Fix 88 var pos = 'fixed'; 89 90 $("#popup_container").css({ 91 position: pos, 92 zIndex: 99999, 93 padding: 0, 94 margin: 0 95 }); 96 97 98 $("#popup_title").text(title); 99 $("#popup_content").addClass(type); 100 $("#popup_message").text(msg); 101 $("#popup_message").html( $("#popup_message").text().replace(/\n/g, '<br />') ); 102 103 $("#popup_container").css({ 104 minWidth: $("#popup_container").outerWidth(), 105 maxWidth: $("#popup_container").outerWidth() 106 }); 107 108 $.alerts._reposition(); 109 $.alerts._maintainPosition(true); 110 111 switch( type ) { 112 case 'alert': 113 $("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /></div>'); 114 $("#popup_ok").click( function() { 115 $.alerts._hide(); 116 callback(true); 117 }); 118 $("#popup_ok").focus().keypress( function(e) { 119 if( e.keyCode == 13 || e.keyCode == 27 ) $("#popup_ok").trigger('click'); 120 }); 121 break; 122 case 'confirm': 123 $("#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>'); 124 $("#popup_ok").click( function() { 125 $.alerts._hide(); 126 if( callback ) callback(true); 127 });
128 $("#popup_cancel").click( function() { 129 $.alerts._hide(); 130 if( callback ) callback(false); 131 }); 132 $("#popup_ok").focus(); 133 $("#popup_ok, #popup_cancel").keypress( function(e) { 134 if( e.keyCode == 13 ) $("#popup_ok").trigger('click'); 135 if( e.keyCode == 27 ) $("#popup_cancel").trigger('click'); 136 }); 137 break; 138 case 'prompt': 139 $("#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>'); 140 $("#popup_prompt").width( $("#popup_message").width() ); 141 $("#popup_ok").click( function() { 142 var val = $("#popup_prompt").val(); 143 $.alerts._hide(); 144 if( callback ) callback( val ); 145 }); 146 $("#popup_cancel").click( function() { 147 $.alerts._hide(); 148 if( callback ) callback( null ); 149 }); 150 $("#popup_prompt, #popup_ok, #popup_cancel").keypress( function(e) { 151 if( e.keyCode == 13 ) $("#popup_ok").trigger('click'); 152 if( e.keyCode == 27 ) $("#popup_cancel").trigger('click'); 153 }); 154 if( value ) $("#popup_prompt").val(value); 155 $("#popup_prompt").focus().select(); 156 break; 157 } 158 159 // Make draggable 160 if( $.alerts.draggable ) { 161 try { 162 $("#popup_container").draggable({ handle: $("#popup_title") }); 163 $("#popup_title").css({ cursor: 'move' }); 164 } catch(e) { /* requires jQuery UI draggables */ } 165 } 166 }, 167 168 _hide: function() { 169 $("#popup_container").remove(); 170 $.alerts._overlay('hide'); 171 $.alerts._maintainPosition(false); 172 }, 173 174 _overlay: function(status) { 175 switch( status ) { 176 case 'show': 177 $.alerts._overlay('hide'); 178 $("BODY").append('<div id="popup_overlay"></div>'); 179 $("#popup_overlay").css({ 180 position: 'absolute', 181 zIndex: 99998, 182 top: '0px', 183 left: '0px', 184 width: '100%', 185 height: $(document).height(), 186 background: $.alerts.overlayColor, 187 opacity: $.alerts.overlayOpacity 188 }); 189 break; 190 case 'hide': 191 $("#popup_overlay").remove(); 192 break; 193 } 194 }, 195 196 _reposition: function() { 197 var top = ((window.innerHeight / 2) - ($("#popup_container").outerHeight() / 2)) + $.alerts.verticalOffset; 198 var left = (($(window).width() / 2) - ($("#popup_container").outerWidth() / 2)) + $.alerts.horizontalOffset; 199 if( top < 0 ) top = 0; 200 if( left < 0 ) left = 0; 201 202 // IE6 fix 203// if($.support.opacity && $.support.style && 204// typeof document.documentElement.style.maxHeight == "undefined" ) top = top + $(window).scrollTop(); 205 206 $("#popup_container").css({ 207 top: top + 'px', 208 left: left + 'px' 209 }); 210 $("#popup_overlay").height( $(document).height() ); 211 }, 212 213 _maintainPosition: function(status) { 214 if( $.alerts.repositionOnResize ) { 215 switch(status) { 216 case true: 217 $(window).bind('resize', $.alerts._reposition); 218 break; 219 case false: 220 $(window).unbind('resize', $.alerts._reposition); 221 break; 222 } 223 } 224 } 225 226 } 227 228 // Shortuct functions 229 jAlert = function(message, title, callback) { 230 $.alerts.alert(message, title, callback); 231 } 232 233 jConfirm = function(message, title, okButton, cancelButton, callback) { 234 $.alerts.confirm(message, title, okButton, cancelButton, callback); 235 }; 236 237 jPrompt = function(message, value, title, callback) { 238 $.alerts.prompt(message, value, title, callback); 239 }; 240 241})(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.