⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 radwindow.js

📁 Telerik是很大的第三方软件制造商
💻 JS
📖 第 1 页 / 共 3 页
字号:
/************************************************
 *
 *	Class RadWindow
 *
 ************************************************/
function RadWindow(id)
{
	this.IsIE = (null != document.all) && (window.opera == null);
	this.Id = id;
	this.Width = 0;
	this.Height = 0;	
	this.OnClientClose = null;
	//Private members
	this.ContentWindow = null;	
	this.ContentWrapperTable = null;
	this.Caption = null;
	this.X = 0;
	this.Y = 0;
	this.ShowContentWhenMoving = true;	
	this.CanMove = true;
	this.CanResize = true;

	this.DragMode = "";	// "move" "size"

	// dialogs-related stuff
	this.IsModal = false;
	this.Container = null;
	this.Parent = null;

	this.Argument = null;
	this.ReturnValue = null;
	this.ExitCode = null;	// OK, CANCEL, etc.
	this.ZIndex = 0;
	this.AdjustPosInterval = -1;
	this.CallbackFunc = null;	// signature: function CallbackFunc() { }
	this.OnLoadFunc = null;
	this.Param = null;

	this.ModalSetCapture = false;

	this.UseRadWindow = true;
	this.Window = null;	// IHTMLWindow object - this.UseRadWindow == true
	this.InnerHTML = null;
}

RadWindow.prototype.OnLoad = function()
{
	if (this.Window && "" != this.Window.document.title)
	{
		this.SetCaption(this.Window.document.title);
	}

	if (this.OnLoadFunc)
	{
		this.OnLoadFunc();
	}
}

RadWindow.prototype.SetCapture = function(bContainerCapture)
{
	if (this.UseRadWindow)
	{
		if (null != bContainerCapture)
		{
			this.bContainerCapture = bContainerCapture;
		}
		else if (null != this.bContainerCapture)
		{
			bContainerCapture = this.bContainerCapture;
		}
		else
		{
			bContainerCapture = false;
		}

		if (this.ModalSetCapture && this.IsIE)
		{
			this.ContentWrapperTable.setCapture(bContainerCapture);
		}
	}
}

RadWindow.prototype.ReleaseCapture = function()
{
	if (this.UseRadWindow)
	{
		if (this.ModalSetCapture && this.IsIE)
		{
			if (this.ContentWrapperTable)
				this.ContentWrapperTable.releaseCapture();
		}
	}
}

RadWindow.prototype.SetZIndex = function(zIndex)
{
	this.ZIndex = zIndex;
	if (this.ContentWrapperTable)
	{
		this.ContentWrapperTable.style.zIndex = this.ZIndex;
	}
}

RadWindow.prototype.ToggleContent = function()
{
	return;
	if (this.UseRadWindow && this.IsIE)
	{
		var displayStyle = "";
		if (parseInt(this.Height) == parseInt(this.ContentWrapperTable.style.height))
		{
			this.SetHeight(0);
			displayStyle = "none";
		}
		else
		{
			this.SetHeight(this.Height);
			displayStyle = "inline";
		}

		this.ContentWindow.style.display = displayStyle;
	}
}

RadWindow.prototype.IsVisible = function()
{
	if (this.ContentWrapperTable)
	{
		return this.ContentWrapperTable.style.display == "";//block
	}
	return false;
}

RadWindow.prototype.ShowWindow = function(show, x, y)
{
	if (null == show)
	{
		show = true;
	}
	var displayStyle = show ? "" : "none";//block

	if (this.ContentWrapperTable)
	{
		this.ContentWrapperTable.style.display = displayStyle;
	}

	if (null != this.ContentWindow && show)
	{						
		if (null != x && null != y)
		{
			x += 10;
			if (this.ContentWrapperTable)
			{
				this.ContentWrapperTable.style.left = x + 'px';
				this.ContentWrapperTable.style.top = y + 'px';
			}
		}	
	}

	if (this.Parent)
	{
		this.Parent.OnShowWindow(this, show);
	}
}

RadWindow.prototype.Initialize2 =  function(contentElem, show, containerElem, modal, zIndex)
{
	this.Initialize(contentElem, show);

	this.IsModal = modal;
	this.Container = containerElem;

	this.SetZIndex(zIndex);
}

RadWindow.prototype.Initialize =  function(contentElem, show)
{
	//Use the Id to get a reference to the ContentWindow
	if (this.Id)
	{
		this.ContentWrapperTable = document.getElementById("RadWindowContentWrapper" + this.Id);
		this.ContentWindow = document.getElementById("RadWindowContentWindow" + this.Id);		
		this.Caption = document.getElementById("RadWindowCaption" + this.Id);
		
		//Set the content of the r.a.d.window
		if (contentElem)
		{
			this.SetContentElement(contentElem);
		}

		if (null == show)
		{
			var show = true;
		}

		this.ShowWindow(show);
	}
	else
	{
		alert ("No window Id provided");
	}
};

RadWindow.prototype.SetContentElement = function (contentElem)
{
	var parentNode = contentElem.parentNode;
	if (parentNode)
	{
		parentNode.removeChild(contentElem);
	}

	while (this.ContentWindow && this.ContentWindow.childNodes.length > 0)
	{
		this.ContentWindow.removeChild(this.ContentWindow.childNodes.item(0));
	}

	if (this.ContentWindow)
	{
		this.ContentWindow.appendChild(contentElem);
		this.SetContentWindowSize(contentElem.style.width, null);
	}
}

RadWindow.prototype.SetContentWindowSize = function (width, height)
{
	this.Width = width;
	this.Height = height;	
};

RadWindow.prototype.SetContentVisible = function (visible)
{
	if (this.ContentWindow)
	{
		this.ContentWindow.style.visibility = visible ? "visible" : "hidden";
	}
};

