>  기사  >  웹 프론트엔드  >  QQ Mailbox_javascript 기술을 위한 텍스트 편집기 코드

QQ Mailbox_javascript 기술을 위한 텍스트 편집기 코드

WBOY
WBOY원래의
2016-05-16 19:16:381900검색
edt_color_slt.js
复代码 代码如下:

var _r = "";
var color_table=[
['000000','993300','333300','003300','003366','000080','333399','333333'],
['800000 ','FF6600','808000','008000','008080','0000FF','666699','808080'],
['FF0000','FF9900','99CC00','339966' ,'33CCCC','3366FF','800080','999999'],
['FF00FF','FFCC00','FFFF00','00FF00','00FFFF','00CCFF','993366', 'C0C0C0'],
['FF99CC','FFCC99','FFFF99','CCFFCC','CCFFFF','99CCFF','CC99FF','FFFFFF']
];
함수 a1(obj)
{
    obj.style.border='1px solid #000080';
    obj.style.Background='#FFEEC2';
}
함수 a2(obj)
{
    obj.style.border='1px solid #F6F6F6';
    obj.style.Background='#F6F6F6';
}
함수 paintCell(color) 
{
    //_r  = '';
    _r  = '';
    _r  = "}
function paintRow(color_row) //一行
{    
    _r  ='';
    for (var i = 0,l=color_row.length; i < l;  i) 
    {
        paintCell(color_row[i]);
    }
    _r  ='';
}
function paintTable(b) //表格
{
    _r  ='';
    for (var i = 0,l=b.length; i < l;  i) {
        paintRow(b[i]);
    }
    _r  ='';
}
함수 페인트 큐브() { //大边框    
    _r  = '';
    _r  ='';
    paintTable(color_table);
    _r  =('');
    _r  ='';
    return _r;
}

edt_main.js
复主代码 代码如下:

//html输출
function output(dat,templ,b)
{
    for(var i=0;i    {
      var d = dat[i];
      if(d.join)
      {  
        for(var j=0;j         if (templ[j*2 1])
            templ[j *2 1] = d[j];
        if(b) alert(templ.join(""));
        document.write(templ.join(""));
      }
      else document.write(d); 
    }
}
//B I U
var commFunc = " onmousedown=OnTBMouseDown(this) onmouseover=OnTBMouseOver(this) onmouseout=OnTBMouseOut(this) ";
var commAttr = ' style="position:absolute;clip:direct($ret$);margin:$margin$;" title="$title$" ';
var commHead = ' var commHeadMask = ' var sComm = commHead   commFunc;



//模块结构: 1.基础函数 2.接집정义 3.事件函数 4.HTML编辑框 5.전체局事件绑定 6.전체局变weight声명
//基础函数
함수 GetDoc(win){ return (win?win:window).document;}
함수 S(i,win) {return GetDoc(win).getElementById(i);}
함수 F(sID,win) //sunny for firefox
{    
    if( sID == "" || sID == null ) return null;
    var frame = S(sID,win);
    if( !frame) return null;
    frame.contentWindow?frame.contentWindow:(win?win:window).frames[sID]를 반환합니다.
}
함수 Disp(obj,flag) // 0 隐藏,1显示
{
    if(obj){ obj.style.display = flag?"":"none";}
}
함수 getPosX(e)
{
    var l=e.offsetLeft;
    while(e=e.offsetParent){
        l =e.offsetLeft;
    }
    return l;
}
함수 getPosY(e)
{
    var t=e.offsetTop;
    while(e=e.offsetParent){
        t =e.offsetTop;
    }
    반환 t;
}
String.prototype.trim = function(){
    return this.replace(/(^s*)|(s*$)/g, "");
};

function ExecCmd(type, para){
    LoadPos();
    var f = F("HtmlEditor");
    var sAlert = "";
    if(!gIsIE)
    {
        스위치(유형){
            case "잘라내기":
             sAlert = "你          sAlert不允许编辑器自动执行剪切操작품,请使用键盘快捷键(Ctrl X)来完成";
                휴식;
            사례 '복사'
              sAlert = "你的浏览器安全设置不允许编辑器自动执行拷贝操作,䷽用键盘快捷键(Ctrl C)来完成";
                휴식;
            '붙여넣기':
              sAlert = "你的浏览器安全设置不允许编辑器自动执行粘贴操작,䷽用键盘快捷键(Ctrl V)来完成";
                휴식;
        }
}
if(sAlert != ""){
경고(sAlert);
return
f.focus()
var doc = f. > if(!para)
{
gIsIE?doc.execCommand(type):doc.execCommand(type,false,false)
}
else
{ <入> // 사진을 삽입한 후 사진 뒷면에 포커스를 둡니다.
if (type == "Insertimage" && GISIE) {
var r = doc.selection.createrange ()
}


doc.execCommand(type,false,para)

//이미지 삽입 후 포커스를 뒤에 놓습니다.
if (type == "InsertImage" && gIsIE) {
r.move("문자");
          r.select(); {
return ( ( str.indexOf("://") > 1 ) || (str.indexOf(":\ ") > 1) );
}
function addHyperLink() {
var f = F("HtmlEditor");
//하하, 드디어 mf와 호환되는 메서드를 찾았습니다
var sel = f.document.selection != null ? f.document.selection.createRange( ).text : f.document.getSelection()
if(sel.length>0)
{
var sURL=window.prompt("링크의 대상 주소를 입력하세요(예: http://www.qq.com/):", "http://")
if(sURL != null)
{
if(!IsValidURL(sURL))
{
sURL= "http://" sURL
                                       else
{
alert("선택하세요. 먼저 연결할 텍스트입니다.");
    }
}
function addImage()
{
    var width="380px", height="150px";
    //modify by angusdu 2006-10- 13
    //showModalDialog("uploadImg.htm", window, vfeature)
    var url = "uploadImg.htm";
    if(gIsIE)//IE   
    {
        창. showModalDialog(url,window,"dialogWidth:"   너비   ";dialogHeight:"   높이   ";center:Yes;help:off;status:no;scroll:no");   
    }   
    else 
    {
        window.open(url,window,"width=" width ",height=" height ",menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes");   🎜>    }  
}
function getIEVer(){
    var s = navigator.userAgent;
    if(s.indexOf("MSIE")>-1)
        return parseFloat(s .split(";")[1].replace("MSIE",""));
}
//接口정义
function editor()
{
 this.get_contents = GetContents;
 this.get_plaincontents = GetPlainContents;
 this.put_contents = PutContents;
 this.put_plaincontents = PutPlainContents;
}
함수 PutFirstLine(s) 
{
    return;
}
함수 GetContents() {
    if (curEditor == "source")
        return S("sourceEditor").value;
    HtmlEditor.document.body.innerHTML을 반환합니다.
}
함수 GetPlainContents() {
    //angusdu에 의해 수정 2006-10-11
    var bc = HtmlEditor.document.body;
    if (curEditor == "source")
        bc.innerHTML = S("sourceEditor").value;
    if (bc.innerText != null) {
        return bc.innerText;
    }
    else {
        return bc.textContent;
    }
}
함수 PutContents(contents)
{
    HtmlEditor.document.designMode="on";
    HtmlEditor.document.body.innerHTML = 내용;
    SetDiv();
    S("sourceEditor").value = HtmlEditor.document.body.innerHTML;
}

함수 PutPlainContents(contents)
{
    HtmlEditor.document.designMode="on";
    //angusdu에 의해 수정 2006-10-12
    var bc = HtmlEditor.document.body;
    if (bc.innerText != null) {
        bc.innerText = contents;
    }
    else {
        bc.textContent = contents;
    }
    S("sourceEditor").value = HtmlEditor.document.body.innerHTML;
}
//==========
//事件函数
함수 OnLoad() {
    시도
    {
        if( !window. top.isFireFox)
        {
            F("HtmlEditor").document.designMode="on";
        }
        gLoaded = true;
        SetEditable();
        SetFrameClick();
        document.parentWindow.onclick=HideMenu();
    }catch(e){
    }
    setTimeout(SetColor,100); //--sunny 一开始就画颜color表,那么第一次就不会慢了
}
var editorTxtRange = null;
function SavePos() {
if (document.selection) {
editorTxtRange = F("HtmlEditor").document.selection.createRange()
}
}
function LoadPos() {
if (editorTxtRange) {
editorTxtRange.select()
editorTxtRange = null;
}
}
// 써니 : foreColor 및 backColor는 ColorBoard 팝업만 담당하며 ExecCmd가 필요하지 않습니다(ExecCmd는 현재 흰색을 발생시킵니다)
function OnForeColor(e) {
SavePos()
HideMenu(); > var sColor = DispColorBrd (e)
gSetColorType = "foreColor";
if(gIsIE && gIEVer < 6)
{
ExecCmd(gSetColorType, sColor)
return ;
}
function OnBackColor(e){
SavePos();
HideMenu()
var sColor = DispColorBrd(e,1); )?"backColor":"hilitecolor";
if(gIsIE && gIEVer < 6)
{
ExecCmd(gSetColorType, sColor)
}
return
}

function OnMo(e) {
SavePos();
HideMenu()
var sMo = DispMoBrd(e)
if(gIsIE && gIEVer < 6 && sMo != null)
{
ExecCmd("InsertImage",sMo);
}
return
}
function OnTBMouseOver(obj) {
SetBorderMouse(obj,0);
}
function OnTBMouseDown(obj) {
SetBorderMouse(obj,1);
}
function OnTBMouseOut(obj) {
obj.style.border="none"; 🎜>}
//HTML 편집 상자
function SetEditable(){
var doc = window.frames["HtmlEditor"].document;
doc.designMode="on"; if(!gIsIE) {
                                                                                             > 문서 .onmousemove = function(){
window.onblur();
}
doc.onclick = function(){
//alert("aa")
HideMenu();
};
doc.onkeydown = function()
{
if(frm.event.keyCode == 13 && frm.event.ctrlKey)
{
if(parent. DoCtrlEnter) parent.DoCtrlEnter();
                                                                               ~
function SetDiv()
{

var loc = "" + window.parent.location;
if(loc.indexOf("setting") > 0)
    {
        Disp(document.getElementById("add_pic_id"),0);
/*        removed by angusdu 2006-11-17
        if( !/^
 <\/DIV>/.test(HtmlEditor.document.body.innerHTML))
        {
            HtmlEditor.document.body.innerHTML = HtmlEditor.document.body.innerHTML+"
 
";
        }
*/        S("HtmlEditor").style.height = gIsIE ? "182px" : "188px";
        S("sourceEditor").style.height = "184px";
        S("sourceEditor").style.width = "100%";
        S("htmlbtn").style.marginLeft = "393px";
    }
    else if (loc.indexOf("compose_card") > 0)
    {
        Disp(document.getElementById("add_pic_id"),0);
        S("HtmlEditor").style.height = "181px";
        S("sourceEditor").style.height = "183px";
        S("sourceEditor").style.width = "100%";
    }
    else if(loc.indexOf("compose") > 0)
    {
        if(GetSetting())
        {
            if( HtmlEditor.document.getElementById("QQMail_signature") )
            {
                HtmlEditor.document.getElementById("QQMail_signature").innerHTML = GetSetting().nSignature;
            }

        }
    }

    var doc = F("HtmlEditor").document;
    doc.designMode="on";

    //    HtmlEditor.document.body.innerHTML="
 
" HtmlEditor.document.body.innerHTML;
    if(doc.body)
    {
        doc.body.style. background = '#ffffff';
       doc.body.style.fontSize =
        doc.body.style.fontFamily = 'verdana';
        시도
       {
           if( HtmlEditor.document.body.innerHTML.indexOf("           {
              doc.body.style.margin = '0.5% 0 0 0';
             doc.body.style. background =
                doc.body. style.fontSize = '12px';
               return;
           } 

        }catch(e)
        {}
        doc.body.style.mar 진 = '4px'
> dvForeColor.innerHTML = paintCube();//  dvForeColor.innerHTML;
       //window.top.document.write(dvForeColor.innerHTML);
    }
}
함수 SetMo(){
    var dvMo =S("dvMo")
    dvMo.innerHTML = moCube();
}
//工具栏
//angusdu에 의해 추가 2006-10-13
function showDialog(url, type, feature)   
{   
    if(gIsIE)//IE
    {      
        return window.showModalDialog(url,type,feature);   
    }   
    else   
    {   
        //modelessDialog可以将modal换成dialog=yes   
        기능   ="너비=300, 높이=200, 메뉴바=아니요 ,도구 모음=아니요,위치= 아니요,";   
        기능 ="scrollbars=no,status=no,modal=yes";     
        window.open(url,type,feature);   
    }   

함수 DispColorBrd(e,isBC){
    if(gIEVer<6 && gIsIE){
        var arr = showModalDialog("color_slt.html", "", "font -family:Verdana;  글꼴 크기:12;  상태: 없음;  대화상자 너비:17em");
        if (arr != null) return arr;
        반품;
    }
    var dvForeColor =S("dvForeColor");
    SetColor();
    Disp(dvForeColor,1);
    dvForeColor.style.left = (isBC?bcL:fcL)   "px";
    dvForeColor.style.top = 33   "px";
    dvForeColor.focus();
    e.cancelBubble =true;
    true를 반환합니다.
}
함수 DispMoBrd(e) {
    if(gIEVer<6 && gIsIE){
        var arr = showModalDialog("mo_slt.html", "", "font-family:Verdana; 글꼴 -크기:12; 상태:아니요; 대화상자 너비:265px; 대화상자 높이:190px")
        if (arr != null) return arr;
        반품;
    }
    var dvMo =S("dvMo");
    SetMo();
    Disp(dvMo, 1);
    dvMo.focus();
    e.cancelBubble =true;
    true를 반환합니다.
}
함수 CommCheck(obj,str,func)
{
    if (obj.id == str) {
        return true;
    }
    if(obj.parentNode) {
        return func(obj.parentNode);
    }
    false를 반환합니다.
}
함수 CommObjectCheck(obj, inObj)
{
    if (obj == inObj)
    {
        return true;
    }
    if(obj.parentNode) {
        return CommObjectCheck(obj.parentNode, inObj);
    }
    false를 반환합니다.
}
함수 HideMenu()
{
    var elementTable=["fontface","fontsize","dvForeColor","dvPortrait","divAlign","divList","dvMo"] ;
    for(var i=0;i      Disp(S(elementTable[i]),0);
}
함수 IsInColorBrd(obj){
    return CommCheck(obj,"dvForeColor",IsInColorBrd);
}
함수 IsInFontFaceBrd(obj){
    return CommCheck(obj,"fontface",IsInFontFaceBrd);
}
함수 IsInFontSizeBrd(obj){
    return CommCheck(obj,"fontsize",IsInFontSizeBrd);
}
함수 IsInMoBrd(obj){
    return CommCheck(obj,"dvMo",IsInMoBrd);
}
함수 SetBorderMouse(obj,flag) // 플래그 : 0 over 1 out 
{
    var d = [ 
     ["1px solid #fff","1px solid #fff" ,"1px solid #F3F8FC","1px solid #F3F8FC"]
    ,["1px solid #ccc","1px solid #ccc","1px solid #F3F8FC","1px solid #ccc"]][ 깃발];
    obj.style.borderTop=d[0];
    obj.style.borderRight=d[1];
    obj.style.borderBottom=d[2];
    obj.style.borderLeft=d[3]; <🎜 🎜>}
기능 디스플레이 보드 (요소, displayValue, nleft) {<🎜 🎜> if (giever & lt; = 5.01 && gisie) {
if (element == "fontface") {<🎜 🎜 var sreturnvalue = showmodaldalog ("fontface_slt.html","", "font-family:Verdana; font-size:12; status:no; unadorned:yes; scroll:no; resizing:yes;dialogWidth:112px; dialogHeight:271px");;
            ExecCmd("글꼴 이름",sReturnValue);
        }else if(요소 == "fontsize"){
            var sReturnValue = showModalDialog("fontsize_slt.html","", "font-family:Verdana; font-size:12; status:no; unadorned :예;  스크롤: 아니요;  크기 조정 가능:yes;dialogWidth:130px;  대화상자 높이: 250px");
            ExecCmd("fontsize",sReturnValue);
        }
        반품;
    }
    HideMenu();
    if ( 요소 유형 == "문자열" )
        요소 = S(요소);
    if (요소 == null) 반환;
    element.style.display = displayValue;
    SavePos();
    if(gIsIE){
        var e = 이벤트;
    }else{
        var e = ev;
    }
    var iX = e.clientX;
    var iY = e.clientY;
    Disp(요소,1);
    element.style.left = ((null==nLeft)?(iX-30):nLeft)   "px";
    element.style.top = 33   "px";
    setTimeout("document.getElementById('" element.id "').focus();", 500);
    true를 반환합니다.
}
function SaveEvent(e){
    ev = e;
}
//qqmail增加的函数

function fSetReplyContent(){
    try{
        win.fSetComposeContent(win.gReplyContent);
        window.frames["HtmlEditor"].focus();
    }catch(exp){
        window.setTimeout('fSetReplyContent()',1000);
    }
    win.gReplyContent = null;
}

function setContentType(ContentType)
{
    alert("setContentType");
    if(ContentType=="text")
    {
        PutContents(GetPlainContents());
    }
    window.parent.contenttype.value=ContentType;

}

함수 GetSetting()
{
    시도
    {
        return window.top.GetApp().setting;
    }catch(e)
    {}
    null 반환;
}

함수 BrdBlur() {
    if (gIsIE)
    {
       if (!CommObjectCheck(document.activeElement, event.srcElement)) {
          setTimeout( " LoadPos();HideMenu();", 10);
        }
    }
}

  
//전체局事件绑정
window.onblur =function(){
    if(!gIsIE){
HideMenu();
    }
};
window.onerror = function(){
    true를 반환합니다.
};
document.onmousemove = function(e){
/*    if(gIsIE) var el = event.srcElement;
    else var el = e.target;
    var tdView = S("tdView");
    var tdColorCode = S("tdColorCode");
    var dvForeColor =S("dvForeColor");
    var dvPortrait =S("dvPortrait");
    var fontsize =S("글꼴 크기");
    var fontface =S("글꼴얼굴");
    if(el.tagName == "IMG"){
        시도해 보세요{
            if(IsInColorBrd(el)){
              //tdView.bgColor = el.parentNode.bgColor;
               //tdColorCode.innerHTML = el.parentNode.bgColor
            }
        }catch(e){}
    }else{
        return;
        Disp(dvForeColor,0);
        if(!IsInFontFaceBrd(el)) Disp(fontface,0);
        if(!IsInFontSizeBrd(el)) Disp(fontsize,0);
    }
    */
};
함수 DectoHex(num) {
  var i,j=20,str = "#",N="ABCDEF";
  while(j >= 0) {
    i = (num >> j) ;
    str  = (i>9)?N.charAt(i-10):i;
    j -= 4;
  }
  return str;
}
함수 GetColorFromBg(bg)
{
    var i = bg.indexOf("("),j=bg.indexOf(")"),s=bg.substr(i 1,j-i-1 ).나뉘다(",");
    return DectoHex((s[0]<<16)   (s[1]<<8)   parseInt(s[2]));
}
document.onclick = function(e){
    if(gIsIE) var el = event.srcElement;
    else var el = e.target;
    var dvForeColor =S("dvForeColor");
    var dvPortrait =S("dvPortrait");

    시도해 보세요{

        if(IsInColorBrd(el)){
            //var _bgColor = (el.tagName == "IMG") ? el.parentNode.bgColor : el.bgColor;
            var t = el;
            if( t.tagName != "IMG")    {
               t = t.getElementsByTagName("IMG")[0];
            }
            var _bgColor = t.style.Background "";
            if(_bgColor.indexOf(")") > -1) //firefox
            {
               _bgColor = GetColorFromBg(_bgColor);
            }
            ExecCmd(gSetColorType, _bgColor);
            Disp(dvForeColor,0);
            반품;
        }

        if (IsInMoBrd(el)) {
           var t = el;
            if( t.tagName == "TD")    {
               t = el.getElementsByTagName("IMG")[0];
            }
            if (t.tagName == "IMG" && t.attributes["data"] != null)
            {
               ExecCmd("Ins ertImage", giMoBaseUrl   t.attributes["data "].nodeValue);
                Disp(S("dvMo"), 0);
            }
            반품;
        }
    }catch(e){}

    HideMenu();
    var idTable = [
     "imgFontface","fontface"
    ,"imgFontsize","fontsize"
    ,"imgFontColor","fontsize"
    ,"imgBackColor","dvForeColor"
    ,"imgFace","dvPortrait"
    ,"imgAlign","divAlign"
    ,"imgList","divList"];
    for(var i=0;i      if( idTable[i]==el.id)
      {
        var obj = S(idTable[ 나는 1]);
        obj?(obj.style.display = ""):0;
        휴식;
      }
    }
};
//전체 규모
public_description = 새 편집자;
var gSetColorType = ""; 
var gIsIE = document.all; 
var gIEVer = getIEVer();
var gLoaded = false;
var ev = null;

//增加源代码编辑器...
//add by angusdu 2006-11-21
var curEditor = "Html";
함수 EnableToolBar(플래그) {
    var tools = document.getElementsByName("tool_mask");
    for (i = tools.length - 1; i >= 0; i--) {
        Disp(tools[i], flag);
    }
    if (S("add_pic_id").style.display == "") {
        Disp(S("add_pic_mask_id"), flag);
    }
}
함수 ChangeEditor() {
    if (curEditor == "Html") {
        curEditor = "소스";
        Disp(S("sourceEditor"), 1);
        Disp(S("HtmlEditor"), 0);
        S("sourceEditor").value = HtmlEditor.document.body.innerHTML;
        S("sourceEditor").focus();
        S("htmlbtn").title = "图文编辑";
        S("htmlbtn").innerHTML = "<普通模式>";
        EnableToolBar(1);
    }
    else {
        curEditor = "Html";
        Disp(S("sourceEditor"), 0);
        Disp(S("HtmlEditor"), 1);
        HtmlEditor.document.body.innerHTML = S("sourceEditor").value;
        F("HtmlEditor").focus();
        S("htmlbtn").title = "编辑HTML源码";
        S("htmlbtn").innerHTML = "";
        EnableToolBar(0);
    }
}
function GetEditorType() {
    return (curEditor == "Html" ? "Html" : "source");
}

//增加对编辑器적고도修改接口
var gMinSize = 0;
함수 GetMinSize() {
    if (!gMinSize) {
        gMinSize = parseInt(S("HtmlEditor").style.height);
    }
    return gMinSize;
}
함수 AddElementHeight(el, l) {
    el.style.height = (parseInt(el.style.height)   l)   "px";
}
기능 StretchEditor(bIsLarge, l, frameid) {
    //默认伸缩长島为50px
    l =(l != null ? l : 50);
    var pw = window.parent;
    var pwif = pw.document.getElementsByTagName("iframe");
    for (i = pwif.length - 1; i >= 0; i--) {
        if (pwif[i].id &&(frameid ? pwif[i].id == frameid : GetDoc (pw.frames[pwif[i].id]).body.innerHTML == GetDoc().body.innerHTML)) {
            if (parseInt(S("HtmlEditor").style.height) <= GetMinSize() && !bIsLarge) {
               반환;
            }
            l =(bIsLarge ? l : (-1)*l);
            AddElementHeight(pwif[i], l);
            AddElementHeight(S("HtmlEditor"), l);
            AddElementHeight(S("sourceEditor"), l);
            반품 ;
       }
    }
}


地地下载
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.