一个符号插入器 中用到的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 相关文章推荐
js获取元素在浏览器中的绝对位置
Jul 24 Javascript
jQuery不间断滚动效果(模拟百度新闻支持文字/图片/垂直滚动)
Feb 05 Javascript
深入探秘jquery瀑布流的实现
Jan 30 Javascript
基于jQuery Tipso插件实现消息提示框特效
Mar 16 Javascript
JS随机洗牌算法之数组随机排序
Mar 23 Javascript
onmouseover事件和onmouseout事件全面理解
Aug 15 Javascript
D3.js封装文本实现自动换行和旋转平移等功能
Oct 14 Javascript
微信小程序scroll-view实现滚动穿透和阻止滚动的方法
Aug 20 Javascript
Puppet的一些技巧
Sep 17 Javascript
使用apifm-wxapi快速开发小程序过程详解
Aug 05 Javascript
如何利用React实现图片识别App
Feb 18 Javascript
vue生命周期钩子函数以及触发时机
Apr 26 Vue.js
【消息提示组件】,兼容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制作静态网站的模板框架(三)
2006/10/09 PHP
php中的实现trim函数代码
2007/03/19 PHP
Yii2 rbac权限控制之rule教程详解
2016/06/23 PHP
PHP5.5安装PHPRedis扩展及连接测试方法
2017/01/22 PHP
小程序微信退款功能实现方法详解【基于thinkPHP】
2019/05/05 PHP
PHP 实现重载
2021/03/09 PHP
可以显示单图片,多图片ajax请求的ThickBox3.1类下载
2007/12/23 Javascript
用tip解决Ext列宽度不够的问题
2008/12/13 Javascript
获取内联和链接中的样式(js代码)
2013/04/11 Javascript
jquery ajax实现下拉框三级无刷新联动,且保存保持选中值状态
2013/10/29 Javascript
JavaScript字符串常用类使用方法汇总
2015/04/14 Javascript
js显示当前日期时间和星期几
2015/10/22 Javascript
angular2路由切换改变页面title的示例代码
2017/08/23 Javascript
用nodejs实现json和jsonp服务的方法
2017/08/25 NodeJs
Vue.js 中的 v-model 指令及绑定表单元素的方法
2018/12/03 Javascript
详解一个基于套接字实现长连接的express
2019/03/28 Javascript
vue实现条件叠加搜索的解决方法
2019/05/28 Javascript
es6中reduce的基本使用方法
2019/09/10 Javascript
[04:02]2014DOTA2国际邀请赛 BBC每日综述中国战队将再度登顶
2014/07/21 DOTA
[03:39]这就是刀塔,我们是冠军!燃情短片讲述我们的DOTA故事
2019/07/02 DOTA
Python实现向服务器请求压缩数据及解压缩数据的方法示例
2017/06/09 Python
python获取微信小程序手机号并绑定遇到的坑
2018/11/19 Python
Django ImageFiled上传照片并显示的方法
2019/07/28 Python
pycharm 批量修改变量名称的方法
2019/08/01 Python
Django中的FBV和CBV用法详解
2019/09/15 Python
Python3实现mysql连接和数据框的形成(实例代码)
2020/01/17 Python
python+selenium爬取微博热搜存入Mysql的实现方法
2021/01/27 Python
献爱心大型公益活动策划方案
2014/09/15 职场文书
党员自我评议个人对照检查材料
2014/09/16 职场文书
升职自荐信怎么写
2015/03/05 职场文书
2015年学生会主席工作总结
2015/04/21 职场文书
反腐倡廉学习心得体会范文
2015/08/15 职场文书
解决Golang中ResponseWriter的一个坑
2021/04/27 Golang
go语言中http超时引发的事故解决
2021/06/02 Golang
使用Springboot实现健身房管理系统
2021/07/01 Java/Android
vue elementUI批量上传文件
2022/04/26 Vue.js