This dongdong implements some commonly used function, today just completes, everybody gives the point suggestion more!
Under the FF imperfect, some features have not yet been realized!
This is also I wrote the first editor (OH), do not do well, do not throw eggs over ...
Let's Go!
Copy Code code as follows:
/*******************************************
The best freeeditor in a litter (2006-08-22)
This JavaScript is writen by CXP.
*******************************************/
var ColorType;
var currentmode= "Design"; Current mode
var Ie=document.all?true:false;
Document.onclick=function () {
}
function Format (str,arg) {
if (currentmode!= "designs") {//non-design mode
Return
}
var obj=window.frames["Design"];
if (!ie) {
var salert= "";
Switch (str) {
Case "Cut":
Salert = "Your browser security settings do not allow the editor to perform cut operations automatically, please use the keyboard shortcuts (ctrl+x) to complete";
Break
Case "Copy":
Salert = "Your browser security settings do not allow the editor to automate copy operations, please use keyboard shortcuts (CTRL + C) to complete";
Break
Case "Paste":
Salert = "Your browser security settings do not allow the editor to perform the paste operation automatically, please use the keyboard shortcuts (Ctrl + V) to complete";
Break
}
if (salert!= "") {
alert (Salert);
Return
}
}
Obj.focus ();
if (ARG) {
Return Obj.document.execCommand (STR,FALSE,ARG);
}
else{
if (IE) {
Obj.document.execCommand (str);
}
else{
Obj.document.execCommand (Str,false,false);
}
}
Obj.focus ();
}
Show Color Menu
function Showcolormenu (obj,e) {
if (currentmode!= "designs") {//non-design mode
Return
}
var target=document.all?e.srcelement:e.target;
var colormode=target.getattribute ("title");
Switch (ColorMode) {
Case "Background color":
Colortype= "Bodybackcolor";
Break
Case "Font background color":
Colortype= "BackColor";
Break
Case "Font Color":
Colortype= "ForeColor";
Break
Default
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
var db=window.frames["Design"].document;
var height=125;
if (colortype== "ForeColor") {
height=145;
}
var color=showmodaldialog ("dialog/color.html", Window, "dialogwidth:263px;dialogheight": "+height+" PX;HELP:NO; Status:no;scroll:no;dialogleft: "+left+";d ialogtop: "+top+";p x);
if (color!=null) {
if (colortype== "Bodybackcolor") {
Db.body.style.backgroundcolor=color;
Return
}
else if (colortype== "ForeColor") {
var arr=color.split ("|");
if (arr.length==2) {
Format (colortype,arr[0]);
Set the Glow filter, ieonly
if (Db.selection.type.toLowerCase ()!= "None") {
var selecttext=db.selection.createrange (). HTMLText;
selecttext= "<span style=\" Height:18px;filter:glow (color= "+arr[0]+", strength=2); \ "> +selecttext+" </span > ";
Inserthtml (SelectText);
Return
}
}
}
Format (Colortype,color);
}
}
else{
if (colortype== "BackColor") {
Alert (' Stay perfect! ');
Return
}
Ffopenwidnow ("dialog/color.html", 263,112,top+25,left);
}
}
Show Insert Picture window
function Showimagemenu (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
var path=showmodaldialog ("dialog/image.html", "", "Dialogwidth:390px;dialogheight:120px;help:no;status:no;scroll: No;dialogleft: "+left+";d ialogtop: "+top+";p x);
if (path==null) {
Return
}
Format ("Insertimage", Path);
}
else{
Ffopenwidnow ("dialog/image.html", 385,100,top+25,left);
}
}
Show Insert Flash window
function Showflashmenu (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj);
if (document.all) {
var path=showmodaldialog ("dialog/flash.html", "", "Dialogwidth:402px;dialogheight:139px;help:no;status:no;scroll: No;dialogleft: "+left+";d ialogtop: "+ (top+138) +";p x ");
if (path==null) {
Return
}
var arr=path.split ("|");
var str= "<object codebase= ' http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version= 5,0,0,0 ' classid= ' clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 ' width= ' "+arr[1]+" ' height= ' "+arr[2]+" ' ><PARAM Name=movie value= ' "+arr[0]+" ' ><param name=quality value=high><embed src= ' "+arr[0]+" ' Quality=high Pluginspage= ' http://www.macromedia.com/shockwave/download/index.cgi? P1_prod_version=shockwaveflash ' type= ' application/x-shockwave-flash ' width= ' "+arr[1]+" ' height= ' "+arr[2]+" ' > </embed></OBJECT> ";
Inserthtml (str);
}
else{
Alert (' to be perfected ');
Return
}
}
Show insert Face window
function Showfacemenu (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
ShowModalDialog ("dialog/face.html", Window, "Dialogwidth:280px;dialogheight:215px;help:no;status:no;scroll:no"; Dialogleft: "+left+";d ialogtop: "+top+";p x);
}
else{
Ffopenwidnow ("dialog/face.html", 280,180,top+25,left);
}
}
Show FieldSet window
function Showfieldsetmenu (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
ShowModalDialog ("dialog/fieldset.html", Window, "Dialogwidth:330px;dialogheight:120px;help:no;status:no;scroll: No;dialogleft: "+left+";d ialogtop: "+top+";p x);
}
else{
Ffopenwidnow ("dialog/fieldset.html", 330,100,top+25,left);
}
}
function getwidth (obj) {
var parentobj=obj;
var left=obj.offsetleft;
while (parentobj=parentobj.offsetparent) {
Left+=parentobj.offsetleft;
}
return to left;
}
function GetHeight (obj) {
var parentobj=obj;
var top=obj.offsettop;
while (parentobj=parentobj.offsetparent) {
Top+=parentobj.offsettop;
}
return top;
}
function Showmediamenu (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj);
if (document.all) {
ShowModalDialog ("dialog/media.html", Window, "Dialogwidth:330px;dialogheight:119px;help:no;status:no;scroll:no"; Dialogleft: "+left+";d ialogtop: "+ (top+138) +"; ");
}
else{
Alert (' to be perfected ');
}
}
Show Insert File window
function Showfilemenu (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
ShowModalDialog ("dialog/file.html", Window, "Dialogwidth:390px;dialogheight:115px;help:no;status:no;scroll:no"; Dialogleft: "+left+";d ialogtop: "+top+");
}
else{
Ffopenwidnow ("dialog/file.html", 380,100,top+25,left);
}
}
function SetColor (color) {
if (color== "") {
Return
}
if (colortype== "Bodybackcolor") {
window.frames["Design"].document.body.style.backgroundcolor=color;
Return
}
Format (Colortype,color);
}
Insert Caption
function Showmarqueemenu (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
ShowModalDialog ("dialog/marquee.html", window, "Dialogwidth:439px;dialogheight:260px;help:no;status:no;scroll:no ;d ialogleft: "+left+";d ialogtop: "+top+");
}
else{
Ffopenwidnow ("dialog/marquee.html", 435,220,top+25,left);
}
}
inserting special characters
function Showsymbolmenu (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
ShowModalDialog ("dialog/symbol.html", Window, "Dialogwidth:385px;dialogheight:235px;help:no;status:no;scroll:no"; Dialogleft: "+left+";d ialogtop: "+top+");
}
else{
Ffopenwidnow ("dialog/symbol.html", 370,190,top+25,left);
}
}
Insert File
function InsertFile (TXT) {
var arr=txt.split (".");
var filename=getfilename (arr[arr.length-1]);
var str= "<img src=\" img\/file\/"+filename+" \ "Border=0><a href=\" "+txt+" \ "target=\" _blank\ ">";
Arr=txt.split ("/");
FILENAME=ARR[ARR.LENGTH-1];
Str+=filename+ "</a>";
var db=window.frames["Design"].document;
Inserthtml (str);
}
Insert Current time
function Inserttime (b) {
var d=new Date ();
var Year,month,day,hour,minute,second;
Year=d.getfullyear ();
Month=d.getmonth ();
Day=d.getdate ();
Hour=d.gethours ();
Minute=d.getminutes ();
Second=d.getseconds ();
var str;
if (b) {
str=year+ "-" +month+ "-" +day;
}
else{
str=hour+ ":" +minute+ ":" +second;
}
Inserthtml (str);
}
Insert Reference
function Insertquote () {
var str= "<table style=\" border-right: #cccccc 1px dotted; table-layout:fixed; Border-top: #cccccc 1px dotted; Border-left: #cccccc 1px dotted; Border-bottom: #cccccc 1px dotted\ "cellspacing=0 cellpadding=6 width=\" 95%\ "Align=center border=0><tbody> <TR><TD style=\ "word-wrap:break-word\" bgcolor=\ "#f3f3f3 \ valign=\" top\ "><font style=\" FONT-WEIGHT : bold; Color:green;font-size:13px;\ "> Reference:</font><br></td></tr></tbody></table>" ;
Inserthtml (str);
}
Insert a radio box
function Insertradio (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
ShowModalDialog ("dialog/radio.html", Window, "Dialogwidth:275px;dialogheight:156px;help:no;status:no;scroll:no"; Dialogleft: "+left+";d ialogtop: "+top+");
}
else{
Ffopenwidnow ("dialog/radio.html", 270,125,top+25,left);
}
}
Insert check box
function Insertcheckbox (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
ShowModalDialog ("dialog/checkbox.html", Window, "Dialogwidth:275px;dialogheight:156px;help:no;status:no;scroll: No;dialogleft: "+left+";d ialogtop: "+top+");
}
else{
Ffopenwidnow ("dialog/checkbox.html", 270,125,top+25,left);
}
}
Insert check box
function Insertinputtext (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
ShowModalDialog ("dialog/text.html", Window, "Dialogwidth:275px;dialogheight:156px;help:no;status:no;scroll:no"; Dialogleft: "+left+";d ialogtop: "+top+");
}
else{
Ffopenwidnow ("dialog/text.html", 270,125,top+25,left);
}
}
Insert multiple lines of text box
function Inserttextarea (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
ShowModalDialog ("dialog/textarea.html", Window, "Dialogwidth:305px;dialogheight:250px;help:no;status:no;scroll: No;dialogleft: "+left+";d ialogtop: "+top+");
}
else{
Ffopenwidnow ("dialog/textarea.html", 300,250,top+25,left,true);
}
}
Insert Table
function inserttable (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
ShowModalDialog ("dialog/table.html", Window, "Dialogwidth:265px;dialogheight:239px;help:no;status:no;scroll:no"; Dialogleft: "+left+";d ialogtop: "+top+");
}
else{
Ffopenwidnow ("dialog/table.html", 256,210,top+25,left,true);
}
}
Insert drop down list
function Insertselect (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
ShowModalDialog ("dialog/select.html", Window, "Dialogwidth:380px;dialogheight:250px;help:no;status:no;scroll: Auto;dialogleft: "+left+";d ialogtop: "+top+");
}
else{
Ffopenwidnow ("dialog/select.html", 380,250,top+25,left);
}
}
Insert button
function Insertbutton (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
ShowModalDialog ("dialog/button.html", Window, "Dialogwidth:239px;dialogheight:170px;help:no;status:no;scroll: Auto;dialogleft: "+left+";d ialogtop: "+top+");
}
else{
Ffopenwidnow ("dialog/button.html", 236,139,top+25,left);
}
}
Insert Form
function Insertform (obj) {
if (currentmode!= "designs") {//non-design mode
Return
}
var left,top;
Left=getwidth (obj);
Top=getheight (obj) +138;
if (document.all) {
ShowModalDialog ("dialog/form.html", Window, "Dialogwidth:239px;dialogheight:170px;help:no;status:no;scroll:auto"; Dialogleft: "+left+";d ialogtop: "+top+");
}
else{
Ffopenwidnow ("dialog/form.html", 236,139,top+25,left);
}
}
Set mode
function SetMode (modetype,btnobj) {
if (Currentmode==modetype) {
Return
}
Btnobj.style.border= "1px solid #000000";
var CObj;
if (currentmode== "Preview") {
Cobj=document.getelementbyid ("preview");
}
else if (currentmode== "design") {
Cobj=document.getelementbyid ("Design");
}
else{
Cobj=document.getelementbyid ("Textcode");
}
document.getElementById ("BNT" +currentmode). style.border= "1px solid #999999";
Switch (modetype) {
Case ' code '://code
var Obj=document.getelementbyid ("Textcode");
var db=window.frames["Design"].document.body;
var htmlcode=db.innerhtml;
Prevent FF from wrapping before no code
if (htmlcode== "<br>\n" | | htmlcode== "<br>") {
Htmlcode= "";
}
Obj.value=htmlcode;
Cobj.style.display= "None";
obj.style.display= "Block";
Break
Case "Designs"://Design
Cobj.style.display= "None";
document.getElementById ("Design")-style.display= "block";
Break
Case "Preview":
var obj=window.frames["Preview"].document.body;
var db=window.frames["Design"].document.body;
Obj.style.backgroundcolor=db.style.backgroundcolor;
if (currentmode== "Code") {
Obj.innerhtml=cobj.value;
}
else{
var str=db.innerhtml;
OBJ.INNERHTML=STR;
}
Cobj.style.display= "None";
document.getElementById ("Preview"). style.display= "Block";
Break
}
Currentmode=modetype; Set Current mode
}
Create a link
function Createlink () {
if (currentmode!= "designs") {//non-design mode
Return
}
if (document.all) {
Format ("Createlink");
}
else{
var str=window.prompt ("Enter Link Location (example:http://www.baidu.com/or ftp://127.0.0.1/)", "http://");
if (Str==null | | str== "http://" | | str== "") return;
Format ("Createlink", str);
}
}
New
function NewPage () {
if (currentmode!= "designs") {//non-design mode
Return
}
window.frames["Design"].document.body.innerhtml= "";
}
Set font
function setfacefamily (obj) {
var Val=obj.options[obj.selectedindex].value;
if (val== "") return;
Format ("FontName", Val);
}
Set Font size
function Setfacesize (obj) {
var Val=obj.options[obj.selectedindex].text;
if (val== "Font size") return;
Format ("FontSize", Val);
}
function GetFileName (str) {
Str=str.tolowercase ();
var name;
Switch (str) {
Case "avi":
Name= "Avi.gif";
Break
Case "BMP":
Name= "Bmp.gif";
Break
Case "CHM":
Name= "Chm.gif";
Break
Case "Doc":
Name= "Doc.gif";
Break
Case "EXE":
Name= "Exe.gif";
Break
Case "GIF":
Name= "Gif.gif";
Break
Case "HTML":
Name= "Html.gif";
Break
Case "htm":
Name= "Html.gif";
Break
Case "JPG":
Name= "Jpg.gif";
Break
Case "MDB":
Name= "Mdb.gif";
Break
Case "Mid":
Name= "Mid.gif";
Break
Case "MP3":
Name= "Mp3.gif";
Break
Case "PDF":
Name= "Pdf.gif";
Break
Case "ppt":
Name= "Ppt.gif";
Break
Case "rar":
Name= "Rar.gif";
Break
Case "RM":
Name= "Rm.gif";
Break
Case "RMVB":
Name= "Rm.gif";
Break
Case "SWF":
Name= "Swf.gif";
Break
Case "TXT":
Name= "Txt.gif";
Break
Case "XLS":
Name= "Xls.gif";
Break
Case "Zip":
Name= "Zip.gif";
Break
Default
Name= "Unknow.gif";
Break
}
return name;
}
function SetFocus () {
window.frames["Design"].focus ();
}
Inserting HTML code
function inserthtml (str) {
if (IE) {
SetFocus ();
window.frames["Design"].document.selection.createrange (). pastehtml (str);
}
else{
var newstr=window.frames["Design"].document.body.innerhtml;
if (newstr.tolowercase () = "<br>" | | newstr.tolowercase () = "<br>\n") {
window.frames["Design"].DOCUMENT.BODY.INNERHTML=STR;
}
else{
window.frames["Design"].DOCUMENT.BODY.INNERHTML+=STR;
}
}
SetFocus ();
}
FF Open Window
function Ffopenwidnow (url,w,h,top,left) {
window.open (URL, "", "Location=no,menubar=no,toolbar=no,dependent=yes,dialog=yes,minimizable=no,modal=yes, Alwaysraised=yes,resizable=no,width= "+w+", height= "+h+", screenx= "+left+", screeny= "+top";
}
Local Downloads