1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695 |
-
- 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://disk.1473.cn/USUpfile.ashx?typename=UseStudioEditor&UserId=FA92AAC5-4134-449F-9659-0DC12F4F68E9', 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) {
- var _range = U.UF.E.getRangeAt();
- U.UF.UP.inputUpload([input], 'http://disk.1473.cn/USUpfile.ashx?typename=UseStudioEditor&UserId=FA92AAC5-4134-449F-9659-0DC12F4F68E9', function (r) {
- var _input = r.context[0];
- var _imgarray = [];
- if (Object.prototype.toString.call(r.value[0]) != "[object Array]") {
- _imgarray = [r.value];
- } else {
- _imgarray = r.value;
- }
-
- var _img = '';
- for (i = 0; i < _imgarray.length; i++) {
-
- _img += '<span> <img src="http://fs.1473.cn/' + _imgarray[i][0] + '"> </span>';
- }
-
-
- var _editor = editor || U.selectEl('#U_MD_O_H_wordEditor')[0];
- U.UF.E.textFormat(_img, _editor);
- }, [input]);
- }
- }
- 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;
- }
|