RadWindow.prototype.Close = function(exitCode, dialogCallbackFunction, execCallBack)
{
	if (null != this.OnClientClosing
		&& (this.OnClientClosing(exitCode) == false))
	{
		return;
	}

	this.ShowWindow(false);

	this.ExitCode = exitCode;

	if (this.AdjustPosInterval > -1)
	{
		window.clearInterval(this.AdjustPosInterval);
		this.AdjustPosInterval = -1;
	}

	if (this.IsModal)
		this.ReleaseCapture();

	try
	{
		if (this.CallbackFunc && false != execCallBack)
			this.CallbackFunc(this.ReturnValue, this.Param);
		if (dialogCallbackFunction)
		{
			dialogCallbackFunction(this.ReturnValue, this.Param);
		}
	}
	catch (ex)
	{
	}

	if (this.Parent)
		this.Parent.DestroyWindow(this);

	if (!this.UseRadWindow && this.Window)
		this.Window.close();
};

RadWindow.prototype.ToggleCanMove = function(oDiv)
{
	if (!this.UseRadWindow)
		return;

	this.CanMove = !this.CanMove;

	oDiv.className = this.CanMove ? "RadERadWindowButtonPinOff" : "RadERadWindowButtonPinOn";

	if (!this.CanMove)
	{
		if (this.IsIE)
		{
			this.TopOffset = parseInt(this.ContentWrapperTable.style.top) - RadGetScrollTop(document);
			this.StartUpdatePosTimer(100);
		}
		else
		{
			this.ContentWrapperTable.style.position = "fixed";
		}
	}
	else
	{
		if (this.IsIE)
		{
			window.clearInterval(this.AdjustPosInterval);
			this.TopOffset = null;
		}
		else
		{
			this.ContentWrapperTable.style.position = "absolute";
		}
	}
}

RadWindow.prototype.StartUpdatePosTimer = function(iInterval)
{
	if (!this.UseRadWindow) return;
	this.AdjustPosInterval = window.setInterval("UpdateWindowPos('" + this.Id + "')", iInterval);
}

function UpdateWindowPos(wndId)
{
	var wnd = GetEditorRadWindowManager().LookupWindow(wndId);
	if (wnd)
		wnd.SetPosition();
}

RadWindow.prototype.CanDrag = function()
{
	if (!this.UseRadWindow)
		return true;

	return ("move" == this.DragMode && this.CanMove)
			|| ("size" == this.DragMode && this.CanResize);
}

RadWindow.prototype.OnDragStart = function(e)
{
	this.SetActive(true);	//RadWindowActiveWindow = this;

	if (!this.CanDrag()) return;

	this.X = (e.offsetX == null) ? e.layerX : e.offsetX;
	this.Y = (e.offsetY == null) ? e.layerY : e.offsetY;

	MousePosX = e.clientX;
	MousePosY = e.clientY;

	this.SetContentVisible(this.ShowContentWhenMoving);
	RadWindowDragStart();
};

RadWindow.prototype.SetActive = function(activate)
{
	if (!this.UseRadWindow) return;

	if (activate)
	{
		if (null != RadWindowActiveWindow && RadWindowActiveWindow != this)
			RadWindowActiveWindow.SetActive(false);

		RadWindowActiveWindow = this;

		if (this.Parent)
			this.Parent.ActivateWindow(this);
	}
	else
	{
		if (this == RadWindowActiveWindow)
			RadWindowActiveWindow = null;
	}
}

RadWindow.prototype.HitTest = function(x, y)
{
	var left = parseInt(this.ContentWrapperTable.style.left);
	if (isNaN(left))
		return false;

	var top = parseInt(this.ContentWrapperTable.style.top);
	if (isNaN(top))
		return false;

	return	left <= x
			&& x <= (left + this.Width)
			&& top <= y
			&& y <= (top + this.Height);
}

RadWindow.prototype.SetPosition = function(left, top)
{
	if (!this.UseRadWindow)
	{
		if (this.Window)
		{
			this.Window.dialogLeft = left;
			this.Window.dialogTop = top;
		}
	}
	else
	{
		if (!left)
			left = this.ContentWrapperTable.style.left;

		if (!top)
		{
			if (this.TopOffset != null)
				top = parseInt(this.TopOffset) + RadGetScrollTop(document);
			else
				top = this.ContentWrapperTable.style.top;
		}

		left = parseInt(left);
		top = parseInt(top);

		if (!isNaN(left) && !isNaN(top))
		{
			if (left <= 0) left = 0;
			if (top <= 0) top = 0;

			this.ContentWrapperTable.style.left = left + 'px';
			this.ContentWrapperTable.style.top = top + 'px';
		}
	}
}

RadWindow.prototype.GetWidth = function()
{
	var width = 0;
	if (!this.UseRadWindow)
	{
		if (this.Window) width = this.Window.dialogWidth;
	}
	else
	{
		if (this.IsIE)
		{
			width = parseInt(this.ContentWrapperTable.clientWidth);
		}
		else
		{
			width = parseInt(this.ContentWrapperTable.scrollWidth);
		}
		
		if (isNaN(width)) width = 0;	
	}
	return width;
}

RadWindow.prototype.SetWidth = function(width)
{
	width = parseInt(width);
	if (isNaN(width)) return;

	if (!this.UseRadWindow)
	{
		if (this.Window)
		{
			if (this.Window.dialogWidth)
			{
				this.Window.dialogTop = this.Window.screenTop - 30;
				this.Window.dialogLeft = this.Window.screenLeft - 4;

				this.Window.dialogWidth = width + "px";
			}
			else
			{
				this.Window.outerWidth = width;
			}
		}
	}
	else
	{
		this.ContentWrapperTable.style.width = width + "px";		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -