/
HTML_editor.hta
516 lines (440 loc) · 16 KB
/
HTML_editor.hta
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
<HTML xmlns:mytb
xmlns:mymenu
xmlns:t ="urn:schemas-microsoft-com:time" >
<head>
<?IMPORT namespace="mytb" implementation="toolbar.htc">
<?IMPORT namespace="mymenu" implementation="menu.htc">
<?IMPORT namespace="t" implementation="#default#time2">
<style>
.time { behavior: url(#default#time2) }
</style>
<TITLE>HTML Editor</TITLE>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="HTML Editor"
BORDER="thick"
BORDERSTYLE="raised"
CAPTION="yes"
ICON="netpad.ico"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
VERSION="1.0"
WINDOWSTATE="normal"/>
<script>
window.onload=doInit
//sInitColor is a global variable. It holds the value of the selected color in the color dialog box when it displays
var sInitColor = null;
//sPersistValue holds the value of the saved innerHTML
var sPersistValue
function doInit(){
for (i=0; i<document.all.length; i++)
//ensure that all document elements except the content editable DIV are unselectable
document.all(i).unselectable = "on";
oDiv.unselectable = "off";
//clear any text in the Document window and set the focus
oDiv.innerHTML="";
oDiv.focus();
//call routines to populate the drop-down list boxes on the toolbar
getSystemFonts();
getBlockFormats();
window.resizeTo(730,560);
goContext();
}
//This function works for all of the command identifiers used in this page
function callFormatting(sFormatString){
document.execCommand(sFormatString);
}
//Fonts routines
//getSystemFonts uses the dialog helper object to return an array of all of the fonts on the user's system, then populates a drop-down listbox in the toolbar with the array elements
function getSystemFonts(){
var a=dlgHelper.fonts.count;
var fArray = new Array();
var oDropDown = oToolBar.createDropDownListAt("4");
oDropDown.setAttribute("id","FontNameList");
for (i = 1;i < dlgHelper.fonts.count;i++){
fArray[i] = dlgHelper.fonts(i);
var aOptions = oDropDown.getOptions();
var oOption = document.createElement("OPTION");
aOptions.add(oOption);
oOption.text = fArray[i];
oOption.Value = i;
}
//attaching the onchange event is necessary in order to detect when a user changes the value in the drop-down listbox
oDropDown.setAttribute("onchange",ChangeFont);
}
//changeFontSize detects the value of the item in the drop-down listbox and applies the value to the font of the selected text
function changeFontSize(){
var sSelected=oToolBar.getItem(6).getOptions().item(oToolBar.getItem(6).getAttribute("selectedIndex"));
document.execCommand("FontSize", false, sSelected.value);
}
//changeFont detects the value of the item in the drop-down listbox and applies the value to the font of the selected text
function ChangeFont(){
var sSelected=oToolBar.getItem(4).getOptions().item(oToolBar.getItem(4).getAttribute("selectedIndex"));
document.execCommand("FontName", false, sSelected.text);
}
//BlockFormats routines
//getBlockFormats uses the dialog helper object to return an array of all of the block formats on the user's system, then populates a drop-down listbox in the toolbar with the array elements
function getBlockFormats(){
var a=dlgHelper.blockFormats.count;
var fArray = new Array();
var oDropDown = oToolBar.createDropDownListAt("5");
oDropDown.setAttribute("id","FormatList");
for (i = 1;i < dlgHelper.blockFormats.count;i++)
{
fArray[i] = dlgHelper.blockFormats(i);
var aOptions = oDropDown.getOptions();
var oOption = document.createElement("OPTION");
aOptions.add(oOption);
oOption.text = fArray[i];
oOption.Value = i;
}
//attach the onchange event
oDropDown.setAttribute("onchange",ChangeFormat);
}
//ChangeFormat detects the value of the item in the drop-down listbox and applies the value to the font of the selected text
function ChangeFormat(){
var sSelected=oToolBar.getItem(5).getOptions().item(oToolBar.getItem(5).getAttribute("selectedIndex"));
document.execCommand("FormatBlock", false, sSelected.text);
}
//callColorDlg uses the dialog helper object's ChooseColorDlg method to open the color dialog box, then changes the font or back color of the selected text
function callColorDlg(sColorType){
if (sInitColor == null)
//display color dialog box
var sColor = dlgHelper.ChooseColorDlg();
else
var sColor = dlgHelper.ChooseColorDlg(sInitColor);
//change decimal to hex
sColor = sColor.toString(16);
//add extra zeroes if hex number is less than 6 digits
if (sColor.length < 6) {
var sTempString = "000000".substring(0,6-sColor.length);
sColor = sTempString.concat(sColor);
}
//change color of the selected text
document.execCommand(sColorType, false, sColor);
sInitColor = sColor;
oDiv.focus();
}
//VerticalMode changes the orientation of the text from left to right to top to bottom
function VerticalMode(){
if (oDiv.style.writingMode == 'tb-rl')
oDiv.style.writingMode = 'lr-tb';
else
oDiv.style.writingMode = 'tb-rl';
}
//SaveDocument uses the common dialog box object to display the save as dialog, then writes a textstream object from the value of the div's innerHTML property
function SaveDocument(){
//Setting CancelError to true and using try/catch allows the user to click cancel on the save as dialog without causing a script error
cDialog.CancelError=true;
try{
cDialog.Filter="HTM Files (*.htm)|*.htm|Text Files (*.txt)|*.txt"
cDialog.ShowSave();
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.CreateTextFile(cDialog.filename, true);
f.write(oDiv.innerHTML);
f.Close();
sPersistValue=oDiv.innerHTML;}
catch(e){
var sCancel="true";
return sCancel;}
oDiv.focus();
}
//LoadDocument uses the common dialog box object to display the open dialog box, then reads the file and displays its contents in the div
function LoadDocument(){
//Setting CancelError to true and using try/catch allows the user to click cancel on the save as dialog without causing a script error
cDialog.CancelError=true;
try{
var answer = checkForSave();
//The user has clicked yes in the modal dialog box called in the checkForSave function
if (answer) {var sCancel = SaveDocument();
//The user has clicked cancel in the save as dialog box; exit function
if (sCancel) return;
cDialog.Filter="HTM Files (*.htm)|*.htm|Text Files (*.txt)|*.txt"
cDialog.ShowOpen();
var ForReading = 1;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile(cDialog.filename, ForReading);
var r = f.ReadAll();
f.close();
oDiv.innerHTML=r;
//This variable is used in the checkForSave function to see if there is new content in the div
sPersistValue=oDiv.innerHTML;
}
//The user has clicked no in the modal dialog box called in the checkForSave function
if (answer==false)
{cDialog.Filter="HTM Files (*.htm)|*.htm|Text Files (*.txt)|*.txt"
cDialog.ShowOpen();
var ForReading = 1;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile(cDialog.filename, ForReading);
var r = f.ReadAll();
f.close();
oDiv.innerHTML=r;
sPersistValue=oDiv.innerHTML;
}
oDiv.focus();
}
catch(e){
var sCancel="true";
return sCancel;}
}
//NewDocument creates a new "document" by clearing the content of the div. If there is any new content in the div, the user is asked whether or not to save
function NewDocument(){
var answer = checkForSave();
if (answer) {var sCancel = SaveDocument();
if (sCancel) return;
oDiv.innerHTML="";}
if (answer==false)
oDiv.innerHTML="";
oDiv.focus();
}
//This function checks to see if the div has new text, then displays a modal dialog box if appropriate
function checkForSave()
{
if ((oDiv.innerHTML!=sPersistValue)&&(oDiv.innerHTML !=""))
var checkSave=showModalDialog('dcheckForSave.htm','','dialogHeight:125px;dialogWidth:250px;scroll:off');
else
var checkSave=false;
return checkSave;
}
//this function is used to call other functions when the user clicks on a menu item. These are the same functions that are called by the toolbar buttons.
function CallMenuFunction(){
var menuChoice = event.result;
switch(menuChoice){
case "open":
LoadDocument();
break;
case "new":
NewDocument();
break;
case "save":
SaveDocument();
break;
case "exit":
window.close();
break;
case "cut":
callFormatting('Cut');
break;
case "copy":
callFormatting('Copy');
break;
case "paste":
callFormatting('Paste');
break;
case "bold":
callFormatting('Bold');
break;
case "underline":
callFormatting('Underline');
break;
case "italic":
callFormatting('Italic');
break;
case "fontColor":
callColorDlg('ForeColor');
break;
case "highlight":
callColorDlg('BackColor');
break;
case "about":
goContext();
break;
default:
break;
}
}
//These functions create and display the splash screen and are used when the application is launched (called by onInit function) as well as when the user clicks help/about on the menu
var oPopup = window.createPopup()
function goContext()
{
var oPopupBody = oPopup.document.body;
oPopupBody.innerHTML = oContext.innerHTML;
oPopup.show(175, 125, 400, 300, document.body);
document.body.onmousedown = oPopup.hide;
}
</script>
</HEAD>
<BODY STYLE="overflow:hidden; margin:0px" >
<!--Create the Dialog Helper Object-->
<OBJECT ID=dlgHelper CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" WIDTH="0px" HEIGHT="0px"></OBJECT>
<!-- Create the licensing object for the common dialog activex control -->
<OBJECT CLASSID="clsid:5220cb21-c88d-11cf-b347-00aa00a28331">
<PARAM NAME="LPKPath" VALUE="comdlg.lpk">
</OBJECT>
<!--Create the Common Dialog Box activex control-->
<OBJECT ID="cDialog" WIDTH="0px" HEIGHT="0px"
CLASSID="CLSID:F9043C85-F6F2-101A-A3C9-08002B2F49FB"
CODEBASE="http://activex.microsoft.com/controls/vb5/comdlg32.cab">
</OBJECT>
<t:animate dur="5" onend="oPopup.hide();"/>
<DIV ID="oContext" STYLE="display:none">
<DIV STYLE="position:absolute; top:0; left:0; width:400px; height:300px; border:1px solid black; background:#eeeeee; ">
<DIV STYLE="padding:20px; background:white; border-bottom:5px solid #cccccc">
<img src="htmledlogo.gif" align="absmiddle"></div>
<DIV STYLE="padding:20px; font-size:8pt; line-height:1.5em; font-family:verdana; color:black;">This HTML Editor is created entirely with DHTML technologies and is provided as an example for developers using Internet Explorer 6.
<br>
<br>
<br>
<br><center>
©2001 Microsoft Corporation. All rights reserved. </center>
</DIV>
</DIV>
</DIV>
<DIV ID="oContainer" STYLE="background-color:threedface; border:1px solid #cccccc; position:relative; height:100%; top:0;">
<mymenu:menu id="File" backcolor="threedface" onsubmenu_click="CallMenuFunction();">File
<mymenu:menu id="new" backcolor="threedface">New</mymenu:menu>
<mymenu:menu id="open" backcolor="threedface">Open</mymenu:menu>
<mymenu:menu id="save" backcolor="threedface">Save</mymenu:menu>
<mymenu:menu id="exit" backcolor="threedface">Exit</mymenu:menu>
</mymenu:menu>
<mymenu:menu id="Edit" backcolor="threedface" onsubmenu_click="CallMenuFunction();">Edit
<mymenu:menu id="cut" backcolor="threedface">Cut Ctrl+X</mymenu:menu>
<mymenu:menu id="copy" backcolor="threedface">Copy Ctrl+C</mymenu:menu>
<mymenu:menu id="paste" backcolor="threedface">Paste Ctrl+V</mymenu:menu>
</mymenu:menu>
<mymenu:menu id="Format" backcolor="threedface" onsubmenu_click="CallMenuFunction();">Format
<mymenu:menu id="bold" backcolor="threedface">Bold</mymenu:menu>
<mymenu:menu id="italic" backcolor="threedface">Italic</mymenu:menu>
<mymenu:menu id="underline" backcolor="threedface">Underline</mymenu:menu>
<mymenu:menu id="fontColor" backcolor="threedface">Font Color</mymenu:menu>
<mymenu:menu id="highlight" backcolor="threedface">HighLight</mymenu:menu>
</mymenu:menu>
<mymenu:menu id="Help" backcolor="threedface" onsubmenu_click="CallMenuFunction();">Help
<mymenu:menu id="about" backcolor="threedface">About</mymenu:menu>
</mymenu:menu>
<nobr>
<mytb:TOOLBAR STYLE="display:inline; width:100%" ID="oToolBar"
>
<!--New document button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_new.gif"
title="New Document"
onclick="NewDocument();"/>
<!--Open document button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_open.gif"
title="Open Document"
onclick="LoadDocument();" />
<!--Save document button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_save.gif"
title="Save Document"
onclick="SaveDocument();"/>
<mytb:TOOLBARSEPARATOR />
<!-- Font size list-->
<mytb:TOOLBARDROPDOWNLIST id="oFontSize" onchange="changeFontSize();">
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4 selected>4
<option value=5 >5
<option value=6>6
<option value=7>7
</mytb:TOOLBARDROPDOWNLIST>
<mytb:TOOLBARSEPARATOR/>
<!--Bold button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_bold.gif"
title="Bold"
onclick="callFormatting('Bold');"/>
<!--Italic button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_italic.gif"
title="Italic"
onclick="callFormatting('Italic');"/>
<!--Underline button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_underline.gif"
title="Underline"
onclick="callFormatting('Underline');"/>
<!--Strikethrough button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_form-strike.gif"
title="StrikeThrough"
onclick="callFormatting('StrikeThrough');"/>
<mytb:TOOLBARSEPARATOR/>
<!--Superscript button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_superscript.gif"
title="SuperScript"
onclick="callFormatting('SuperScript');"/>
<!--Subscript button -->
<mytb:TOOLBARBUTTON IMAGEURL="UI_subscript.gif"
title="SubScript"
onclick="callFormatting('SubScript');"/>
</mytb:TOOLBAR>
</nobr>
<nobr>
<mytb:TOOLBAR STYLE="display:inline; width:100%" ID="oToolBar2"
>
<!--Cut button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_tool-cut.gif"
title="Cut"
onclick="callFormatting('Cut');"/>
<!--Copy button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_form-copy.gif"
title="Copy"
onclick="callFormatting('Copy');"/>
<!--Paste button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_paste.gif"
title="Paste"
onclick="callFormatting('Paste');"/>
<mytb:TOOLBARSEPARATOR/>
<!--Undo button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_undo.gif"
title="Undo"
onclick="callFormatting('Undo');"/>
<!--Redo button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_redo.gif"
title="Redo"
onclick="callFormatting('Redo');"/>
<mytb:TOOLBARSEPARATOR/>
<!--Numbered list button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_numberlist.gif"
title="InsertOrderedList"
onclick="callFormatting('InsertOrderedList');"/>
<!--Bulleted list button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_bulletlist.gif"
title="InsertUnorderedList"
onclick="callFormatting('InsertUnorderedList');"/>
<!--Outdent button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_outdent.gif"
title="Outdent"
onclick="callFormatting('Outdent');"/>
<!--Indent button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_indent.gif"
title="Indent"
onclick="callFormatting('Indent');"/>
<mytb:TOOLBARSEPARATOR/>
<!--Left alignment button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_leftalign.gif"
title="JustifyLeft"
onclick="callFormatting('JustifyLeft');"/>
<!--Center alignment button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_centeralign.gif"
title="JustifyCenter"
onclick="callFormatting('JustifyCenter');"/>
<!--Right alignment button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_rightalign.gif"
title="JustifyRight"
onclick="callFormatting('JustifyRight');"/>
<mytb:TOOLBARSEPARATOR/>
<!--Vertical alignment button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_tool_vertical.gif"
title="Vertical Alignment"
onclick="VerticalMode();"/>
<mytb:TOOLBARSEPARATOR/>
<!--Font Color button-->
<mytb:TOOLBARBUTTON IMAGEURL="UI_fontcolor.gif"
title="Font Color"
onclick="callColorDlg('ForeColor');"/>
<!--Background color button -->
<mytb:TOOLBARBUTTON IMAGEURL="UI_backcolor.gif"
title="HighLight"
onclick="callColorDlg('BackColor');"/>
</mytb:TOOLBAR>
</nobr>
<!--The content editable div-->
<DIV
ID=oDiv
CONTENTEDITABLE
STYLE="height:80%;background-color:white; overflow:auto; width:100%;">
</DIV>
</DIV>
</BODY>
</HTML>