<?php

//载入全局配置和函数包
require_once(dirname(__FILE__)."/../include/global.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $Project["charset"];?>" />
<title>IFRAME 引用代码 - Powered By VeryIDE</title>

<?php

echo loader_script(array(VI_BASE."js/mo.js",VI_BASE."js/mo.drag.js"),$Project["charset"],$Project["version"]);

?>

<script type="text/javascript">

Mo.reader(function(){

	//iframe
	var ifm = Mo("iframe").item(0);

	//onload
	var onLoad = function(){

		var pos = Mo(ifm).position();

		//set iframe
		var tbr = Mo('#handle').item(0);

		tbr.style.left	= pos.left + pos.width +"px";
		tbr.style.top	= pos.top + pos.height +"px";	

		var dg = new Mo.Drag(tbr);

		dg.onStart = function(x, y) {	

			var doc = Mo.document;

			//Mo("#bg").remove();
			
			if( Mo("#bg").size() == 0 ){

				//bg
				var bg=document.createElement("DIV");
					bg.id="bg";
					bg.style.height=Math.max(doc.scrollHeight,doc.clientHeight)+"px";
					bg.style.width="100%";
	
					document.body.appendChild(bg);
				
			}else{
			
				Mo("#bg").show();
			
			}
				
		}

		dg.onDrag = function(x, y) {
			
			var pos = Mo(ifm).position();

			var w = x - pos.left;
			var h = y - pos.top ;

			Mo("#width").value(w +"px");
			Mo("#height").value(h +"px");

			ifm.style.width  = w +"px";
			ifm.style.height = h +"px";

			getCode(w,h);

		}

		dg.onEnd = function(x, y) {
			Mo("#bg").hide();
		}
		
		getCode(ifm.offsetWidth,ifm.offsetHeight);

	}
	
	//code
	var getCode = function(w,h){
	
		Mo("#code").value('<iframe border="0" id="IFRAME-'+Mo.get("id",ifm.contentWindow.location.href)+'" src="'+ifm.contentWindow.location.href+'" width="'+w+'" frameborder="0" height="'+h+'"></iframe>');
	}
	
	//bind
	if ( ifm.attachEvent ){
		ifm.attachEvent("onload", function(){
			onLoad();
		});
	} else {
		ifm.onload = function(){
			onLoad();
		};
	}

	//set iframe
	var s = location.search.substring(1);
	if (s !=''){
		Mo("#url").value(s);
		ifm.src= s;
		ifm.id = "IFRAME-"+getQuery("id",location.search)
	}	
	

});
</script>

<style type="text/css">
html{ font-size:13px; font-family:Verdana, Arial, Helvetica, sans-serif;}
h1{ font-size:24px; text-align:center;}
form{ border:#999 solid 1px; width:425px; margin:10px auto; padding:10px;}
form input{ vertical-align:middle;}
div{padding:10px; background:#efefef; text-align:center;}

#handle{position:absolute; cursor:se-resize; z-index:1000;}
#bg{position:absolute;background:#333; filter:alpha(opacity=10); opacity:0.1;z-index:0; top:0;left:0; z-index:999;}
</style>
</head>

<body>
	
	<h1>获取 IFRAME 引用代码</h1>

	<div>
		<img id="handle" src="<?php echo VI_BASE;?>/image/cursor/se-resize.png" />
		<iframe id="iframe" src="" frameborder="0" style="width:400px;height:400px;"></iframe>
	</div>

	<form onsubmit="return false;" style="clear:both;">
		地址：<input type="text" id="url" value="" style="width:370px;" />
		<br /><br />
		尺寸：<input type="text" id="width" value="" />×
		<input type="text" id="height" value="" />
		<br /><br />
		<hr />
		代码：<br />
		<textarea cols="45" rows="5" id="code" style="width:420px;"></textarea>
	</form>
</body>
</html>