GeneralDlg.htm
<input type="text" style="behavior:url('GeneralDlg.htc');">
<input type="text" style="behavior:url('GeneralDlg.htc');" defineType="FontDlg">
<input type="text" style="behavior:url('GeneralDlg.htc');" defineType="OpenDlg">
<input type="text" style="behavior:url('GeneralDlg.htc');" defineType="SaveDlg">
GeneralDlg.htc
<public:property name="defineType">
<public:attach event=oncontentready onevent=initGeneralDlg()>
<script>
//默认颜色
var strColor="";
//默认字体
var strFont="";
//对象
var vColorObject=null;
var vFontObject=null;
var vFontDiv=null;
var vOpenObject=null;
var vSaveObject=null;
//参数[ColorDlg,FontDlg,OpenDlg,SaveDlg]
var strDefineType="";
function initGeneralDlg()
{
//初始化组件
if(defineType)
{strDefineType=defineType;}
else
{strDefineType="ColorDlg";}
initByType(strDefineType);
//事件绑定
element.attachEvent("onmousedown",onMouseDown);
}
//元素中鼠标按下[显示面板]
function onMouseDown()
{
if(strDefineType=="ColorDlg")
{
strColor=chooseColor();
element.value=strColor;
element.style.backgroundColor=strColor;
}
else if(strDefineType=="FontDlg")
{
chooseFont();
}
else if(strDefineType=="OpenDlg")
{
try
{
vOpenObject.CancelError=true;
vOpenObject.ShowOpen();
element.value=vOpenObject.filename;
}
catch(e)
{
//window.confirm(e);
}
}
else if(strDefineType=="SaveDlg")
{
try
{
vSaveObject.CancelError=true;
vSaveObject.ShowSave();
element.value=vSaveObject.filename;
}
catch(e)
{
//window.confirm(e);
}
}
}
//颜色滴管
function chooseColor()
{
var strReturnColor=vColorObject.ChooseColorDlg(strColor.substr(1));
strReturnColor=strReturnColor.toString(16);
if(strReturnColor.length<6)
{
var strTempString="000000".substring(0,6-strReturnColor.length);
strReturnColor=strTempString.concat(strReturnColor);
}
return "#"+strReturnColor;
}
//字体选择
function chooseFont()
{
vFontDiv.style.display="";
vFontDiv.style.left=getElementDefineLeft(element);
vFontDiv.style.top=getElementDefineTop(element)+element.offsetHeight;
element.document.attachEvent('onmousedown',onDocumentMouseDown);
}
function onFontChange()
{
var vObject=window.event.srcElement;
strFont=vObject.options[vObject.selectedIndex].text;
element.value=strFont;
element.style.fontFamily=strFont;
}
function onDocumentMouseDown()
{
if(vFontDiv.contains(event.srcElement))
{
return;
}
if(event.srcElement==element)
{
return;
}
element.value=strFont;
element.style.fontFamily=strFont;
vFontDiv.style.display="none";
element.document.detachEvent("onmousedown",onDocumentMouseDown);
}
function initByType(strType)
{
element.readOnly="true";
if(strType=="ColorDlg")
{
if(element.value)
{strColor=element.value;}
else
{strColor="#FFFFFF";}
element.style.backgroundColor=strColor;
vColorObject=document.createElement("object");
vColorObject.classid="clsid:3050F819-98B5-11CF-BB82-00AA00BDCE0B";
vColorObject.codeBase="";
vColorObject.style.width=0;
vColorObject.style.height=0;
window.document.body.insertAdjacentElement("afterbegin",vColorObject);
}
else if(strType=="FontDlg")
{
if(element.value)
{strFont=element.value;}
else
{strFont="宋体";}
element.style.fontFamily=strFont;
vFontObject=document.createElement("object");
vFontObject.classid="clsid:3050F819-98B5-11CF-BB82-00AA00BDCE0B";
vFontObject.codeBase="";
vFontObject.style.width=0;
vFontObject.style.height=0;
window.document.body.insertAdjacentElement("afterbegin",vFontObject);
vFontDiv=document.createElement("div");
var vSelect=document.createElement("select");
vSelect.style.border="1px solid #000000";
vSelect.length=vFontObject.fonts.count;
for(kIndex=1;kIndex<=vFontObject.fonts.count;kIndex++)
{
vOption=document.createElement("option");
vOption.value=kIndex;
vOption.text=vFontObject.fonts(kIndex);
vSelect.add(vOption);
}
vSelect.attachEvent("onchange",onFontChange);
vFontDiv.appendChild(vSelect);
window.document.body.insertAdjacentElement("afterbegin",vFontDiv);
vFontDiv.style.display="none";
vFontDiv.style.position="absolute";
}
else if(strType=="OpenDlg")
{
vOpenObject=document.createElement("object");
vOpenObject.classid="clsid:F9043C85-F6F2-101A-A3C9-08002B2F49FB";
vOpenObject.codeBase="http://activex.microsoft.com/controls/vb5/comdlg32.cab";
vOpenObject.style.width=0;
vOpenObject.style.height=0;
window.document.body.insertAdjacentElement("afterbegin",vOpenObject);
}
else if(strType=="SaveDlg")
{
vSaveObject=document.createElement("object");
vSaveObject.classid="clsid:F9043C85-F6F2-101A-A3C9-08002B2F49FB";
vSaveObject.codeBase="http://activex.microsoft.com/controls/vb5/comdlg32.cab";
vSaveObject.style.width=0;
vSaveObject.style.height=0;
window.document.body.insertAdjacentElement("afterbegin",vSaveObject);
}
}
//取元素绝对位置Left
function getElementDefineLeft(vObject)
{
var iElementLeft=vObject.offsetLeft;
while(vObject=vObject.offsetParent)
{
iElementLeft+=vObject.offsetLeft;
}
return iElementLeft;
}
//取元素绝对位置Top
function getElementDefineTop(vObject)
{
var iElementTop=vObject.offsetTop;
while(vObject=vObject.offsetParent)
{
iElementTop+=vObject.offsetTop;
}
return iElementTop;
}
</script>
</public:attach>
本文地址:http://com.8s8s.com/it/it12928.htm