Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * jAlert v.1.0.0
- * Copyright (c) 2008 Julian Castaneda
- * http://www.smooka.com/blog/2009/02/22/jalert-jquery-alert-box-plugin/
- * Requires: jQuery 1.2+
- *
- * Edit / Tweak by aeroson
- * example call $('.lalal').alert("This is a jAlert success Box", { type:'success', timeout:'5000', width:'350', y_offset:0 } );
- * alert ( msg [, options ] )
- * options => type (default 'fatal') , timeout (default 0 = no timeout), width (default 350), y_offset (default -4-box height }
- */
- $(window).resize(function() {
- $(".msg-box-cont").each(function( index ) {
- //align center all
- var width = $(this).width();
- var container=$("#"+$(this).attr('cont'));
- var container_width = container.innerWidth();
- var container_left = container.position().left;
- var actual_left = ((container_width-width)/2)+container_left;
- $(this).css("left",actual_left+"px");
- });
- });
- (function($) {
- $.fn.alert = function (msg, options)
- {
- if(!options) options=0;
- var container = this;
- var overlay = 0;
- var uid = this.attr('id');
- if ($('#jalert_cont_'+uid).css('display') == 'block')
- {
- milisec=(new Date()).getTime();
- $('#jalert_cont_'+uid).attr('id','jalert_cont_t'+milisec);
- $('#jalert_close_'+uid).attr('id','jalert_close_t'+milisec);
- remove($('#jalert_cont_t'+milisec),500);
- }
- var type=options.type||'fatal';
- var width=options.width||350;
- if (overlay==1) {
- $('<div id="jalert_overlay_'+uid+'"></div>').prependTo('body');
- var overlayWidth = $(window).width();
- var overlayHeight = $(document).height();
- var winHeight = $(window).height();
- $("#jalert_overlay_"+uid).css({
- top: 0,
- left: 0,
- width: overlayWidth,
- height: winHeight,
- position: "fixed",
- display: "block",
- background: "#000",
- zIndex: "1000"
- });
- $("#jalert_overlay_"+uid).css("opacity", 0.7);
- }
- $('<div class="msg-box-cont msg-'+type+'" cont="'+uid+'" id="jalert_cont_'+uid+'"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td><div class="msg-text"><div class="msg-icon msg-icon-'+type+'"></div>'+msg+'</div></td><td width="21" valign="top"><div id="jalert_close_'+uid+'" class="msg-btn close-'+type+'"></div></td></tr></table></div>').appendTo('body');
- var jqobj=$("#jalert_cont_"+uid);
- jqobj.width(width);
- //align center
- var width = jqobj.width();
- var container_width = container.innerWidth();
- var container_left = container.position().left;
- var actual_left = ((container_width-width)/2)+container_left;
- jqobj.css("left",actual_left+"px");
- var y_offset = options.y_offset||-4-jqobj.height();
- var top=this.position().top + y_offset;
- jqobj.css("top",(top+20)+"px").animate({top:top+"px"},{duration:500,queue:false}).fadeIn(500);
- $(document).click(function() {
- $("#jalert_overlay_"+uid).fadeOut(100);
- $("#jalert_overlay_"+uid).remove();
- });
- $('#jalert_close_'+uid).click(function() {
- remove(jqobj);
- });
- if (options.timeout) {
- var timeoutId=setTimeout(function(){
- remove(jqobj);
- },options.timeout);
- };
- function remove(id,t) {
- if (t==undefined) t=300;
- if (timeoutId!=undefined) window.clearTimeout(timeoutId);
- id.fadeOut(t, function(){
- id.empty().remove();
- });
- }
- };
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement