主頁 > 知識庫 > 一款垃圾中的極品HTML編輯器(兼容IE OR FF)

一款垃圾中的極品HTML編輯器(兼容IE OR FF)

熱門標簽:興化400電話辦理多少錢 長春銷售外呼系統(tǒng)業(yè)務 靈聲智能電話機器人招聘 天津電銷卡外呼系統(tǒng)線路 智能電銷機器人真的好嗎 長春防封卡電銷卡套餐 企業(yè)電話機器人辦理 四平電話機器人哪家好 株洲外呼營銷系統(tǒng)有哪些
這東東實現(xiàn)了一些常用的功能,今天剛完成,大家多給點建議!
在FF下不完善,有些功能暫時還沒實現(xiàn)!
這也是本人寫的第一個編輯器(處女作哦),做得不好,千萬別丟雞蛋過來...
先閃人!
復制代碼 代碼如下:

/*******************************************
  一款垃圾中的極品FreeEditor(2006-08-22)
  This JavaScript was writen by CXP.
*******************************************/
var colorType;
var currentMode="Design";    //當前模式
var ie=document.all?true:false;
document.onclick=function(){    
}
function format(str,arg){
    if(currentMode!="Design"){    //非設(shè)計模式
        return;
    }
    var obj=window.frames["design"];
    if(!ie){
        var sAlert="";
        switch(str){
            case "Cut":
                sAlert = "你的瀏覽器安全設(shè)置不允許編輯器自動執(zhí)行剪切操作,請使用鍵盤快捷鍵(Ctrl+X)來完成";
                break;
            case "Copy":
                sAlert = "你的瀏覽器安全設(shè)置不允許編輯器自動執(zhí)行拷貝操作,請使用鍵盤快捷鍵(Ctrl+C)來完成";
                break;
            case "Paste":
                sAlert = "你的瀏覽器安全設(shè)置不允許編輯器自動執(zhí)行粘貼操作,請使用鍵盤快捷鍵(Ctrl+V)來完成";
                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();
}

//顯示顏色菜單
function showColorMenu(obj,e){
    if(currentMode!="Design"){    //非設(shè)計模式
        return;
    }
    var target=document.all?e.srcElement:e.target;
    var colorMode=target.getAttribute("title");
    switch(colorMode){
        case "背景顏色":
            colorType="BodyBackColor";
            break;
        case "字體背景顏色":
            colorType="backColor";
            break;
        case "字體顏色":
            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+";dialogTop:"+top+";px");
        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]);
                        //設(shè)置發(fā)光濾鏡,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('待完善!');
            return;
        }    
        FFOpenWidnow("dialog/color.html",263,112,top+25,left);
    }
}

//顯示插入圖片窗口
function showImageMenu(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+top+";px");
        if(path==null){
            return;
        }
        format("insertImage",path);
    }
    else{
        FFOpenWidnow("dialog/image.html",385,100,top+25,left);
    }
}

//顯示插入FLASH窗口
function showFlashMenu(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+(top+138)+";px");
        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('待完善');
        return;
    }
}

//顯示插入Face窗口
function showFaceMenu(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+top+";px");
    }
    else{
        FFOpenWidnow("dialog/face.html",280,180,top+25,left);
    }
}

//顯示fieldSet窗口
function showFieldSetMenu(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+top+";px");
    }
    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 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!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+(top+138)+";");
    }
    else{
        alert('待完善');
    }
}

//顯示插入文件窗口
function showFileMenu(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+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);
}

//插入字幕
function showMarqueeMenu(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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;dialogLeft:"+left+";dialogTop:"+top+";");
    }
    else{
        FFOpenWidnow("dialog/marquee.html",435,220,top+25,left);
    }
}

//插入特殊字符
function showSymbolMenu(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+top+";");
    }
    else{
        FFOpenWidnow("dialog/symbol.html",370,190,top+25,left);
    }
}

//插入文件
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);
}

//插入當前時間
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);
}

//插入引用
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;\">引用:/FONT>BR>/TD>/TR>/TBODY>/TABLE>";
    insertHTML(str);
}

//插入單選框
function insertRadio(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+top+";");
    }
    else{
        FFOpenWidnow("dialog/radio.html",270,125,top+25,left);
    }
}

//插入復選框
function insertCheckBox(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+top+";");
    }
    else{
        FFOpenWidnow("dialog/checkbox.html",270,125,top+25,left);
    }
}

//插入復選框
function insertInputText(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+top+";");
    }
    else{
        FFOpenWidnow("dialog/text.html",270,125,top+25,left);
    }
}

//插入多行文本框
function insertTextArea(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+top+";");
    }
    else{
        FFOpenWidnow("dialog/textarea.html",300,250,top+25,left,true);
    }
}

//插入表格
function insertTable(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+top+";");
    }
    else{
        FFOpenWidnow("dialog/table.html",256,210,top+25,left,true);
    }
}

//插入下拉列表
function insertSelect(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+top+";");
    }
    else{
        FFOpenWidnow("dialog/select.html",380,250,top+25,left);
    }
}

//插入按鈕
function insertButton(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+top+";");
    }
    else{
        FFOpenWidnow("dialog/button.html",236,139,top+25,left);
    }
}

//插入表單
function insertForm(obj){
    if(currentMode!="Design"){    //非設(shè)計模式
        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+";dialogTop:"+top+";");
    }
    else{
        FFOpenWidnow("dialog/form.html",236,139,top+25,left);
    }
}

//設(shè)置模式
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":    //代碼    
            var obj=document.getElementById("textCode");
            var db=window.frames["design"].document.body;
            var HTMLCode=db.innerHTML;
            //防止FF在沒有任何代碼前產(chǎn)生的換行
            if(HTMLCode=="br>\n" || HTMLCode=="br>"){
                HTMLCode="";
            }
            obj.value=HTMLCode;
            cObj.style.display="none";
            obj.style.display="block";
            break;
        case "Design":    //設(shè)計    
            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;    //設(shè)置當前模式
}

//創(chuàng)建鏈接
function createLink(){
    if(currentMode!="Design"){    //非設(shè)計模式
        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);
    }
}

//新建
function newPage(){
    if(currentMode!="Design"){    //非設(shè)計模式
        return;
    }
    window.frames["design"].document.body.innerHTML="";
}

//設(shè)置字體
function setFaceFamily(obj){
    var val=obj.options[obj.selectedIndex].value;
    if(val=="")    return;
    format("fontname",val);
}

//設(shè)置字號
function setFaceSize(obj){
    var val=obj.options[obj.selectedIndex].text;
    if(val=="字號")    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();
}

//插入HTML代碼
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打開窗口
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);         
}

本地下載

標簽:貴港 青海 石嘴山 漯河 運城 巴彥淖爾 黑龍江 新疆

巨人網(wǎng)絡(luò)通訊聲明:本文標題《一款垃圾中的極品HTML編輯器(兼容IE OR FF)》,本文關(guān)鍵詞  一款,垃圾,中的,極品,HTML,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《一款垃圾中的極品HTML編輯器(兼容IE OR FF)》相關(guān)的同類信息!
  • 本頁收集關(guān)于一款垃圾中的極品HTML編輯器(兼容IE OR FF)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章