一个符号插入器 中用到的js代码


Posted in Javascript onSeptember 04, 2007

/**
 * @author tin555
 */
function setHTML(html) {
    ContentEdit.value = html;
        eWebEditor.document.designMode="On";
        eWebEditor.document.open();
        eWebEditor.document.write(html);
        eWebEditor.document.body.contentEditable="true";
        eWebEditor.document.execCommand("2D-Position",true,true);
        eWebEditor.document.execCommand("MultipleSelection", true, true);
        eWebEditor.document.execCommand("LiveResize", true, true);
        eWebEditor.document.close();
    eWebEditor.document.body.onpaste = onPaste ;
    //eWebEditor.document.body.onhelp = onHelp ;
    //eWebEditor.document.body.ondragend = new Function("return doDragEnd();");
    eWebEditor.document.onkeydown = new Function("return onKeyDown(eWebEditor.event);");
    //eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);");
    //eWebEditor.document.onmousedown = new Function("return onMouseDown();");
    //eWebEditor.document.onmouseup = new Function("return onMouseUp();");
}

function getHTML() {
    var html;

        html = eWebEditor.document.body.innerHTML;

        if ((html.toLowerCase()=="<p> </p>")||(html.toLowerCase()=="<p></p>")){
            html = "";
        }

    return html;
}

function insertHTML(html) {

    eWebEditor.focus();
    if (eWebEditor.document.selection.type.toLowerCase() != "none"){
        eWebEditor.document.selection.clear() ;
    }
    eWebEditor.document.selection.createRange().pasteHTML(html) ; 
}

function appendHTML(html) {
    if (eWebEditor.document.selection.type.toLowerCase() != "none"){
        eWebEditor.document.selection.clear() ;
    }
        eWebEditor.document.body.innerHTML += html;

}

function doDragEnd(){
    var oSelection = eWebEditor.document.selection.createRange();
    var sRangeType = eWebEditor.document.selection.type;
    if (sRangeType == "Control") {
        var oControl = oSelection.item(0);
        if (oControl.tagName == "IMG"){
            oControl.src = FullPath2SetPath(oControl.src);
        }
    }
    if (sRangeType == "Text") {
        var els = eWebEditor.document.body.getElementsByTagName("IMG");
        var oRngTemp = eWebEditor.document.body.createTextRange();
        for(var i=0;i<els.length;i++){
            oRngTemp.moveToElementText(els(i));
            if (oSelection.inRange(oRngTemp)){
                els(i).src = FullPath2SetPath(els(i).src)
            }
        }
    }

    return true;
}

function onKeyDown(event){
    var n_KeyCode = event.keyCode;
        if (n_KeyCode==13){
                    return false;
        }
}

var oResizing = new Object;
function onMouseDown(){
    oResizing.El = null;
    if (eWebEditor.document.selection.type == "Control") {
        var oControlRange = eWebEditor.document.selection.createRange();
        oResizing.El = oControlRange(0);
        oResizing.W = oResizing.El.style.width;
        oResizing.H = oResizing.El.style.height;
    }

    
}

function GetClipboardHTML() {
    var oDiv = document.getElementById("eWebEditor_Temp_HTML");
    oDiv.innerHTML = "" ;
    var oTextRange = document.body.createTextRange() ;
    oTextRange.moveToElementText(oDiv) ;
    oTextRange.execCommand("Paste") ;

    var sData = oDiv.innerHTML ;
    oDiv.innerHTML = "" ;

    return sData ;
}

function cleanAndPaste( html ) {
    html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
    html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
    html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
    html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
    html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
    html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
    html = html.replace(/ /, " " );

    insertHTML( html ) ;
}
function onPaste() {
        var sHTML = GetClipboardHTML() ;
            var re = /<\w[^>]* class="?MsoNormal"?/gi ;
            if ( re.test(sHTML)){
                if ( confirm("你要粘贴的内容好象是从Word中拷出来的,是否要先清除Word格式再粘贴?") ){
                    cleanAndPaste( sHTML ) ;
                    return false ;
                }
                }
}

