| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989 | /*编辑使用区域*/Namespace.register("U.D.E");//#region 编辑区域/*** 编辑器区域初始化设置全局变量** @param   {window} window* @param   {element} 当前编辑框元素* @param   {object} 编辑传参对象-----------[CB] 回调函数-----------[TF] 识别id*/U.D.E.setVariable = function (id, cursor) {    var _cursors = U.D.E.SORange;    if (id) {        //设置监视前进后退变化使用 函数有问题以后要修改        _cursors["OAT"][id] = [{ "OR": new cursor.init(cursor, false), "C": ""}]; //创建前进后退处理        _cursors["OAT"][id].l = 0; //当前前进后退所在的位置        _cursors["OE"][id] = cursor; //保存当前光标变量    }}/*** 初始化编辑区域 判断光标是否存在、创建光标、写入全局光标变量、监听键盘** @param   {window} window* @param   {element} 当前编辑框元素* @param   {object} 编辑传参对象-----------[CB] 回调函数-----------[TF] 识别id*/U.D.E.GetSelectionRange = function (win, el, obj) {    try {        var _id = obj["TF"], //对该光标的唯一标识        _cursors = U.D.E.SORange, //所有使用编辑光标        _cursor = _cursors["OE"][_id]; //获取已经创建的光标功能区        //已经创建直接刷新光标        if (_id && _cursor) {            //_cursor = _cursor.setVariable(win, win.document, el, obj); //光标存在,把光标的变量重新赋值            _cursor.CreateR(); //重新创建光标        }        else { //创建一个新的光标控制            _cursor = new U.D.E.SelectionRange(win, win.document, el, obj).CreateR(true); //创建光标            //设置光标的全局变量            U.D.E.setVariable(_id, _cursor); //全局变量初始化            //把键盘事件和光标一起绑定,因为要使用光标的地方全部都要监控键盘输入输出,所以绑定在一起,如果有机会,可以独立。            //事件监视使用 处理页面在选择 输入 点击的时候的处理            U.D.E.KeyboardBinding(_cursor.PSO, _cursor); //键盘绑定处理        }        return _cursor;    }    catch (e) { return false; }}/*** 键盘绑定处理** @param   {element} window* @param   {U.D.E.SelectionRange} 光标对象*/U.D.E.KeyboardBinding = function (el, cursor) {    $(el).bind({        "keydown": U.M.apply(cursor, cursor.GetKE), //键盘点击        "keyup": U.M.apply(cursor, cursor.CLKU), //键盘结束处理        "copy": U.M.apply(cursor, cursor.Copy), //键盘结束处理        "paste": U.M.apply(cursor, cursor.Paste), //键盘结束处理        "cut": U.M.apply(cursor, cursor.Cut), //键盘结束处理        //selectstart: U.M.apply(_URE, _URE.selectAll), //页面选择处理函数        "click": U.M.apply(cursor, cursor.CLMU) //点击处理    });}/*** 初始化编辑区域 光标的前进后退有问题 需要用其他的解决方案** @param   {window} 触发的域* @param   {document} 触发的域下的document* @param   {element} 当前编辑元素* @param   {object} 传参-----------[CB] 回调函数-----------[TF] 识别id* @param   {element} 上级不变的元素*/U.D.E.SelectionRange = function (UW, UD, UDOD, UDE) {    this.setVariable(UW, UD, UDOD, UDE);}///**//* 获取可编辑的元素//*//* @param   {window} 触发的域//*///U.D.E.SelectionRange.GetEditElement = function () {//    //获取可编辑对象//    while (_UCE && ((_UTF = _UCE.tagName.toLocaleLowerCase()) == "p" || _UCE.contentEditable != "true") && _UTF != "body") {//        _UCE = _UCE.parentNode;//    }//    this.PSO = _UCE; //设置可编辑区域值//}//使用方法集U.D.E.SORange = U.D.E.SelectionRange.prototype = {    OAT: {}, //前进后退使用集    OE: {}, //记录创建光标值    setVariable: function (UW, UD, UDOD, UDE) {        this.CW = UW; //编辑的windows层次        this.CD = UD; //编辑的document        this.SO = UDOD || this.Parent(); //编辑区域        this.PSO = $(UDOD).Parent({ "contentEditable": "true" }); //编辑区域的父亲        this.CB = UDE["CB"]; //编辑的回调函数        this.TF = UDE["TF"]; //创建光标的唯一识别码        this.TIM = [];        this.S = null;        this.R = null;        this.J = null;        this.TR = null;        this.BCB = null;        this.FCB = null;        this.Dectect = U.D.E.codeDetect();        this.CTH = "";    },    /**    * 创建一个光标记载查看    *    * @param   {boolean} 创建对象时候时候聚焦对象    */    CreateR: function (UTF) {        //  U.Ut.AddObj(this, { SO: this.SO || this.Parent(), PSO: this.SO }); //设置当前元素和上级元素        //变量定义        var _b,        _win = this.CW, //当前域        _doc = this.CD; //域下的document对象        //设置加载对象        try {            if (_win.getSelection) { //html5                 U.Ut.AddObj(this, { S: _win.getSelection(), TR: _doc.createRange() }); //添加可编辑对象                if (UTF !== false && this.SO) { //聚焦到制定的位置                    if (this.SO.focus && (!this.S.rangeCount || !U.M.EISE(this.PSO, this.Parent(this.S.getRangeAt(0))))) {  //判断对象是否在元素内                        this.SO.focus(); //当前对象聚焦                        this.QX(this.getLen(this.SO), this.getLen(this.SO), this.SO); //设置对象在当前位置                        this.S = _win.getSelection(); //设置选择区对象                    }                }                this.R = this.S.rangeCount ? this.S.getRangeAt(0) : this.R || _doc.createRange(); //选取对象            }            else { //老ie                U.Ut.AddObj(this, { //光标选区的创建                    S: _doc.selection, //选取对象                    R: _doc.selection.createRange(), //光标对象                    TR: document.body.createTextRange() //输入光标对象                });                if ((_UTF = (UTF !== false && this.SO && !U.M.EISE(this.PSO, this.Parent(this.R)))) || UTF) { //需要插入光标                    if (_UTF) { //是否聚焦到指定位置中                        this.R = this.QX(this.getLen(this.SO), this.getLen(this.SO), this.SO) || this.R; //设置选取位置                    }                    else { //当前元素聚焦                        this.SO.focus();                        this.Replace(""); //写入光标                    }                    this.S = _doc.selection; //插入光标                }            }        } catch (e) { }        return this;    },    /**    * 初始化编辑区域    *    * @param   {object} 编辑对象    -----------[CW] 当前域    -----------[CD] 当前域下的doc    -----------[SO] 对象    -----------[{}]     -------[TF] 识别id    -------[CB] 回调函数    -----------[PSO] 编辑的上级元素    * @param   {boolean} 变化的数组 实现数组 0 、 1 切换    */    init: function (URE, UTF) { //创建光标监视区域        this.setVariable(URE["CW"], URE["CD"], URE["SO"], { "TF": URE["TF"], "CB": URE["CB"] }, URE["PSO"])        this.CreateR(UTF);    },    //#region 获取指定编辑元素    /**    * 初始化编辑区域    *    * @param   {object} 光标对象     * @param   {document} 是否连text也获取    */    Parent: function (UDR, UTF, NT) { //获取当前光标所在的区域        if (UDR = UDR || this.R) { //光标存在使用             if (UDR.parentElement || UDR.commonParentElement) { //老IE获取                return (UDR.parentElement || UDR.commonParentElement)(); //上级元素 选择元素区域            }            else { //统一使用                var _UDOD = UDR.commonAncestorContainer;                if (NT) {                    return UDR.endContainer.parentElement;                }                return ((_UDOD.nodeName == "#text" && UTF) ? _UDOD.parentNode : _UDOD);            }        }    },    /**    * 获取当前选中的元素    */    Element: function (UDR) {        if (UDR = UDR || this.R) { //光标存在使用            if (UDR.parentElement || UDR.commonParentElement) { //老IE获取                return (UDR.parentElement || UDR.commonParentElement)();            }            else { //统一使用                return UDR.commonAncestorContainer;            }        }    },    /**    * 获取父亲层    *    * @param   {object} 光标对象     * @param   {document} 是否连text也获取    */    IParent: function (UTH, UDR) {        UTH = U.Ut.isUndefined(UTH) ? this.GetSelectedHtml() : UTH; //选中的蚊子        var _UDPD,            _UDOD = this.Parent(UDR),            _UDTD = $$("div", { "innerHTML": UTH });        while (_UDOD && _UDOD.innerText && (_UDTD.innerText == _UDOD.innerText) && (_UDOD != this.PSO) && (_UDPD = _UDOD)) {            _UDOD = _UDOD.parentNode;        }        return _UDPD;    },    //#endregion    /**    * 文字替换 同时也是插入文字的方法 这里用在 设置文字大小 字号等..    *    * @param   {string} 需要插入或者替换的文字     * @param   {object} range光标对象    * @param   {boolean} 是否聚焦到最后    * @return   {object} 光标编辑对象    */    Replace: function (UTS, URD, UTF) { //光标选区文字替换        var i, _userid, _UDOD, _UDCD, _UDTD, _UDSD, _UDE, _UTF, _UST = "",            _UTH = UTS == null ? UTS : (UTS.outerHTML || UTS); //需要插入或者替换的文字        URD = URD || this.R; //光标对象        if (URD && UTS != null) { //判断是否具有光标和替换的文字7            _UDE = [];            _UDOD = this.Parent(URD); //获取上级元素            _userid = "R" + Guid.newGuid();            _UDTD = $$("span", { "id": _userid, "innerHTML": _UTH }); //生成需要写入的数据元素            _UTF = this.GetSelectedText(); //当前需要替换的文字            if (_UDOD != document) { //判断处理的编辑区域是否在原来的编辑框里  U.M.EISE(this.PSO, _UDOD) &&                if (window.getSelection) { //html5                    _UDTD = URD.createContextualFragment(_UTH); //创建选取                    (_UDOD.innerText == this.GetSelectedText() && _UDOD.innerText) && (URD.selectNodeContents(_UDOD)); //文字聚焦到当前选取中                    URD.deleteContents(); //移除文字                    this.S.removeAllRanges(); //移除选取                    //                    if (_UDTD.children[0]) {                    //                        URD.selectNodeContents(_UDTD.children[0])                    //                    }                    URD.insertNode(_UDTD); //插入选择的蚊子                    //                    if ($("#" + _userid).Child()[0]) {                    //                        URD.selectNodeContents($("#" + _userid).Child()[0]);                    //                        $("#" + _userid)[0].outerHTML = $("#" + _userid)[0].innerHTML;                    //                    }                    if (UTF) {                        URD.collapse(false);                    }                    this.S.addRange(URD); //把替换的文章添加到当前指定的选取中                }                else { //老IE兼容                    if (!_UDTD.innerText && !$("div", _UDTD).length && !$("div", this.PSO).length) { //无输入的内容 直接新建换行内容符号 div                        this.SL($$("div", {}, this.PSO)); //添加输入的div                        _UST = _UDTD.innerHTML; //设置使用的值                    }                    else { //获取需要插入的内容                        _UST = (_UDTD.innerHTML && !UTF) ? _UDTD.outerHTML : _UDTD.innerHTML;                    }                    URD.select(); //选取聚焦                    URD.pasteHTML(""); //添加选取文字                    URD.pasteHTML(_UST); //添加选取文字                    if (UTF || !_UDTD.innerHTML) { URD.collapse(false); } //聚焦到最后                    else { //选取聚焦                        _UDTD = $("span", this.Parent())[_UDTD.id]; //选择元素                        _UDTD.outerHTML = _UDTD.innerHTML; //替换焦点                        this.R.select(); //元素聚焦                    }                }                this.CreateR(); //选择成功后 重新生成选取 光标                //U.Ut.AddObj(this, { "SO": this.Parent(), "TR": URD }); //设置对象和光标            }        }        return this;    },    //#region 元素选择选区处理    /**    *  指定的位置创建光标选区    *    * @param   {number} 文字插入到指定位置     * @param   {number} range光标对象    * @param   {element} 是否聚焦到最后    * @return   {object} 光标编辑对象    */    QX: function (US, UE, UDOD) { //        try {            var _UOE, _UTE,                _UD = this.CD; //使用域下的document            UDOD = UDOD || this.Parent(); //获取元素的上一级             if (window.getSelection) { //Html5                this.S = (this.S || this.CW.getSelection());                (!this.S.rangeCount) && (this.CW.focus(), UDOD.focus(),                     this.R = this.S.getRangeAt(0));  //获取选区                if (this.R.commonAncestorContainer != document) { //指定的位置可编辑可聚焦                    _UOE = document.createRange();                    _UOE.selectNode((UDOD)); //聚焦制定的位置                    US = US == null ? _UOE.startOffset : US == -1 ? _UOE.endOffset : US;                    UE = UE == null ? _UOE.endOffset : UE == -1 ? _UOE.endOffset : UE; //获取位置                    try {                        _UOE.setStart((UDOD || this.R.startContainer), US);                        _UOE.setEnd((UDOD || this.R.endContainer), UE);                    }                    catch (e) {                        _UOE.setStart(this.R.startContainer, US);                        _UOE.setEnd(this.R.endContainer, UE);                    }                    this.S.removeAllRanges();                    this.S.addRange(_UOE); //设置位置                }            }            else { //老IE使用                 if (U.Ut.isNumber(US)) {                    _UOE = _UD.body.createTextRange();                    _UTE = _UD.body.createTextRange();                    _UOE.moveToElementText(UDOD);                    (U.Ut.isNumber(US)) && (_UOE.moveStart("character", US), _UTE.moveToElementText(UDOD), _UTE.moveStart("character", UE), _UOE.setEndPoint("EndToStart", _UTE));                    (US !== UE) && (_UOE.select());                }                else { this.R.select(); }            }            return _UOE;        }        catch (e) { return false; }    },    /**    *  移动光标处理    *    * @param   {number} 需要移动的范围     * @return   {object} 光标编辑对象    */    moveRange: function (US) {        this.CreateR(false);        if (window.getSelection) { //Html5            try {                this.TR.setStart(this.R.startContainer, this.R.startOffset + US);                this.TR.setEnd(this.R.endContainer, this.R.endOffset);            }            catch (e) { }            this.S.removeAllRanges();            this.S.addRange(this.TR); //设置位置        }        else { //老IE使用             this.TR.moveToElementText(this.Parent());            _UOE.moveStart("character", US);        }        this.CreateR();    },    /**    *  选择选中区域元素    *    */    GetSE: function () {        if (window.getSelection) { //HTML5            _USE = this.CW.getSelection();            _URE = _USE.rangeCount ? _USE.getRangeAt(0) : this.R;            (UDR) && (_URE.setStart(UDR.endContainer, UDR.endOffset));        }        else {//老IE兼容            _USE = document.selection;            _URE = document.selection.createRange();            (UDR) && (_URE.setEndPoint("EndToEnd", UDR));        }    },    /**    *  设定元素为选择元素    *    * @param   {element} 文字插入到指定位置     * @param   {object} range光标对象    * @return   {object} 光标编辑对象    */    SL: function (UDOD, UDR) {        UDOD = UDOD || this.SO;        if (window.getSelection) {  //html5选择              (!UDR) && (UDR = document.createRange());            UDR.selectNodeContents(UDOD);            this.S = this.S || this.CW.getSelection();            this.S.removeAllRanges();            this.S.addRange(UDR);            this.R = UDR;        }        else { //老IE选择元素             (!UDR) && (UDR = document.body.createTextRange(), UDR.moveToElementText(UDOD));            UDR.select();        }        // (!UDR) && (UDR = document.body.createTextRange(), UDR.moveToElementText(UDOD)); UDR.collapse(false); UDR.select();         return this;    },    //#endregion    //#region 获取文字    /**    *  获取当前选区的html    *    * @param   {object} range对象     */    GetSelectedHtml: function (UDR) {        if ((UDR = UDR || this.R)) {            var i, _UDAD, _UDCD, _URE, UST = "",            _UIE = 1;            if (UDR.cloneContents) { //判断是否                var _UDOD = $$("div");                _UDOD.appendChild(UDR.cloneContents());                UST = _UDOD.innerHTML;                _UDCD = $($$("div", { "innerHTML": UST })).Nodes();                UST = "";                for (i = 0; i < _UDCD.length; i++) {                    UST += _UDCD[i].outerHTML ? _UDCD[i].outerHTML : "<span>" + _UDCD[i].data + "</span>";                }            }            else if (UDR.commonParentElement) {                UST = UDR.commonParentElement();                UST = UST.outerHTML || UST.innerHTML || UST.value || "";            }            else {                UST = UDR.htmlText;                _UDAD = $$("div", { "innerHTML": UDR.htmlText }).childNodes;                if (_UDAD.length) {                    UST = ""; _URE = UDR.duplicate();                    _URE.moveStart("character", -1);                    _UDCD = $($$("div", { "innerHTML": _URE.htmlText })).Nodes();                    if ((_UDCD.length == _UDAD.length && _UDAD[0].outerHTML == _UDCD[0].outerHTML) || (_UDCD.length != _UDAD.length && _URE.htmlText != UDR.htmlText)) {                        UST = $$("div", { "innerHTML": _UDAD[0].outerHTML || _UDAD[0].nodeValue || _UDAD[0].data || _UDAD[0].text }).innerHTML;                    }                    else {                        UST = ($($$("div", { "innerHTML": _UDAD[0].innerHTML })).Child().length ? _UDAD[0].innerHTML : (_UDAD[0].innerHTML || _UDAD[0].nodeValue || _UDAD[0].data || _UDAD[0].text ? $$("span", { "innerHTML": _UDAD[0].innerHTML || _UDAD[0].nodeValue || _UDAD[0].data || _UDAD[0].text }).outerHTML : ""));                    }                    if (_UDAD.length > 1) {                        for (i = 1; i < _UDAD.length - 1; i++) {                            UST += _UDAD[i].outerHTML || _UDAD[i].nodeValue || _UDAD[i].data || _UDAD[i].text;                        }                        _URE = UDR.duplicate(); _URE.moveEnd("character", 1);                        _UDCD = $($$("div", { "innerHTML": _URE.htmlText })).Child();                        if ((_UDCD.length == _UDAD.length && _UDAD[_UDAD.length - 1].outerHTML == _UDCD[_UDCD.length - 1].outerHTML) || (_UDCD.length != _UDAD.length && _URE.htmlText != UDR.htmlText)) {                            UST += $$("div", { "innerHTML": _UDAD[_UDAD.length - 1].outerHTML || _UDAD[_UDAD.length - 1].nodeValue || _UDAD[_UDAD.length - 1].data || _UDAD[_UDAD.length - 1].text }).innerHTML;                        }                        else {                            UST += ($($$("div", { "innerHTML": _UDAD[_UDAD.length - 1].innerHTML })).Child().length ? _UDAD[_UDAD.length - 1].innerHTML : _UDAD[_UDAD.length - 1].innerHTML || _UDAD[_UDAD.length - 1].nodeValue || _UDAD[_UDAD.length - 1].data || _UDAD[_UDAD.length - 1].text ? $$("span", { "innerHTML": _UDAD[_UDAD.length - 1].innerHTML || _UDAD[_UDAD.length - 1].nodeValue || _UDAD[_UDAD.length - 1].data || _UDAD[_UDAD.length - 1].text }).outerHTML : "");                        }                    }                }            }            return UST;        }    },    /**    *  设定元素为选择元素    *    * @param   {element} 获取当前光标选区的text     */    GetSelectedText: function (UDR) {        return (UDR = UDR || this.R) == null || UDR.add ? null : UDR.text != undefined ? UDR.text : (this.S.toString()); //全兼容的获取    },    //#endregion    //#region 键盘操作处理    /**    *  设定元素为选择元素    *    * @param   {string}      */    GetKE: function (UTF) { //输入处理        var i, _UCE, _UDE, _UKE, _UL, _UDSD,                    _UTP = this.TF;        UTF = UTF && U.Ut.isString(UTF) ? UTF : this.Dectect.getValue(); //获取键盘的值         switch (UTF) {            case "redo": //前进                //                U.M.StopDefault();                //                _UDE = this.OAT[_UTP];                //                _UL = _UDE.l;                //                _UKE = _UDE[_UL];   //使用值                //                for (i = _UL; i < _UDE.length; i++) {                //                    if (_UDE[i].C) {                //                        _UCE = _UDE[i]; _UDE.l = i; break;                //                    }                //                } //获取使用列                //                if (_UCE) {                //                    if (!window.getSelection) { //光标位置使用                //                        try {                //                            _UKE = _UKE.OR.R;                //                            if (_UCE.P.boundingLeft || _UCE.P.boundingTop) {                //                                _UCE.OR.R.moveToPoint(_UCE.P.boundingLeft, _UCE.P.boundingTop);                //                            };                //                        }                //                        catch (e) {                //                            try {                //                                if (_UCE.OR.R.boundingTop < _UCE.P.boundingTop) {                //                                    _UCE.OR.R.moveToPoint(_UKE.boundingLeft + _UKE.boundingWidth - 1, _UKE.boundingTop);                //                                }                //                            } catch (e) { }                //                        }                //                    }                //                    _UCE.OR.Replace(_UCE.C); _UCE.C = "";                //                }                break;            case "undo": //后退                //                                (this.TIM[1]) && (this.TIM[1]());                //                                _UDE = this.OAT[_UTP];                //                                _UL = _UDE.l;                //                                _UCE = _UDE[_UL];                //                                U.M.StopDefault();                //                                if (!_UCE.OR.GetSelectedText()) {                //                                    if (_UL > 0) {                //                                        _UL = (_UDE.l -= 1);                //                                        _UCE = _UDE[_UL];                //                                    } else { _UCE = null; }                //                                }                //                                if (_UCE) {                //                                    _UCE.C = _UCE.C || _UCE.OR.GetSelectedHtml();                //                                    _UCE.OR.Replace("");                //                                }                break;            default:                //                if (U.Ut.isNumber(UTF[0])) { //是否为数字                //                    if (UTF[0] == 9) { //tab处理                //                        U.M.StopDefault();                //                        this.CreateR().Replace(" ", null, true); //插入tag值                //                    }                //                    //                    else if (!(UTF[1] || UTF[2]) && UTF[4].length < 2) { //需要重新记录                //                    //                        _UDE = this.OAT[_UTP];                //                    //                        if (_UDE.l != _UDE.length - 1) {                //                    //                            _UDE[_UDE.l].C = "";                //                    //                            _UDE.splice(_UDE.l + 1, _UDE.length);                //                    //                        }                //                    //                        else {                //                    //                            this.ADQJ();                //                    //                        }                //                    //                    }                //                    else if (!(UTF[1] || UTF[2]) && (UTF[0] == 13 || UTF[0] == 8 || UTF[0] == 3 || (UTF[0] > 32 && UTF[0] < 40) || UTF[0] == 46 || (UTF[0] > 63231 && UTF[0] < 63236) || (UTF[0] > 63272 && UTF[0] < 63278 && UTF[0] != 63274)) && this.TF) { //特殊键处理                 //                    }                //                }                break;        }        if (this.CB && this.CB(U.Ut.isString(UTF) ? UTF : UTF[4], [this.Parent()], this, UTF, window) === 1) { //回调设置            //  U.M.StopDefault();        }    },    /**    *  键盘输入输出处理    *    */    CLKU: function () {        var _UDPD = this.PSO,                _UTF = this.Dectect.getValue(); //获取键盘属性值        //        //后退键的处理        //        if (_UTF[4] == "Backspace" && !$(_UDPD).Child().length) { } //后退键处理        //        //方向输出键         //        else if (!(_UTF[1] || _UTF[2]) && (_UTF[0] == 13 || _UTF[0] == 8 || _UTF[0] == 3 || (_UTF[0] > 32 && _UTF[0] < 40) || _UTF[0] == 46 || (_UTF[0] > 63231 && _UTF[0] < 63236) || (_UTF[0] > 63272 && _UTF[0] < 63278 && _UTF[0] != 63274))) {        //            this.ADQJS("");        //        }        //执行回调使用        if ((this.CB) && (this.CB("UP", [this.Parent()], this, _UTF, window) == 1)) {            //    U.M.StopDefault();        }        //this.CreateR(false); //创建记录    },    //#endregion    /**    *  点击时候创建光标    *    * @param   {element}   需要复制到的元素    */    CLMU: function () {        // this.ADQJS("");        this.CreateR(); //重新记录光标        var mb = window.parent.document.getElementsByClassName("UD_SYF_S UD_SYKO")[window.parent.document.getElementsByClassName("UD_SYF_S UD_SYKO").length - 1];        // UDPD = $(this.Parent(null, true,true)).Parent({ "tagName": "DIV" }); //获取当前行的元素        _UTH = this.getBoundingClientRect(); //获取光标位置和大小        // U.Alert(_UTH.height);        // window.parent.document.getElementById("UD_Word"+U.Word.TF.fileinfo.UserDirectoryParentID).children[2].children[0].children[0].children[0].children[7].children[0].value=this.Parent(null, true,true).style.fontSize||"10.5pt";        mb.children[2].children[0].children[0].children[0].children[7].children[0].value = this.Parent(null, true, true).style.fontSize || "10.5pt";    },    //#endregion    Cut: function () {        this.CreateR(); //重新记录光标        this.CTH = this.GetSelectedHtml(); //复制的文字处理        if (this.CB && this.CB("Cut", [this.Parent()], this, "Cut", window) === 1) { //回调设置            //  U.M.StopDefault();        }    },    /**    *  复制    *    * @param   {string}   需要复制的位置    */    Copy: function () { //复制        this.CreateR(); //重新记录光标        this.CTH = this.GetSelectedHtml(); //复制的文字处理        if (this.CB && this.CB("Copy", [this.Parent()], this, "Cut", window) === 1) { //回调设置            //  U.M.StopDefault();        }    },    /**    *  粘贴    *    * @param   {element}   需要粘贴到的元素    */    Paste: function (UDOD) { //粘贴        this.CreateR(); //重新记录光标        if (this.CB && this.CB("Paste", [this.Parent()], this, "Cut", window) === 1) { //回调设置            //  U.M.StopDefault();        }        //        if (this.CTH) {        //            if (UDOD) { //添加到指定的元素        //                UDOD.innerHTML = this.CTH.outerHTML || this.CTH;        //            }        //            else { //添加到指定的位置        //                this.Replace(this.CTH, null, true); this.CLMU();        //            }        //        }    },    /**    *  指定的文字生成写入的样式元素    *    * @param   {string}   需要写入的文字    * @param   {object}   转化的样式集 {width:100px,height:100px}    * @return   {string}   需要粘贴到的元素    */    SetStyle: function (UTH, UDE) { //写入样式生成元素        var i, _UDAD, _UTH = "",        _UDOD = $$("span", { "innerHTML": UTH });        this.writeStyle(_UDOD, UDE); //设置样式输出        return $("*", _UDOD).length ? _UDOD.innerHTML : _UDOD.outerHTML; //设置新的样式     },    /**    *  通过元素设置样式    *    * @param   {string}   需要写入的元素    * @param   {object}   转化的样式集 {width:100px,height:100px}    * @return   {string}   需要粘贴到的元素    */    writeStyle: function (UDOD, UDE) { //        var i, j, _UTF,        _UKE = {},        _UCE = {},        _USE = ["textAlign"], //textAlign 无法设置行内元素 要设置块状元素才可以        _UDPD = this.Parent(), //上级元素        _UDAD = $(UDOD).Nodes(); //获取所有的子元素        while (_UDPD.tagName == "SPAN") {            _UDPD = $(_UDPD).Parent();        }        //循环需要添加的样式集合        for (i in UDE) {            if (UDE.hasOwnProperty(i)) {                if (_USE.indexOf(U.M.CssTHH(i)) > -1 ? _UCE : _UKE == _UCE) { //判断样式中是否有行内元素无法设置的样式 如果有就添加到全局设置样式的区域                    _UCE[i] = UDE[i][0] == _UDPD.style[i] ? UDE[i][1] : UDE[i][0];                }                else { //可设置样式区域                    _UKE[i] = UDE[i][0];                    if (UDOD.style && UDOD.style[i] == UDE[i][0]) { //判断元素的样式是否已经存在                         _UKE[i] = UDE[i][1];                    }                    else {                        //子元素设置样式                        for (j = 0; j < _UDAD.length; j++) {                            if (_UDAD[j].style && _UDAD[j].style[i] == UDE[i][0]) {                                _UKE[i] = UDE[i][1]; break;                            }                        }                    }                }            }        }        //设置只有块状元素才能设置的样式        (_UDPD.style) && ($(_UDPD).addAttrArray({ "style": _UCE }));        //所有元素设置指定的样式        $(UDOD).addAttrArray({ "style": _UKE });        $("*", UDOD).addAttrArray({ "style": _UKE });    },    /**    *  获取光标据制定元素所在的位置    *    * @param   {element}   指定的元素    * @param   {boolean}   获取到指定的元素的开头的范围    * @return   {number}   范围    */    GetGBWZ: function (UDOD, UTF) {        var _USE, _URE, _UDTD;        if (window.getSelection) {//HTML5            _USE = this.CW.getSelection();            _URE = _USE.rangeCount ? _USE.getRangeAt(0) : this.R;            return UTF ? _URE.startOffset : _URE.endOffset;        }        else { //ie            try {                UDOD = UDOD || this.Parent();                _URE = this.QX(0, 0, UDOD);                _URE.setEndPoint("EndTo" + (UTF ? "Start" : "End"), this.R);                return (_UDTD = $$("div", { "innerHTML": _URE.htmlText })).innerText.length + ($("img", _UDTD).length);            } catch (e) { }        }        return 0;    },    /**    *  获取光标据制定元素所在的位置    *    * @param   {element}   指定的元素    * @param   {boolean}   获取到指定的元素的开头的范围    * @return   {number}   范围    */    getBoundingClientRect: function () {        if (window.getSelection) {//HTML5            return this.R.getBoundingClientRect();        }        else {            return {                bottom: this.R.P.boundingBottom,                height: this.R.P.boundingHeight,                left: this.R.P.boundingLeft,                right: this.R.P.boundingRight,                top: this.R.P.boundingTop,                width: 1,                x: this.R.P.boundingLeft,                y: this.R.P.boundingTop            };        }    },    /**    *  判断是否在相同的范围    *    * @param   {object}   range 光标对象    * @return  {booean}   是否在指定的范围中    */    IsP: function (UDR) {        if (!UDR) { return true; }        if (window.getSelection) {            var _UDE = document.getSelection();            return (!_UDE.rangeCount || ((_UDE = _UDE.getRangeAt(0)) && UDR.endContaine == _UDE.endContaine && UDR.startContaine == _UDE.startContaine && UDR.endOffset == _UDE.endOffset && UDR.startOffset == _UDE.startOffset));        }        else {            try { return UDR.isEqual(document.selection.createRange()); } catch (e) { }        }        return false;    },    /**    *  判断元素是否在指定区域    *    * @param   {object}   range 光标对象    * @return  {booean}   是否在指定的范围中    */    isE: function (UDOD) {        if (window.getSelection) { //HTML5            return this.S.containsNode(UDOD, true);        }        else {            _URE = document.body.createTextRange();            try {                _URE.moveToElementText(UDOD);                return this.R.inRange(_URE);            }            catch (e) { return false; }        }    },    /**    *  选取元素计算长度    *    * @param   {object}   元素    * @return  {number}   元素文字的长度    */    getLen: function (UDOD) { //        return $("img", UDOD).length + UDOD.innerText.length;    },    //#region 前进后退处理区域    /**    * 输入等待添加前进后退    *    * @param   {obnject} U.D.E.SelectionRange的派生对象    * @return   {funciotn} 光标记录回调函数    */    ADQJ: function (UDR) {        clearTimeout(this.TIM[0]); //清除等待        this.TIM[0] = setTimeout((this.TIM[1] = U.M.apply(this, [[this.ADQJS, ["", UDR]]])), 500); //等待生成记录        return this.TIM[1]; //返回回调    },    /**    * 添加前进后退记录    *    * @param   {string} 前进后退记录的内容    * @param   {object} U.D.E.SelectionRange的派生对象    */    ADQJS: function (UHT, UDR) { //判断添加        clearTimeout(this.TIM[0]); //清除等待        this.TIM = []; //记录前进后退的对象        this.JHGB(UHT, UDR, this); //记录    },    /**    * 记录前进后退(每一次结束自动创建)    *    * @param   {string} 前进后退记录的内容    * @param   {object} U.D.E.SelectionRange的派生对象    * @param   {object} 当前使用的this对象    */    JHGB: function (UHT, UDR, UE) {        var _UTF = this.TF, //标记 识别id            _UDE = this.OAT[_UTF], //获取识别id下的光标对象            _UKE = this.IsP(_UDE[_UDE.l]["OR"]["R"]); //判断光标是否上次记录的范围        (!_UKE && _UTF) && (this.AddHT(UHT, UDR, UE)); //如果没有记录该光标 记录    },    /**    * 添加前进后退区域 直接传参记录    *    * @param   {string} 前进后退记录的内容    * @param   {object} U.D.E.SelectionRange的派生对象    * @param   {object} 当前使用的this对象    */    AddHT: function (UHT, UDR, UE) {        var i, _UTP,        _UTF = this.TF, //识别id        _UDE = this.OAT[_UTF], //识别id下前进后退所有的对象        _UOE = _UDE[_UDE.l]; //当前前进后退所在的对象        _UDE.l++; //生成新的对象的位置        _UDE.splice(_UDE.l, _UDE.length - _UDE.l, (_UTE = { "OR": new this.init(UE, false), "C": (UHT || "") })); //添加新的前进后退对象        if (window.getSelection) { //html5 光标保存            _UOE["OR"]["R"].setEnd(_UTE["OR"]["R"].startContainer, _UTE["OR"]["R"].startOffset);        }        else { //ie位置大小保存            _UTE = ["boundingWidth", "offsetLeft", "boundingLeft", "boundingTop", "offsetTop", "boundingHeight"]; //这里为光标的位置记录            _UOE.P = {};            for (i = 0; i < _UTE.length; i++) { //循环记录光标                _UOE.P[_UTE[i]] = _UOE.OR.R[_UTE[i]];            }        }    },    /**    *  失去焦点的时候保存    *    * @param   {element}   需要粘贴到的元素    */    Brul: function () {        (this.TIM[1]) && (this.TIM[1]());    }    //#endregion}//前进后退的处理 需要修改U.D.E.SORange.init.prototype = U.D.E.SORange;//前进后退处理函数区域//#region 编辑器提供的接口处理区域/***  设置选择区域的样式处理** @param   {element}   编辑元素* @param   {element}   需要修改的样式集* @param   {element}   光标方法集合对象* @param   {element}   光标所在的域的识别id* @return   {element}   需要粘贴到的元素*/U.D.E.FontSizeType = function (UDOD, USE, UDE, UTF) {    UDE = UDE || U.D.E.GetSelectionRange(window, UDOD, { "TF": UTF || "QL" }); //获取光标方法集    var i, _UFT,    _UST = "", //获取设置样式后的html值    _UKE = {}, //最终修改样式的值    _UDPD = UDE.Parent(), //获取父亲层    _UTH = UDE.GetSelectedHtml(); //选择的元素    //获取可设置样式的层    while (!_UDPD.tagName) {        _UDPD = $(_UDPD).Parent();    }    //样式设置    for (i in USE) {        if (USE.hasOwnProperty(i)) {            USE[i] = typeof USE[i] == "object" ? USE[i] : [USE[i], USE[i]];            _UKE[i] = USE[i];        }    }    //有选取    if (_UTH) {        _UST = UDE.SetStyle(_UTH, USE);        USE = USE;    }    else {        UDE.writeStyle(UDE.Parent(null, true), USE);    }    UDE.Replace(_UST, null, _UST ? null : true);    return UDE; //生成添加的内容}//#endregion//键盘检查器U.D.E.codeDetect = (function () {    var _UKE = { 3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt", 19: "Pause",        20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", 36: "Home", 37: "Left",        38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert", 46: "Delete", 48: "0", 49: "1", 50: "2", 51: "3", 52: "4", 53: "5", 54: "6", 55: "7", 56: "8", 57: "9", 59: ";", 65: "A", 66: "B", 67: "C", 68: "D", 69: "E", 70: "F", 71: "G", 72: "H", 73: "I", 74: "J", 75: "K", 76: "L", 77: "M", 78: "N", 79: "O", 80: "P", 81: "Q", 82: "R", 83: "S", 84: "T", 85: "U", 86: "V", 87: "W", 88: "X", 89: "Y", 90: "Z", 91: "Mod", 92: "Mod", 93: "Mod", 107: "=", 109: "-", 112: "F1", 113: "F2", 114: "F3", 115: "F4", 116: "F5", 117: "F6", 118: "F7", 119: "F8", 120: "F9", 121: "F10", 122: "F11", 123: "F12", 127: "Delete", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\"", 221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63236: "F1", 63237: "F2", 63238: "F3", 63239: "F4", 63240: "F5", 63241: "F6", 63242: "F7", 63243: "F8", 63244: "F9", 63245: "F10", 63246: "F11", 63247: "F12", 63272: "Delete", 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"    },            _USE = { "alt": [[37, "goLineStart"], [38, "goDocStart"], [39, "goLineEnd"]], "ctrl": [[65, "selectAll"], [8, "delGroupBefore"], [67, "copy"], [86, "paste"], [68, "deleteLine"], [46, "delGroupAfter"], [40, "goDocEnd"], [63275, "goDocEnd"], [70, "find"], [71, "findNext"], [63273, "goDocStart"], [37, "goGroupLeft"], [39, "goGroupRight"], [83, "save"], [89, "redo"], [90, "undo"], [219, "indentLess"], [221, "indentMore"]], "shift-ctrl": [[70, "replace"], [71, "findPrev"], [82, "replaceAll"], [90, "redo"]] },            _ = function (UDE) { return new _.init(UDE); }; //初始化查看使用    U.Ut.AddObj(_, _.prototype = {        init: function (UDE) { //初始化检测器            UDE = UDE || {}; U.Ut.AddObj(this, UDE); (UDE.el) && (this.bind(UDE.el));        },        bind: function (UDOD) { //绑定函数时间            $(UDOD).bind({ keydown: U.M.apply(this, this.down) });        },        down: function () { //键盘事件            (this.cb) && (this.cb.call(this, this.getValue(), this.el));        },        getValue: function () { //根据输入获取检测器值            var i, j, _UGE, _UCE, e = event, k = e.keyCode;  //基础编辑器快捷键            _UGE: for (i in _USE) {                if (_USE.hasOwnProperty(i)) {                    _UCE = i.split("-"); for (j = 0; j < _UCE.length; j++) { if (!e[_UCE[j] + "Key"]) { continue _UGE; } } for (j = 0; j < _USE[i].length; j++) {                        if ((_UCE = _USE[i][j])[0] == k) {                            return _UCE[1];                        };                    }                }            }            return [k, e.altKey, e.ctrlKey, e.shiftKey, _UKE[k] || ""];        },        set: function () { //键盘设置 允许自定义键监视        }    });    _.init.prototype = _; return _;})()
 |