Support for link target selection

This commit is contained in:
Len Kranendonk 2003-05-09 08:39:45 +00:00
parent fff79f97b4
commit 66a25ffdef

View file

@ -0,0 +1,200 @@
<html style="Width: 310px; Height: 170px;">
<head>
<title>Hyperlink Editor</title>
<style type="text/css">
<!--
td { font-family: arial;
font-size: 8pt; }
select { font-family: arial;
font-size: 8pt; }
input { font-family: arial;
font-size: 8pt; }
-->
</style>
<script language="javascript">
document.title = "HyperLink Editor";
var myValues = window.dialogArguments;
var URLtext = myValues.href_attribute;
var highlightedText = myValues.highlightedText;
var target = myValues.tar_attribute;
var linkText = myValues.linkText;
function returnSelected() {
// the following checks to see if the user has entered a RELATIVE link
// either beginning with ? or # or the name of a file. If so, it sends some
// extra values back to editor.js telling it to strip out the absolute path,
// after the editor_insertHTML() call.
var re = /^(\?|\#)/;
var re2 = /^(html|htm|php|php4|php3|asp|cgi)/; // change this line to account for other relative file extensions
if (document.set.link_value.value.search(re) != -1) {
document.set.link_value.value = "http://www.___relativelink___.com/"
+ document.set.link_value.value;
}
var isRelativeFile = document.set.link_value.value.split(/\./);
if (isRelativeFile.length != 1 && isRelativeFile[1].search(re2) != -1) {
document.set.link_value.value = "http://www.___relativelink___.com/"
+ document.set.link_value.value;
}
var text = escape( "<a href='" );
text = text + escape( document.set.link_value.value );
if (target != "") {
text = text + escape( "' target='" );
text = text + escape( target );
}
text = text + escape( "'>" );
text = text + escape( document.set.desc.value );
text = text + escape( "</a>" );
window.returnValue = text; // set return value
window.close(); // close dialog
}
// Now, if a person changes the protocol AFTER having entered the
// link, the inputted link info isn't erased.
function myChange() {
var selectedItem = document.set.type.selectedIndex;
var selectedItemValue = document.set.type.options[selectedItem].value;
var selectedItemText = document.set.type.options[selectedItem].text;
var inputtedText = document.set.link_value.value;
var protocol = document.set.link_value.value.split(":");
if (protocol[1]) { // if there's content
var datum = protocol[1].replace(/^\/\//, "");
document.set.link_value.value = selectedItemValue + datum;
}
else {
if (protocol[0].search(/^(file|gopher|mailto|news|ftp|http|https|telnet|wias)$/) == -1) {
document.set.link_value.value = selectedItemValue + protocol[0];
}
else { document.set.link_value.value = selectedItemValue; }
}
}
function updateTarget() {
var selectedItem = document.set.target.selectedIndex;
var selectedItemValue = document.set.target.options[selectedItem].value;
target = selectedItemValue;
}
function updateForm() {
if (URLtext != '') {
// 1. set protocol
var compare = URLtext.substring(0,5);
for (i=0; i<document.set.type.length; i++) {
if (document.set.type.options[i].value.search(compare) != -1) {
document.set.type.options[i].selected = true;
}
}
// 2. set link URL
URLtext = URLtext.replace(/\/\/\//, "//");
URLtext = URLtext.replace(/http:\/\/www\.___relativelink___\.com\//, "");
document.set.link_value.value = URLtext;
}
// 3. set link text
if (linkText == '') { document.set.desc.value = highlightedText; }
else { document.set.desc.value = linkText; }
// 4. set target
if (target != '') {
for (i=0; i<document.set.target.length; i++) {
if (document.set.target.options[i].value.search(target) != -1) {
document.set.target.options[i].selected = true;
}
}
}
}
</script>
</head>
<body bgcolor="#CCCCCC" topmargin=5 leftmargin=0 onload="updateForm();">
<center>
<form method="post" name="set">
<table cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td align="center">
<fieldset align="center" width="290">
<legend align="left">Hyperlink Information</legend>
<table border="0" cellspacing="4" align="center">
<tr>
<td align="right" nowrap="nowrap" width="40">Type: </td>
<td nowrap="nowrap">
<select name="type" onchange="javascript: myChange();">
<option value="">other
<option value="file://">File
<option value="ftp://">FTP
<option value="gopher:">Gopher
<option value="http://" selected>HTTP
<option value="https://">HTTPS
<option value="mailto:">mailTo
<option value="news:">News
<option value="telnet:">Telnet
<option value="wias:">WIAS
</select>
</td>
<td align="right">Target: </td>
<td><select name="target" onChange="javascript: updateTarget();">
<option value="">
<option value="_blank">_blank
<option value="_parent">_parent
<option value="_self">_self
<option value="_top">_top
</select>
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap">Link: </td>
<td nowrap="nowrap" colspan="3">
<input type="text" name="link_value" value="http://" size="30">&nbsp;&nbsp;&nbsp;&nbsp;
</td>
</tr>
<tr>
<td align="right" nowrap="nowrap">Text: </td>
<td nowrap="nowrap" colspan="3">
<input type="text" name="desc" value="" size="30">
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<table cellpadding="3">
<tr><td align="center">
<input type="hidden" value="" name="empty">
<input type="button" value=" OK " onClick="returnSelected()">
<input type="button" value="Cancel" onClick="window.close()">
</td></tr></table>
</form>
</td>
</tr>
</table>
</center>
</body>
</html>