Fiz em 10 minutinhos um pequeno plugin para exibir caixas de erro, você pode mandar opções de tempo de exibição assim como especificar uma mensagem de erro específica para ser exibida.
O código é bem pequeno, fica disponível para quem quiser utilizar:
/* MIT Licenced: Copyright (c) 2010 Leonardo Balter Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * contact: * leo @ balter.com.br * usages: * in HTML: * <div id="errorBox">This would better start as an invisible box</div> * in JS: * jQuery('#errorBox').showErrorBox() // this will preserve the box text * jQuery('.errorBoxes').showErrorBox() // it applies to one or many error boxes * jQuery(selector).showErrorBox( { message: 'There´s an error, bro!' } ); * */ (function() { jQuery.fn.showErrorBox = function( opts ) { var $this = jQuery(this); if( !$this.length ) { return; } var settings = { message : false, speedIn : 'slow', speedOut : 'fast', delay : 1000 } jQuery.extend(settings, opts); if ( settings.message ) { $this.text( settings.message ) } $this .stop(true,true) .fadeIn(settings.speedIn, function() { jQuery(this).delay(settings.delay).fadeOut(settings.speedOut); }); }; })(jQuery);
Se quiser ele compactado:
/* MIT Licenced: Copyright (c) 2010 Leonardo Balter Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ (function(){jQuery.fn.showErrorBox=function(c){var b=jQuery(this);if(b.length){var a={message:false,speedIn:"slow",speedOut:"fast",delay:1E3};jQuery.extend(a,c);a.message&&b.text(a.message);b.stop(true,true).fadeIn(a.speedIn,function(){jQuery(this).delay(a.delay).fadeOut(a.speedOut)})}}})(jQuery);








