yoho_dialog_common.js 2.45 KB
// Lee dialog 1.0 http://www.xij.cn/blog/?p=68

var dialogFirst=true;
function dialog(title,content,width,height,cssName){

if(dialogFirst==true){
  var temp_float=new String;
  temp_float="<div id=\"dialogBoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;\"></div>";
  temp_float+="<div id=\"dialogBox\" class=\"dialogBox\">";
  temp_float+="<div class=\"dialogtitle\"><h4></h4><span class=\"dialogclose\"></span></div>";
  temp_float+="<div class=\"dialogcontent\"></div>";
  temp_float+="</div>";
  $("body").append(temp_float);
  dialogFirst=false;
}

$("#dialogBox .dialogclose").click(function(){
  $("#dialogBoxBg").animate({opacity:"0"},"normal",function(){$(this).hide();});
  $("#dialogBox").animate({top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px"},"normal",function(){$(this).hide();}); 
});

function closeDialog() {
	 $("#dialogBoxBg").animate({opacity:"0"},"normal",function(){$(this).hide();});
	  $("#dialogBox").animate({top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px"},"normal",function(){$(this).hide();}); 
}

$("#dialogBox .dialogtitle h4").html(title);
contentType=content.substring(0,content.indexOf(":"));
content=content.substring(content.indexOf(":")+1,content.length);
switch(contentType){
  case "url":
  var content_array=content.split("?");
  $("#dialogBox .dialogcontent").ajaxStart(function(){
    $(this).html("loading...");
  });
  $.ajax({
    type:content_array[0],
    url:content_array[1],
    data:content_array[2],
	error:function(){
	  $("#dialogBox .dialogcontent").html("error...");
	},
    success:function(html){
      $("#dialogBox .dialogcontent").html(html);
    }
  });
  break;
  case "text":
  $("#dialogBox .dialogcontent").html(content);
  break;
  case "id":
  $("#dialogBox .dialogcontent").html($("#"+content+"").html());
  break;
  case "iframe":
  $("#dialogBox .dialogcontent").html("<iframe src=\""+content+"\" width=\"100%\" height=\""+(parseInt(height)-30)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
}

$("#dialogBoxBg").show();
$("#dialogBoxBg").animate({opacity:"0.9"},"normal");
$("#dialogBox").attr("class","dialogBox "+cssName);
$("#dialogBox").css({display:"block",left:(($(document).width())/2-(parseInt(width)/2))+"px",top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px",width:width,height:height});
$("#dialogBox").animate({top:($(document).scrollTop()+50)+"px"},"normal"); 
}