一个符号插入器 中用到的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 相关文章推荐
Google韩国首页图标动画效果
Aug 26 Javascript
JavaScript 编写匿名函数的几种方法
Feb 21 Javascript
jQuery常用操作方法及常用函数总结
Jun 19 Javascript
js实现编辑div节点名称的方法
Dec 17 Javascript
JavaScript常用脚本汇总(三)
Mar 04 Javascript
easyui-edatagrid.js实现回车键结束编辑功能的实例
Apr 12 Javascript
使用 Node.js 开发资讯爬虫流程
Jan 07 Javascript
JS实现匀速与减速缓慢运动的动画效果封装示例
Aug 27 Javascript
js脚本中执行java后台代码方法解析
Oct 11 Javascript
Vue 实现从文件中获取文本信息的方法详解
Oct 16 Javascript
Node.js 深度调试方法解析
Jul 28 Javascript
JQuery基于FormData异步提交数据文件
Sep 01 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
PHP 数组教程 定义数组
2009/10/23 PHP
php中$this-&amp;gt;含义分析
2009/11/29 PHP
PHP-CGI进程CPU 100% 与 file_get_contents 函数的关系分析
2011/08/15 PHP
php实现的短网址算法分享
2014/06/20 PHP
php实现递归抓取网页类实例
2015/04/03 PHP
PHP+HTML+JavaScript+Css实现简单爬虫开发
2016/03/28 PHP
jqTransform form表单美化插件使用方法
2012/07/05 Javascript
浅析js中取绝对值的2种方法
2013/07/09 Javascript
js倒计时小程序
2013/11/05 Javascript
5个数组Array方法: indexOf、filter、forEach、map、reduce使用实例
2015/01/29 Javascript
js实现的牛顿摆效果
2015/03/31 Javascript
javascript正则表达式基础知识入门
2015/04/20 Javascript
浅谈JS原生Ajax,GET和POST
2016/06/08 Javascript
使用vue.js制作分页组件
2016/06/27 Javascript
jQuery EasyUi 验证功能实例解析
2017/01/06 Javascript
详解基于angular路由的requireJs按需加载js
2017/01/20 Javascript
js实现动态添加上传文件页面
2018/10/22 Javascript
如何将百度地图包装成Vue的组件的方法步骤
2019/02/12 Javascript
jQuery动态生成的元素绑定事件操作实例分析
2019/05/04 jQuery
详解JavaScript数据类型和判断方法
2020/09/04 Javascript
[01:09:19]DOTA2-DPC中国联赛 正赛 VG vs Aster BO3 第二场 2月28日
2021/03/11 DOTA
Python3实现发送QQ邮件功能(html)
2017/12/15 Python
Python Django给admin添加Action的方法实例详解
2019/04/29 Python
Python中@property的理解和使用示例
2019/06/11 Python
pytorch 自定义卷积核进行卷积操作方式
2019/12/30 Python
PyTorch 普通卷积和空洞卷积实例
2020/01/07 Python
python如何使用Redis构建分布式锁
2020/01/16 Python
python输出结果刷新及进度条的实现操作
2020/07/13 Python
Python:__eq__和__str__函数的使用示例
2020/09/26 Python
如何基于Python爬虫爬取美团酒店信息
2020/11/03 Python
美国最大的珠宝商之一:Littman Jewelers
2016/11/13 全球购物
欧姆龙医疗欧洲有限公司:Omron Healthcare Europe B.V
2020/06/13 全球购物
复制别人的成功真的会成功吗?
2019/10/17 职场文书
导游词之沈阳清昭陵
2019/12/28 职场文书
血轮眼轮回眼特效 html+css
2021/03/31 HTML / CSS
MySQL 数据丢失排查案例
2021/05/08 MySQL