popup.js 2.15 KB
Newer Older
1 2 3 4 5
// jQuery Message Popup
// Display a message on the top of page, with floating
//

(function ($, document, window) {
6 7
  var isShow = null;
  var showDelayTimer = null;
8 9
  $.extend($.fn, {
    Popup: function(msg, option) {
10
      var h;
11 12 13 14
      if (option.type == undefined) option.type = "info";
      if (option.closebtn == undefined) option.closebtn = false;
      if (option.duration == undefined) option.duration = 0;
      if (option.load == undefined) option.load = false;
15
      $box = $(this);
16 17 18 19 20
      if(showDelayTimer){clearTimeout(showDelayTimer);}
      if(isShow){
        $box.fadeOut('normal', function() {
          setupBox();
        });
21
      }
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
      else{setupBox();}
      function setupBox(){
        $box.empty();
        $box.css('top','-1000px');
        $box.show();
        $box.append('<div><table id="bcontent"><tr>' +
        '<td valign="middle" class="logo ' + option.type + '_message"></td>' +
  	    '<td valign="middle"><p>' + msg + '</p></td>' +
  	    '<td valign="middle" class="b_close"><span id="pClose"></span></td></tr></table></div>');
        $(window).scroll(function(){
  	      $box.animate({top:$(window).scrollTop()+"px" },{queue: false, duration: 350});
        });
        h = $("#bcontent").height()+5;
        $("#pClose").bind("click", function() {
  	      close();
        });
        showBox();
        if(option.duration != 0){
        	showDelayTimer = setTimeout(function(){
            showDelayTimer = null;
        	  close();
        	}, option.duration);
        }
45
      }
46 47 48 49 50 51 52 53 54 55 56 57 58
      function showBox(){
        if(option.load){
          $(window).load(function(){
            $box.css('top', + ($(window).scrollTop() - h) +'px');
        	  $box.animate({ top:"+=" + h + "px" }, "slow");
            isShow = true;
        	});
        }
        else{
        	$box.css('top', + ($(window).scrollTop() - h) +'px');
        	$box.animate({ top:"+=" + h + "px" }, "slow");
          isShow = true;
        }
59 60
      }
      function close(){
61 62 63 64 65
      	$box.animate({ top:"-=" + h + "px" }, "slow", function(){
      	  $box.fadeOut("normal", function() {
            isShow = false;
          });
      	});
66 67
      }
    }
68
  });
69
}(jQuery, document, this));