1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
4 <html xmlns="http://www.w3.org/1999/xhtml">
5 <head>
6 <title>火输文本编辑器</title>
7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
8 <link rel="stylesheet" href="chrome://fireinput/skin/editor.css" type="text/css"/>
9 <link rel="stylesheet" href="chrome://fireinput/skin/common.css" type="text/css"/>
10 <script type="text/javascript" src="chrome://fireinput/content/constant.js"></script>
11 <script type="text/javascript" src="chrome://fireinput/content/lib.js"></script>
12 <script type="text/javascript" src="chrome://fireinput/content/stream.js"></script>
13 <script type="text/javascript" src="chrome://fireinput/content/utils.js"></script>
14 <script type="text/javascript" src="chrome://fireinput/content/store/storedoc.js"></script>
15 <script type="text/javascript" language="JavaScript1.2">
16 function copyToClipboard()
17 {
18 var source = document.getElementById("editorContext");
19 if(source)
20 {
21 if(source.value.length <= 0)
22 return;
23 try {
24 var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
25 .getService(Components.interfaces.nsIClipboardHelper);
26 clipboard.copyString(source.value);
27 }
28 catch(e) {}
29 }
30 }
31
32 function setInitSize()
33 {
34 var dheight = document.documentElement.clientHeight;
35 var dwidth = document.documentElement.clientWidth;
36 document.getElementById("localEditor").style.height =(dheight - 50) + "px";
37 document.getElementById("localEditor").style.width =(dwidth - 100) + "px";
38 document.getElementById("fireinputEditor").style.height =(dheight - 180) + "px";
39 document.getElementById("fireinputEditor").style.width = (dwidth - 105) + "px";
40 }
41
42 function setOpacity (obj, opacity)
43 {
44 opacity = (opacity == 100)?99.999:opacity;
45 obj.style.MozOpacity = opacity/100;
46 }
47
48 function confirmDialog(title, message)
49 {
50 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
51 .getService(Components.interfaces.nsIPromptService);
52 var flags=promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 +
53 promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1 +
54 promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2;
55
56 var ret = promptService.confirmEx(window,title, message,
57 flags, '保存', '取消', "不保存", null, {});
58
59 return ret;
60 }
61
62 function confirmExitDialog(title, message)
63 {
64 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
65 .getService(Components.interfaces.nsIPromptService);
66 var flags=promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 +
67 promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1;
68
69 var ret = promptService.confirmEx(window,title, message,
70 flags, '保存', "不保存", null, null, {});
71
72 return ret;
73 }
74
75 function showHelp(e)
76 {
77 var id = document.getElementById("helpContext");
78 var mouseY = e.clientY + document.body.scrollTop +
79 document.documentElement.scrollTop;
80 var mouseX = e.clientX + document.body.scrollLeft +
81 document.documentElement.scrollLeft;
82 if(id.style.display == "block")
83 {
84 id.style.display = "none";
85 return;
86 }
87
88 id.style.display = "block";
89 id.style.left = (mouseX - 220) + "px";
90 id.style.top = (mouseY + 20) + "px";
91 }
92
93 const BLANK_DOC = "<br>";
94
95 var FireinputEditor = {
96 viewsourcing: false,
97 autoSaveTimer: null,
98 savedFileName: null,
99 savedContent: BLANK_DOC,
100 audosavedContent: BLANK_DOC,
101 dirty: false,
102
103 initToolbarButtons: function()
104 {
105 var kids = document.getElementsByTagName('div');
106
107 for (var i= kids.length-1; i >=0; i--) {
108 if (/imagebutton/.test(kids[i].className)) {
109 kids[i].addEventListener("click", bind(this.buttonClick, this), true);
110 }
111 else if(/styleFormat/.test(kids[i].id) && /floatWindowItem/.test(kids[i].className)) {
112 kids[i].addEventListener("click", bind(this.selectStyle, this), true);
113 kids[i].addEventListener("mouseover", bind(this.setUIStyle, this), true);
114 }
115 else if(/fontSizeWindow/.test(kids[i].id) && /floatWindowItem/.test(kids[i].className)) {
116 kids[i].addEventListener("click", bind(this.selectFontSize, this), true);
117 kids[i].addEventListener("mouseover", bind(this.setUIStyle, this), true);
118 }
119 else if(/fontWindow/.test(kids[i].id) && /floatWindowItem/.test(kids[i].className)) {
120 kids[i].addEventListener("click", bind(this.selectFontName, this), true);
121 kids[i].addEventListener("mouseover", bind(this.setUIStyle, this), true);
122 }
123 else if(/linkFormProtocolWindow/.test(kids[i].id) && /floatWindowItem/.test(kids[i].className)) {
124 kids[i].addEventListener("click", bind(this.selectLinkProtocol, this), true);
125 }
126
127 }
128
129 },
130
131 newDocInternal: function(keepContent)
132 {
133 if(keepContent)
134 return;
135
136 var editor = document.getElementById('fireinputEditor');
137 this.setHTML(BLANK_DOC);
138 this.savedFileName = null;
139 this.savedContent = BLANK_DOC;
140 document.getElementById('savedFileName').innerHTML = '<span style="color:#EDC555">草稿</span>';
141
142 // clear autosave stuff
143 this.dirty = false;
144 this.audosavedContent = BLANK_DOC;
145 FireinputDocSaver.autosave(BLANK_DOC);
146 // launch autoSave if it was cancelled
147 if(!this.autoSaveTimer)
148 this.autoSaveTimer = setInterval(bind(this.autoSave, this), 10000);
149 },
150
151
152 newDoc: function(keepContent)
153 {
154 var html = this.getHTML();
155
156 if(this.savedFileName)
157 {
158 if(this.savedContent == html)
159 {
160 this.newDocInternal(keepContent);
161 return true;
162 }
163 }
164 else if(!this.dirty && this.audosavedContent == html)
165 {
166 this.newDocInternal(keepContent);
167 return true;
168 }
169
170 var ret = confirmDialog('保存文档?', '您的文档还没有保存, 需要保存?');
171 if(ret == 1)
172 return false;
173 if(ret == 2)
174 {
175 this.newDocInternal(keepContent);
176 return true;
177 }
178
179 ret = FireinputDocSaver.save(html, '保存文档...', true, this.savedFileName);
180 if(ret)
181 this.newDocInternal(keepContent);
182
183 return true;
184 },
185
186 openDoc: function()
187 {
188 if(!this.newDoc(true))
189 return;
190
191 var openfile = FireinputDocSaver.open("打开文档...");
192 if(!openfile)
193 return;
194
195 var editor = document.getElementById('fireinputEditor');
196 var readDone = function(docData)
197 {
198 var openContent = FireinputUnicode.getUnicodeString(docData);
199 FireinputEditor.setHTML(openContent);
200 FireinputEditor.savedContent = openContent;
201
202 };
203
204 FireinputDocSaver.read(openfile, readDone);
205 this.savedFileName = openfile;
206 document.getElementById('savedFileName').innerHTML = openfile;
207 this.clearAutoSave();
208 },
209
210 saveDoc: function()
211 {
212 var html = this.getHTML();
213 if(!this.savedFileName)
214 {
215 this.savedFileName = FireinputDocSaver.save(html, '保存文档...');
216 if(!this.savedFileName)
217 return false;
218
219 this.savedContent = html;
220 document.getElementById('savedFileName').innerHTML = this.savedFileName;
221
222 // file has been saved. clear auto save
223 this.clearAutoSave();
224
225 }
226 else
227 {
228 var handle = document.getElementById('savedFileName');
229 setOpacity(handle, 50);
230 FireinputDocSaver.save(html, '保存文档...', true, this.savedFileName);
231 this.savedContent = html;
232 setTimeout(function() { setOpacity(handle, 100);}, 1000);
233 }
234
235 return true;
236
237 },
238
239 saveasDoc: function()
240 {
241 var html = this.getHTML();
242 if(!this.savedFileName)
243 {
244 this.saveDoc();
245 }
246 else
247 {
248 var path = FireinputDocSaver.save(html, '另保存文档为...');
249 if(!path)
250 return;
251
252 this.savedFileName = path;
253 this.savedContent = html;
254 document.getElementById('savedFileName').innerHTML = this.savedFileName;
255 }
256
257 },
258
259 saveDocExit: function()
260 {
261 var html = this.getHTML();
262
263 if(this.savedFileName)
264 {
265 if(this.savedContent == html)
266 return true;
267 }
268 else if(!this.dirty && this.audosavedContent == html)
269 return true;
270
271 var ret = confirmExitDialog('保存文档?', '您的文档还没有保存, 需要保存?');
272 if(ret == 1)
273 {
274 this.clearAutoSave();
275 return false;
276 }
277
278 ret = FireinputDocSaver.save(html, '保存文档...', true, this.savedFileName);
279 return ret;
280 },
281
282 clearAutoSave: function()
283 {
284 if(this.autoSaveTimer)
285 clearInterval(this.autoSaveTimer);
286 this.autoSaveTimer = null;
287 this.audosavedContent = BLANK_DOC;
288 this.dirty = false;
289 FireinputDocSaver.autosave(BLANK_DOC);
290 },
291
292 autoSave: function()
293 {
294 if(this.viewsourcing)
295 return;
296
297 var html = this.getHTML();
298
299 if(this.audosavedContent == html)
300 return;
301
302 if(this.savedFileName)
303 return;
304
305 var handle = document.getElementById('autoSavedMessage');
306 handle.style.display = "";
307 setOpacity(handle, 100);
308 FireinputDocSaver.autosave(html);
309 var i = 100;
310 var fadetimer=setInterval(function() {
311 setOpacity(handle, i);
312 i-= 10;
313 if(i < 10)
314 {
315 clearInterval(fadetimer);
316 handle.style.display = "none";
317 }
318 }, 100);
319
320 this.audosavedContent = html;
321 this.dirty = true;
322 },
323
324 loadAutoSaved: function()
325 {
326 var editor = document.getElementById('fireinputEditor');
327 var readDone = function(docData)
328 {
329 var openContent = FireinputUnicode.getUnicodeString(docData);
330 editor.contentWindow.document.body.innerHTML = openContent;
331 FireinputEditor.audosavedContent = openContent;
332 };
333
334 FireinputDocSaver.autoload(readDone);
335 },
336
337 printDoc: function()
338 {
339 // frames.fireinputEditor.focus();
340 // frames.fireinputEditor.print();
341 var title = this.savedFileName ? this.savedFileName : '打印火输编辑器文本';
342 var wsetting ="toolbar=no,location=no,directories=no,menubar=no,resizable=yes,";
343 wsetting +="scrollbars=yes,width=600, height=700";
344 var htmlContent = this.getHTML();
345
346 var printdoc =window.open("","火输编辑器",wsetting);
347 printdoc.moveTo(100, 50);
348 printdoc.document.open();
349 printdoc.document.write('<html style="background-color: #FFF; padding: 25px; 15px; 5px; 15px;"><head><title>' + title + '</title>\n');
350 printdoc.document.write('<style type="text/css">body { margin: 0px; padding: 0px; height: 90%; width: 90%;} a {color: #000} a.visited {color: #000}</style>\n');
351 printdoc.document.write('<scr'+'ipt type="text/javascript">function printDoc() {window.print(); return false;}' + '</scr'+'ipt>\n');
352 printdoc.document.write('</head><body onLoad="printDoc()" style="font-family: Arial, Tahoma; font-size: 1.0em;">');
353 printdoc.document.write(htmlContent);
354 printdoc.document.write('</body></html>');
355 printdoc.document.close();
356 printdoc.focus();
357 },
358
359 insertNodeAtSelection: function(win, insertNode)
360 {
361 // get current selection
362 var sel = win.getSelection();
363
364 // get the first range of the selection
365 // (there's almost always only one range)
366 var range = sel.getRangeAt(0);
367
368 // deselect everything
369 sel.removeAllRanges();
370
371 // remove content of current selection from document
372 range.deleteContents();
373
374 // get location of current selection
375 var container = range.startContainer;
376 var pos = range.startOffset;
377
378 // make a new range for the new selection
379 range=document.createRange();
380
381 if (container.nodeType==3 && insertNode.nodeType==3) {
382
383 // if we insert text in a textnode, do optimized insertion
384 container.insertData(pos, insertNode.nodeValue);
385
386 // put cursor after inserted text
387 range.setEnd(container, pos+insertNode.length);
388 range.setStart(container, pos+insertNode.length);
389
390 } else {
391
392 var afterNode;
393 if (container.nodeType==3) {
394
395 // when inserting into a textnode
396 // we create 2 new textnodes
397 // and put the insertNode in between
398
399 var textNode = container;
400 container = textNode.parentNode;
401 var text = textNode.nodeValue;
402
403 // text before the split
404 var textBefore = text.substr(0,pos);
405 // text after the split
406 var textAfter = text.substr(pos);
407
408 var beforeNode = document.createTextNode(textBefore);
409 afterNode = document.createTextNode(textAfter);
410
411 // insert the 3 new nodes before the old one
412 container.insertBefore(afterNode, textNode);
413 container.insertBefore(insertNode, afterNode);
414 container.insertBefore(beforeNode, insertNode);
415
416 // remove the old node
417 container.removeChild(textNode);
418
419 } else {
420
421 // else simply insert the node
422 afterNode = container.childNodes[pos];
423 container.insertBefore(insertNode, afterNode);
424 }
425
426 range.setEnd(afterNode, 0);
427 range.setStart(afterNode, 0);
428 }
429
430 sel.addRange(range);
431 },
432
433 getOffsetTop: function(elm) {
434 var mOffsetTop = elm.offsetTop;
435 var mOffsetParent = elm.offsetParent;
436
437 while(mOffsetParent){
438 mOffsetTop += mOffsetParent.offsetTop;
439 mOffsetParent = mOffsetParent.offsetParent;
440 }
441 return mOffsetTop;
442 },
443
444 getOffsetLeft: function(elm) {
445 var mOffsetLeft = elm.offsetLeft;
446 var mOffsetParent = elm.offsetParent;
447 while(mOffsetParent){
448 mOffsetLeft += mOffsetParent.offsetLeft;
449 mOffsetParent = mOffsetParent.offsetParent;
450 }
451 return mOffsetLeft;
452 },
453
454 buttonClick: function(e)
455 {
456 var evt = e ? e : window.event;
457 var target = evt.target;
458
459 if (/^linkFormProtocol/.test(target.id)) {
460 var buttonElement = document.getElementById(target.id);
461 var handle = document.getElementById("linkFormProtocolWindow");
462 handle.style.left = this.getOffsetLeft(buttonElement)+ "px";
463 handle.style.top = (this.getOffsetTop(buttonElement) + buttonElement.offsetHeight+4) + "px";
464 handle.style.display = "block";
465 }
466 else if (/^formatblock/.test(target.id)) {
467 var buttonElement = document.getElementById(target.id);
468 var handle = document.getElementById("styleFormat");
469 handle.style.left = this.getOffsetLeft(buttonElement)+ "px";
470 handle.style.top = (this.getOffsetTop(buttonElement) + buttonElement.offsetHeight+4) + "px";
471 handle.style.display = "block";
472 this.previewCommand = null;
473 this.htmlSource = this.getHTML();
474 }
475 else if(/^fontname/.test(target.id)) {
476 var buttonElement = document.getElementById(target.id);
477 var handle = document.getElementById("fontWindow");
478 handle.style.left = this.getOffsetLeft(buttonElement)+ "px";
479 handle.style.top = (this.getOffsetTop(buttonElement) + buttonElement.offsetHeight+4) + "px";
480 handle.style.display = "block";
481 this.previewCommand = null;
482 this.htmlSource = this.getHTML();
483 }
484 else if (/^fontsize/.test(target.id)) {
485 var buttonElement = document.getElementById(target.id);
486 var handle = document.getElementById("fontSizeWindow");
487 handle.style.left = this.getOffsetLeft(buttonElement)+ "px";
488 handle.style.top = (this.getOffsetTop(buttonElement) + buttonElement.offsetHeight+4) + "px";
489 handle.style.display = "block";
490 this.previewCommand = null;
491 this.htmlSource = this.getHTML();
492 }
493 else if ((target.id == "forecolor") || (target.id == "backcolor")) {
494 document.getElementById("colorpalette").setAttribute("command", target.id);
495
496 var buttonElement = document.getElementById(target.id);
497 var handle = document.getElementById("colorpalette");
498 handle.style.left = (this.getOffsetLeft(buttonElement) -100)+ "px";
499 handle.style.top = (this.getOffsetTop(buttonElement) + buttonElement.offsetHeight - 25) + "px";
500 handle.style.display = "block";
501 this.previewCommand = null;
502 this.htmlSource = this.getHTML();
503 } else if (target.id == "createlink") {
504 var handle = document.getElementById('dform');
505 var form = document.getElementById('linkForm');
506 if(handle.style.display != 'none' && handle.hasAttribute('showup') && handle.getAttribute('showup') == "linkForm")
507 {
508 handle.setAttribute("showup", "");
509 handle.style.display = "none";
510 document.getElementById("fireinputEditor").contentWindow.focus();
511 return;
512 }
513 handle.innerHTML = form.innerHTML;
514 handle.style.display = "block";
515 document.getElementById('linkFormField').focus();
516 handle.setAttribute("showup", "linkForm");
517 } else if (target.id == "createimage") {
518 var handle = document.getElementById('dform');
519 var form = document.getElementById('imageForm');
520 if(handle.style.display != 'none' && handle.hasAttribute('showup') && handle.getAttribute('showup') == "imageForm")
521 {
522 handle.setAttribute("showup", "");
523 handle.style.display = "none";
524 document.getElementById("fireinputEditor").contentWindow.focus();
525 return;
526 }
527 handle.innerHTML = form.innerHTML;
528 handle.style.display = "block";
529 document.getElementById('imageFormField').focus();
530 handle.setAttribute("showup", "imageForm");
531
532 } else if (target.id == "createtable") {
533 var handle = document.getElementById('dform');
534 var form = document.getElementById('tableForm');
535 if(handle.style.display != 'none' && handle.hasAttribute('showup') && handle.getAttribute('showup') == "tableForm")
536 {
537 handle.setAttribute("showup", "");
538 handle.style.display = "none";
539 document.getElementById("fireinputEditor").contentWindow.focus();
540 return;
541 }
542 handle.innerHTML = form.innerHTML;
543 handle.style.display = "block";
544 document.getElementById('tableFormColField').focus();
545 handle.setAttribute("showup", "tableForm");
546
547 } else if (target.id == 'new') {
548 this.newDoc();
549
550 } else if (target.id == 'open') {
551 this.openDoc();
552
553 } else if (target.id == 'openfire') {
554 this.openDocFromServer();
555
556 } else if (target.id == 'save') {
557 this.saveDoc();
558
559 } else if (target.id == 'saveas') {
560 this.saveasDoc();
561
562 } else if (target.id == 'savefire') {
563 this.savefireToServer();
564
565 } else if (target.id == 'print') {
566 this.printDoc();
567
568 } else if (target.id == 'savetoserver') {
569 this.saveDocToServer();
570
571 } else if (target.id == 'viewsource') {
572 this.viewSource();
573 }
574 else {
575 document.getElementById('fireinputEditor').contentWindow.document.execCommand(target.id, false, null);
576 }
577 },
578
579 setUIStyle: function(e)
580 {
581 var evt = e ? e : window.event;
582 var target = evt.target;
583 var value = target.getAttribute('stylevalue');
584 var command = target.getAttribute('command');
585 if(this.previewCommand)
586 {
587 try {
588 document.getElementById('fireinputEditor').contentWindow.document.execCommand("undo", false, null);
589 }
590 catch(e) {}
591 }
592
593 this.previewCommand = command;
594 document.getElementById('fireinputEditor').contentWindow.document.execCommand(command, false, value);
595 },
596
597 selectStyle: function(e)
598 {
599 var evt = e ? e : window.event;
600 var target = evt.target;
601 var stylevalue = target.getAttribute('stylevalue');
602 this.previewCommand = null;
603 document.getElementById('formatblockinput').value = target.innerHTML;
604 // document.getElementById('fireinputEditor').contentWindow.document.execCommand("formatblock", false, stylevalue);
605 document.getElementById('styleFormat').style.display = 'none';
606 document.getElementById("fireinputEditor").contentWindow.focus();
607 },
608
609 selectFontSize: function(e)
610 {
611 var evt = e ? e : window.event;
612 var target = evt.target;
613 var stylevalue = target.getAttribute('stylevalue');
614
615 this.previewCommand = null;
616 document.getElementById('fontsizeinput').value = target.innerHTML;
617 // document.getElementById('fireinputEditor').contentWindow.document.execCommand("fontsize", false, stylevalue);
618 document.getElementById('fontSizeWindow').style.display = 'none';
619 document.getElementById("fireinputEditor").contentWindow.focus();
620 },
621
622 selectFontName: function(e)
623 {
624 var evt = e ? e : window.event;
625 var target = evt.target;
626 var stylevalue = target.getAttribute('stylevalue');
627
628 this.previewCommand = null;
629 document.getElementById('fontnameinput').value = target.innerHTML;
630 // document.getElementById('fireinputEditor').contentWindow.document.execCommand("fontname", false, stylevalue);
631 document.getElementById('fontWindow').style.display = 'none';
632 document.getElementById("fireinputEditor").contentWindow.focus();
633 },
634
635 selectLinkProtocol: function(e)
636 {
637 var evt = e ? e : window.event;
638 var target = evt.target;
639
640 document.getElementById('linkFormProtocolValue').value = target.innerHTML;
641 document.getElementById('linkFormProtocolWindow').style.display = 'none';
642 document.getElementById("linkFormField").focus();
643 },
644
645 hideAllFloatWindows: function(e)
646 {
647 var handle1 = document.getElementById("colorpalette");
648 var handle2 = document.getElementById("styleFormat");
649 var handle3 = document.getElementById("fontSizeWindow");
650 var handle4 = document.getElementById("fontWindow");
651
652 if(handle1.style.display != 'none' || handle2.style.display != 'none' ||
653 handle3.style.display != 'none' || handle4.style.display != 'none')
654 {
655 var evt = e ? e : window.event;
656 var target = evt.target;
657 if(!target.hasAttribute('command'))
658 {
659 if(this.previewCommand)
660 this.setHTML(this.htmlSource);
661 }
662 }
663 handle1.style.display = 'none';
664 handle2.style.display = 'none';
665 handle3.style.display = 'none';
666 handle4.style.display = 'none';
667
668 document.getElementById("linkFormProtocolWindow").style.display="none";
669 },
670
671 start: function()
672 {
673 document.getElementById('fireinputEditor').contentWindow.document.designMode = "on";
674 try {
675 document.getElementById('fireinputEditor').contentWindow.document.execCommand("undo", false, null);
676 } catch (e) {
677 alert("Freinput Text Editor couldn't run in your browser");
678 }
679 setInitSize();
680 this.initToolbarButtons();
681 document.addEventListener("mouseup", bind(this.hideAllFloatWindows, this), true);
682 document.getElementById("fireinputEditor").contentWindow.document.addEventListener("mousedown", bind(this.hideAllFloatWindows,this), true);
683 document.addEventListener("keypress", this.hideAllFloatWindows, true);
684 document.getElementById("fireinputEditor").contentWindow.document.addEventListener("keypress", bind(this.hideAllFloatWindows,this), true);
685
686 // launch autoSave
687 this.autoSaveTimer = setInterval(bind(this.autoSave, this), 10000);
688 },
689
690 viewSource: function()
691 {
692 var html;
693 var button = document.getElementById('viewsource');
694 var editor = document.getElementById('fireinputEditor');
695 if(!this.viewsourcing) {
696 this.viewsourcing = true;
697 html = document.createTextNode(editor.contentWindow.document.body.innerHTML);
698 editor.contentWindow.document.body.innerHTML = "";
699 html = editor.contentWindow.document.importNode(html,false);
700 editor.contentWindow.document.body.appendChild(html);
701 button.className = 'imagebutton textbutton viewsourcing';
702 } else {
703 this.viewsourcing = false;
704 html = editor.contentWindow.document.body.ownerDocument.createRange();
705 html.selectNodeContents(editor.contentWindow.document.body);
706 editor.contentWindow.document.body.innerHTML = html.toString();
707 button.className = 'imagebutton textbutton viewsource';
708 }
709 },
710 setHTML: function(html)
711 {
712 var editor = document.getElementById('fireinputEditor');
713 if(!this.viewsourcing)
714 {
715 editor.contentWindow.document.body.innerHTML = html;
716 return;
717 }
718
719 var texthtml = document.createTextNode(html);
720 editor.contentWindow.document.body.innerHTML = "";
721 texthtml = editor.contentWindow.document.importNode(texthtml,false);
722 editor.contentWindow.document.body.appendChild(texthtml);
723 },
724
725 getHTML: function()
726 {
727 var editor = document.getElementById('fireinputEditor');
728 if(!this.viewsourcing)
729 return editor.contentWindow.document.body.innerHTML;
730
731 html = editor.contentWindow.document.body.ownerDocument.createRange();
732 html.selectNodeContents(editor.contentWindow.document.body);
733 return html.toString();
734 },
735
736 onEnter: function(e, callback)
737 {
738 if(e.keyCode == '13' )
739 {
740 callback(e);
741 return false;
742 }
743 return true;
744 },
745
746 confirmLinkForm: function(e, cancel)
747 {
748 var handle = document.getElementById('linkFormField');
749 var protocol = document.getElementById('linkFormProtocolValue').value;
750 var link = handle.value;
751 if(protocol == 'http' || protocol == 'ftp' || protocol == 'mailto')
752 link = protocol + "://" + link;
753
754 if(!cancel && handle.value != '')
755 {
756 document.getElementById('fireinputEditor').contentWindow.document.execCommand("CreateLink",false,link);
757 }
758 document.getElementById('dform').style.display = "none";
759 document.getElementById("fireinputEditor").contentWindow.focus();
760 },
761
762 confirmImageForm: function(e, cancel)
763 {
764 var handle = document.getElementById('imageFormField');
765 var link = handle.value;
766
767 if(!cancel && link != '')
768 {
769 document.getElementById('fireinputEditor').contentWindow.document.execCommand("InsertImage",false,link);
770 }
771 document.getElementById('dform').style.display = "none";
772 document.getElementById("fireinputEditor").contentWindow.focus();
773 },
774
775 confirmTableForm: function(e, cancel)
776 {
777 if(cancel)
778 {
779 document.getElementById('dform').style.display = "none";
780 document.getElementById("fireinputEditor").contentWindow.focus();
781 return;
782 }
783
784 var editor = document.getElementById("fireinputEditor");
785 var cols = parseInt(document.getElementById('tableFormColField').value);
786 cols = cols > 0 ? cols : 1;
787 var rows = parseInt(document.getElementById('tableFormRowField').value);
788 rows = rows > 0 ? rows : 1;
789
790 var table = editor.contentWindow.document.createElement("table");
791 table.setAttribute("border", "1");
792 table.setAttribute("width", "90%");
793 table.setAttribute("cellpadding", "2");
794 table.setAttribute("cellspacing", "2");
795 var tbody = editor.contentWindow.document.createElement("tbody");
796 for (var i=0; i < rows; i++) {
797 var tr =editor.contentWindow.document.createElement("tr");
798 for (var j=0; j < cols; j++) {
799 var td =editor.contentWindow.document.createElement("td");
800 var br =editor.contentWindow.document.createElement("br");
801 td.appendChild(br);
802 tr.appendChild(td);
803 }
804 tbody.appendChild(tr);
805 }
806 table.appendChild(tbody);
807 this.insertNodeAtSelection(editor.contentWindow, table);
808
809 document.getElementById('dform').style.display = "none";
810 editor.contentWindow.focus();
811 }
812
813 };
814 function editor_onbeforeunload()
815 {
816 if(this.autoSaveTimer)
817 clearInterval(this.autoSaveTimer);
818 FireinputEditor.autoSave();
819 FireinputEditor.saveDocExit();
820 }
821
822 function editor_start()
823 {
824 FireinputEditor.start();
825 FireinputEditor.loadAutoSaved();
826 document.getElementById("fireinputEditor").contentWindow.focus();
827
828 }
829
830 window.addEventListener("resize", setInitSize, true);
831 window.addEventListener("beforeunload", editor_onbeforeunload, true);
832 </script>
833 </head>
834 <body onLoad="editor_start()">
835 <div id="localEditor" class="localEditor">
836 <div class="editorHead">火输文本编辑器<span style="font-size: 10px; font-style: italic" id="savedFileName"><span style="color: #EDC555">草稿</span></span></div>
837 <div class="editorHeadSaveFile"><span id="autoSavedMessage" style="display: none; background-color: #EDC555">自动保存草稿</span></div>
838 <div id="editorToolbar">
839 <table cellpadding=0>
840 <tr>
841 <td>
842 <div class="imagebutton textbutton viewsource" id="viewsource" title="源代码">源代码</div>
843 </td>
844 <td>
845 <div class="imagebutton newimagebutton" id="new" title="新建"></div>
846 </td>
847 <td>
848 <div class="imagebutton openimagebutton" id="open" title="打开"></div>
849 </td>
850 <td>
851 <div class="imagebutton openfireimagebutton" id="openfire" style="display: none" title="打开(从火输网fireinput.com)"></div>
852 </td>
853 <td>
854 <div class="imagebutton saveimagebutton" id="save" title="保存"></div>
855 </td>
856 <td>
857 <div class="imagebutton saveasimagebutton" id="saveas" title="另保存"></div>
858 </td>
859 <td>
860 <div class="imagebutton savefireimagebutton" id="savefire" style="display: none" title="保存到火输网(fireinput.com)"></div>
861 </td>
862 <td>
863 <div class="imagebutton printimagebutton" id="print" title="打印"></div>
864 </td>
865 <td>
866 <div class="imagebutton cutimagebutton" id="cut" title="剪切"></div>
867 </td>
868 <td>
869 <div class="imagebutton copyimagebutton" id="copy" title="复制"></div>
870 </td>
871 <td>
872 <div class="imagebutton pasteimagebutton" id="paste" title="粘贴"></div>
873 </td>
874 <td>
875 <div class="imagebutton undoimagebutton" id="undo" title="撤消">
876 </div>
877 </td>
878 <td>
879 <div class="imagebutton redoimagebutton" id="redo" title="重做">
880 </div>
881 </td>
882 <td>
883 <div class="imagebutton linkimagebutton" id="createlink" title="插入链接">
884 </div>
885 </td>
886 <td>
887 <div class="imagebutton unlinkimagebutton" id="unlink" title="删除链接">
888 </div>
889 </td>
890 <td>
891 <div class="imagebutton imageimagebutton" id="createimage" title="插入图象">
892 </div>
893 </td>
894 <td>
895 <div class="imagebutton tableimagebutton" id="createtable" title="插入/编辑表格">
896 </div>
897 </td>
898 </tr>
899 </table>
900 <table>
901 <tr>
902 <td>
903 <table cellspacing=0 cellpadding=0>
904 <tr>
905 <td><div class="textbutton">格式 </div></td>
906 <td>
907 <div id="formatblock" class="inputblockArrow" onclick="FireinputEditor.buttonClick(event);">
908 <input id="formatblockinput" class="inputblock" value="" readonly="true"></input>
909 </div>
910 </td>
911 </tr>
912 </table>
913 </td>
914 <td>
915 <table cellspacing=0 cellpadding=0>
916 <tr>
917 <td><div class="textbutton">字体 </div></td>
918 <td>
919 <div id="fontname" class="inputblockArrow" onclick="FireinputEditor.buttonClick(event);">
920 <input id="fontnameinput" class="inputblock" value="" readonly="true"></input>
921 </div>
922 </td>
923 </tr>
924 </table>
925 </td>
926 <td>
927 <table cellspacing=0 cellpadding=0>
928 <tr>
929 <td><div class="textbutton">大小 </div></td>
930 <td>
931 <div id="fontsize" class="inputblockArrow" onclick="FireinputEditor.buttonClick(event);">
932 <input id="fontsizeinput" class="inputblock" value="" readonly="true"></input>
933 </div>
934 </td>
935 </tr>
936 </table>
937 </td>
938 <td>
939 <div class="imagebutton boldimagebutton" id="bold" title="加粗">
940 </div>
941 </td>
942 <td>
943 <div class="imagebutton italicimagebutton" id="italic" title="倾斜">
944 </div>
945 </td>
946 <td>
947 <div class="imagebutton underlineimagebutton" id="underline" title="下划线">
948 </div>
949 </td>
950 <td>
951 <div class="imagebutton underlinedoubleimagebutton" style="display: none" id="underlinedouble" title="双删除线">
952 </div>
953 </td>
954 <td>
955 <div class="imagebutton strikethroughimagebutton" id="strikethrough" title="删除线">
956 </div>
957 </td>
958 <td>
959 <div class="imagebutton subscriptmagebutton" id="subscript" title="下标">
960 </div>
961 </td>
962 <td>
963 <div class="imagebutton superscriptmagebutton" id="superscript" title="上标">
964 </div>
965 </td>
966 <td>
967 <div class="imagebutton forecolorimagebutton" id="forecolor" title="字体颜色">
968 </div>
969 </td>
970 <td>
971 <div class="imagebutton backcolorimagebutton" id="backcolor" title="背景颜色">
972 </div>
973 </td>
974 <td>
975 <div class="imagebutton alignleftimagebutton" id="justifyleft" title="左对齐">
976 </div>
977 </td>
978 <td>
979 <div class="imagebutton aligncenterimagebutton" id="justifycenter" title="居中对齐">
980 </div>
981 </td>
982 <td>
983 <div class="imagebutton alignrightimagebutton" id="justifyright" title="右对齐">
984 </div>
985 </td>
986 <td>
987 <div class="imagebutton numberlistimagebutton" id="insertorderedlist" title="插入/删除编号列表">
988 </div>
989 </td>
990 <td>
991 <div class="imagebutton bulletlistimagebutton" id="insertunorderedlist" title="插入/删除项目列表">
992 </div>
993 </td>
994 <td>
995 <div class="imagebutton outdentimagebutton" id="outdent" title="减少缩进">
996 </div>
997 </td>
998 <td>
999 <div class="imagebutton indentimagebutton" id="indent" title="增加缩进">
1000 </div>
1001 </td>
1002 </tr>
1003 </table>
1004 <div id="dform" style="display: none" class="embeddedForm">
1005 </div>
1006 </div>
1007 <div style="margin: 0px; padding: 0px;">
1008 <iframe id="fireinputEditor" name="fireinputEditor" style="min-width: 795px; background-color: #FFFFFF"></iframe>
1009 <iframe width="250" height="185" id="colorpalette" src="chrome://fireinput/content/color.html" style="display:none; z-index: 10; position: absolute;"></iframe>
1010 </div>
1011 </div>
1012
1013 <!-- all hidden panels -->
1014 <div id="styleFormat" class="floatWindow" style="width: 140px; height: 250px;">
1015 <div id="styleFormat1" class="floatWindowItem" command="formatblock" style="font-weight: 500; margin-top: 3px" stylevalue="<p>">普通</div>
1016 <div id="styleFormat2" class="floatWindowItem" command="formatblock" style="font-weight: 500" stylevalue="<div>">段落(div)</div>
1017 <div id="styleFormat3" class="floatWindowItem" command="formatblock" style="font-weight: 500; font-style: italic" stylevalue="<address>">地址</div>
1018 <div id="styleFormat4" class="floatWindowItem" command="formatblock" style="font-weight: 500" stylevalue="<pre>">已编排格式</div>
1019 <div id="styleFormat5" class="floatWindowItem" command="formatblock" style="height: 30px; font-size: 20px" stylevalue="<h1>">标题1</div>
1020 <div id="styleFormat6" class="floatWindowItem" command="formatblock" style="height: 24px; font-size: 15px;" stylevalue="<h2>">标题2</div>
1021 <div id="styleFormat7" class="floatWindowItem" command="formatblock" style="height: 20px; font-size: 13px;" stylevalue="<h3>">标题3</div>
1022 <div id="styleFormat8" class="floatWindowItem" command="formatblock" style="height: 15px; font-size: 11px;" stylevalue="<h4>">标题4</div>
1023 <div id="styleFormat9" class="floatWindowItem" command="formatblock" style="height: 12px; font-size: 10px;" stylevalue="<h5>">标题5</div>
1024 <div id="styleFormat10" class="floatWindowItem" command="formatblock" style="height: 10px; font-size: 8px;" stylevalue="<h6>">标题6</div>
1025 </div>
1026
1027 <div id="fontSizeWindow" class="floatWindow" style="width: 140px; height: 190px;">
1028 <div id="fontSizeWindow1" class="floatWindowItem" command="fontsize" style="margin-top: 3px; font-size: 10px;" stylevalue="1">小小小</div>
1029 <div id="fontSizeWindow2" class="floatWindowItem" command="fontsize" style="height: 15px; font-size: 12px;" stylevalue="2">小小</div>
1030 <div id="fontSizeWindow3" class="floatWindowItem" command="fontsize" style="height: 20px; font-size: 14px;" stylevalue="3">小</div>
1031 <div id="fontSizeWindow4" class="floatWindowItem" command="fontsize" style="height: 20px; font-size: 16px;" stylevalue="4">中</div>
1032 <div id="fontSizeWindow5" class="floatWindowItem" command="fontsize" style="height: 20px; font-size: 18px;" stylevalue="5">大</div>
1033 <div id="fontSizeWindow6" class="floatWindowItem" command="fontsize" style="height: 22px; font-size: 20px;" stylevalue="6">大大</div>
1034 <div id="fontSizeWindow7" class="floatWindowItem" command="fontsize" style="height: 25px; font-size: 24px;" stylevalue="7">大大大</div>
1035 </div>
1036 <div id="fontWindow" class="floatWindow" style="width: 140px; height: 115px;">
1037 <div id="fontWindow1" class="floatWindowItem" command="fontname" style="margin-top: 3px; font-family: Arial" stylevalue="Arial">Arial</div>
1038 <div id="fontWindow2" class="floatWindowItem" command="fontname" style="font-family: Courier New" stylevalue="Courier New">Courier New</div>
1039 <div id="fontWindow2" class="floatWindowItem" command="fontname" style="font-family: Times New Roman" stylevalue="Times New Roman">Times New Roman</div>
1040 <div id="fontWindow2" class="floatWindowItem" command="fontname" style="font-family: Tahoma" stylevalue="Tahoma">Tahoma</div>
1041 <div id="fontWindow2" class="floatWindowItem" command="fontname" style="font-family: Comic Sans MS" stylevalue="Comic Sans MS">Comic Sans MS</div>
1042 </div>
1043 <div id="linkFormProtocolWindow" class="floatWindow" style="width: 60px; height: 90px;">
1044 <div id="linkFormProtocolWindow1" class="floatWindowItem" style="width: 50px">http</div>
1045 <div id="linkFormProtocolWindow2" class="floatWindowItem" style="width: 50px">ftp</div>
1046 <div id="linkFormProtocolWindow3" class="floatWindowItem" style="width: 50px">mailto</div>
1047 <div id="linkFormProtocolWindow4" class="floatWindowItem" style="width: 50px">其它</div>
1048 </div>
1049
1050 <div id="linkForm" style="display: none">
1051 <table cellspacing=0 cellpadding=0 border=0>
1052 <tr>
1053 <td>
1054 <div class="textInputName">网址(www)或其他链接:</div>
1055 </td>
1056 <td>
1057 <table cellspacing=0 cellpadding=0 border=0>
1058 <tr>
1059 <td>
1060 <div id="linkFormProtocol" class="inputblockArrow" style="width: 60px; margin-right: 2px" onclick="FireinputEditor.buttonClick(event);">
1061 <input id="linkFormProtocolValue" class="inputblock" style="width: 40px" value="http" readonly="true"></input>
1062 </div>
1063 </td>
1064 <td>
1065 <div class="textInput">
1066 <input type="text" id="linkFormField" class="textInputField" value=""
1067 onkeypress="FireinputEditor.onEnter(event, FireinputEditor.confirmLinkForm)"></input>
1068 </div>
1069 </td>
1070 </tr>
1071 </table>
1072 </td>
1073 <td>
1074 <input class="textInputButton" style="margin-left: 20px;" type="button" value="确定" onclick="FireinputEditor.confirmLinkForm(event)">
1075 <input class="textInputButton" type="button" value="取消" onclick="FireinputEditor.confirmLinkForm(event, true)">
1076 </td>
1077 </tr>
1078 </table>
1079 </div>
1080
1081 <div id="imageForm" style="display: none">
1082 <table cellspacing=0 cellpadding=0 border=0>
1083 <tr>
1084 <td>
1085 <div class="textInputName">图案的链接:</div>
1086 </td>
1087 <td>
1088 <div class="textInput">
1089 <input type="text" id="imageFormField" class="textInputField" value="http://"
1090 onkeypress="FireinputEditor.onEnter(event, FireinputEditor.confirmImageForm)"></input>
1091 </div>
1092 </td>
1093 <td>
1094 <input class="textInputButton" style="margin-left: 20px;" type="button" value="确定" onclick="FireinputEditor.confirmImageForm(event)">
1095 <input class="textInputButton" type="button" value="取消" onclick="FireinputEditor.confirmImageForm(event, true)">
1096 </td>
1097 </tr>
1098 </table>
1099 </div>
1100
1101 <div id="tableForm" style="display: none">
1102 <table cellspacing=0 cellpadding=0 border=0>
1103 <tr>
1104 <td>
1105 <div class="textInputName">方格的列数:</div>
1106 </td>
1107 <td>
1108 <div class="textInput" style="width: 40px">
1109 <input type="text" _no_cjk_input="true" id="tableFormColField" class="textInputField" style="width: 40px" value="2"
1110 onkeypress="FireinputEditor.onEnter(event, function() { document.getElementById('tableFormRowField').focus();})"></input>
1111 </div>
1112 </td>
1113 <td>
1114 <div class="textInputName"> 行数:</div>
1115 </td>
1116 <td>
1117 <div class="textInput" style="width: 40px">
1118 <input type="text" _no_cjk_input="true" id="tableFormRowField" class="textInputField" style="width: 40px" value="2"
1119 onkeypress="FireinputEditor.onEnter(event, FireinputEditor.confirmTableForm)"></input>
1120 </div>
1121 </td>
1122 <td>
1123 <input class="textInputButton" style="margin-left: 20px;" type="button" value="确定" onclick="FireinputEditor.confirmTableForm(event)">
1124 <input class="textInputButton" type="button" value="取消" onclick="FireinputEditor.confirmTableForm(event, true)">
1125 </td>
1126 </tr>
1127 </table>
1128 </div>
1129
1130 </body>
1131 </html>
syntax highlighted by Code2HTML, v. 0.9.1