Javascript 相关文章推荐
2007/12/23更新创意无限,简单实用(javascript log)
Dec 24 Javascript
JQuery 控制内容长度超出规定长度显示省略号
May 23 Javascript
javascript继承机制实例详解
Nov 20 Javascript
Javascript基础教程之变量
Jan 18 Javascript
JavaScript中的分号插入机制详细介绍
Feb 11 Javascript
JS+CSS实现带有碰撞缓冲效果的竖向导航条代码
Sep 15 Javascript
js前端实现多图图片上传预览的两个方法(推荐)
Nov 18 Javascript
遍历json获得数据的几种方法小结
Jan 21 Javascript
hammer.js实现图片手势放大效果
Aug 29 Javascript
web前端vue实现插值文本和输出原始html
Jan 19 Javascript
vue2中使用less简易教程
Mar 27 Javascript
jquery validate 实现动态增加/删除验证规则操作示例
Oct 28 jQuery
【消息提示组件】,兼容IE6/7&amp;&amp;FF2
Sep 04 #Javascript
一个用js实现控制台控件的代码
Sep 04 #Javascript
科讯商业版中用到的ajax空间与分页函数
Sep 02 #Javascript
PNGHandler-借助JS让PNG图在IE下实现透明(包括背景图)
Aug 31 #Javascript
给Javascript数组插入一条记录的代码
Aug 30 #Javascript
用javascript实现给出的盒子的序列是否可连为一矩型
Aug 30 #Javascript
Expandable &quot;Detail&quot; Table Rows
Aug 29 #Javascript
You might like
一个程序下载的管理程序(三)
2006/10/09 PHP
解析PHP函数array_flip()在重复数组元素删除中的作用
2013/06/27 PHP
PHP中使用php5-ffmpeg撷取视频图片实例
2015/01/07 PHP
PHP 文件上传限制问题
2019/09/01 PHP
PHP文件操作简单介绍及函数汇总
2020/12/11 PHP
JavaScript打开word文档的实现代码(c#)
2012/04/16 Javascript
jquery遍历checkbox介绍
2014/02/21 Javascript
javascript最基本的函数汇总
2015/06/25 Javascript
JS中用try catch对代码运行的性能影响分析
2016/12/26 Javascript
微信小程序实现登录页云层漂浮的动画效果
2017/05/05 Javascript
利用pm2部署多个node.js项目的配置教程
2017/10/22 Javascript
vue一个页面实现音乐播放器的示例
2018/02/06 Javascript
详解Angular Forms中自定义ngModel绑定值的方式
2018/12/10 Javascript
深入学习JavaScript 高阶函数
2019/06/11 Javascript
CKeditor4 字体颜色功能配置方法教程
2019/06/26 Javascript
VUE 动态组件的应用案例分析
2019/12/02 Javascript
[34:56]Ti4冒泡赛LGD vs Liquid 1
2014/07/14 DOTA
从零学Python之hello world
2014/05/21 Python
python 接口_从协议到抽象基类详解
2017/08/24 Python
python基于http下载视频或音频
2018/06/20 Python
Python按钮的响应事件详解
2019/03/04 Python
pandas 层次化索引的实现方法
2019/07/06 Python
选择Python写网络爬虫的优势和理由
2019/07/07 Python
django实现用户注册实例讲解
2019/10/30 Python
Python Des加密解密如何实现软件注册码机器码
2020/01/08 Python
django orm模块中的 is_delete用法
2020/05/20 Python
numpy 矩阵形状调整:拉伸、变成一位数组的实例
2020/06/18 Python
Python常驻任务实现接收外界参数代码解析
2020/07/21 Python
canvas像素点操作之视频绿幕抠图
2018/09/11 HTML / CSS
粉红色的鲸鱼:Vineyard Vines
2018/02/17 全球购物
Happy Socks英国官网:购买五颜六色的袜子
2020/11/03 全球购物
资源环境与城市管理专业推荐信
2013/11/30 职场文书
广告宣传策划方案
2014/05/21 职场文书
2015年园林绿化工作总结
2015/05/23 职场文书
SQL 尚未定义空闲 CPU 条件 - OnIdle 作业计划将不起任何作用
2021/06/30 SQL Server
vue实现登陆页面开发实践
2022/05/30 Vue.js