Salome HOME
a66b7ab20d534d5b84416a60b3c3855c80c9c930
[tools/siman.git] / Workspace / Siman / WebContent / rtef / insert_link.htm
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <!--Thanks to Tom Bovingdon and Rob Rix-->
3 <html>
4 <head> 
5 <script>document.write("<title>"+window.opener.lblInsertLink+"</title>");</script>
6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <style type="text/css">
8 <!-- 
9 body { background-color: #EFEDDE; margin: 10px;}
10 table { font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 12px; }
11 legend { font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 14px; padding-left: 5px; padding-right: 8px; }
12 .style2 {font-size: 18px; background:black; font-wieght:bold; color:white; display:block; width:100%; }
13 .show {left:auto;top:auto;position:auto;}
14 .hide {left:-1000px;top:-1000px;position:absolute;}
15 -->
16 </style>
17 <script language="JavaScript" type="text/javascript"> 
18 <!-- 
19 if(document.all){
20   window.resizeTo(525, 255);
21 } else {
22         window.resizeTo(513, 250);
23 }
24 function get_anchors() {
25    document.getElementById('trDocumentAnchors').className="hide";
26          rte = window.opener.document.getElementById('hdn'+window.opener.currentRTE).value
27          re = new RegExp("<[aA][^>]+?name=\"?(.+?)(\".*?>|>)", "m")
28    anchors = new Array 
29    m = re.exec(rte)
30    while(m) { 
31       anchors.push(m[1]) 
32       m = re.exec(RegExp.rightContext) 
33    } 
34    if(anchors.length) { 
35       s = anchors.length + " matches:\n" 
36       for(i = 0; i < anchors.length; i++) { 
37          s = s + "- " + anchors[i] + "\n" 
38       document.forms['linkForm'].DocumentAnchors.options[i] = new Option(anchors[i],anchors[i]); 
39       } 
40       //alert(s) 
41    } else { 
42       document.forms['linkForm'].DocumentAnchors.options[0] = new Option(window.opener.lblLinkNoA,'');
43    } 
44    return anchors 
45
46
47 var baseurl; 
48 function setType(type) { 
49   var aa = document.getElementById('trText');
50   var ab = document.getElementById('trTarget');
51   var ac = document.getElementById('trAddress');
52   var ad = document.getElementById('trDocumentAnchors');
53   switch (type) {
54     case "mailto" :
55       baseurl= '<a href="mailto:';
56       aa.className="show";
57       ab.className="hide";
58                         ac.className="show";
59       ad.className="hide";
60       if(document.all){
61         window.resizeTo(525, 225);
62       } else {
63               window.resizeTo(513, 218);
64       }
65     break;
66     case "newanchor" :
67       baseurl= '<a "';
68       aa.className="hide";
69       ab.className="hide";
70       ac.className="show";
71       ad.className="hide";
72       if(document.all){
73         window.resizeTo(525, 190);
74       } else {
75               window.resizeTo(513, 185);
76       }
77     break;
78     case "oldanchor" :
79       baseurl= '<a href=""';
80       endurl='#'
81       aa.className="show";
82       ab.className="hide";
83                         ac.className="hide";
84                         ad.className="show";
85                         if(document.all){
86                     window.resizeTo(525, 222);
87       } else {
88               window.resizeTo(513, 218);
89       }
90     break;
91     default:
92       baseurl= '<a href="';
93       aa.className="show";
94       ab.className="show";
95       ac.className="show";
96       ad.className="hide";
97       if(document.all){
98         window.resizeTo(525, 255);
99       } else {
100               window.resizeTo(513, 250);
101       }
102     break;
103   }
104
105 function AddLink() { 
106    var oForm = document.linkForm; 
107    //validate form 
108    var protocol='';
109          var prefix="href";
110          var html;
111          var selIndex = document.linkForm.linktype.options[document.linkForm.linktype.selectedIndex].value;
112    switch (selIndex)
113    { 
114      case 'http':
115                  protocol='http://';
116      break;
117      case 'https':
118                  protocol='https://';
119      break;
120      case 'ftp':
121                  protocol='ftp://';
122      break;
123      case 'relative':
124                  protocol='';
125      break;
126      case 'oldanchor':
127        oForm.url.value=document.linkForm.DocumentAnchors.options[document.linkForm.DocumentAnchors.selectedIndex].value;
128        protocol='#';
129      break;
130      case 'newanchor':
131        oForm.linkText.value=' ';
132        prefix='name';
133      break;
134      case 'mailto':
135        protocol='mailto:';
136      break;
137    }
138    if (oForm.url.value == '') {
139      alert(window.opener.lblLinkVal0);
140      return false;
141    } 
142    if (oForm.linkText.value != '' && (selIndex == "http" || selIndex == "https" || selIndex == "ftp" || selIndex == "relative" )) {
143      html = '<a '+ prefix + '="'+protocol + document.linkForm.url.value + '" target="' + document.linkForm.linkTarget.options[document.linkForm.linkTarget.selectedIndex].value + '">' + document.linkForm.linkText.value + '</a>';
144      window.opener.insertHTML(html);
145    } else if(oForm.linkText.value != '') {
146      html = '<a '+ prefix + '="'+protocol + document.linkForm.url.value + '">' + document.linkForm.linkText.value + '</a>';
147                  window.opener.insertHTML(html);
148          } else {
149                  var param=protocol+document.linkForm.url.value + '" target="' + document.linkForm.linkTarget.options[document.linkForm.linkTarget.selectedIndex].value + '"';
150          window.opener.document.getElementById(rte).contentWindow.document.execCommand('createLink',false,param );
151    }
152          window.close();
153    return true;
154
155 //--> 
156 </script> 
157 </head><body onload="get_anchors()"><form name="linkForm">
158 <table cellpadding="0" cellspacing="0" border="0" width=100%><tr>
159 <td><fieldset style="margin-left: 5px;"><legend><script>document.write(window.opener.lblInsertLink);</script></legend>
160 <div style="padding: 2px;"></div><table cellpadding="4" cellspacing="0" border="0" width=100%><tr>
161       <td align="right" nowrap><script>document.write(window.opener.lblLinkType);</script>:</td>
162       <td><select  name="linktype" onChange="setType(this.value);" style="height:18px;font-size:14px">
163             <option value="http" selected>http://</option>
164             <option value="https">https://</option>
165             <option value="ftp">ftp://</option>
166             <script>if(!document.all) document.write("<option value=\"relative\">relative</option>")</script>
167             <option value="mailto">email</option>
168             <option value="oldanchor"><script>document.write(window.opener.lblLinkOldA);</script></option>
169             <option value="newanchor"><script>document.write(window.opener.lblLinkNewA);</script></option>
170          </select> 
171       </td> 
172    </tr> 
173    <tr name="trDocumentAnchors" id="trDocumentAnchors">
174       <td align="right" nowrap><script>document.write(window.opener.lblLinkAnchors);</script>:</td>
175       <td>
176                         <select name="DocumentAnchors" id="DocumentAnchors" style="height:18px;font-size:14px">
177       </select></td>
178    </tr>
179    <tr  name="trAddress" id="trAddress">
180       <td align="right" nowrap><script>document.write(window.opener.lblLinkAddress);</script>:</td>
181       <td><input name="url" type="text" id="url" style="width:250px;height:18px;font-size:14px" value=""></td>
182    </tr>
183    <tr name="trText" id="trText">
184       <td align="right" nowrap><script>document.write(window.opener.lblLinkText);</script>:</td>
185       <td><input name="linkText" type="text" id="linkText" style="width:250px;height:18px;font-size:14px" value=""></td>
186    </tr> 
187    <tr name="trTarget" id="trTarget">
188       <td align="right" nowrap><script>document.write(window.opener.lblLinkOpenIn);</script>:</td>
189       <td align="left">
190          <select name="linkTarget" id="linkTarget" style="width:180px;height:18px;font-size:14px">
191             <option value="_blank">_blank</option>
192             <option value="_self" selected>_self</option>
193             <option value="_parent">_parent</option>
194             <option value="_top">_top</option>
195          </select> 
196       </td> 
197    </tr>
198 </table> 
199 <div style="padding: 2px;"></div>
200 </fieldset></td><td><td align="left" valign="top" style="padding: 8px;">
201 <input type="button" name="btnsubmit" value="" onclick="AddLink();" style="width:100px;"/><br>
202 <input type="button" name="btncancel" value="" onClick="window.close();" style="width:100px;"/>
203 </td></tr></table></form></body></html>
204 <script>
205 document.getElementById('trDocumentAnchors').className="hide";
206 document.linkForm.btnsubmit.value = window.opener.lblLinkSubmit;
207 document.linkForm.btncancel.value = window.opener.lblLinkCancel;
208 </script>