home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
WindowsServerTrial
/
server.iso
/
sources
/
install.wim
/
1
/
Windows
/
System32
/
mshtmler.dll
/
HTML
/
EDLINK.JS
< prev
next >
Wrap
Text (UTF-16)
|
2006-11-02
|
10KB
|
222 lines
var g_fOKEnabled = false;
var g_fURLLoaded = false;
function findAnchor(range)
{
var rangeWorking;
var elmWorking;
var index;
elmWorking = range.parentElement()
while ("HTML" != elmWorking.tagName)
{
if ("A" == elmWorking.tagName)
{
return elmWorking;
}
else
{
elmWorking = elmWorking.parentElement
}
}
rangeWorking = range.duplicate();
rangeWorking.collapse(true);
rangeWorking.moveEnd("character", 1);
while (rangeWorking.compareEndPoints("EndToEnd", range) < 0)
{
rangeWorking.move("Character");
if (null != findAnchor(rangeWorking))
{
return findAnchor(rangeWorking);
}
}
return null;
}
function getProtocolFromURL(strURL)
{
var index;
return strURL.substring(0, strURL.indexOf(":") + 1);
}
function updateProtocolSel()
{
var index;
var strProtocol = getProtocolFromURL(txtURL.value);
selProtocol.value = strProtocol;
if (selProtocol.value != strProtocol)
{
selProtocol.value = "";
}
}
function updateProtocolTxt()
{
var strSlashProts = " file:ftp:gopher:http:https:";
var strProtocolTxt = getProtocolFromURL(txtURL.value);
var strProtocolSel = selProtocol.value;
var strTempURL;
if ("//" == (txtURL.value.substring(strProtocolTxt.length,
strProtocolTxt.length + 2)))
{
strProtocolTxt = strProtocolTxt + "//";
}
strTempURL = txtURL.value.substring(strProtocolTxt.length);
if (0 < strSlashProts.indexOf(strProtocolSel))
{
strProtocolSel = strProtocolSel + "//";
}
txtURL.value = strProtocolSel + strTempURL;
}
function setOKState()
{
var htmlKeyAlt = 18;
if (!g_fURLLoaded)
{
if ((("" == txtURL.value) || (txtURL.value == selProtocol.value)
||(txtURL.value == selProtocol.value + "//"))
== g_fOKEnabled)
{
btnOK.disabled = g_fOKEnabled
g_fOKEnabled = !g_fOKEnabled;
}
}
}
function bdyLoad()
{
var globalDoc = window.dialogArguments;
var rngMaster;
var rngLink;
var elmLink;
document.onhelp = new
Function("callHelp(window.event.srcElement)");
document.onmouseup = new Function("mouseClick()");
selProtocol.onchange = new Function("updateProtocolTxt()");
btnOK.onclick = new Function("btnOKClick()");
btnCancel.onclick = new Function("btnCancelClick()");
txtURL.onfocus = new Function("txtURL.select()");
txtURL.onpropertychange = new Function("if (event.propertyName == 'value') setOKState();");
txtURL.onkeypress = new Function("txtDefaultESC()");
if ("Control" == globalDoc.selection.type)
{
rngMaster = globalDoc.selection.createRange();
if (1 == rngMaster.length)
{
rngMaster = getTextRange(rngMaster(0));
rngMaster.select();
}
}
if (("Text" == globalDoc.selection.type) ||
("None" == globalDoc.selection.type))
{
rngMaster = globalDoc.selection.createRange();
globalDoc.execCommand("AutoDetect");
elmLink = findAnchor(rngMaster);
if (null != elmLink)
{
rngLink = getTextRange(elmLink);
if (rngLink.compareEndPoints("StartToStart", rngMaster) < 0)
{
rngMaster.setEndPoint("StartToStart", rngLink);
}
if (rngLink.compareEndPoints("EndToEnd", rngMaster) > 0)
{
rngMaster.setEndPoint("EndToEnd", rngLink);
}
rngMaster.select();
if ("" != elmLink.href)
{
txtURL.value = elmLink.href;
txtURL.href = elmLink.href;
g_fURLLoaded = true;
btnOK.disabled = false;
}
updateProtocolSel();
}
txtURL.focus();
txtURL.select();
setOKState();
}
}
function IsRangeEmpty( range )
{
var tempRange;
tempRange = range.duplicate();
result = tempRange.compareEndPoints( "StartToEnd", range );
if ( result == 0 )
{
return true;
}
else
{
return false;
}
}
function btnOKClick()
{
var globalDoc = window.dialogArguments;
var cmdCreateLink = "CreateLink";
var cmdUnlink = "Unlink";
var range = globalDoc.selection.createRange();
var strSlashProts = " file:ftp:gopher:http:https:";
var strProtocol = selProtocol.value;
var dupRange;
var initialRange;
var iRight;
var fUseExecCommand = true;
if ("" == txtURL.value)
{
range.execCommand(cmdUnlink, false);
window.close();
return;
}
if (g_fURLLoaded && (txtURL.value == txtURL.href))
{
window.close();
return;
}
updateProtocolSel();
if (0 < strSlashProts.indexOf(strProtocol))
{
strProtocol = strProtocol + "//";
}
initialRange = range.duplicate();
if ( IsRangeEmpty( range ) )
{
range.text = txtURL.value;
fUseExecCommand = false;
}
else
{
dupRange = range.duplicate();
iRight = dupRange.moveEnd( "Character", 2 );
if ( iRight < 2 && dupRange.htmlText == "" )
{
range.text = txtURL.value;
fUseExecCommand = false;
}
}
if ( fUseExecCommand )
{
range.execCommand(cmdCreateLink, false, txtURL.value);
}
else
{
dupRange = range.duplicate();
dupRange.move( "Character", -1 );
elmParent = dupRange.parentElement();
if (elmParent.tagName == "A")
{
elmParent.href = txtURL.value;
}
else
{
range.setEndPoint( "StartToEnd", initialRange );
dupRange = range.duplicate();
dupRange.collapse(true);
elmParent = dupRange.parentElement();
if (elmParent.tagName == "A")
{
range.execCommand(cmdUnlink, false);
}
range.execCommand(cmdCreateLink, false, txtURL.value);
}
}
window.close();
}