123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727 |
-
- Namespace.register("U.UF.E");
- U.UF.E.initEditor = function (el, synergy, content, stylestate) {
-
-
-
- if (content) {
-
- el.innerHTML = content;
- el.focus();
-
- if (!$("div", el)[0] || U.selectEl("div", el)[0].id.length != "37") {
- el.innerHTML = "";
- U.UF.E.textFormat(content, el);
- U.selectEl("div", el)[0].focus();
- }
-
-
-
- }
-
- else {
-
- var _div = $$("div", { "id": "e" + Guid.newGuid(), "innerHTML": content || "<span><br /></span>" }, el);
- el.focus();
- }
-
- U.UF.E.variable(el, synergy, stylestate);
-
- U.UF.E.key(el);
-
- U.UF.E.formatBrush(el, false);
-
- U.UF.E.picture.stretch(el);
-
- el.idarr = U.UF.E.key.getLineIdArr(el);
-
- el.editor.recordOpera = { "line": el.idarr }
- return U.UF.E.getRangeAt();
- }
- U.UF.E.variable = function (el, synergy, stylestate) {
- var _range = U.UF.E.getRangeAt();
-
- el.editor = {
- "isrecord": true,
- "idarr": [],
-
- "brushStyle": {
- "font-family": {},
- "font-size": {},
- "font-weight": {},
- "font-style": {},
- "text-decoration": {},
- "color": {},
- "backgroundColor": {}
- },
-
- "recordRangeStyle": {
- "font-family": "",
- "font-size": "",
- "font-weight": "",
- "font-style": "",
- "text-decoration": "",
- "color": "",
- "backgroundColor": ""
- },
- "styleState": stylestate,
- "maxWidth": U.selectEl(el)[0].offsetWidth,
- "operaNotice": synergy,
- "recordRange": _range,
- "recordHTML": "",
- "recordOpera": {},
- "dpi": U.UF.CI.getDPI()[0],
- "log": true,
- "recordsEditor": [],
- "recordsEditorIndex": 0
- };
- }
- U.UF.E.onpaste = function (e, editor, text) {
- var _content, event = e || window.event;
- if (text != undefined) {
- _text = text;
- }
- else {
- _text = U.UF.C.pasteText();
- }
- _content = _text.SplitAngleBrackets();
- if (_content && _content.length < 2) {
-
- _text = "<div>" + _text.replaceAngleBrackets().replace(/\r\n/g, "</div><div>").replace(/ /g, " ") + "</div>";
- }
-
- _text = _text.replace(/<(BR)[^<>]*>/ig, "</div></br><div>").replace(/ /g, " ");
- _text.trim() != "" && U.UF.E.textFormat(_text, editor);
- U.UF.EV.stopDefault();
- return _text.trim();
- }
- U.UF.E.textFormat = function (text, editor) {
- var _editor = editor || this.editor;
- var _range = U.UF.E.getRangeAt(),
- _div = $$("div", { "innerHTML": text, "style": { "display": "none"} }, U.selectEl("body")[0]),
- _frag = U.UF.E.unifiedFormat(_div);
- U.UF.E.insertContent(_frag, _range, _editor);
-
- var _table = U.selectEl('table', _editor);
-
- for (var i = _table.length - 1; i >= 0; i--) {
- U.UF.E.table.load(_table[i]);
- }
- U.selectEl(_div).remove();
- }
- U.UF.E.insertContent = function (el, range, editor) {
- range = range || U.UF.E.getRangeAt();
-
- if (window.getSelection) {
-
- var _i,
- _frag,
- _stylecsstext,
- _span,
- _child = el.childNodes,
- _lastchild,
- _extractcontent,
- _record,
- _focusel,
- _frag = $$("frag"),
- _startline = range.startContainer == editor ? editor.children[0] : U.UF.E.getLineElement(range.startContainer),
- _endline = range.endContainer == editor ? editor.children[0] : U.UF.E.getLineElement(range.endContainer),
- _selection = window.getSelection()
- ;
- if (editor.innerHTML == "") {
- _record = { addLine: [] };
- for (_i = 0; _i < _child.length; ) {
- _record.addLine.push(_child[_i].id);
-
- editor.appendChild(_child[_i]);
- }
- U.UF.E.elementFocus(range, editor.children[0], true);
- editor.editor.recordHTML = editor.children[editor.children.length - 1].outerHTML;
- }
- else {
- _record = { updateLine: [_startline.id], addLine: [] };
-
- range.deleteContents();
- _selection.removeAllRanges();
-
-
-
- _lastchild = _endline.lastChild;
-
- if (_lastchild && (_lastchild.innerHTML != undefined || _lastchild.data != undefined)) {
- _stylecsstext = (_lastchild.style || _lastchild.parentNode.style).cssText;
- _focusel = _child[_child.length - 1].childNodes[_child[_child.length - 1].childNodes.length - 1] || _child[_child.length - 1];
-
- try {
- range.setEnd(_lastchild, _lastchild.innerHTML != undefined ? 1 : _lastchild.data.length);
- }
- catch (e) {
- range.setEnd(_lastchild, 0);
- }
- _extractcontent = range.extractContents();
-
- if (_extractcontent.childNodes[0] && _extractcontent.childNodes[0].nodeType != 1) {
-
- _frag = $$("frag");
- _span = $$("span", { "style": { "cssText": _stylecsstext} }, _frag);
- _span.appendChild(_extractcontent);
- _extractcontent = _frag;
- }
-
- if (_extractcontent.childNodes[0] && _extractcontent.childNodes[0].tagName == "DIV") {
-
- for (_i = 0; _i < _extractcontent.childNodes[0].childNodes.length; _i) {
-
- _extractcontent.childNodes[0].childNodes[_i].style.cssText = _extractcontent.childNodes[0].style.cssText + ";" + _extractcontent.childNodes[0].childNodes[_i].style.cssText;
- _child[_child.length - 1].appendChild(_extractcontent.childNodes[0].childNodes[_i]);
- }
- }
-
- else {
- _child[_child.length - 1].appendChild(_extractcontent);
- }
-
- for (_i = 0; _i < el.childNodes[0].childNodes.length; _i) {
- _startline.appendChild(el.childNodes[0].childNodes[_i]);
- }
- }
-
- else if (_child[0]) {
-
- _startline.style.cssText += " " + U.UF.E.getRemainAttr(_child[0]);
-
- _startline.innerHTML = _child[0].innerHTML;
- _focusel = _startline;
- }
-
- for (_i = 1; _i < _child.length; ) {
- _record.addLine.push(_child[_i].id);
-
- _frag.appendChild(_child[_i]);
- }
- U.selectEl(_startline.parentNode).append(_frag, 0, U.selectEl(_startline).next()[0]);
- U.UF.E.elementFocus(range, _focusel, true);
- var _focusline = U.UF.E.getLineElement(_focusel);
- if (_focusline != _startline) {
- editor.editor.recordRange = range;
- }
- editor.editor.recordHTML = _focusline.outerHTML;
- }
- U.UF.E.operationNotice(_record, editor);
- clearTimeout(editor.editor.interval);
- }
-
- else {
- range.pasteHTML(el.outerHTML);
- }
- };
- U.UF.E.elementFocus = function (range, el, islast) {
-
- if (window.getSelection) {
- var _selection = window.getSelection();
- range.selectNodeContents(el);
- _selection.removeAllRanges();
- _selection.addRange(range);
-
- if (islast) {
- range.collapse(false);
- }
- }
-
- else {
- range.moveToElementText(el);
- range.select();
- }
- };
- U.UF.E.createRnage = function () {
-
- if (window.getSelection) {
- return document.createRange();
- }
-
- else {
- return document.body.createTextRange();
- }
- }
- U.UF.E.getRangeAt = function (win) {
- var _selection,
- _range
- ;
- win = win || window;
-
- if (win.getSelection) {
- _selection = win.getSelection();
-
- if (_selection.rangeCount) {
- _range = _selection.getRangeAt(0);
- }
- }
-
- else {
- _selection = win.document.selection;
- _range = _selection.createRange();
- }
- return _range;
- };
- U.UF.E.addRange = function (str, range, islast) {
- range = range || U.UF.E.getRangeAt();
-
- if (window.getSelection) {
- var _selection = window.getSelection(),
- _frag = range.createContextualFragment(str);
- range.deleteContents();
- _selection.removeAllRanges();
- range.insertNode(_frag);
-
- if (islast) {
- range.collapse(false);
- }
- _selection.addRange(range);
- }
-
- else {
- range.select();
- range.pasteHTML(str);
-
- if (islast) {
- range.collapse(false);
- }
- }
-
- return U.UF.E.getRangeAt();
- };
- U.UF.E.getRangeElement = function (range) {
-
- if (range.commonAncestorContainer) {
- return range.commonAncestorContainer;
- }
-
- else {
-
- if (range.parentElement) {
- return range.parentElement();
- }
-
- else {
- return range.commonParentElement();
- }
- }
- };
- U.UF.E.reSelectRange = function (range) {
-
- if (window.getSelection) {
- var _selection = window.getSelection();
- _selection.removeAllRanges();
- _selection.addRange(range);
- }
-
- else {
- range.select();
- }
- };
- U.UF.E.setRangeStyle = function (attr, range, editor) {
- range = range || U.UF.E.getRangeAt();
- if (range.startContainer == range.endContainer && range.startOffset == range.endOffset) {
- return true;
- }
- var _i,
- _textstyle,
- _isdel,
- _start = range.startContainer,
- _end = range.endContainer,
- _startoffset = range.startOffset,
- _endoffset = range.endOffset,
- _startline = U.UF.E.getLineElement(_start),
- _endline = U.UF.E.getLineElement(_end),
- _frag = $$("frag")
- ;
- editor = editor || _startline.parentNode;
- if (!editor.editor) { return; }
- var _record = U.UF.E.getUpdateLine(_startline, _endline, editor);
-
- if (_startline != _endline) {
-
- var _rangselect = range.extractContents().childNodes;
-
- _start = _rangselect[0].childNodes[0];
-
- _textstyle = attr["text-decoration"] || attr["textDecoration"];
-
- U.UF.E.setStyle(attr, _rangselect[0], true);
- if (attr.cssText == "") {
- _startline.style.cssText = "";
- }
-
- while (_rangselect[0].childNodes[0]) {
- _startline.appendChild(_rangselect[0].childNodes[0]);
- }
-
- if (_textstyle) {
-
- _isdel = (attr["text-decoration"] || attr["textDecoration"] || "").indexOf(_textstyle) > -1 ? 1 : 0;
- attr["text-decoration"] = _textstyle;
- }
-
- for (_i = 1; _i < _rangselect.length - 1; ) {
-
- U.UF.E.setStyle(attr, _rangselect[_i], _isdel);
- if (_textstyle) {
- attr["text-decoration"] = _textstyle;
- }
- if (attr.cssText == "") {
- _rangselect[_i].style.cssText = "";
- }
-
- _frag.appendChild(_rangselect[_i]);
- }
-
- U.UF.E.setStyle(attr, _rangselect[_rangselect.length - 1], _isdel);
-
- var _end = _rangselect[_rangselect.length - 1].childNodes[_rangselect[_rangselect.length - 1].childNodes.length - 1];
-
- while (_rangselect[_rangselect.length - 1].childNodes[0]) {
- U.selectEl(_endline).append(_rangselect[_rangselect.length - 1].childNodes[_rangselect[_rangselect.length - 1].childNodes.length - 1], 0, _endline.firstChild);
- }
- if (attr.cssText == "") {
- _endline.style.cssText = "";
- }
- range.insertNode(_frag);
- U.UF.E.setRange(_start, _end || _start, 0, 1, range);
- }
-
-
- else if (_start == _end && (_start.parentNode.tagName.toLowerCase() == "span" || _start.parentNode.tagName.toLowerCase() == "a")) {
- var _parentspan = _start.parentNode;
- var _tagname = _parentspan.tagName.toLowerCase() == "a" ? "a" : "span";
- var _startsplitel = U.UF.E.splitText(_start, _startoffset);
- var _endsplitel = U.UF.E.splitText(_startsplitel, _endoffset - _startoffset);
-
- if (_start.data) {
-
- var _span = $$(_tagname, {
- "style": { "cssText": U.UF.E.getRemainAttr(_parentspan) },
- "innerHTML": _start.data
- });
-
- if (_tagname == "a") {
- _span.href = _parentspan.href;
- }
-
- _parentspan.replaceChild(_span, _start);
- }
-
- var _rangspan = $$(_tagname, {
- "style": { "cssText": U.UF.E.getRemainAttr(_parentspan) },
- "innerHTML": _startsplitel.data
- });
-
- U.selectEl(_rangspan).css(U.UF.E.setSpecialAttr(_rangspan, attr));
-
- if (_tagname == "a") {
- _rangspan.href = _parentspan.href;
- }
-
- _parentspan.replaceChild(_rangspan, _startsplitel);
-
- if (_endsplitel.data) {
-
- var _span1 = $$(_tagname, {
- "style": { "cssText": U.UF.E.getRemainAttr(_parentspan) },
- "innerHTML": _endsplitel.data
- });
-
- if (_tagname == "a") {
- _span1.href = _parentspan.href;
- }
-
- _parentspan.replaceChild(_span1, _endsplitel);
- }
-
- for (i = 0; i < _parentspan.childNodes.length; ) {
- _frag.appendChild(_parentspan.childNodes[i]);
- }
-
- _parentspan.parentNode.replaceChild(_frag, _parentspan);
-
- U.UF.E.setRange(_rangspan, _rangspan, 0, _startsplitel.data ? 1 : 0, range);
- }
-
- else if (_end == _start && _start.tagName && (_start.tagName.toLowerCase() == "span" || _start.tagName.toLowerCase() == "a")) {
-
- U.UF.E.getRemainAttr(_start);
-
- U.selectEl(_start).css(U.UF.E.setSpecialAttr(_start, attr));
- }
-
- else {
- var _rangselect = range.extractContents();
- U.UF.E.setStyle(attr, _rangselect, true);
- range.insertNode(_rangselect);
- }
-
- U.UF.E.operationNotice(_record, editor);
- };
- U.UF.E.getUpdateLine = function (startline, endline, edit) {
- var _record = { updateLine: [] };
-
- while (startline) {
- _record.updateLine.push(startline.id);
-
- if (startline != endline) {
- startline = startline.nextElementSibling;
- }
- else {
- startline = false;
- }
- }
-
- return _record;
- };
- U.UF.E.setStyle = function (attr, el, istop) {
- var _nowattr,
- _nowspan,
- _newspan,
- _textstyle = attr["text-decoration"] || attr["textDecoration"],
- _span = U.UF.E.getTagNameElement(el);
- var _spanText = _span && _span.innerHTML;
-
- if (_span && _spanText == el.data) {
- _nowattr = U.UF.E.setSpecialAttr(_span, attr);
- U.selectEl(_span).css(_nowattr);
- }
-
- else {
- var _rangselect = el.childNodes;
-
- for (var i = 0; i < _rangselect.length; i++) {
-
- if (istop === true && !i) {
- U.UF.E.setSpecialAttr(_rangselect[i], attr);
-
- istop = (attr["text-decoration"] || attr["textDecoration"] || "").indexOf(_textstyle) > -1 ? 1 : 0;
- }
-
- if (attr["text-decoration"] || attr["textDecoration"]) {
-
- if (istop === 1) {
-
- if (_rangselect[i].style && _rangselect[i].style["text-decoration"] && _rangselect[i].style["text-decoration"] != "inherit" && _rangselect[i].style["text-decoration"] != "none") {
-
- attr["text-decoration"] = _rangselect[i].style["text-decoration"].replace(_textstyle, "") + " " + _textstyle;
- }
-
- else {
- attr["text-decoration"] = _textstyle;
- }
- }
-
- else if (istop === 0) {
-
-
- if (_rangselect[i].style) {
-
-
- if (_rangselect[i].style["text-decoration"].indexOf(_textstyle) > -1) {
-
- attr["text-decoration"] = _rangselect[i].style["text-decoration"].replace(_textstyle, "");
-
- if (attr["text-decoration"] == "") {
- attr["text-decoration"] = "inherit";
- }
- }
-
- else {
- attr["text-decoration"] = _rangselect[i].style["text-decoration"];
- }
- }
-
- else {
- attr["text-decoration"] = "inherit";
- }
- }
- }
-
-
- if (_rangselect[i].tagName) {
- U.selectEl(_rangselect[i]).css(attr);
- }
-
- else if (_rangselect[i].nodeValue) {
-
- _newspan = $$("span", {
- "innerHTML": _rangselect[i].nodeValue,
- "style": attr
- });
-
- _rangselect[i].parentNode.replaceChild(_newspan, _rangselect[i]);
- }
- }
- }
- };
- U.UF.E.setSpecialAttr = function (element, attr) {
- var _key,
- _newvalue,
- _value;
- if (element.style) {
-
- for (_key in attr) {
- if (attr[_key] == "") {
- attr[_key] = "";
- }
- else {
-
- if (_key == "text-decoration" || _key == "textDecoration") {
-
- _value = element.style[_key];
-
- if (_value && _value != "inherit" && _value != 'none') {
-
- _newvalue = _value.replace(attr[_key], "");
-
- if (_newvalue == "") {
- attr[_key] = "inherit";
- }
-
- else if (_newvalue == _value) {
- attr[_key] = attr[_key] + " " + _value;
- }
-
- else {
- attr[_key] = _newvalue;
- }
- }
- }
-
- else if (attr[_key] == element.style[_key] && "font-weight|fontWeight|font-style|fontStyle|".indexOf(_key) > -1) {
- attr[_key] = "inherit";
- }
- }
- }
- }
-
- return attr;
- };
- U.UF.E.splitText = function (node, offset) {
-
- if (offset == node.nodeValue.length) {
- var next = document.createTextNode('');
- U.selectEl(node.parentNode).append(next, null, node);
- return next;
- }
- var retval = node.splitText(offset);
- return retval;
- };
- U.UF.E.getLineElement = function (el) {
- var _mel = el,
- _tagname = el.tagName ? el.tagName.toLowerCase() : "";
-
- while (el && _tagname != "body" && (_tagname != "div" || !(el.id && el.id.length == "37"))) {
- el = el.parentNode;
- if (el) {
- _tagname = el.tagName ? el.tagName.toLowerCase() : "";
- }
- };
- return (el && el.id) ? el : null;
- };
- U.UF.E.getTagNameElement = function (node, tagname) {
- tagname = tagname || 'span';
- while (node) {
- if (node.nodeName.toLocaleLowerCase() === tagname) {
- return node;
- } else if (node.nodeName.toLocaleLowerCase() === 'div' && !node.inline) {
- return null;
- }
- node = node.parentNode;
- }
- };
- U.UF.E.setLineStyle = function (style, range) {
- if ($('.U_UF_E_Picture_dragDot')[0]) {
- U.selectEl('.U_UF_E_Picture_dragDot')[0].style.display = "none";
- }
- range = range || U.UF.E.getRangeAt();
- var _rangeline,
- _start = range.startContainer
- _td = U.selectEl(_start).Parent({ "tagName": "TD" });
-
- if (_td && _td.tagName == "TD") {
- _rangeline = [_td];
- }
- else {
- _rangeline = U.UF.E.getRangeLineElement(range);
- }
- var i = 0;
- for (i = 0; i < _rangeline.length; i++) {
- U.selectEl(_rangeline[i]).css(style);
- }
- U.UF.E.reSelectRange(range);
- return range;
- };
- U.UF.E.getRangeLineElement = function (range) {
- range = range || U.UF.E.getRangeAt();
- var _start = range.startContainer,
- _end = range.endContainer,
- _stratline = U.UF.E.getLineElement(_start),
- _endline = U.UF.E.getLineElement(_end),
- _nextline = U.selectEl(_stratline).next()[0],
- _rangeline = [_stratline];
- if (_stratline != _endline) {
- while (_nextline) {
- _rangeline.push(_nextline);
- if (_nextline != _endline) {
- _nextline = U.selectEl(_nextline).next()[0];
- } else {
- _nextline = false;
- }
- }
- }
- return _rangeline;
- }
- U.UF.E.textAlign = function (direction) {
- U.UF.E.setLineStyle({ 'text-align': direction });
- };
- U.UF.E.setRange = function (startel, endel, start, end, range) {
- range = range || U.UF.E.getRangeAt();
-
- if (window.getSelection) {
-
- if (startel == endel && range.startContainer != startel) {
- range.selectNodeContents(startel);
- }
- range.setStart(startel, start);
- range.setEnd(endel, end);
- }
-
- else {
- var _range1 = document.body.createTextRange(),
- _range2 = document.body.createTextRange();
- _range1.moveToElementText(startel);
- _range1.moveStart("character", startel);
- _range2.moveToElementText(endel);
- _range2.moveStart("character", end);
- _range1.setEndPoint("EndToStart", _range2);
- _range1.select();
- range = _range1;
- }
- return range;
- }
- U.UF.E.unifiedFormat = function (el) {
- var _i,
- _float,
- _tagname,
- _removeTagName = ['head', 'meta', 'script', 'link', 'style', 'title'],
- _frag = $$("frag"),
- _div,
- _child = el.childNodes;
-
- U.UF.E.unifiedFormat.remove(el);
-
- for (_i = 0; _i < _child.length; _i++) {
- _display = _child[_i].currentStyle ? _child[_i].currentStyle.display : "";
- _tagname = _child[_i].tagName ? _child[_i].tagName.toLowerCase() : "";
- _float = _child[_i].currentStyle ? _child[_i].currentStyle.float : "";
-
- if (_child[_i].className == "U_MD_O_attachment") {
- U.selectEl(_child[_i]).appendTo(_frag);
- continue;
- }
-
- if (!_div || (_display != "" && _display != "inline") && (_float != "left" || _float != "right")) {
-
-
- _div = $$("div", { "id": "e" + Guid.newGuid(), "style": { "cssText": U.UF.E.getRemainAttr(_child[_i])} }, _frag);
- }
-
- U.UF.E.unifiedFormat.next(_child[_i], true, _div);
- if (!_div.childNodes.length && _frag.childNodes.length > 1) {
- U.selectEl(_div).remove();
- }
- }
-
- return _frag;
- };
- U.UF.E.unifiedFormat.remove = function (el) {
- var _i,
- _tagname,
- _removeTagName = ['head', 'meta', 'script', 'link', 'style', 'title'],
- _child = el.childNodes;
-
- for (_i = 0; _i < _child.length; _i++) {
- _tagname = _child[_i].tagName ? _child[_i].tagName.toLowerCase() : "";
-
- if (_child[_i].nodeType === 8 || (_child[_i].nodeType == 3 && _child[_i].data.trim() == "")) {
- _child[_i].remove();
- _i--;
- continue;
- }
-
- if (_removeTagName.indexOf(_tagname) >= 0) {
- U.selectEl(_child[_i]).remove();
- _i--;
- continue;
- }
- }
- }
- U.UF.E.unifiedFormat.next = function (el, top, fragel) {
- var _i, _j,
- _float,
- _display,
- _tagname,
- _nowspan,
- _tdchild,
- _fraga = $$("frag"),
- _frag = fragel,
- _span,
- _childcsstext,
- _child = el.childNodes,
- _tagname = el.tagName ? el.tagName.toLowerCase() : "",
- _cssText = (top.style ? top.style.cssText : "") + ";" + fragel.style.cssText + (_tagname == "img" ? "" : U.UF.E.getRemainAttr(el));
-
- U.UF.E.unifiedFormat.remove(el);
-
- if (_child.length) {
-
- for (_i = 0; _i < _child.length; _i++) {
- _span = null;
-
- _childcsstext = _cssText + ";" + (_child[_i].tagName == "IMG" ? "" : U.UF.E.getRemainAttr(_child[_i]));
- _display = _child[_i].currentStyle ? _child[_i].currentStyle.display : "";
- _float = _child[_i].currentStyle ? _child[_i].currentStyle.float : "";
-
-
- if (_tagname == "b") {
- _childcsstext += ";font-weight: bold;";
- }
-
- else if (_tagname == "i") {
- _childcsstext += ";font-style: italic;";
- }
-
- else if (_tagname == "u") {
- _childcsstext += ";text-decoration: underline;";
- }
-
- else if (_tagname == "s") {
- _childcsstext += ";text-decoration: line-through;";
- }
-
- if (el.className == "U_MD_O_attachment_wrapper") {
- }
-
- else if (_tagname == "a" || (U.UF.C.isElement(top) && top.tagName == "A")) {
-
-
-
- _child[_i].name = _child[_i].name || top.name || el.name || "";
-
- _child[_i].href = _child[_i].href || top.href || el.href;
-
- _span = $$("a", {
- "name": _child[_i].name,
- "href": _child[_i].href || "javascript:void(0)",
- "style": { "cssText": _childcsstext }
- }, _fraga);
- }
-
- else if (_tagname == "style") {
- el = U.selectEl(el).clone(true);
- el.appendTo(_frag);
-
- arguments[2] = _frag = fragel = $$("div", {
- "id": "e" + Guid.newGuid(),
- "style": { "cssText": _childcsstext }
- }, fragel.parentNode);
- break;
- }
-
- else if (_tagname == "table") {
- if (_frag.innerHTML) {
-
- _span = $$("div", {
- "id": "e" + Guid.newGuid(),
- "style": { "cssText": _childcsstext }
- }, fragel.parentNode);
- }
- else {
- _span = _frag;
- }
-
- el = U.selectEl(el).clone(true);
-
- el.appendTo(_span);
-
- _tdchild = U.selectEl("td", el[0]);
-
- for (_j = 0; _j < _tdchild.length; _j++) {
- _tdchild[_j].innerHTML = _tdchild[_j].innerText;
- }
-
- arguments[2] = _frag = fragel = $$("div", {
- "id": "e" + Guid.newGuid(),
- "style": { "cssText": _childcsstext }
- }, fragel.parentNode);
- break;
- }
-
- else if ((_display != "" && _display != "inline") && (_float != "left" || _float != "right") && _child[_i].innerHTML.trim() != "") {
- if (_frag.innerHTML) {
-
- arguments[2] = _frag = fragel = $$("div", {
- "id": "e" + Guid.newGuid(),
- "style": { "cssText": _childcsstext }
- }, fragel.parentNode);
- }
- else {
- fragel.style.cssText += _childcsstext;
- }
- }
-
- else {
- _span = $$("span", { "style": { "cssText": _childcsstext} }, _fraga);
- }
-
- var _nowspan = U.UF.E.unifiedFormat.next(_child[_i], _span || top, fragel);
-
- if (_span) {
- if (_nowspan.children.length) {
-
- _fraga.replaceChild(_nowspan, _span);
- _frag.appendChild(_fraga);
- }
-
- else if (_nowspan.childNodes.length) {
- _span.appendChild(_nowspan);
- _frag.appendChild(_fraga);
- }
- else {
- U.selectEl(_span).remove();
- }
- }
- else if (_nowspan) {
-
- _fraga.appendChild(_nowspan);
- _frag.appendChild(_fraga);
- }
- }
- }
-
- else {
-
- if (top == true) {
- if (_tagname == "img") {
- var _img = U.selectEl(el).clone(true)[0];
- _img.style.maxWidth = "100%";
- _img.onerror = function () {
- this.src = "/img/editorError.png";
- this.width = 150;
- this.height = 112;
- }
- _span = $$("span", {
- "style": { "cssText": top.style.cssText },
-
- "innerHTML": el.innerHTML != null ? el.innerHTML : el.data
- });
- _span.appendChild(_img);
- _frag.appendChild(_span);
- }
- else {
-
- $$("span", {
- "style": { "cssText": _cssText },
-
- "innerHTML": el.innerHTML != null ? el.innerHTML : el.data
- }, _frag);
- }
- }
-
- else {
-
- if (el.data) {
- _fraga.appendChild(document.createTextNode(el.data));
- }
-
- else if (_tagname == "img") {
- var _img = U.selectEl(el).clone(true)[0];
- _img.style.maxWidth = "100%";
- _img.onerror = function () {
- this.src = "/img/editorError.png";
- this.width = 150;
- this.height = 112;
- }
- _span = $$("span", {
- "style": { "cssText": top.style.cssText },
-
- "innerHTML": el.innerHTML != null ? el.innerHTML : el.data
- });
- _span.appendChild(_img);
- _fraga.appendChild(_span);
- }
- }
- }
-
- return _fraga;
- };
- U.UF.E.getRemainAttr = function (ele) {
-
- if (!ele || !ele.style) {
- return '';
- }
-
- var _removeattr = ['position', 'width', 'height', 'background-image', 'border', 'min-height', 'float', 'min-width', 'display', 'padding', 'margin'];
- var _i;
-
- for (_i = 0; _i < _removeattr.length; _i++) {
-
- ele.style[_removeattr[_i]] = "";
- }
-
- return ele.style.cssText;
- };
- U.UF.E.clearStyle = function (range) {
- range = range || U.UF.E.getRangeAt();
- var _start = range.startContainer,
- _end = range.endContainer,
- _startline = U.UF.E.getLineElement(_start),
- _endline = U.UF.E.getLineElement(_end);
-
- if (_startline == _endline && range.toString() == _startline.innerText) {
- for (var i = 0; i < _startline.childNodes.length; i++) {
- if (_startline.childNodes[i].nodeName !== "#text") {
- _startline.childNodes[i].style.cssText = "font-family: 微软雅黑; font-weight: normal; font-size: 10.5pt; line-height: 2;";
- }
- }
- } else {
- U.UF.E.setRangeStyle({ "cssText": "" }, range);
- }
- U.UF.E.reSelectRange(range);
- };
- U.UF.E.addHref = function (el, range) {
- U.selectEl("#U_UF_E_herfAlert").remove();
- range = range || U.UF.E.getRangeAt();
- var _start = range.startContainer,
- _end = range.endContainer,
- _selectel = range.cloneContents(),
- _startline = U.UF.E.getLineElement(_start),
- _endline = U.UF.E.getLineElement(_end);
- el = el || U.UF.E.getTagNameElement(range.startContainer, "a");
-
- if (_startline !== _endline || U.selectEl('img', _selectel)[0]) {
-
- U.UF.UI.alertClick('选择范围横跨多个段落或存在图片,因此无法编辑');
- } else {
- var _box = $$('div');
- if (el) {
- _text = el.innerHTML;
- _href = el.href;
- var _textinput = $$('div', { innerHTML: '<span style="margin-right:7px;">文本</span> <input class="U_MD_O_H_Inputactive" placeholder="输入文本" value="' + _text + '" style="width:210px;height:25px;border:1px solid rgba(169,169,169,1);border-radius:2px;text-indent: 3px;" />', "style": { "line-height": "25px", "margin": "40px 41px 17px"} }, _box);
- var _hrefinput = $$('div', { innerHTML: '<span style="margin-right:7px;">链接</span> <input class="U_MD_O_H_Inputactive" placeholder="请输入网页链接地址" value="' + _href + '" style="width:210px;height:25px;border:1px solid rgba(169,169,169,1);border-radius:2px;text-indent: 3px;"/>', "style": { "margin": "0px 41px 27px", "line-height": "25px"} }, _box);
- U.UF.UI.confirm(_box, U.UF.C.closure(U.UF.E.addHref.confirm, [range, _hrefinput, _textinput, _text, el]));
- } else {
-
- _a = U.selectEl('a', _selectel)[0],
- _href = _a ? _a.href : '',
- _text = range.toString();
- var _textinput = $$('div', { innerHTML: '<span style="margin-right:7px;">文本</span> <input class="U_MD_O_H_Inputactive" placeholder="输入文本" value="' + _text + '" style="width:210px;height:25px;border:1px solid rgba(169,169,169,1);border-radius:2px;text-indent: 3px;"/>', "style": { "line-height": "25px", "margin": "40px 41px 17px"} }, _box);
- var _hrefinput = $$('div', { innerHTML: '<span style="margin-right:7px;">链接</span> <input class="U_MD_O_H_Inputactive" placeholder="请输入网页链接地址" value="http://' + _href + '" style="width:210px;height:25px;border:1px solid rgba(169,169,169,1);border-radius:2px;text-indent: 3px;"/>', "style": { "margin": "0px 41px 27px", "line-height": "25px"} }, _box);
- U.UF.UI.confirm(_box, U.UF.C.closure(U.UF.E.addHref.confirm, [range, _hrefinput, _textinput, _text]));
- }
- }
- };
- U.UF.E.addHref.excelConfirm = function (_cellList, hrefinput, textinput, text) {
- href = U.selectEl('input', hrefinput)[0].value;
- if (U.UF.S.Url.test(href)) {
- var _newtext = U.selectEl('input', textinput)[0].value;
-
- if (_cellList[0]) {
- $$('a', { href: href, innerHTML: _newtext, target: "_blank" }, _cellList[0]);
- _cellList[0].removeChild(_cellList[0].children[0]);
- } else {
- $$('a', { href: href, innerHTML: _newtext, target: "_blank" }, _cellList[0]);
- }
- }
- else {
-
- U.alert('输入的链接有误,无法添加');
- }
- };
- U.UF.E.addHref.confirm = function (range, hrefinput, textinput, text, el) {
- href = U.selectEl('input', hrefinput)[0].value;
- if (new RegExp(/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/).test(href)) {
- var _newtext = U.selectEl('input', textinput)[0].value;
- var _start = range.startContainer,
- _end = range.endContainer,
- _startspan = U.UF.E.getTagNameElement(_start, 'span'),
- _endspan = U.UF.E.getTagNameElement(_end, 'span');
- if (el) {
- el.innerHTML = _newtext;
- el.href = href;
- } else {
- var _frag = $$('frag');
- if (_newtext !== text) {
-
- _frag = $$('a', { href: href, innerHTML: _newtext, target: "_blank" });
- } else {
- var _selectel = range.extractContents(),
- _rangselect = _selectel.childNodes;
- var _text = _rangselect.innerHTML || _rangselect.data;
- if (_newtext.trim() == "") {
- $$('a', { href: href, innerHTML: href, style: { cssText: _startspan.style.cssText }, target: "_blank" }, _frag);
- } else {
- var i, _csstext;
-
- for (i = 0; i < _rangselect.length; i++) {
- if (_rangselect[i].nodeType == 3) {
- _csstext = i == _rangselect.length ? U.UF.E.getTagNameElement(_startspan, 'span').style.cssText : U.UF.E.getTagNameElement(_end, 'span').style.cssText;
- $$("a", { href: href, innerHTML: _rangselect[i].data, style: { cssText: _csstext }, target: "_blank" }, _frag);
- } else {
- $$("a", { href: href, innerHTML: _rangselect[i].innerHTML, style: { cssText: _rangselect[i].style.cssText }, target: "_blank" }, _frag);
- }
- }
- }
- }
- _frag = U.UF.E.unifiedFormat(_frag);
- _frag.firstChild.firstChild.setAttribute("target", "_blank");
- if (_startspan.innerHTML == "") {
- U.selectEl(_startspan).remove();
- }
- if (_endspan.innerHTML == "") {
- U.selectEl(_startspan).remove();
- }
- U.UF.E.insertContent(_frag, range, U.selectEl('#U_MD_O_H_wordEditor')[0]);
- }
- }
- else {
-
- U.alert('输入的链接有误,无法添加');
- return false;
- }
- };
- U.UF.E.addHref.click = function (e) {
- if (document.getElementById('U_UF_E_herfAlert')) {
- document.getElementById('U_UF_E_herfAlert').remove();
- }
- U.UF.EV.stopBubble(e);
- var parent = U.selectEl("#U_MD_O_R_Parent")[0];
- var _hyperlinkalert = $$('div', {
- id: "U_UF_E_herfAlert",
- style: {
- "min-width": "250px", "max-width": "360px", height: "34px", background: "rgba(255,255,255,1)", border: "1px solid rgba(243,243,243,1)", "box-shadow": "0px 5px 5px 0px rgba(45,45,45,0.1)",
- "border-radius": "2px", "line-height": "34px", "font-size": "12px", "font-family": "MicrosoftYaHei", "font-weight": "400", color: "rgba(48,126,209,1)", width: "fit-content",
- width: "-webkit-fit-content", width: "-moz-fit-content", position: "absolute", zIndex: "999"
- }
- }, parent);
- var _link = $$('a', {
- innerHTML: e.target.href,
- style: {
- "overflow": "hidden", "text-overflow": "ellipsis", "white-space": "nowrap", cursor: "pointer",
- "max-width": "212px", "float": "left", "margin-left": "10px", "font-size": "14px"
- }
- }, _hyperlinkalert);
- var _rightButton = $$('div', { classname: "out_2", style: { "float": "right"} }, _hyperlinkalert);
- var _unlink = $$('div', { innerHTML: "取消链接", style: { "float": "left", "margin-left": "20px", "margin-right": "10px", cursor: "pointer"} }, _rightButton);
- var _modify = $$('div', { innerHTML: "修改", style: { "float": "left", "margin-left": "10px", "margin-right": "10px", cursor: "pointer"} }, _rightButton);
- _link.onclick = function () {
- U.UF.EV.stopBubble(e);
- parent.blur();
- window.open(e.target.href);
- }
- _unlink.onclick = function () {
- U.UF.EV.stopBubble(e);
- e.target.parentElement.replaceChild($$('span', { innerText: e.target.innerText }), e.target);
- _hyperlinkalert.remove();
- parent.blur();
- }
- _modify.onclick = function () {
- U.UF.EV.stopBubble(e);
- U.UF.E.addHref(e.target);
- parent.blur();
- _hyperlinkalert.remove();
- }
-
-
- console.log("超链接的位置", e.target.offsetLeft, e.target.offsetTop);
- console.log("光标的位置", e.clientX, e.clientY);
- console.log("滚动过的高度", U.selectEl('#U_MD_O_W_E_body')[0].offsetTop);
- var EditorScrollTop = U.selectEl('#U_MD_O_R_Parent')[0].parentNode.scrollTop;
- var EditorOffsetTop = U.selectEl('#U_MD_O_W_E_body')[0].offsetTop;
- _hyperlinkalert.style.left = e.clientX + "px";
- _hyperlinkalert.style.top = e.clientY + EditorScrollTop - EditorOffsetTop + 12 + "px";
- }
- U.UF.E.key = function (editor) {
- editor.editor.idarr = U.UF.E.key.getLineIdArr(editor);
-
- editor.onkeydown = function (e) {
- if (!editor.editor.recordOpera.range) {
- U.UF.E.recordRangeIndex(editor);
- }
- U.UF.E.key.keyDown(e, editor);
- };
-
- editor.onblur = function (e) {
- U.UF.E.key.blur(e, editor);
- };
-
- editor.onkeyup = function (e) {
- U.UF.E.key.keyUp(e, editor);
- };
-
- editor.onmouseup = function (e) {
- U.UF.E.key.keyUp(e, editor, true);
- };
- editor.onclick = function (e) {
- setTimeout(function () {
- U.UF.E.key.click(e, editor);
- }, 0);
- };
-
- editor.onmousedown = function (e) {
- setTimeout(function () {
- U.UF.E.recordRangeIndex(editor);
- }, 0);
- };
-
- editor.onpaste = function (e) {
- var _text = U.UF.E.onpaste(e, editor);
-
- if (!_text) {
- U.UF.E.pasteImage(e, editor);
- }
- };
- editor.ondragenter = U.UF.E.pasteImage.ignoreDrag;
- editor.ondragover = U.UF.E.pasteImage.ignoreDrag;
- editor.ondrop = U.UF.E.pasteImage.drop;
-
- };
- U.UF.E.key.click = function (e, edit) {
- var _nowel, _range = U.UF.E.getRangeAt(),
- _startel = U.UF.E.getLineElement(_range.startContainer)
- if (_startel != (_nowel = U.UF.E.getLineElement(edit.editor.recordRange.startContainer))) {
- edit.editor.recordHTML = _startel.outerHTML;
- }
- edit.editor.recordRange = _range;
- U.selectEl('#U_UF_E_herfAlert').remove();
- if (e.target.tagName == "A") {
- if (e.ctrlKey == true) {
- window.open(e.target.href);
- } else {
- U.UF.E.addHref.click(e);
- }
- }
- else if (e.target.tagName == "IMG" && e.target.offsetParent.className != "U_MD_F_D") {
- edit.imgStretch.img = e.target;
- U.UF.E.picture.stretch.setPosition(edit.imgStretch, e);
- } else {
- edit.imgStretch.stretch.style.display = "none";
- }
- }
- U.UF.E.key.blur = function (e, edit) {
- var _range = U.UF.E.getRangeAt();
- if (_range) {
- var _startel = U.UF.E.getLineElement(_range.startContainer);
- _oldstartel = U.UF.E.getLineElement(edit.editor.recordRange.startContainer);
- if (_startel) {
- edit.editor.recordRange = _range;
- edit.editor.recordHTML = _startel.outerHTML;
- edit.editor.log && console.log({ updateLine: [_startel.id] }, "在哪行失焦的");
- if (_oldstartel && _oldstartel.id != "U_MD_O_H_wordEditor" && _startel == _oldstartel && _oldstartel.outerHTML != edit.editor.recordHTML) {
- U.UF.E.operationNotice({ updateLine: [_startel.id] }, edit);
- clearTimeout(edit.editor.interval);
- }
- }
- }
- }
- U.UF.E.key.keyDown = function (e, edit) {
- var _range = U.UF.E.getRangeAt();
- if (!_range) { return; }
- var _el,
- _oldstartel,
- _line,
- _result,
- _startel = U.UF.E.getLineElement(_range.startContainer),
- _endel = U.UF.E.getLineElement(_range.endContainer);
- var _code = e.keyCode || e.which || e.charCode;
- if (_startel && _endel) {
- if (e.ctrlKey || e.metaKey) {
- edit.editor.recordRange = _range;
- switch (_code) {
- case 90:
- U.UF.E.key.undo(e, edit);
- return;
- case 89:
- U.UF.E.key.redo(e, edit);
- return;
- }
- }
-
- clearTimeout(edit.editor.interval);
-
- if (edit.childNodes.length == 0) {
- _result = U.UF.E.key.addDelLine(edit, _range);
-
- edit.editor.idarr = U.UF.E.key.getLineIdArr(edit);
-
- edit.editor.log && console.log(_result, "内容被情况默认添加行");
-
- edit.editor.recordRange = _range;
- edit.editor.recordHTML = U.UF.E.getLineElement(_range.startContainer).outerHTML;
-
- U.UF.E.operationNotice(_result, edit);
- return;
- }
-
- if (_code == 9) {
- _range.deleteContents();
- var _frag = $$("frag");
- var _fragel = $$('div', { innerHTML: " " });
- _frag.appendChild(_fragel.childNodes[0]);
- U.selectEl(_fragel).remove();
- _range.insertNode(_frag);
- U.UF.E.setRange(_range.endContainer, _range.endContainer, _range.endOffset, _range.endOffset, _range);
- U.UF.EV.stopDefault();
- return;
- }
-
- if (_code === 13) {
- if (!U.UF.E.getTagNameElement(_range.commonAncestorContainer, 'table')) {
- _result = U.UF.E.key.addLine(_range);
-
- edit.editor.idarr = U.UF.E.key.getLineIdArr(edit);
- U.UF.EV.stopDefault();
-
- edit.editor.log && console.log(_result, "更新换行的行,添加新的行");
-
- edit.editor.recordRange = _range;
- edit.editor.recordHTML = U.UF.E.getLineElement(_range.startContainer).outerHTML;
-
- U.UF.E.operationNotice(_result, edit);
- }
- }
- else {
- edit.editor.recordDownHTML = _startel.outerHTML;
- if (_startel == _endel && edit.editor.recordRange.endOffset != edit.editor.recordRange.startOffset) {
- setTimeout(U.UF.C.closure(function (startel, edit) {
- if (edit.editor.recordHTML != startel.outerHTML) {
- var _result = { updateLine: [_startel.id] };
- U.UF.E.operationNotice(_result, edit);
- edit.editor.log && console.log(_result, "存在选区的输入,即时更新");
- edit.editor.recordHTML = startel.outerHTML;
- edit.editor.recordRange = U.UF.E.getRangeAt();
- }
- }, [_startel, edit]), 0);
- clearTimeout(edit.editor.interval);
- }
- _line = U.UF.E.key.getLineIdArr(edit);
- _result = U.UF.E.diff(_line, edit.editor.idarr);
- edit.editor.idarr = _line;
-
- if (_result.deleteLine.length) {
- U.UF.E.operationNotice(_result, edit);
- edit.editor.log && console.log(_result, "未松开删除按钮时,删除了行");
- if (_result.updateLine[0]) {
- edit.editor.recordHTML = U.selectEl("#" + _result.updateLine[0])[0].outerHTML;
- edit.editor.recordRange = _range;
- }
- }
-
- else {
-
- edit.editor.interval = setTimeout(function () {
- if (edit.editor.recordHTML != _startel.outerHTML) {
-
- U.UF.E.operationNotice({ updateLine: [_startel.id] }, edit);
- edit.editor.log && console.log({ updateLine: [_startel.id] }, "超时更新行");
-
- edit.editor.recordRange = _range;
- edit.editor.recordHTML = _startel.outerHTML;
- }
- }, 1000);
- }
- }
- }
- };
- U.UF.E.key.keyUp = function (e, edit, click) {
- var _range = U.UF.E.getRangeAt();
- var _code = e.keyCode || e.which || e.charCode;
- if (e.ctrlKey == false) {
- U.selectEl(edit).removeClass('U_MD_O_ctrlPress');
- }
- if (_range) {
- var _line,
- _result,
- _oldstartel,
- _startel = U.UF.E.getLineElement(_range.startContainer),
- _endel = U.UF.E.getLineElement(_range.startContainer);
-
- if (edit.childNodes.length == 0) {
- _result = U.UF.E.key.addDelLine(edit, _range);
-
- edit.editor.idarr = U.UF.E.key.getLineIdArr(edit);
-
- edit.editor.log && console.log(_result, "内容被情况默认添加行");
-
- edit.editor.recordRange = _range;
- edit.editor.recordHTML = U.UF.E.getLineElement(_range.startContainer).outerHTML;
-
- U.UF.E.operationNotice(_result, edit);
- return;
- }
- _oldstartel = U.UF.E.getLineElement(edit.editor.recordRange.startContainer);
-
- if (_oldstartel && (_oldstartel != edit && _oldstartel != _startel || (_startel == _oldstartel && _startel.outerHTML != edit.editor.recordDownHTML))) {
- if (edit.editor.recordHTML != _oldstartel.outerHTML) {
- var _result = { "updateLine": [_oldstartel.id] };
- U.UF.E.operationNotice(_result, edit);
- edit.editor.log && console.log(_result, "光标切换且内容发送变化时");
- clearTimeout(edit.editor.interval);
- }
- edit.editor.recordRange = _range;
- edit.editor.recordHTML = _startel.outerHTML;
- }
- if (_code > 36 && _code < 41) {
- U.UF.E.recordRangeIndex(edit);
- }
- _line = U.UF.E.key.getLineIdArr(edit);
- _result = U.UF.E.diff(_line, edit.editor.idarr);
- edit.editor.idarr = _line;
-
- if (_result.deleteLine.length) {
- U.UF.E.operationNotice(_result, edit);
- edit.editor.log && console.log(_result, "删除了行");
- var _range = U.UF.E.getRangeAt();
- edit.editor.recordRange = _range;
- edit.editor.recordHTML = U.UF.E.getLineElement(_range.commonAncestorContainer).outerHTML;
- clearTimeout(edit.editor.interval);
- }
- U.UF.E.formatBrush(edit, false);
- }
- };
- U.UF.E.key.getLineIdArr = function (edit) {
- var _i,
- _arr = [];
-
- for (_i = 0; _i < edit.childNodes.length; _i++) {
-
- if (edit.childNodes[_i].tagName && edit.childNodes[_i].tagName.toLowerCase() === "div") {
-
- _arr.push({ "id": edit.childNodes[_i].id, "innerHTML": edit.childNodes[_i].outerHTML });
- }
- }
- return _arr;
- };
- U.UF.E.diff = function (arr1, arr2) {
- var temp = [];
- var temparray = [];
- var _i, _j;
- var _updateLine = [];
- for (_i = 0; _i < arr1.length; _i++) {
- temp[arr1[_i].id] = true;
- }
- for (_j = 0; _j < arr2.length; _j++) {
-
- if (!temp[arr2[_j].id]) {
- if (_updateLine.length == 0) {
- _updateLine.push(arr2[_j - 1].id);
- }
- temparray.push(arr2[_j].id);
- }
- }
- return {
- updateLine: _updateLine,
- deleteLine: temparray
- };
- }
- U.UF.E.key.addDelLine = function (edit, range) {
- var _range = range || U.UF.E.getRangeAt(),
- _el = $$("div", { id: edit.editor.idarr[0] ? edit.editor.idarr[0].id : "e" + Guid.newGuid(), innerHTML: "<span><br></span>" }, edit);
- _range.selectNodeContents(_el);
- _range.collapse(true);
- return { addLine: [_el.id] };
- }
- U.UF.E.key.addLine = function (range) {
- var _txtnode,
- _range = range || U.UF.E.getRangeAt(),
- _startline = U.UF.E.getLineElement(_range.startContainer),
- _el = $$('div', { id: "e" + Guid.newGuid(), style: { cssText: _startline.style.cssText} }),
- _result = {}
- ;
-
- if (_range.startOffset != _range.endOffset && _range.startContainer.innerHTML !== "<br>") {
- _range.deleteContents();
- }
- _range.setEnd(_startline, _startline.childNodes.length);
- _txt = _range.extractContents();
- if ($("img", _txt)[0]) {
- _txtnode = _txt;
- }
-
- else if (_txt.textContent.trim() === '') {
- _txtnode = $$('span', { style: { cssText: (_startline.lastChild && _startline.lastChild.style) ? _startline.lastChild.style.cssText : "" }, innerHTML: "<br>" });
- }
-
- else {
- _txtnode = _txt;
- }
-
- if (_startline.innerText == '' && !U.UF.E.validElement(_startline)) {
- var _clone = _txtnode.nodeName == "SPAN" ? _txtnode : U.selectEl('span', _txtnode)[0];
- var _content = _clone ? U.selectEl(_clone).clone()[0] : $$('span', { innerHTML: "<br>" });
- _content.innerHTML = "<br>";
- U.selectEl(_content).appendTo(_startline);
- }
- _el.appendChild(_txtnode);
- U.UF.E.insertAfter(_el, _startline);
- _range.selectNodeContents(_el);
- _range.collapse(true);
- _result.addLine = [_el.id];
- _result.updateLine = [_startline.id];
- return _result;
- };
- U.UF.E.validElement = function (el) {
- var i,
- _children = el.children,
- _valid = false;
- for (i = 0; i < _children.length; i++) {
- if (_children[i].nodeName == "BR") {
- continue;
- }
- else if (_children[i].nodeName == "IMG" || _children[i].innerText.length > 0 || ($('img', _children[i])[0] && _children[i].innerText.length == 0)) {
- _valid = true;
- }
- else {
- U.selectEl(_children[i]).remove();
- i--;
- }
- }
- return _valid;
- }
- U.UF.E.insertAfter = function (newEl, targetEl) {
-
- var parentEl = targetEl.parentNode;
-
- if (parentEl.lastChild === targetEl) {
-
- parentEl.appendChild(newEl);
- } else {
-
- parentEl.insertBefore(newEl, targetEl.nextSibling);
- }
-
- return newEl;
- };
- U.UF.E.formatBrush = function (el, pattern) {
- el = el || U.selectEl('#U_MD_O_H_wordEditor')[0];
- if (U.UF.E.formatBrush.callBack && U.UF.E.formatBrush.pattern) {
- U.UF.E.formatBrush.pattern = undefined;
- U.selectEl(el).bind('mouseup', U.UF.E.formatBrush.callBack);
- return;
- }
- var _style = pattern == false ? el.editor.recordRangeStyle : el.editor.brushStyle;
- var range = U.UF.E.getRangeAt();
-
- var _start = range.startContainer;
-
- if (_start.nodeName == "DIV") {
-
- if (!range.cloneContents().children[0]) {
- _style = {
- "font-family": "",
- "font-size": "",
- "font-weight": "",
- "font-style": "",
- "text-decoration": "",
- "color": "",
- "background-color": ""
- };
- pattern == false && (_style["text-align"] = "", _style["name"] = "");
- return;
- }
-
-
- }
-
- var _value;
- _start = _start.nodeType == 1 ? _start : _start.parentElement;
- for (var name in _style) {
-
- if (name == "font-size") {
- _value = (parseFloat(_start.currentStyle[name]) * 72 / el.editor.dpi).toFixed(1) + "pt";
- } else {
- _value = _start.currentStyle[name];
- }
- _style[name] = _value;
- }
- if (pattern !== false) {
- U.UF.E.formatBrush.pattern = pattern;
- if (pattern !== true) {
- U.selectEl(el).unbind("mouseup", U.UF.E.formatBrush.callBack);
- U.UF.E.formatBrush.callBack = function () {
- U.UF.E.fomatBrushNext(el);
- U.UF.E.formatBrush.pattern == undefined && U.selectEl(el).unbind("mouseup", U.UF.E.formatBrush.callBack);
- };
- U.selectEl(el).bind('mouseup', U.UF.E.formatBrush.callBack);
- }
- }
- else {
- _style["text-align"] = U.UF.E.getLineElement(_start).currentStyle.textAlign;
- _style["name"] = U.UF.E.getLineElement(_start).getAttribute('name');
- U.UF.C.isFunction(el.editor.styleState) && el.editor.styleState(el.editor.recordRangeStyle);
- }
- };
- U.UF.E.fomatBrushNext = function (el) {
- U.UF.E.setRangeStyle({ "cssText": '' });
-
- U.UF.E.setRangeStyle(el.editor.brushStyle);
- };
- U.UF.E.attachment = function (input, editor) {
- if (input.files.length) {
- var _range = U.UF.E.getRangeAt();
- U.UF.UP.inputUpload([input], 'http://upload.1473.cn/upload', function (r) {
- var _file, _filetype, _input = r.context[0];
- var _imgtype = /.*(jpg|png|gif|jpeg|JPG|PNG|GIF|JPEG|bmp|BMP)$/;
- var _filearray = [];
- if (Object.prototype.toString.call(r.value[0]) != "[object Array]") {
- _filearray = [r.value];
- } else {
- _filearray = r.value;
- }
- var _el, _frag = $$('frag');
- for (i = 0; i < _filearray.length; i++) {
- _file = _input.files[i];
- _filetype = _file.name.substring(_file.name.lastIndexOf('.') + 1, _file.name.length);
- if (_filetype.match(_imgtype)) {
- _el = $$("div", {}, _frag); ;
- $$('span', { innerHTML: ' <img src="http://fs.1473.cn/' + _filearray[i][0] + '">' }, _el);
- }
- else {
- _el = U.UF.E.attachment.create(_file, _filearray[i][0], _filetype);
- U.selectEl(_el).appendTo(_frag);
- }
- }
- _frag = U.UF.E.unifiedFormat(_frag);
- U.UF.E.insertContent(_frag, _range, editor || U.selectEl('#U_MD_O_H_wordEditor')[0]);
- }, [input]);
- }
- }
- U.UF.E.attachment.create = function (file, fileinfo, type) {
-
- var _attachment = $$("div", { className: "U_MD_O_attachment", id: "e" + Guid.newGuid(), contenteditable: "false" }),
- _wrapper;
- var _imgtype = /.*(jpg|png|gif|jpeg|bmp)$/;
-
- if (type.match(_imgtype)) {
- $$('span', { innerHTML: ' <img src="http://fs.1473.cn/' + fileinfo[0] + '">' }, _attachment);
- } else {
- var _videotype = /.*(mp4|avi|wmv|ogg|webm|mpg|mpeg)$/;
- var _musictype = /.*(mp3|wav|mid|midi)$/;
- $$("span", { innerHTML: "​" }, _attachment);
- _wrapper = $$("span", { contenteditable: "false" }, _attachment);
-
- if (type.match(_videotype)) {
- $$('video', { src: "http://fs.1473.cn/" + fileinfo, controls: "controls", style: { "width": "530px", "height": "300px"} }, _wrapper);
- }
-
- else if (type.match(_musictype)) {
- $$('audio', { src: "http://fs.1473.cn/" + fileinfo, controls: "controls" }, _wrapper);
- }
-
- else {
- _wrapper.className = "U_MD_O_attachment_wrapper";
- $$('span', { "className": "U_MD_O_attachment_wrapper_img", contenteditable: "false" }, _wrapper);
- var _info = $$("span", { className: "U_MD_O_attachment_fileinfo", contenteditable: "false" }, _wrapper);
- $$("span", { innerHTML: U.UF.E.attachment.fileNameSplice(file.name), contenteditable: "false" }, _info);
- $$("span", { innerHTML: U.UF.C.computeFileSize(file.size), contenteditable: "false" }, _info);
- $$("a", {
- "href": "/Pages/Download.htm?id=" + fileinfo[2],
- fileid: fileinfo[2],
- name: file.name,
- type: file.name.substring(file.name.lastIndexOf('.') + 1, file.name.length),
- target: "_blank",
- innerHTML: "打开",
- contenteditable: "false"
- }, _wrapper);
- }
- $$("span", { innerHTML: "​" }, _attachment);
- }
- return _attachment;
- }
- U.UF.E.attachment.fileNameSplice = function (name, maxlength) {
- maxlength = maxlength || 30;
- var i, _index = 0, _gblen = 0, _start = "", _end = "";
- for (i = 0; i < name.length; i++) {
- if (name.charCodeAt(i) > 127 || name.charCodeAt(i) == 94) {
- _gblen += 2;
- } else {
- _gblen++;
- }
- _gblen < maxlength / 2 - 2 && (_start += name[i]);
- }
- if (_gblen > maxlength) {
- i = name.length;
- while (_index < maxlength / 2 - 2) {
- if (name.charCodeAt(i) > 127 || name.charCodeAt(i) == 94) {
- _index += 2;
- } else {
- _index++;
- }
- _end = name[name.length - _index] + _end;
- i--;
- }
- name = _start + "..." + _end;
- }
- return name;
- }
- U.UF.E.picture = function (input, editor) {
- if (input.files.length) {
-
-
-
- input.files[0].input = input;
- for (var i = 0; i < input.files.length;i++) {
- U.UF.UP.HTML5.upload("http://upload.1473.cn/upload", input.files[i], function (r) {
-
-
-
- var _img = '';
-
-
- _img += '<span> <img src="http://fs.1473.cn/' + r.fileServerName + '"> </span>';
-
-
-
- var _editor = editor || U.selectEl('#U_MD_O_H_wordEditor')[0];
- U.UF.E.textFormat(_img, _editor);
-
- var _input = r.input;
- if (_input) {
- _input.value = "";
- }
- }, function (r) { }, function (r) { });
- }
- }
- }
- U.UF.E.pasteImage = function (e, editor) {
- e.preventDefault();
- var files = e.clipboardData.files;
- if (files.length && e.clipboardData.types.indexOf('Files') > -1) {
- var filebtn = $$('input', { type: "file" })
- filebtn.files = files;
- U.UF.E.picture(filebtn);
- filebtn.remove();
- }
- else {
- return true;
- }
- }
- U.UF.E.pasteImage.ignoreDrag = function (e) {
-
- e.stopPropagation();
- e.preventDefault();
- }
- U.UF.E.pasteImage.drop = function (e) {
-
- e.stopPropagation();
- e.preventDefault();
-
- var data = e.dataTransfer;
- var files = data.files;
-
- var filebtn = $$('input', { type: "file" })
- filebtn.files = files;
- U.UF.E.picture(filebtn, this);
- filebtn.remove();
- }
- U.UF.E.picture.stretch = function (el) {
- var _breadth = 12;
- if (!el.imgStretch) {
- var _img = $$("div", {
- style: { display: "none", border: "1px dashed #535353", position: "absolute", minWidth: "30px", minHeight: "30px" }
- }, document.body);
- var _csstext = "width:" + _breadth + "px; height:" + _breadth + "px;position:absolute;z-index:999;background:url('/EditorImage/yuan1.png') no-repeat";
- var _deviant = -_breadth / 2;
-
- el.imgStretch = {
-
- stretch: _img,
-
- nw: $$("div", { name: "nw", style: { cssText: _csstext, top: _deviant + "px", left: _deviant + "px", cursor: "nw-resize"} }, _img),
-
- ne: $$("div", { name: "ne", style: { cssText: _csstext, top: _deviant + "px", right: _deviant + "px", cursor: "ne-resize"} }, _img),
-
- sw: $$("div", { name: "sw", style: { cssText: _csstext, bottom: _deviant + "px", left: _deviant + "px", cursor: "sw-resize"} }, _img),
-
- se: $$("div", { name: "se", style: { cssText: _csstext, bottom: _deviant + "px", right: _deviant + "px", cursor: "se-resize"} }, _img),
-
- n: $$("div", { name: "n", style: { cssText: _csstext, top: _deviant + "px", left: "calc(50% - " + -_deviant + "px)", cursor: "n-resize"} }, _img),
-
- s: $$("div", { name: "s", style: { cssText: _csstext, bottom: _deviant + "px", left: "calc(50% - " + -_deviant + "px)", cursor: "s-resize"} }, _img),
-
- w: $$("div", { name: "w", style: { cssText: _csstext, left: _deviant + "px", top: "calc(50% - " + -_deviant + "px)", cursor: "w-resize"} }, _img),
-
- e: $$("div", { name: "e", style: { cssText: _csstext, right: _deviant + "px", top: "calc(50% - " + -_deviant + "px)", cursor: "e-resize"} }, _img),
-
- l: $$("div", { name: "l", style: { position: "absolute", cursor: "e-resize", left: "-1px", width: "3px", height: "100%"} }, _img),
-
- r: $$("div", { name: "r", style: { position: "absolute", cursor: "e-resize", right: "-1px", width: "3px", height: "100%"} }, _img),
-
- t: $$("div", { name: "t", style: { position: "absolute", cursor: "n-resize", top: "-1px", width: "100%", height: "3px"} }, _img),
-
- b: $$("div", { name: "b", style: { position: "absolute", cursor: "n-resize", bottom: "-1px", width: "100%", height: "3px"} }, _img),
- maxWidth: U.selectEl(el)[0].offsetWidth
- };
- }
-
- new U.UF.E.picture.stretch.bindEvent(el);
- };
- U.UF.E.picture.stretch.bindEvent = function (el) {
- this.el = el;
- this.init();
- }
- U.UF.E.picture.stretch.bindEvent.prototype = {
-
- init: function () {
- for (key in this.el.imgStretch) {
- key !== "stretch" && key !== "maxWidth" && this.el.imgStretch[key].addEventListener('mousedown', this.mouseDown.bind(this));
- }
- document.body.addEventListener('mousemove', this.mouseMove.bind(this));
- document.body.addEventListener('mouseup', this.mouseUp.bind(this));
- },
-
- mouseDown: function (e) {
- this.name = e.target.name;
- this.stratX = e.clientX;
- this.stratY = e.clientY;
- this.down = true;
- },
-
- mouseMove: function (e) {
- if (this.down) {
-
- var _moveX = e.clientX - this.stratX;
- var _moveY = this.stratY - e.clientY;
- var _click = this.name;
-
- window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
-
- if (_click.length == 2 || _click == "w" || _click == "e" || _click == "l" || _click == "r") {
-
- (_click == "w" || _click == "sw" || _click == "nw" || _click == "l") && (_moveX = -_moveX);
-
- U.UF.E.picture.stretch.moveX(this.el, this.el.imgStretch, _moveX);
- }
- if (_click.length == 2 || _click == "n" || _click == "s" || _click == "t" || _click == "b") {
-
- (_click == "n" || _click == "nw" || _click == "ne" || _click == "t") && (_moveY = -_moveY)
-
- U.UF.E.picture.stretch.moveY(this.el.imgStretch, _moveY);
- }
-
- this.stratX = e.clientX;
- this.stratY = e.clientY;
- }
- },
-
- mouseUp: function (e) {
- if (this.down) {
- var _imgstretch = this.el.imgStretch;
- _imgstretch.img.style.width = _imgstretch.stretch.offsetWidth + "px";
- _imgstretch.img.style.height = _imgstretch.stretch.offsetHeight + "px";
- U.UF.E.picture.stretch.setPosition(_imgstretch, e);
- this.down = false;
- }
- }
- }
- U.UF.E.picture.stretch.setPosition = function (obj, event) {
- var _stretch = obj.stretch;
- var _imgel = obj.img;
-
- _stretch.style.display = "block";
- var _imgelattr = _imgel.getBoundingClientRect();
- if (event.clientX == event.pageX && event.clientY == event.pageY) {
- _stretch.style.left = _imgelattr.left + "px";
- _stretch.style.top = _imgelattr.top + U.selectEl('body')[0].scrollTop + "px";
- } else {
- var _offset = U.UF.E.picture.parentOfferset(_imgel, { "offsetLeft": 0, "offsetTop": 0 });
- _stretch.style.left = _imgel.offsetLeft + _offset.offsetLeft + parseInt($(_imgel).css("padding-left")) + "px";
- _stretch.style.top = _imgel.offsetTop + _offset.offsetTop + parseInt($(_imgel).css("padding-top")) + "px";
- }
- _stretch.style.width = _imgelattr.width - 2 + "px";
- _stretch.style.height = _imgelattr.height - 2 + "px";
- var _objattr = _stretch.getBoundingClientRect();
- var _breadth = obj.n.offsetWidth / 2;
- obj.n.style.left = _objattr.width / 2 - _breadth + "px";
- obj.w.style.top = _objattr.height / 2 - _breadth + "px";
- obj.s.style.left = _objattr.width / 2 - _breadth + "px";
- obj.e.style.top = _objattr.height / 2 - _breadth + "px";
- }
- U.UF.E.picture.stretch.moveX = function (el, obj, moveX) {
- var _stretch = obj.stretch;
- if ((parseInt(_stretch.style.width) + moveX < obj.maxWidth && parseInt(_stretch.style.width) + moveX > 30)) {
- var _align = el.editor ? el.editor.recordRangeStyle["text-align"] : "";
- switch (_align) {
- case "end":
- case "right":
- _stretch.style.left = _stretch.offsetLeft - moveX + 'px';
- U.selectEl(_stretch)[0].style.width = parseInt(_stretch.style.width) + moveX + "px";
- break;
- case "center":
- _stretch.style.width = parseInt(_stretch.style.width) + moveX + 'px';
- _stretch.style.left = parseFloat(_stretch.style.left) - moveX / 2 + 'px';
- break;
- default:
- _stretch.style.width = parseInt(_stretch.style.width) + moveX + "px";
- }
- obj.n.style.left = obj.s.style.left = _stretch.offsetWidth / 2 - obj.s.offsetWidth / 2 + "px";
- }
- };
- U.UF.E.picture.stretch.moveY = function (obj, moveY) {
- var _stretch = obj.stretch;
-
- _stretch.style.height = _stretch.offsetHeight - 2 - moveY + "px";
-
- obj.w.style.top = obj.e.style.top = _stretch.offsetHeight / 2 - obj.w.offsetWidth / 2 + 'px';
- };
- U.UF.E.picture.parentOfferset = function (obj, json) {
- var _offset = {};
-
- if (obj.offsetParent.offsetLeft != 0) {
-
- _offset.offsetLeft = obj.offsetParent.offsetLeft;
- } else {
-
- _offset.offsetLeft = 0;
- }
-
- if (obj.offsetParent.offsetTop != 0) {
-
- _offset.offsetTop = obj.offsetParent.offsetTop;
- } else {
-
- _offset.offsetTop = 0;
- }
- json.offsetLeft = _offset.offsetLeft + json.offsetLeft;
- json.offsetTop = _offset.offsetTop + json.offsetTop;
-
- if (_offset.offsetTop == 0 && _offset.offsetLeft == 0) {
- return json;
- } else {
- return U.UF.E.picture.parentOfferset(obj.offsetParent, json);
- }
- }
- U.UF.E.editInfo = function (id, content, next) {
- var _data = {
- id: id,
- content: content,
- nextId: next
- };
- return _data;
- };
- U.UF.E.operationNotice = function (operaRecord, editor) {
- var _opera = {};
-
- if (operaRecord.addLine) {
- _opera.addLine = U.UF.E.addLineMessage(operaRecord.addLine, editor);
- }
-
- if (operaRecord.updateLine) {
- _opera.updateLine = U.UF.E.updateLineMessage(operaRecord.updateLine, editor);
- }
-
- if (operaRecord.deleteLine) {
- _opera.deleteLine = U.UF.E.deleteLineMessage(operaRecord.deleteLine, editor);
- }
-
- U.UF.E.setRecord(operaRecord, editor);
-
- if (U.UF.C.isFunction(editor.editor.operaNotice)) {
- editor.editor.operaNotice(_opera);
- }
- }
- U.UF.E.addLineMessage = function (array, edit) {
- var _i,
- _nextlineid,
- _el,
- _editinfo,
- _message = []
- ;
-
- for (_i = 0; _i < array.length; _i++) {
- _el = U.selectEl('#' + array[_i])[0];
- _nextlineid = (_nextlineid = U.selectEl('#' + array[_i])[0].nextElementSibling) ? _nextlineid.id : null;
- _editinfo = U.UF.E.editInfo(array[_i], _el.outerHTML, _nextlineid);
- _message.push(_editinfo);
- }
- return _message;
- };
- U.UF.E.updateLineMessage = function (array, edit) {
- var _i,
- _el,
- _editinfo,
- _message = [];
- for (_i = 0; _i < array.length; _i++) {
- _el = U.selectEl('#' + array[_i])[0];
- _editinfo = U.UF.E.editInfo(array[_i], _el.outerHTML, null);
- _message.push(_editinfo);
- }
- return _message;
- };
- U.UF.E.deleteLineMessage = function (array, edit) {
- var _i,
- _editinfo,
- _message = []
- ;
- for (_i = 0; _i < array.length; _i++) {
- _editinfo = U.UF.E.editInfo(array[_i], "", null);
- _message.push(_editinfo);
- }
- return _message;
- };
- U.UF.E.setRecord = function (opera, editor) {
- if (editor.editor.isrecord && editor.editor.recordOpera && editor.editor.recordOpera.range) {
- editor.editor.recordsEditor.splice(editor.editor.recordsEditorIndex, editor.editor.recordsEditor.length - editor.editor.recordsEditorIndex);
- editor.editor.recordsEditorIndex = editor.editor.recordsEditor.length;
-
- editor.editor.recordsEditor.push({
- "opera": opera,
- "recordLine": editor.editor.recordOpera
- });
- editor.editor.recordsEditorIndex++;
-
- editor.editor.recordOpera = { "line": U.UF.E.key.getLineIdArr(editor) };
- U.UF.E.recordRangeIndex(editor);
- }
- editor.editor.isrecord = true;
- }
- U.UF.E.recordRangeIndex = function (editor) {
-
- var _range = U.UF.E.getRangeAt();
- if (_range) {
- var _startel = U.UF.E.getLineElement(_range.startContainer),
- _endel = U.UF.E.getLineElement(_range.endContainer)
- ;
- if (_startel && _endel) {
-
- editor.editor.recordOpera.range = {
- "startid": _startel.id,
- "endid": _endel.id,
- "endOffset": _range.endOffset,
- "startOffset": _range.startOffset,
- "start": U.UF.E.getElementByAncestorsIndex(_startel, _range.startContainer),
- "end": U.UF.E.getElementByAncestorsIndex(_endel, _range.endContainer)
- };
- }
- }
- }
- U.UF.E.getElementByAncestorsIndex = function (el, childel) {
- var i, j, _child, _cindex;
-
- if (el !== childel) {
- _child = el.childNodes;
- for (i = 0; i < _child.length; i++) {
-
- if (_child[i] == childel) {
- _cindex = i;
- break;
- }
-
- else if (U.UF.EL.isChild(_child[i], childel)) {
- _child = _child[i].childNodes;
-
- for (j = 0; j < _child.length; j++) {
- if (_child[j] == childel) {
- _cindex = [i, j];
- break;
- }
- }
- }
- }
- }
- return _cindex;
- }
- U.UF.E.key.undo = function (e, editor) {
- var i, j, k,
- _info,
- _operarecord = {},
- _index = editor.editor.recordsEditorIndex - 1,
- _record,
- _line;
- if (_index > -1 && editor.editor.recordsEditor.length >= _index) {
- _record = editor.editor.recordsEditor[_index];
- _line = _record.recordLine.line;
-
- if (_record.recordLine) {
- for (i in _record.opera) {
- switch (i) {
-
- case "addLine":
-
- for (j = 0; j < _record.opera[i].length; j++) {
- U.UF.E.deleteEditorLine(_record.opera[i][j]);
- }
- break;
- case "updateLine":
-
- for (j = 0; j < _record.opera[i].length; j++) {
- U.UF.E.updateEditorLine({ "id": _record.opera[i][j], "content": U.UF.E.getLineContentById(_line, _record.opera[i][j]) });
- }
- break;
- case "deleteLine":
-
- for (j = 0; j < _record.opera[i].length; j++) {
- _info = U.UF.E.getLineInfoById(_line, _record.opera[i][j]);
- U.UF.E.addEditorLine({ "nextId": _info.next ? _info.next.id : null, "content": _info.info.innerHTML }, editor);
- }
- break;
- }
- }
- U.UF.E.setRecordRange(_record.recordLine.range);
-
- if (editor.editor.recordsEditor.length == _index + 1) {
- U.UF.E.setRecord(_record.opera, editor);
- }
- editor.editor.recordsEditorIndex--;
- editor.editor.isrecord = false;
- }
- }
-
- U.UF.EV.stopDefault();
- }
- U.UF.E.key.redo = function (e, editor) {
- var i, j, k,
- _info,
- _operarecord = {},
- _index = editor.editor.recordsEditorIndex,
- _record,
- _line;
- if (_index > -1 && _index < editor.editor.recordsEditor.length) {
- _record = editor.editor.recordsEditor[_index];
- _line = _record.recordLine.line;
-
- if (_record.recordLine) {
- for (i in _record.opera) {
- switch (i) {
-
- case "addLine":
-
- for (j = 0; j < _record.opera[i].length; j++) {
- _info = U.UF.E.getLineInfoById(_line, _record.opera[i][j]);
- U.UF.E.addEditorLine({ "nextId": _info.next ? _info.next.id : null, "content": _info.info.innerHTML }, editor);
- }
- break;
- case "updateLine":
-
- for (j = 0; j < _record.opera[i].length; j++) {
- U.UF.E.updateEditorLine({ "id": _record.opera[i][j], "content": U.UF.E.getLineContentById(_line, _record.opera[i][j]) });
- }
- break;
- case "deleteLine":
-
- for (j = 0; j < _record.opera[i].length; j++) {
- U.UF.E.deleteEditorLine(_record.opera[i][j]);
- }
- break;
- }
- }
- U.UF.E.setRecordRange(_record.recordLine.range);
- editor.editor.isrecord = false;
- editor.editor.recordsEditorIndex++;
- }
- }
-
- U.UF.EV.stopDefault();
- }
- U.UF.E.setRecordRange = function (range) {
- var _startel,
- _start,
- _endel,
- _end;
-
- if (range.startid && U.selectEl("#" + range.startid)[0]) {
- _start = range.startOffset;
-
- if (range.start.length) {
- _startel = U.selectEl("#" + range.startid)[0].childNodes[range.start[0]].childNodes[range.start[1]];
- }
- else {
- _startel = U.selectEl("#" + range.startid)[0].childNodes[range.start];
- }
- }
-
- if (range.endid && U.selectEl("#" + range.endid)[0]) {
- _end = range.endOffset;
-
- if (range.start.length) {
- _endel = U.selectEl("#" + range.endid)[0].childNodes[range.end[0]].childNodes[range.end[1]];
- }
- else {
- _endel = U.selectEl("#" + range.endid)[0].childNodes[range.end];
- }
- }
-
- U.UF.E.setRange(_startel, _endel, _start, _end)
- }
- U.UF.E.getLineContentById = function (line, id) {
- for (var i = 0; i < line.length; i++) {
- if (line[i].id == id) {
- return line[i].innerHTML;
- }
- }
- return "";
- }
- U.UF.E.getLineInfoById = function (line, id) {
- for (var i = 0; i < line.length; i++) {
- if (line[i].id == id) {
- return { "pre": line[i - 1], "next": line[i + 1], "info": line[i] }
- }
- }
- return null;
- }
- U.UF.E.updateEditorLine = function (opera) {
-
- if ($('#' + opera.id)[0]) {
- U.selectEl('#' + opera.id)[0].outerHTML = opera.content;
- }
- else {
- console.log('updateError', opera.id);
- }
- };
- U.UF.E.deleteEditorLine = function (opera) {
-
- U.selectEl('#' + opera.id).remove();
- };
- U.UF.E.addEditorLine = function (opera, editor) {
- editor = editor || U.selectEl('#U_MD_O_H_wordEditor')[0];
- var _next,
- _line = $$("div", {}, editor);
-
- if (opera.nextId && (_next = U.selectEl('#' + opera.nextId))[0]) {
- _next.Parent().insertBefore(_line, _next[0]);
- }
- U.selectEl(_line)[0].outerHTML = opera.content;
- }
|