PageSourceSearch

https://corporate.vipp.mx/AdminVipp/ScriptResource.axd?d=D2eF7Wo5k…mzT1VjD13n1mPN9woC1oL3A2&t=ffffffffda74082d

js vipp.mx collected 2026-10-02 01:06:53 UTC 122,662 bytes, 3,143 lines download raw bytes

1// Name:        HTMLEditor.DesignPanel.debug.js
2// Assembly:    AjaxControlToolkit
3// Version:     4.5.7.1213
4// FileVersion: 4.5.7.1213
5Type.registerNamespace("Sys.Extended.UI.HTMLEditor");
6
7Sys.Extended.UI.HTMLEditor.DesignPanel = function(element) {
8    Sys.Extended.UI.HTMLEditor.DesignPanel.initializeBase(this, [element]);
9    this._doc = null;
10    this._updated_now = false;
11    this._updateTimer = null;
12    this._popup = null;
13    this._contextElement = null;
14    this._a_prize = false;
15    this.__stack = null;
16    this._StyleForTyping = null;
17    this.isWord = false;
18    this.isPlainText = false;
19    this.dfltBlockElement = "P";
20    this._FontNotSet = true;
21    this._design_timer1 = null;
22   
23
24    this._events$delegate = Function.createDelegate(this, Sys.Extended.UI.HTMLEditor.DesignPanelEventHandler);
25    this._blur$delegate = Function.createDelegate(this, this._blur);
26    this._focus$delegate = Function.createDelegate(this, this._focus_event);
27}
28
29Sys.Extended.UI.HTMLEditor.DesignPanel.prototype = {
30    initialize: function() {
31        Sys.Extended.UI.HTMLEditor.DesignPanel.callBaseMethod(this, "initialize");
32    },
33
34    dispose: function() {
35        Sys.Extended.UI.HTMLEditor.DesignPanel.callBaseMethod(this, "dispose");
36    },
37
38    _activate: function(value) {
39        Sys.Extended.UI.HTMLEditor.DesignPanel.callBaseMethod(this, "_activate");
40        this._wasFocused = false;
41        this._initIframe(value);
42        this._onDocumentLoaded();
43    },
44
45    _deactivate: function() {
46        this._deactivateCommon();
47        if (Sys.Extended.UI.HTMLEditor.isIE) {
48            this._doc.open();
49            this._doc.write("");
50            this._doc.close();
51            this.get_element().src = "javascript:false;";
52        }
53        this._doc = null;
54        Sys.Extended.UI.HTMLEditor.DesignPanel.callBaseMethod(this, "_deactivate");
55    },
56
57    _deactivateCommon: function() {
58        this._editPanel.__blured = false;
59        var aList = this._doc.body.getElementsByTagName("IMG");
60
61        for (var i = 0; i < aList.length; i++) {
62            if (aList[i].getAttribute(Sys.Extended.UI.HTMLEditor.attachedIdAttribute) && aList[i].getAttribute(Sys.Extended.UI.HTMLEditor.attachedIdAttribute).length > 0) {
63                try {
64                    if (Sys.Extended.UI.HTMLEditor.isIE) {
65                        $removeHandler(aList[i], "dragstart", Sys.Extended.UI.HTMLEditor.stopDrag);
66                    } else {
67                        $removeHandler(aList[i], "draggesture", Sys.Extended.UI.HTMLEditor.stopDrag);
68                    }
69                } catch (e) { }
70            }
71        }
72
73        Sys.Extended.UI.HTMLEditor._removeEvents(this._doc, ["keydown", "keypress", "mousedown", "mouseup", "dblclick"], this._events$delegate);
74        Sys.Extended.UI.HTMLEditor._removeEvents(this.get_element().contentWindow, ["blur"], this._blur$delegate);
75        Sys.Extended.UI.HTMLEditor._removeEvents(this.get_element().contentWindow, ["focus"], this._focus$delegate);
76    },
77
78    _initIframe: function(value) {
79        if (!Sys.Extended.UI.HTMLEditor.isIE) {
80            this._savedValue = value;
81            this._absAndFixedParents = this._getAbsAndFixedParents();
82        }
83        var str = Sys.Extended.UI.HTMLEditor.Trim(this._prepareContent(value));
84        this._doc = this.get_element().contentWindow.document;
85
86        if (!Sys.Extended.UI.HTMLEditor.isIE) {
87            this._doc.designMode = "on";
88        }
89
90        this._doc.open();
91        this._doc.write("<html><head><link rel=\"stylesheet\" href=\"" + this._editPanel.get_documentCssPath() + "\" media=\"all\" /><link rel=\"stylesheet\" href=\"" + this._editPanel.get_designPanelCssPath() + "\" media=\"all\" /></head><body>" + str + "</body></html>");
92        this._doc.close();
93        this._doc.id = "EditorDocument";
94
95        if (Sys.Extended.UI.HTMLEditor.isIE) {
96            this._doc.body.contentEditable = true;
97            this._tryForward = true;
98        }
99    },
100
101    _blur: function(event) {
102        this._editPanel.__blured = true;
103        if (!Sys.Extended.UI.HTMLEditor.isIE && this._design_timer1 != null) {
104            clearTimeout(this._design_timer1);
105            this._design_timer1 = null;
106        }
107        if (!this.isPopup) {
108            this._editPanel._validate(event, null);
109        }
110        return true;
111    },
112
113    _focus_event: function() {
114        this._editPanel.__blured = false;
115        if (Sys.Extended.UI.HTMLEditor.isIE) {
116            this._really_focused();
117        }
118        else {
119            var panel = this;
120            Sys.Extended.UI.HTMLEditor.LastFocusedEditPanel = this._editPanel;
121            if (this._design_timer1 == null) {
122                this._design_timer1 = setTimeout(function() { panel._really_focused(); panel._design_timer1 = null; }, 0);
123            }
124        }
125        return true;
126    },
127
128    _getAbsAndFixedParents: function() {
129        var el = this.get_element();
130        var str = "";
131        while (el != null && el.tagName && el.tagName.toLowerCase() != "body") {
132            str += el.tagName;
133            if (el.style.position == "absolute" || el.style.position == "fixed") {
134                str += ": " + el.style.position;
135            }
136            str += "\n";
137            el = el.parentNode;
138        }
139        return str;
140    },
141
142    _onDocumentLoaded: function() {
143        var editor = this;
144        if (!Sys.Extended.UI.HTMLEditor.isIE) {
145            var absAndFixedParents = this._getAbsAndFixedParents();
146            if (absAndFixedParents != this._absAndFixedParents) {
147                this._initIframe(this._savedValue);
148                setTimeout(function() { editor._onDocumentLoaded() }, 10);
149                return;
150            }
151        }
152
153        try {
154            if (!Sys.Extended.UI.HTMLEditor.isIE) {
155                this._doc.queryCommandValue("forecolor");
156                if (Sys.Extended.UI.HTMLEditor.isSafari || Sys.Extended.UI.HTMLEditor.isOpera) {
157                    if (!Sys.Extended.UI.HTMLEditor.isReallyVisible(this.get_element())) {
158                        setTimeout(function() { editor._onDocumentLoaded() }, 10);
159                        return;
160                    }
161                }
162            }
163            var temp = editor._doc.body.innerHTML;
164        } catch (e) {
165            setTimeout(function() { editor._onDocumentLoaded() }, 10); // waiting for loading
166            return;
167        }
168
169        this._afterBodyIsFormed();
170
171        setTimeout(function() { editor._activateFinished(); if (Sys.Extended.UI.HTMLEditor.isIE && !editor._editPanel.get_autofocus()) { editor._getSelection().empty(); } }, 0);
172    },
173
174    _afterBodyIsFormed: function() {
175        var editor = this;
176
177        Sys.Extended.UI.HTMLEditor._addEvents(this._doc, ["keydown", "keypress", "mousedown", "mouseup", "dblclick"], this._events$delegate);
178        Sys.Extended.UI.HTMLEditor._addEvents(this.get_element().contentWindow, ["blur"], this._blur$delegate);
179        Sys.Extended.UI.HTMLEditor._addEvents(this.get_element().contentWindow, ["focus"], this._focus$delegate);
180
181        Sys.Extended.UI.HTMLEditor.inspectForShadows(editor._doc.body);
182
183        var body = this._doc.body;
184
185        if (body.childNodes.length == 1 && body.firstChild.tagName && body.firstChild.tagName.toUpperCase() == "DIV" &&
186                body.firstChild.style.cssText.length > 0 && body.firstChild.style.direction.length > 0 &&
187                Sys.Extended.UI.HTMLEditor.getStyle(body.firstChild, "position") != "absolute") {
188
189            body.style.cssText = body.firstChild.style.cssText;
190            var temp = body.firstChild;
191
192            while (temp.firstChild) body.insertBefore(temp.firstChild, temp);
193            body.removeChild(temp);
194        }
195
196        editor._clearP();
197    },
198
199    _getContent: function() {
200        if (this._popup != null) {
201            if (typeof this._popup._forceImClose == "function") {
202                var func = this._popup._forceImClose;
203                func(this._popup._iframe.contentWindow);
204            }
205        }
206
207        this._clearP();
208        var temp;
209
210        if (Sys.Extended.UI.HTMLEditor.isIE) {
211            Sys.Extended.UI.HTMLEditor.spanJoiner(this._doc.body, this._doc);
212            temp = Sys.Extended.UI.HTMLEditor.getHTML(this._doc.body, false, true);
213
214            temp = temp.replace(/(<td[^>]*?>)([\s ]*?)(<\/td[^>]*?>)/ig, "$1&nbsp;$3")
215                .replace(/(<td[^>]*?>)\s*(&nbsp;)\s*(<\/td[^>]*?>)/ig, "$1<br/>$3")
216                .replace(/(<p[^>]*?>)\s*(&nbsp;)\s*(<\/p[^>]*?>)/ig, "$1<br/>$3");
217            temp = ((this._doc.body.style.cssText.length > 0) ? "<div style=\"" + this._doc.body.style.cssText.replace("\"", "'") + "\">" : "") + temp + ((this._doc.body.style.cssText.length > 0) ? "</div>" : "");
218
219            if (this._editPanel.get_noScript()) {
220                temp = temp.replace(/(<script(?:[^>]*?)>(?:[^<]*?)<\/script(?:[^>]*?)>)/gi, "");
221            }
222
223            if (/<embed/ig.test(temp)) {
224                temp = temp.replace(/(<embed(?:.*?))(\sloop=\"true\")((?:.*?)>)/ig, "$1$3")
225                    .replace(/(<embed(?:.*?))(\splay=\"true\")((?:.*?)>)/ig, "$1$3")
226                    .replace(/(<embed(?:.*?))(\sbgcolor=\"\")((?:.*?)>)/ig, "$1$3")
227                    .replace(/(<embed(?:.*?))(\sscale=\"\")((?:.*?)>)/ig, "$1$3")
228                    .replace(/(<embed(?:.*?))(\shspace=\"0\")((?:.*?)>)/ig, "$1$3")
229                    .replace(/(<embed(?:.*?))(\svspace=\"0\")((?:.*?)>)/ig, "$1$3")
230                    .replace(/(<embed(?:.*?))(\swmode=\"[^\"]+\")((?:.*?)>)/ig, "$1$3")
231                    .replace(/(<embed(?:.*?))(pseudomode=)(\"[^\"]*\")((?:.*?)>)/ig, "$1wmode=$3$4")
232                    .replace(/(<embed(?:.*?))(\swmode=\"\")((?:.*?)>)/ig, "$1$3");
233            }
234
235            var nnreg = new RegExp("(<[/]?)(teo" + Sys.Extended.UI.HTMLEditor.smartClassName + ":)", "ig");
236            temp = temp.replace(nnreg, "$1");
237        } else {
238            var trg = this._doc.createElement("DIV");
239            var scriptRecover = new Sys.Extended.UI.HTMLEditor.DesignPanel.ScriptRecover();
240
241            trg.style.cssText = this._doc.body.style.cssText;
242            if (!this._editPanel.get_noScript()) {
243                this._doc.body.innerHTML.replace(/<script(?:[^>]*?)>(.*?)<\/script(?:[^>]*?>)/gi, function(p0, p1) { return scriptRecover.regReplScript1(p0, p1); });
244            }
245
246            trg.innerHTML = Sys.Extended.UI.HTMLEditor.Trim(this._doc.body.innerHTML);
247
248            var tempCollection = trg.getElementsByTagName("IMG");
249            var imgCollection = [];
250            for (var i = 0; i < tempCollection.length; i++) imgCollection.push(tempCollection[i]);
251
252            for (var j = 0; j < imgCollection.length; j++) {
253                var img = imgCollection[j];
254                var attr;
255
256                attr = img.getAttribute("dummytag");
257                if (attr && attr.length > 0 && attr.toLowerCase() == "embed") {
258                    var src = img.getAttribute("dummysrc");
259                    var bgcolor = img.getAttribute("dummybgcolor");
260                    var wmode = img.getAttribute("pseudomode");
261                    var attrs = img.attributes;
262                    var embed = this._doc.createElement("EMBED");
263
264                    embed.src = src;
265                    embed.width = img.width;
266                    embed.height = img.height;
267
268                    if (bgcolor && bgcolor.length > 0) {
269                        bgcolor = Sys.Extended.UI.HTMLEditor.tryReplaceRgb(bgcolor);
270                        embed.setAttribute("bgcolor", bgcolor);
271                    }
272
273                    if (wmode && wmode.length > 0) {
274                        embed.setAttribute("wmode", wmode);
275                    }
276
277                    for (var i = 0; i < attrs.length; ++i) {
278                        var a = attrs.item(i);
279                        if (!a.specified) continue;
280
281                        var name = a.name.toLowerCase();
282                        var value = a.value;
283
284                        if (name == "dummytag" || name == "dummysrc" ||
285                           name == "dummybgcolor" || name == "style" ||
286                           name == "wmode" || name == "pseudomode" ||
287                           name == "src")
288                            continue;
289
290                        if (name == "loop" && value == "true") continue;
291                        if (name == "play" && value == "true") continue;
292                        if (name == "hspace" && value == "0") continue;
293                        if (name == "vspace" && value == "0") continue;
294                        if (name == "scale" && value.length == 0) continue;
295                        if (name == "align" && value.length == 0) continue;
296
297                        embed.setAttribute(name, value);
298                    }
299
300                    if (img.style.width && img.style.width.length > 0) embed.style.width = img.style.width;
301                    if (img.style.height && img.style.height.length > 0) embed.style.height = img.style.height;
302
303                    img.parentNode.insertBefore(embed, img);
304                    img.parentNode.removeChild(img);
305                }
306            }
307
308            Sys.Extended.UI.HTMLEditor.spanJoiner(trg, this._doc);
309
310            temp = Sys.Extended.UI.HTMLEditor.getHTML(trg, (trg.style.cssText.length > 0) ? true : false, true);
311            if (!this._editPanel.get_noScript()) {
312                temp = temp.replace(/(<script(?:[^>]*?)>)(.*?)(<\/script(?:[^>]*?)>)/gi, function(p0, p1, p2, p3) { return scriptRecover.regReplFromScript1(p0, p1, p2, p3); });
313            } else {
314                temp = temp.replace(/(<script(?:[^>]*?)>(?:[^<]*?)<\/script(?:[^>]*?)>)/gi, "");
315            }
316
317            delete trg;
318        }
319
320        temp = Sys.Extended.UI.HTMLEditor.brXHTML(temp.replace(/^([\n|\r]+)/, ""));
321        if (this._editPanel.get_noUnicode()) {
322            temp = temp.replace(/([\u0080-\uFFFF])/g, function(p0, p1) { return "&#" + p1.charCodeAt(0).toString(10) + ";"; });
323        }
324        if (Sys.Extended.UI.HTMLEditor.Trim(temp) == "<br />") {
325            temp = "";
326        }
327        return temp;
328    },
329
330    _setContent: function(value) {
331        this._deactivateCommon();
332        var str = Sys.Extended.UI.HTMLEditor.Trim(this._prepareContent(value));
333        this._doc.open();
334        this._doc.write("<html><head><link rel=\"stylesheet\" href=\"" + this._editPanel.get_documentCssPath() + "\" media=\"all\" /><link rel=\"stylesheet\" href=\"" + this._editPanel.get_designPanelCssPath() + "\" media=\"all\" /></head><body>" + str + "</body></html>");
335        this._doc.close();
336
337        if (Sys.Extended.UI.HTMLEditor.isIE) {
338            this._doc.body.contentEditable = true;
339            this._tryForward = true;
340        }
341
342        this._afterBodyIsFormed();
343        if (this._editPanel.get_autofocus()) {
344            this._focus();
345        }
346        if (Sys.Extended.UI.HTMLEditor.isIE && !this._editPanel.get_autofocus()) {
347            this._getSelection().empty();
348        }
349    },
350
351    _focus: function(prize) {
352        this.focusEditor();
353        this._focused(prize);
354    },
355
356    focusEditor: function() {
357        try {
358            this.get_element().contentWindow.focus();
359        } catch (e) { }
360
361        if (!this._wasFocused) {
362            this._wasFocused = true;
363            if (!this._editPanel.get_startEnd()) {
364                this._setToEnd();
365            }
366        }
367    },
368
369    _prepareContent: function(value) {
370        var temptext = value;
371
372        temptext = temptext.replace(/<object(?:[^>]*?)>(?:[^\u0000]*?)(<embed(?:[^>]*?)>)(?:[^\u0000]*?)<\/object(?:[^>]*?)>/gi, "$1");
373
374        if (Sys.Extended.UI.HTMLEditor.isIE) {
375            temptext = Sys.Extended.UI.HTMLEditor.Trim(temptext.replace(/([\n\r]+<)/g, "<").replace(/([^>
375])([\n\r]+)([^<])/g, "$1 $3"))
376                .replace(/(&amp;)/g, "&amp;amp;")
377                .replace(/<br\s*[\/]*>\s*<\/td>/ig, "</td>")
378                .replace(/(<td[^>]*?>)([\s ]*?)(<\/td[^>]*?>)/ig, "$1&nbsp;$3")
379                .replace(/(<p[^>]*?>)\s*(<br[^>]*?>)\s*(<\/p[^>]*?>)/ig, "$1&nbsp;$3");
380
381            if (/<embed/ig.test(temptext)) {
382                temptext = temptext.replace(/(<embed(?:.*?))(wmode=)(\"[^\"]*\")((?:.*?)>)/ig, "$1pseudomode=$3$4")
383                    .replace(/(<embed)([^>]*?>)/ig, "$1 wmode=\"transparent\"$2");
384            }
385
386            temptext = temptext.replace(/&amp;/ig, "&");
387            return temptext;
388        } else {
389            var scriptRecover = new Sys.Extended.UI.HTMLEditor.DesignPanel.ScriptRecover();
390            var src = document.createElement("DIV");
391
392            if (!this._editPanel.get_noScript()) {
393                temptext.replace(/<script(?:[^>]*?)>(.*?)<\/script(?:[^>]*?>)/gi, function(p0, p1) { return scriptRecover.regReplScript1(p0, p1); });
394            }
395
396            src.innerHTML = Sys.Extended.UI.HTMLEditor.Trim(temptext.replace(/([^>])([\n\r]+)([^<])/g, "$1 $3"));
397
398            var tempCollection = src.getElementsByTagName("EMBED");
399
400            var embedCollection = [];
401            for (var i = 0; i < tempCollection.length; i++) embedCollection.push(tempCollection[i]);
402
403            for (var j = 0; j < embedCollection.length; j++) {
404                var embed = embedCollection[j];
405                var img = document.createElement("IMG");
406                var attrs = embed.attributes;
407
408                img.src = this._editPanel.get_imagePath_1x1();
409                img.setAttribute("dummytag", "embed");
410
411                for (var i = 0; i < attrs.length; ++i) {
412                    var a = attrs.item(i);
413                    if (!a.specified) continue;
414
415                    var name = a.name.toLowerCase();
416                    var value = a.value;
417
418                    if (name == "src") name = "dummysrc";
419                    else
420                        if (name == "bgcolor") name = "dummybgcolor";
421                    else
422                        if (name == "wmode") name = "pseudomode";
423
424                    img.setAttribute(name, value);
425                }
426
427                img.style.cssText = "border: 1px dotted #000000; background-image: url('" + (img.getAttribute("type").toLowerCase() == "application/x-mplayer2" ? this._editPanel.get_imagePath_media() : tthis._editPanel.get_imagePath_flash()) + "'); background-position: center; background-repeat: no-repeat; background-color: #c0c0c0;";
428
429                if (embed.style.width && embed.style.width.length > 0) img.style.width = embed.style.width;
430                if (embed.style.height && embed.style.height.length > 0) img.style.height = embed.style.height;
431
432                embed.parentNode.insertBefore(img, embed);
433                embed.parentNode.removeChild(embed);
434            }
435
436            Sys.Extended.UI.HTMLEditor.spanJoiner(src, document);
437
438            temptext = Sys.Extended.UI.HTMLEditor.Trim(Sys.Extended.UI.HTMLEditor.getHTML(src, false, true));
439            if (!this._editPanel.get_noScript()) {
440                temptext = temptext.replace(/(<script(?:[^>]*?)>)(.*?)(<\/script(?:[^>]*?)>)/gi, function(p0, p1, p2, p3) { return scriptRecover.regReplFromScript1(p0, p1, p2, p3); });
441            }
442
443            delete src;
444            delete scriptRecover;
445            temptext = Sys.Extended.UI.HTMLEditor.brXHTML(temptext);
446            if (temptext.length == 0) {
447                temptext = "<br/>";
448            }
449            return temptext;
450        }
451    },
452
453    _clearP: function() {
454        try {
455            var el = this._doc.body;
456
457            if (el.firstChild)
458                if (el.firstChild.nodeType == 3) {
459                var str = Sys.Extended.UI.HTMLEditor.Trim("" + el.firstChild.data + "");
460
461                if (str.length == 0)
462                    el.removeChild(el.firstChild);
463                else
464                    if (str != ("" + el.firstChild.data + ""))
465                    el.firstChild.data = str;
466            }
467
468            if (Sys.Extended.UI.HTMLEditor.isIE) {
469                if (el.childNodes.length == 1) {
470                    el = el.firstChild;
471
472                    if (el.nodeType == 1) {
473                        var elTagName = el.tagName.toLowerCase();
474                        if (elTagName == "p" || elTagName == "ul" || elTagName == "ol") {
475                            var needDel = false;
476                            var list = (elTagName == "ul" || elTagName == "ol");
477
478                            function checkInner(elem) {
479                                var ret = false;
480                                if (elem.nodeType == 1) {
481                                    var tagName = elem.tagName.toUpperCase();
482                                    if (!(list && tagName == "LI"))
483                                        if (Sys.Extended.UI.HTMLEditor.isRestricted(elem) || tagName == "IMG" || tagName == "IFRAME" || tagName == "EMBED" || tagName == "SCRIPT") return true;
484                                    if (elem.childNodes.length > 1) return true;
485                                    if (elem.childNodes.length == 0) return false;
486                                    ret |= checkInner(elem.firstChild);
487                                } else {
488                                    if (elem.nodeType == 3) {
489                                        ret |= true;
490                                    }
491                                }
492                                return ret;
493                            }
494
495                            if (el.childNodes.length == 1) {
496                                if (!checkInner(el.firstChild)) {
497                                    el.removeChild(el.firstChild); needDel = true;
498                                }
499                            }
500
501                            if (needDel || el.parentNode.innerHTML.toLowerCase() == "<p>&nbsp;</p>") this._doc.body.removeChild(el);
502                        }
503                    }
504                }
505            }
506        } catch (e) { }
507    },
508
509    isControl: function() {
510        try {
511            var sel = this._getSelection();
512
513            if (Sys.Extended.UI.HTMLEditor.isIE) {
514                if (sel.type.toLowerCase() == "control") {
515                    return true;
516                } else {
517                    return false;
518                }
519            } else {
520                var range = this._createRange(sel);
521                var parent = this._getParent(range);
522
523                if (parent.nodeType != 3 && range.startContainer == range.endContainer) {
524                    if (!parent.tagName) {
525                        return false;
526                    }
527
528                    if (range.startContainer.childNodes.item(range.startOffset) == null) {
529                        return false;
530                    }
531
532                    if (range.startOffset == range.endOffset &&
533                    range.startContainer.childNodes.item(range.startOffset).tagName &&
534                    (range.startContainer.childNodes.item(range.startOffset).tagName.toUpperCase() == "BR" ||
535                    Sys.Extended.UI.HTMLEditor.isStyleTag(range.startContainer.childNodes.item(range.startOffset).tagName))
536                    ) {
537                        return false;
538                    }
539
540                    if (parent.tagName.toUpperCase() == "BODY" && range.startOffset == 0 &&
541                    range.endOffset > 0 && range.endOffset == parent.childNodes.length) {
542                        return false;
543                    }
544
545                    if (range.startOffset == range.endOffset && range.startContainer.childNodes.item(range.startOffset).nodeType == 3) {
546                        return false;
547                    }
548
549                    return true;
550                }
551                else {
552                    return false;
553                }
554            }
555        }
556        catch (e) {
557            return true;
558        }
559    },
560
561    isPopup: function() {
562        return (this._popup != null);
563    },
564
565    _getSelection: function() {
566        if (Sys.Extended.UI.HTMLEditor.isIE) {
567            var sel = this._doc.selection;
568            return sel;
569        } else {
570            this.focusEditor();
571
572            var sel;
573            var range;
574            var el;
575            var contentWindow = this.get_element().contentWindow;
576            sel = contentWindow.getSelection();
577            range = this._createRange(sel);
578            el = range.startContainer;
579            try {
580                while (el && el.nodeType) {
581                    el = el.parentNode;
582                }
583            } catch (e) {
584                this._removeAllRanges(sel);
585                range = this._createRange(sel);
586                range.setStart(this._saved_startContainer, this._saved_startOffset);
587                range.setEnd(this._saved_startContainer, this._saved_startOffset);
588                this._selectRange(sel, range);
589                sel = contentWindow.getSelection();
590            }
591            return sel;
592        }
593    },
594
595    _createRange: function(sel) {
596        if (Sys.Extended.UI.HTMLEditor.isIE) {
597            if (typeof sel == "undefined") {
598                return this._doc.body.createTextRange();
599            } else {
600                return sel.createRange();
601            }
602        } else {
603            this.focusEditor();
604            if (typeof sel == "undefined") {
605                return this._doc.createRange();
606            } else {
607                try {
608                    var r = sel.getRangeAt(0);
609                    return r;
610                }
611                catch (e) {
612                    return this._doc.createRange();
613                }
614            }
615        }
616    },
617
618    toEndOfProtected: function() {
619        var editor = this;
620        var sss = this._getSelection();
621        var range;
622        try {
623            range = this._createRange(sss);
624        } catch (ex) {
625            return false;
626        }
627        var el;
628        if (!Sys.Extended.UI.HTMLEditor.isIE) {
629            el = Sys.Extended.UI.HTMLEditor.contentEditable(range.startContainer);
630            if (el == null) {
631                el = Sys.Extended.UI.HTMLEditor.contentEditable(range.endContainer);
632            }
633        } else {
634            el = Sys.Extended.UI.HTMLEditor.contentEditable(Sys.Extended.UI.HTMLEditor.getSelParent(editor));
635        }
636
637        if (Sys.Extended.UI.HTMLEditor.isIE && el != null) {
638            try { range.remove(el); } catch (e) { }
639            range = editor._doc.body.createControlRange();
640            range.add(el);
641            range.select();
642        } else {
643            if (!Sys.Extended.UI.HTMLEditor.isIE && el != null) {
644                var sel = editor._getSelection();
645                var tempText;
646
647                if (el.nextSibling != null && el.nextSibling.nodeType == 3) {
648                    tempText = el.nextSibling;
649                } else {
650                    tempText = editor._doc.createTextNode("");
651
652                    if (el.nextSibling != null) {
653                        el.parentNode.insertBefore(tempText, el.nextSibling);
654                    } else {
655                        el.parentNode.appendChild(tempText);
656                    }
657                }
658
659                editor._removeAllRanges(sel);
660                var range = editor._createRange(sel);
661                range.setStart(tempText, 0);
662                range.setEnd(tempText, 0);
663                editor._selectRange(sel, range);
664            }
665        }
666        return true;
667    },
668
669    _commonPaste: function(ev) {
670        var editor = this;
671
672        this._saveContent();
673
674        if (Sys.Extended.UI.HTMLEditor.isIE) {
675            this.openWait();
676            setTimeout(function() { editor._paste(!editor._editPanel.get_noPaste()); editor.closeWait(); }, 0)
677            Sys.Extended.UI.HTMLEditor._stopEvent(ev);
678        }
679        else {
680            if (!this.isPlainText && !this.isWord && !this._editPanel.get_noPaste()) {
681                setTimeout(function() {
682                    Sys.Extended.UI.HTMLEditor.operateAnchors(editor, editor._doc, !editor._editPanel.get_showAnchors());
683                    Sys.Extended.UI.HTMLEditor.operatePlaceHolders(editor, editor._doc, !editor._editPanel.get_showPlaceHolders());
684                    Sys.Extended.UI.HTMLEditor.inspectForShadows(editor._doc.body);
685                    editor._checkImages(editor._doc.body);
686                    editor.onContentChanged();
687                }, 0);
688            } else {
689                var place = editor._getSafePlace();
690
691                if (place != null) {
692                    var div = editor._doc.createElement("div");
693                    div.style.display = "inline";
694                    div.style.borderStyle = "none";
695                    place.parentNode.insertBefore(div, place);
696                    div.appendChild(place);
697                    div.removeChild(place);
698                    div.innerHTML = "xx";
699                    var sel = editor._getSelection();
700                    var rng = editor._createRange();
701                    editor._removeAllRanges(sel);
702                    rng.setStart(div.firstChild, 0);
703                    rng.setEnd(div.firstChild, 1);
704                    editor._selectRange(sel, rng);
705                    editor.openWait();
706
707                    setTimeout(function() {
708                        var parent = div.parentNode;
709                        div.lastChild.deleteData(div.lastChild.length - 1, 1);
710
711                        if (editor.isWord) {
712                            div.innerHTML = Sys.Extended.UI.HTMLEditor.cleanUp(div.innerHTML);
713                            Sys.Extended.UI.HTMLEditor.replaceOldTags(div, editor);
714                            Sys.Extended.UI.HTMLEditor.spanJoiner(div, editor._doc);
715                        } else {
716                            var div1 = document.createElement("div");
717                            div1.innerHTML = Sys.Extended.UI.HTMLEditor.cleanUp(div.innerHTML);
718
719                            var html = new Sys.Extended.UI.HTMLEditor.jsDocument(true);
720                            Sys.Extended.UI.HTMLEditor.__MozillaGetInnerText(div1, html);
721
722                            div.innerHTML = html.toString().replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\r/g, "").replace(/\n/g, "<br/>").replace(/\t/g, "&nbsp;");
723                            delete div1;
724                        }
725
726                        while (div.firstChild) {
727                            parent.insertBefore(div.firstChild, div);
728                        }
729
730                        var ns = null;
731                        var ps = null;
732                        if (div.nextSibling && div.nextSibling.nodeType == 3 && div.previousSibling && div.previousSibling.nodeType == 3) {
733                            ns = div.nextSibling;
734                            ps = div.previousSibling;
735                        }
736
737                        parent.removeChild(div);
738                        var pslength = null;
739                        if (ns != null && ps != null) {
740                            pslength = ps.data.length;
741                            ps.data = "" + ps.data + "" + ns.data + "";
742                            ns.parentNode.removeChild(ns);
743                        }
744
745                        editor.isWord = false;
746                        editor.isPlainText = false;
747                        editor.closeWait();
748
749                        if (pslength != null) {
750                            var sel = editor._getSelection();
751                            var rng = editor._createRange();
752                            editor._removeAllRanges(sel);
753                            rng.setStart(ps, pslength);
754                            rng.setEnd(ps, pslength);
755                            editor._selectRange(sel, rng);
756                        }
757
758                        editor.onContentChanged();
759                    }, 0);
760                }
761                else {
762                    Sys.Extended.UI.HTMLEditor._stopEvent(ev);
763                }
764            }
765        }
766    },
767
768    _selectRange: function(sel, range) {
769        sel.addRange(range);
770        this.focusEditor();
771    },
772
773    _selectRng: function(rng) {
774        var sel = this._getSelection();
775
776        if (!Sys.Extended.UI.HTMLEditor.isIE) {
777            var range = this._doc.createRange();
778            range.setStart(rng[0], 0);
779            range.setEnd(rng[rng.length - 1], ("" + rng[rng.length - 1].data + "").length);
780
781            this._removeAllRanges(sel);
782            this._selectRange(sel, range);
783        } else {
784            var range1 = this._createRange(sel);
785            var range2 = this._createRange(sel);
786
787            var span1 = this._doc.createElement("span");
788            var span2 = this._doc.createElement("span");
789
790            rng[0].parentNode.insertBefore(span1, rng[0]);
791
792            if (rng[rng.length - 1].nextSibling) {
793                rng[rng.length - 1].parentNode.insertBefore(span2, rng[rng.length - 1].nextSibling);
794            } else {
795                rng[rng.length - 1].parentNode.appendChild(span2);
796            }
797
798            try {
799                range1.moveToElementText(span1);
800                var ii = range1.moveStart('character', 1);
801                range1.moveStart('character', -ii);
802
803                range2.moveToElementText(span2);
804                ii = range2.moveEnd('character', -1);
805                range2.moveEnd('character', -ii);
806
807                range1.setEndPoint("EndToEnd", range2);
808                range1.select();
809            } catch (e) { }
810
811            rng[0].parentNode.removeChild(span1);
812            rng[rng.length - 1].parentNode.removeChild(span2);
813        }
814    },
815
816    _removeAllRanges: function(sel) {
817        sel.removeAllRanges();
818    },
819
820    _setToEnd: function() {
821        var editor = this;
822        setTimeout(function() {
823            editor._setToEnd_();
824            editor._editPanel.updateToolbar();
825        }, 0);
826    },
827
828    _setToEnd_: function() {
829        var editor = this;
830
831        if (Sys.Extended.UI.HTMLEditor.isIE) {
832            var sel = editor._getSelection();
833            var range = editor._createRange(sel);
834
835            if (sel.type.toLowerCase() != "control") {
836                range.moveEnd("textedit", 1);
837                range.collapse(false);
838            }
839            range.select();
840
841            editor.focusEditor();
842            return;
843        }
844
845        var index = 0;
846        var container = editor._doc.body;
847        var anchor = null;
848
849        if (container.lastChild && container.lastChild.nodeType == 3) {
850            container = container.lastChild;
851            index = ("" + container.data + "").length;
852        } else {
853            var tempText = editor._doc.createTextNode("");
854            if (container.lastChild && container.lastChild.nodeType == 1 && container.lastChild.tagName.toUpperCase() == "BR") {
855                container.insertBefore(tempText, container.lastChild);
856            } else {
857                container.appendChild(tempText);
858            }
859            container = tempText;
860            index = 0;
861        }
862
863        var sel = editor._getSelection();
864        editor._removeAllRanges(sel);
865        var range = editor._createRange();
866
867        range.setStart(container, index);
868        range.setEnd(container, index);
869
870        editor._selectRange(sel, range);
871
872        if (anchor != null) {
873            editor._doc.body.removeChild(anchor);
874        }
875
876        editor.focusEditor();
877
878        if (!Sys.Extended.UI.HTMLEditor.isSafari && !Sys.Extended.UI.HTMLEditor.isOpera) {
879            try {
880                var anchor = editor._doc.createElement("button");
881                anchor.style.width = "0px";
882                anchor.style.height = "20px";
883                editor._doc.body.appendChild(anchor);
884
885                anchor.focus();
886
887                anchor.blur();
888                editor.focusEditor();
889                editor._doc.body.removeChild(anchor);
890            } catch (e) { }
891        }
892    },
893
894    isShadowed: function() {
895        if (!this.isControl()) return false;
896
897        var sel = this._getSelection();
898        var range = this._createRange(sel);
899        var element;
900
901        if (Sys.Extended.UI.HTMLEditor.isIE) {
902            element = range.item(0);
903        } else {
904            element = range.startContainer.childNodes.item(range.startOffset);
905        }
906
907        if (element.tagName &&
908            element.tagName.toUpperCase() == "IMG" &&
909            element.getAttribute(Sys.Extended.UI.HTMLEditor.attachedIdAttribute) &&
910            element.getAttribute(Sys.Extended.UI.HTMLEditor.attachedIdAttribute).length > 0
911        ) {
912            var shadowNode = this.getAttachedElement(element);
913
914            if (shadowNode != null) {
915                if (Sys.Extended.UI.HTMLEditor.isIE) {
916                    range = this._doc.body.createControlRange();
917                    range.add(shadowNode);
918                    range.select();
919                } else {
920                    try {
921                        var index = Sys.Extended.UI.HTMLEditor.__getIndex(shadowNode);
922                        sel.collapseToEnd();
923                        this._removeAllRanges(sel);
924                        range = this._createRange(sel);
925                        range.setStart(shadowNode.parentNode, index);
926                        range.setEnd(shadowNode.parentNode, index + 1);
927                        this._selectRange(sel, range);
928                    } catch (e) {
929                        return true;
930                    }
931                }
932                return false;
933            }
934            return true;
935        }
936        return false;
937    },
938
939    _ifShadow: function() {
940        if (Sys.Extended.UI.HTMLEditor.isIE) {
941            try {
942                var selka = this._doc.selection;
943            } catch (e) {
944                return false;
945            }
946        }
947
948        var editor = this;
949        var prot = null;
950        var el = Sys.Extended.UI.HTMLEditor.getSelParent(editor);
951
952        while (el && (el.nodeType == 3 || (el.tagName && el.tagName.toUpperCase() != "BODY"))) {
953            if (el.nodeType == 3 || !el.tagName) {
954                el = el.parentNode;
955                continue;
956            }
957            var tagName = el.tagName.toUpperCase()
958
959            if (tagName == "TABLE" && el.getAttribute(Sys.Extended.UI.HTMLEditor.noContextMenuAttribute) &&
960                el.getAttribute(Sys.Extended.UI.HTMLEditor.noContextMenuAttribute) == "yes") {
961                prot = el.rows.item(0).cells.item(0).firstChild;
962                if (Sys.Extended.UI.HTMLEditor.isIE && tagName == "P") {
963                    prot = prot.firstChild;
964                }
965                break;
966            }
967
968            el = el.parentNode;
969        }
970
971        if (prot != null) {
972            var sel = editor._getSelection();
973            var range = editor._createRange(sel);
974
975            if (Sys.Extended.UI.HTMLEditor.isIE) {
976                range = editor._doc.body.createControlRange();
977                range.add(prot);
978                range.select();
979            } else {
980                try {
981                    sel.collapseToEnd();
982                    editor._removeAllRanges(sel);
983                    range = editor._createRange(sel);
984                    range.setStart(prot.parentNode, 0);
985                    range.setEnd(prot.parentNode, 1);
986                    editor._selectRange(sel, range);
987                } catch (e) { }
988            }
989        }
990    },
991
992    _saveContent: function() {
993        var sel;
994        var range;
995        var marker;
996
997        try {
998            try {
999                sel = this._getSelection();
1000                range = this._createRange(sel);
1001            } catch (e) { }
1002
1003            marker = new Sys.Extended.UI.HTMLEditor._Marker(this, range, sel);
1004        } catch (e) {
1005            return;
1006        }
1007
1008        if (!this.__stack) {
1009            this.__stack = [];
1010            this.__stackPos = 0;
1011        }
1012
1013        while (this.__stackPos < this.__stack.length) {
1014            this.__stack.pop();
1015        }
1016
1017        if (this.__stack.length == Sys.Extended.UI.HTMLEditor.__stackMaxSize) {
1018            this.__stack.reverse();
1019            this.__stack.pop();
1020            this.__stack.reverse();
1021        }
1022
1023        this.__stack.push(marker);
1024        this.__stackPos = this.__stack.length;
1025    },
1026
1027    _restoreContent: function() {
1028        if (this.__stack && this.__stackPos >= 0 && this.__stackPos < this.__stack.length) {
1029            var obj = this.__stack[this.__stackPos];
1030            var sel;
1031            var range;
1032
1033            if (Sys.Extended.UI.HTMLEditor.isIE) {
1034                function rep(p0, p1, p2, p3, p4) {
1035                    return p1.replace(/\salign=[^\s>]*/ig, "") + ((p3 == '"X"') ? "" : ("align=" + p3)) + p4.replace(/\salign=[^\s>]*/ig, "");
1036                }
1037
1038                var tempCollection = this._doc.body.getElementsByTagName("EMBED");
1039
1040                var els = [];
1041                for (var i = 0; i < tempCollection.length; i++) {
1042                    els.push(tempCollection[i]);
1043                }
1044
1045                for (var jk = 0; jk < els.length; jk++) {
1046                    els[jk].parentNode.removeChild(els[jk]);
1047                }
1048
1049                var tuk = obj._save.replace(/&amp;/ig, "&");
1050                tuk = tuk.replace(/(<embed(?:.*?))(teoalign=)(\"[^\"]*\")((?:.*?)>)/ig, rep);
1051                this._doc.body.innerHTML = "!!!<span></span>" + Sys.Extended.UI.HTMLEditor.Trim(tuk);
1052
1053                if (this._doc.body.firstChild) {
1054                    this._doc.body.removeChild(this._doc.body.firstChild);
1055                }
1056                if (this._doc.body.firstChild) {
1057                    this._doc.body.removeChild(this._doc.body.firstChild);
1058                }
1059
1060                var mArr = Sys.Extended.UI.HTMLEditor.getHrefsText(tuk);
1061                Sys.Extended.UI.HTMLEditor.setHrefsText(this._doc.body, mArr);
1062
1063                if (this._editPanel.get_relativeImages()) {
1064                    mArr = Sys.Extended.UI.HTMLEditor.getImagesText(tuk);
1065                    Sys.Extended.UI.HTMLEditor.setImagesText(this._doc.body, mArr);
1066                }
1067
1068                Sys.Extended.UI.HTMLEditor.setNames(this._doc.body, obj._nArr);
1069
1070                Sys.Extended.UI.HTMLEditor.operateAnchors(this, this._doc, !this._editPanel.get_showAnchors());
1071                Sys.Extended.UI.HTMLEditor.operatePlaceHolders(this, this._doc, !this._editPanel.get_showPlaceHolders());
1072
1073                if (obj._tree != null) {
1074                    var el = this._doc.body;
1075                    var i;
1076                    try {
1077                        for (i = obj._tree.length - 1; i >= 0; i--) {
1078                            el = el.childNodes.item(obj._tree[i]);
1079                        }
1080                    } catch (e) {
1081                        if (this.__stackPos > 0) {
1082                            this.__stackPos--;
1083                            this._restoreContent();
1084                            this.__stackPos++;
1085                        }
1086                        return;
1087                    }
1088
1089                    try {
1090                        var rng = this._doc.body.createControlRange();
1091                        rng.add(el);
1092                        rng.select();
1093                    } catch (e) { }
1094                } else {
1095                    var editor = this;
1096                    setTimeout(function() {
1097                        try {
1098                            if (editor._editPanel == Sys.Extended.UI.HTMLEditor.LastFocusedEditPanel) {
1099                                sel = editor._getSelection();
1100                                range = editor._createRange(sel);
1101                                if (sel.type.toLowerCase() != "control") {
1102                                    try { range.moveToPoint(obj._offsetLeft, obj._offsetTop); } catch (e) { }
1103                                }
1104                                range.select();
1105                            }
1106                        } catch (e) { }
1107                    }, 0);
1108                }
1109            } else {
1110                if (Sys.Extended.UI.HTMLEditor.isOpera) {
1111                    this._doc.body.innerHTML = Sys.Extended.UI.HTMLEditor.Trim(obj._save);
1112                } else {
1113                    this._doc.body.innerHTML = "";
1114                    for (var i = 0; i < obj._save.childNodes.length; i++) {
1115                        this._doc.body.appendChild(obj._save.childNodes.item(i).cloneNode(true));
1116                    }
1117                }
1118
1119                Sys.Extended.UI.HTMLEditor.operateAnchors(this, this._doc, !this._editPanel.get_showAnchors());
1120                Sys.Extended.UI.HTMLEditor.operatePlaceHolders(this, this._doc, !this._editPanel.get_showPlaceHolders());
1121
1122                try {
1123                    sel = this._getSelection();
1124                    range = this._createRange();
1125                    this._removeAllRanges(sel);
1126                } catch (e) { }
1127                var str = "";
1128                var el = this._doc.body;
1129                for (var i = obj._tree.length - 1; i >= 0; i--) {
1130                    str += " " + obj._tree[i];
1131                    el = el.childNodes.item(obj._tree[i]);
1132                }
1133
1134                var n_offset = obj._offset;
1135
1136                try {
1137                    range.setStart(el, n_offset);
1138                    range.setEnd(el, n_offset);
1139                } catch (e) {
1140                    Sys.Extended.UI.HTMLEditor.inspectForShadows(this._doc.body);
1141                    return;
1142                }
1143
1144                try {
1145                    this._selectRange(sel, range);
1146                } catch (e) { }
1147            }
1148
1149            try {
1150                Sys.Extended.UI.HTMLEditor.inspectForShadows(this._doc.body);
1151            } catch (e) { }
1152        }
1153    },
1154
1155    SaveContent: function() {
1156        this._saveContent();
1157    },
1158
1159    RestoreContent: function() {
1160        this._undo(false);
1161    },
1162
1163    _undo: function(pr) {
1164        if (this.__stack) {
1165            if (this.__stackPos > 0) {
1166                if (this.__stackPos == this.__stack.length && pr) {
1167                    this._saveContent();
1168                }
1169
1170                do {
1171                    var tmp = Sys.Extended.UI.HTMLEditor.Trim(this._doc.body.innerHTML);
1172                    this.__stackPos--;
1173                    this._restoreContent();
1174                }
1175                while (Sys.Extended.UI.HTMLEditor.Trim(this._doc.body.innerHTML) == tmp && this.__stackPos > 0 && pr)
1176
1177                var editor = this;
1178                setTimeout(function() {
1179                    try { editor._ifShadow(); } catch (e) { };
1180                    if (editor._editPanel == Sys.Extended.UI.HTMLEditor.LastFocusedEditPanel) {
1181                        try { editor._editPanel.updateToolbar(); } catch (e) { }
1182                    }
1183                    if (!pr) editor.onContentChanged();
1184                }, 0);
1185            }
1186        }
1187    },
1188
1189    _redo: function() {
1190        if (this.__stack) {
1191            if (this.__stackPos < this.__stack.length - 1) {
1192                this.__stackPos++;
1193                var editor = this;
1194                var tempCollectionLength;
1195                if (Sys.Extended.UI.HTMLEditor.isIE) {
1196                    tempCollectionLength = editor._doc.body.getElementsByTagName("EMBED").length;
1197
1198                    if (tempCollectionLength > 0) {
1199                        var popup = editor._body.ownerDocument.createElement("div");
1200                        editor._body.appendChild(popup);
1201
1202                        setTimeout(function() {
1203                            editor._body.removeChild(popup);
1204                        }, 0);
1205                    }
1206                }
1207                this._restoreContent();
1208                var editor = this;
1209                setTimeout(function() { editor._ifShadow(); editor._editPanel.updateToolbar(); }, 0);
1210            }
1211        }
1212    },
1213
1214    undo: function() {
1215        this._undo(true);
1216        this.onContentChanged();
1217    },
1218
1219    redo: function() {
1220        this._redo();
1221        this.onContentChanged();
1222    },
1223
1224    _contextMenuCallP: function() {
1225    },
1226
1227    onContentChanged: function() {
1228    },
1229
1230    _copyCut: function(key, prize) {
1231        var editor = this;
1232
1233        if (Sys.Extended.UI.HTMLEditor.isIE) {
1234            var sel = this._getSelection();
1235            var range = this._createRange(sel);
1236            var was = false;
1237            var html = "";
1238
1239            if (key == 'x') {
1240                this._saveContent();
1241            }
1242
1243            if (sel.type.toLowerCase() == "control") {
1244                was = true;
1245                html = Sys.Extended.UI.HTMLEditor.getHTML(range.item(0), true)
1246            } else {
1247                if (range.text != "") {
1248                    was = true;
1249                    html = range.htmlText;
1250
1251                    var sr = range.duplicate();
1252
1253                    var rng = this._getTextNodeCollection();
1254
1255                    if (rng.length < 1) {
1256                        return;
1257                    }
1258
1259                    var fnd = Sys.Extended.UI.HTMLEditor._commonParent(rng[0], rng[rng.length - 1]);
1260
1261                    if (fnd != null && rng[0].previousSibling && rng[0].previousSibling.nodeType == 3) {
1262                        var par = fnd.parent;
1263
1264                        while (par && par.tagName.toUpperCase() != "BODY" && Sys.Extended.UI.HTMLEditor.isStyleTag(par.tagName)) {
1265                            var ttt = par.cloneNode(false);
1266                            ttt.innerHTML = html;
1267                            html = ttt.outerHTML;
1268                            par = par.parentNode;
1269                        }
1270                    }
1271                    sel = this._getSelection();
1272                    sel.empty();
1273                    range = this._createRange(sel);
1274                    range.setEndPoint("EndToEnd", sr);
1275                    range.setEndPoint("StartToStart", sr);
1276                    range.select();
1277                } else {
1278                    if (range.htmlText != "") {
1279                        was = true;
1280                        html = range.htmlText;
1281                    }
1282                }
1283            }
1284
1285            if (was) {
1286                var src = this._doc.createElement("DIV");
1287                src.innerHTML = "!!!<span></span>" + html;
1288                src.removeChild(src.firstChild);
1289                src.removeChild(src.firstChild);
1290
1291                var temp = Sys.Extended.UI.HTMLEditor.getHTML(src, false, true);
1292
1293                var nnreg = new RegExp("(<[/]?)(teo" + Sys.Extended.UI.HTMLEditor.smartClassName + ":)", "ig");
1294                temp = temp.replace(nnreg, "$1");
1295
1296                delete src;
1297                this._contentCopy(temp, true);
1298                range.select();
1299                if (key == 'x') {
1300                    sel.clear();
1301                    this._clearP();
1302                }
1303            } else {
1304                if (key == 'x') {
1305                    sel.clear();
1306                    this._clearP();
1307                }
1308            }
1309
1310            if (prize) {
1311                setTimeout(function() { editor._editPanel.updateToolbar(); }, 0);
1312            }
1313        } else {
1314            if (key == "x") {
1315                this._saveContent();
1316                var sel = this._getSelection();
1317                var range = this._createRange(sel);
1318                this._removeAllRanges(sel);
1319                range.deleteContents();
1320
1321                if (this._doc.body.innerHTML == "") {
1322                    this._doc.body.innerHTML = "<br/>";
1323                    range.setStart(this._doc.body, 0);
1324                    range.setEnd(this._doc.body, 0);
1325                }
1326
1327                editor.onContentChanged();
1328                this._selectRange(sel, range);
1329            } else {
1330                var sel = this._getSelection();
1331                var range = this._createRange(sel);
1332                this._removeAllRanges(sel);
1333
1334                alert(String.format(Sys.Extended.UI.Resources.HTMLEditor_toolbar_button_Use_verb, (Sys.Extended.UI.HTMLEditor.isSafari && navigator.userAgent.indexOf("mac") != -1) ? "Apple-C" : "Ctrl-C"));
1335                this._selectRange(sel, range);
1336            }
1337        }
1338    },
1339
1340    _paste: function(prize, word) {
1341        var editor = this;
1342        var sel = this._getSelection();
1343        var range = this._createRange(sel);
1344        var _left;
1345        var _top;
1346
1347        if (!prize) {
1348            _left = range.offsetLeft;
1349            _top = range.offsetTop;
1350
1351            this.insertHTML(this._getPlain());
1352            editor.onContentChanged();
1353            return;
1354        }
1355
1356        if (this._editPanel.get_noPaste()) {
1357            return;
1358        }
1359
1360        _left = range.offsetLeft;
1361        _top = range.offsetTop;
1362
1363        var temp = this._doc.createElement("span");
1364        var place;
1365        var tText = this._contentCopy("", false, word);
1366
1367        if ((/<[\/]*p[\s>]+/i.test(tText)) || (/<[\/]*h/i.test(tText))) {
1368            place = this._getSafePlace();
1369        } else {
1370            place = this._doc.createElement("SPAN");
1371            place.id = Sys.Extended.UI.HTMLEditor.smartClassName;
1372
1373            if (!this.insertHTML(Sys.Extended.UI.HTMLEditor.getHTML(place, true))) {
1374                return;
1375            }
1376
1377            place = this._doc.getElementById(Sys.Extended.UI.HTMLEditor.smartClassName);
1378
1379            if (place) {
1380                place.id = null;
1381                place.removeAttribute("id");
1382                place.setAttribute("para", "no");
1383            }
1384        }
1385
1386        temp.innerHTML = tText;
1387        if (!place) {
1388            return;
1389        }
1390
1391        this._checkImages(temp);
1392
1393        var par = place.parentNode;
1394        var pos = place.getAttribute("para");
1395
1396        if (pos != "no") {
1397            if (pos.indexOf("left") >= 0 && temp.firstChild) {
1398                if (temp.firstChild.tagName && temp.firstChild.tagName.toUpperCase() == "P") {
1399                    while (temp.firstChild.firstChild) {
1400                        place.previousSibling.appendChild(temp.firstChild.firstChild);
1401                    }
1402                    temp.removeChild(temp.firstChild);
1403                }
1404            }
1405
1406            if (pos.indexOf("right") >= 0 && temp.lastChild) {
1407                if (temp.lastChild.tagName && temp.lastChild.tagName.toUpperCase() == "P") {
1408                    while (temp.lastChild.lastChild) {
1409                        place.nextSibling.insertBefore(temp.lastChild.lastChild, place.nextSibling.firstChild);
1410                    }
1411                    temp.removeChild(temp.lastChild);
1412                }
1413            }
1414        }
1415
1416        var saveEl = place;
1417        var temp1 = null;
1418        if (temp.childNodes.length == 0 && pos.indexOf("left") >= 0 && pos.indexOf("right") >= 0) {
1419            if (place.nextSibling.firstChild) {
1420                temp1 = this._doc.createElement("span");
1421                saveEl = temp1;
1422                temp1.innerHTML = "111";
1423                place.previousSibling.appendChild(temp1);
1424            }
1425            while (place.nextSibling.firstChild) {
1426                place.previousSibling.appendChild(place.nextSibling.firstChild);
1427            }
1428            par.removeChild(place.nextSibling);
1429        } else {
1430            while (temp.firstChild) {
1431                par.insertBefore(temp.firstChild, place);
1432            }
1433        }
1434
1435        setTimeout(function() {
1436            var sel = editor._getSelection();
1437            var range = editor._createRange(sel);
1438            if (sel.type.toLowerCase() == "control") {
1439                while (range.length > 0) {
1440                    range.remove(0);
1441                }
1442            }
1443            try {
1444                range.collapse(false);
1445            } catch (e) { }
1446
1447            editor.focusEditor();
1448            Sys.Extended.UI.HTMLEditor._setCursor(saveEl, editor);
1449            if (temp1) {
1450                temp1.parentNode.removeChild(temp1);
1451            }
1452            par.removeChild(place);
1453            Sys.Extended.UI.HTMLEditor.inspectForShadows(editor._doc.body);
1454            editor.onContentChanged();
1455            range.select();
1456        }, 0);
1457    },
1458
1459    _contentCopy: function(text, prize, word) {
1460        if (text != "") {
1461            text = text.replace(/(<td[^>]*?>)([\s ]*?)(<\/td[^>]*?>)/ig, "$1&nbsp;$3")
1462                .replace(/(<td[^>]*?>)\s*(&nbsp;)\s*(<\/td[^>]*?>)/ig, "$1<br/>$3")
1463                .replace(/(<p[^>]*?>)\s*(&nbsp;)\s*(<\/p[^>]*?>)/ig, "$1<br/>$3");
1464        }
1465
1466        var iframe = this._doc.createElement("iframe");
1467        iframe.width = "0";
1468        iframe.height = "0";
1469        if (Sys.Extended.UI.HTMLEditor.isIE) {
1470            iframe.src = "javascript:false;";
1471        }
1472        this._doc.appendChild(iframe);
1473        var doc = iframe.contentWindow.document;
1474        doc.write("<html><head></head><body>" + text + "</body></html>");
1475        doc.close();
1476        doc.body.contentEditable = true;
1477        var r = doc.body.createTextRange();
1478        var wasNbsp = false;
1479
1480        if (text == "") {
1481            r.execCommand("paste");
1482            var trg = doc.createElement("DIV");
1483            for (var i = 0; i < doc.body.childNodes.length; i++) {
1484                var child = doc.body.childNodes.item(i);
1485                if (child.nodeType == 8) {
1486                    var str = "" + child.data + "";
1487                    if (str.search(/StartFragment/i) >= 0) {
1488                        if (child.nextSibling && child.nextSibling.nodeType == 3) {
1489                            var str = "" + child.nextSibling.data + "";
1490                            if (str.length) {
1491                                if (str.charCodeAt(0) == 160) {
1492                                    str = str.substr(1);
1493                                    child.nextSibling.data = str;
1494                                    wasNbsp = true;
1495                                    break;
1496                                }
1497                            }
1498                        }
1499                    }
1500                }
1501            }
1502
1503            if (typeof word != "undefined" && word) {
1504                doc.body.innerHTML = Sys.Extended.UI.HTMLEditor.cleanUp(doc.body.innerHTML);
1505            }
1506            var str = Sys.Extended.UI.HTMLEditor.Trim(Sys.Extended.UI.HTMLEditor.getHTML(doc.body, false, true));
1507            str = str.replace(/(<script(?:[^>]*?)>(?:[^<]*?)<\/script(?:[^>]*?)>)/gi, "");
1508            doc.body.innerHTML = str;
1509            if (!prize) {
1510                Sys.Extended.UI.HTMLEditor.operateAnchors(this, doc, !this.showAnchors);
1511                Sys.Extended.UI.HTMLEditor.operatePlaceHolders(this, doc, !this.showPlaceHolders);
1512
1513                var tempCollection = doc.body.getElementsByTagName("EMBED");
1514
1515                var els = [];
1516                for (var i = 0; i < tempCollection.length; i++) {
1517                    els.push(tempCollection[i]);
1518                }
1519
1520                for (var jk = 0; jk < els.length; jk++) {
1521                    els[jk].parentNode.removeChild(els[jk]);
1522                }
1523            }
1524            delete r;
1525            delete trg;
1526            if (prize && Sys.Extended.UI.HTMLEditor.isIE) {
1527                r = doc.body.createTextRange();
1528            }
1529        }
1530
1531        if (prize && Sys.Extended.UI.HTMLEditor.isIE) {
1532            if (text != "") {
1533                Sys.Extended.UI.HTMLEditor.operateAnchors(this, doc, true);
1534                Sys.Extended.UI.HTMLEditor.operatePlaceHolders(this, doc, true);
1535            }
1536            r.select();
1537            r.execCommand("copy");
1538        }
1539
1540        var ret = Sys.Extended.UI.HTMLEditor.Trim(doc.body.innerHTML)
1541            .replace(/<br\s*[\/]*>\s*<\/td>/ig, "</td>")
1542            .replace(/(<td[^>]*?>)([\s ]*?)(<\/td[^>]*?>)/ig, "$1&nbsp;$3")
1543            .replace(/(<p[^>]*?>)\s*(<br[^>]*?>)\s*(<\/p[^>]*?>)/ig, "$1&nbsp;$3")
1544            .replace(/(<embed(?:.*?))(wmode=)(\"[^\"]*\")((?:.*?)>)/ig, "$1pseudomode=$3$4")
1545            .replace(/(<embed)([^>]*?>)/ig, "$1 wmode=\"transparent\"$2");
1546        var tempCollection = doc.body.getElementsByTagName("EMBED");
1547        var els = [];
1548        for (var i = 0; i < tempCollection.length; i++) {
1549            els.push(tempCollection[i]);
1550        }
1551
1552        for (var jk = 0; jk < els.length; jk++) {
1553            els[jk].parentNode.removeChild(els[jk]);
1554        }
1555
1556        iframe.src = "";
1557        var editor = this;
1558        editor._doc.removeChild(iframe);
1559        delete iframe;
1560
1561        return ret;
1562    },
1563
1564    insertHTML: function(html, range) {
1565        this.focusEditor();
1566        var sel = this._getSelection();
1567        if (typeof range == "undefined") {
1568            range = this._createRange(sel);
1569        }
1570
1571        if (Sys.Extended.UI.HTMLEditor.isIE) {
1572            function regReplScript(p0, p1) {
1573                return "<span class=\"" + Sys.Extended.UI.HTMLEditor.smartClassName + "_script\" style='display:none;visibility:hidden;'>" + p1.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;") + "</span>";
1574            }
1575
1576            function regReplFromScript(p0, p1, p2, p3) {
1577                return p1.replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&amp;/g, "&");
1578            }
1579            var new_html = "<span id=\"" + Sys.Extended.UI.HTMLEditor.smartClassName + "\">111<span></span>" + html + "</span>";
1580
1581            var mArr = Sys.Extended.UI.HTMLEditor.getHrefsText(new_html);
1582            var mArr1 = Sys.Extended.UI.HTMLEditor.getImagesText(new_html);
1583
1584            if (!this._editPanel.get_noScript()) {
1585                new_html = new_html.replace(/(<script(?:[^>]*?)>.*?<\/script(?:[^>]*?)>)/gi, regReplScript);
1586            } else {
1587                new_html = new_html.replace(/(<script(?:[^>]*?)>.*?<\/script(?:[^>]*?)>)/gi, "");
1588            }
1589
1590            var editor = this;
1591            try {
1592                if (range.pasteHTML) {
1593                    range.pasteHTML(new_html);
1594                } else {
1595                    var div = this._doc.createElement("DIV");
1596                    div.innerHTML = new_html;
1597                    while (div.firstChild) range(0).parentNode.insertBefore(div.firstChild, range(0));
1598                    range(0).parentNode.removeChild(range(0));
1599                    range.remove(0);
1600                    delete div;
1601                }
1602            } catch (e) {
1603                return false;
1604            }
1605
1606            var trg = this._doc.getElementById(Sys.Extended.UI.HTMLEditor.smartClassName);
1607
1608
1609            trg.innerHTML = "<span>qqq</span>" + Sys.Extended.UI.HTMLEditor.getHTML(trg, false, true).replace(new RegExp("<span(?:[^>]*?)class=" + Sys.Extended.UI.HTMLEditor.smartClassName + "_script(?:[^>]*?)>(.*?)<\/span(?:[^>]*?)>", "gi"), regReplFromScript) + "<span>qqq</span>";
1610
1611            trg.removeChild(trg.firstChild);
1612            trg.removeChild(trg.lastChild);
1613
1614            Sys.Extended.UI.HTMLEditor.setHrefsText(trg, mArr);
1615            Sys.Extended.UI.HTMLEditor.setImagesText(trg, mArr1);
1616
1617            if (trg.firstChild) {
1618                trg.removeChild(trg.firstChild);
1619            }
1620            if (trg.firstChild) {
1621                trg.removeChild(trg.firstChild);
1622            }
1623
1624            while (trg.firstChild) {
1625                trg.parentNode.insertBefore(trg.firstChild, trg);
1626            }
1627            trg.parentNode.removeChild(trg);
1628            delete trg;
1629
1630            return true;
1631        } else {
1632            var div = this._doc.createElement("div");
1633            div.innerHTML = html;
1634
1635            var tempCollection = div.getElementsByTagName("EMBED");
1636
1637            var embedCollection = [];
1638            for (var i = 0; i < tempCollection.length; i++) {
1639                embedCollection.push(tempCollection[i]);
1640            }
1641
1642            for (var j = 0; j < embedCollection.length; j++) {
1643                var embed = embedCollection[j];
1644                var img = document.createElement("IMG");
1645                var attrs = embed.attributes;
1646
1647                img.src = this._images_list[1];
1648                img.setAttribute("dummytag", "embed");
1649
1650                for (var i = 0; i < attrs.length; ++i) {
1651                    var a = attrs.item(i);
1652                    if (!a.specified) continue;
1653
1654                    var name = a.name.toLowerCase();
1655                    var value = a.value;
1656
1657                    if (name == "src")
1658                        name = "dummysrc";
1659                    else if (name == "bgcolor")
1660                        name = "dummybgcolor";
1661                    else if (name == "wmode")
1662                        name = "pseudomode";
1663
1664                    img.setAttribute(name, value);
1665                }
1666                img.getAttribute("type")
1667                img.style.cssText = "border: 1px dotted #000000; background-image: url('" + (img.getAttribute("type").toLowerCase() == "application/x-mplayer2" ? this._images_list[3] : this._images_list[2]) + "'); background-position: center; background-repeat: no-repeat; background-color: #c0c0c0;";
1668
1669                embed.parentNode.insertBefore(img, embed);
1670                embed.parentNode.removeChild(embed);
1671            }
1672
1673            var ret = this.insertNodeAtSelection(div, range);
1674            return ret;
1675        }
1676    },
1677
1678    insertNodeAtSelection: function(toBeInserted, range) {
1679        if (!Sys.Extended.UI.HTMLEditor.isIE) {
1680            var sel = this._getSelection();
1681            if (typeof range == "undefined") {
1682                try {
1683                    range = this._createRange(sel);
1684                } catch (ex) {
1685                    this._removeAllRanges(sel);
1686                    return false;
1687                }
1688            }
1689
1690            var node = range.startContainer;
1691            var pos = range.startOffset;
1692            if (node.ownerDocument.id != "EditorDocument") {
1693                return false;
1694            }
1695
1696            if ((range.startContainer.nodeType == 1 && range.startContainer.tagName.toUpperCase() == "TR") ||
1697                (range.endContainer.nodeType == 1 && range.endContainer.tagName.toUpperCase() == "TR")) {
1698                return false;
1699            }
1700
1701            this._removeAllRanges(sel);
1702            range.deleteContents();
1703            try {
1704                range = this._createRange();
1705            } catch (ex) {
1706                this._removeAllRanges(sel);
1707                return false;
1708            }
1709
1710            switch (node.nodeType) {
1711                case 3:
1712                    if (pos > 0) node = node.splitText(pos);
1713                    while (toBeInserted.firstChild) {
1714                        node.parentNode.insertBefore(toBeInserted.firstChild, node);
1715                    }
1716                    range.setStart(node, 0);
1717                    range.setEnd(node, 0);
1718                    break;
1719                case 1:
1720                case 11:
1721                    try {
1722                        this._removeAllRanges(sel);
1723                        if (node.childNodes.length >= pos + 1) {
1724                            node = node.childNodes.item(pos);
1725                            while (toBeInserted.firstChild) {
1726                                node.parentNode.insertBefore(toBeInserted.firstChild, node);
1727                            }
1728                            var tempText = this._doc.createTextNode("");
1729                            node.parentNode.insertBefore(tempText, node);
1730                            node = tempText;
1731                        } else {
1732                            var tempText = this._doc.createTextNode("");
1733
1734                            if (Sys.Extended.UI.HTMLEditor.canHaveChildren(node)) {
1735                                while (toBeInserted.firstChild) {
1736                                    node.appendChild(toBeInserted.firstChild);
1737                                }
1738                                node.appendChild(tempText);
1739                            } else {
1740                                while (toBeInserted.firstChild) {
1741                                    node.parentNode.insertBefore(toBeInserted.firstChild, node);
1742                                }
1743                                node.parentNode.insertBefore(tempText, node);
1744                            }
1745
1746                            node = tempText;
1747                        }
1748
1749                        if (node.nodeType == 1) {
1750                            var par = node.parentNode;
1751                            var container = par;
1752                            var j = 0;
1753
1754                            for (; j < par.childNodes.length; j++) {
1755                                if (node == par.childNodes.item(j)) {
1756                                    break;
1757                                }
1758                            }
1759                            range.setStart(par, j);
1760                            range.setEnd(par, j);
1761                        } else {
1762                            range.setStart(node, 0);
1763                            range.setEnd(node, 0);
1764                        }
1765                    } catch (ex) {
1766                        this._removeAllRanges(sel);
1767                        return false;
1768                    }
1769                    break;
1770            }
1771
1772            this._selectRange(sel, range);
1773            return true;
1774        } else {
1775            return false;
1776        }
1777    },
1778
1779    trickWithStyles: function(tid) {
1780        var editor = this;
1781        var el = editor._doc.getElementById(tid);
1782        if (el != null) {
1783            if (el.nextSibling && el.nextSibling.nodeType == 3) {
1784                var text = el.nextSibling;
1785                el.parentNode.removeChild(el);
1786
1787                var spaceIndex = ("" + text.data + "").indexOf(" ");
1788                if (spaceIndex > 0) {
1789                    text.splitText(spaceIndex);
1790                } else {
1791                    if (spaceIndex == 0) {
1792                        text.splitText(1);
1793                    }
1794                }
1795
1796                if (editor.n_arr != null) {
1797                    for (var im = 0; im < editor.n_arr.length; im++) {
1798                        editor.MSIE_applyCssStyle(editor.n_arr[im], [text], false);
1799                    }
1800                }
1801                editor.n_arr = null;
1802
1803                var sel = editor._getSelection();
1804
1805                if (!Sys.Extended.UI.HTMLEditor.isIE) {
1806                    var range = editor._doc.createRange();
1807                    range.setStart(text, text.length);
1808                    range.setEnd(text, text.length);
1809
1810                    editor._removeAllRanges(sel);
1811                    editor._selectRange(sel, range);
1812                } else {
1813                    var range1 = editor._createRange(sel);
1814
1815                    var span1 = editor._doc.createElement("span");
1816
1817                    if (text.nextSibling) {
1818                        text.parentNode.insertBefore(span1, text.nextSibling);
1819                    } else {
1820                        text.parentNode.appendChild(span1);
1821                    }
1822
1823                    try {
1824                        range1.moveToElementText(span1);
1825                        range1.select();
1826                    } catch (e) { }
1827                    span1.parentNode.removeChild(span1);
1828                }
1829            }
1830            else {
1831                el.parentNode.removeChild(el);
1832            }
1833        }
1834    },
1835
1836    _getParent: function(range) {
1837        if (Sys.Extended.UI.HTMLEditor.isIE) {
1838            return range.parentElement();
1839        } else {
1840            return range.startContainer;
1841        }
1842    },
1843
1844    _checkImages: function(element) {
1845        if (this._editPanel.get_relativeImages()) {
1846            var images = element.getElementsByTagName("IMG");
1847
1848            for (var i = 0; i < images.length; i++) {
1849                var image = images[i];
1850
1851                if (image.src.indexOf("http://") >= 0) {
1852                    var tmp = image.src;
1853
1854                    image.src = "qwerty.gif";
1855                    var n = image.src.indexOf("qwerty.gif");
1856
1857                    if (tmp.substr(0, n) == image.src.substr(0, n)) {
1858                        tmp = tmp.substr(n, tmp.length - n);
1859                    }
1860
1861                    image.src = tmp;
1862                }
1863            }
1864        }
1865    },
1866
1867    _getSafePlace: function(uel) {
1868        var el = this._doc.createElement("SPAN");
1869        var editor = this;
1870        el.id = Sys.Extended.UI.HTMLEditor.smartClassName;
1871
1872        if (typeof uel == "undefined") {
1873            if (!this.insertHTML(Sys.Extended.UI.HTMLEditor.getHTML(el, true))) {
1874                return null;
1875            }
1876        } else {
1877            if (uel.nextSibling == null) {
1878                uel.parentNode.appendChild(el);
1879            } else {
1880                uel.parentNode.insertBefore(el, uel.nextSibling);
1881            }
1882            uel.parentNode.removeChild(uel);
1883        }
1884
1885        el = this._doc.getElementById(Sys.Extended.UI.HTMLEditor.smartClassName);
1886
1887        el.id = null;
1888        el.removeAttribute("id");
1889        el.setAttribute("para", "no");
1890
1891        var parent = el.parentNode;
1892        var tagName = parent.tagName.toUpperCase();
1893
1894        while (tagName != "BODY" && tagName != "TD" && tagName != "P" && tagName != "DIV") {
1895            if (Sys.Extended.UI.HTMLEditor.isStyleTag(parent.tagName)) {
1896                parent = parent.parentNode;
1897                tagName = parent.tagName.toUpperCase();
1898            } else {
1899                break;
1900            }
1901        }
1902
1903        if (tagName == "P") {
1904            el.setAttribute("para", "");
1905
1906            function diver(add, el, rpr, before) {
1907                var neighbour;
1908                var par = Sys.Extended.UI.HTMLEditor.myClone(rpr, editor._doc, false);
1909
1910                if (add) {
1911                    par.appendChild(add);
1912                }
1913
1914                while (el) {
1915                    if (el.nodeType == 1 || (el.nodeType == 3 && Sys.Extended.UI.HTMLEditor.Trim("" + el.data + "").length > 0)) {
1916                        var text = null;
1917                        if (el.tagName && el.tagName.toUpperCase() == "SCRIPT") {
1918                            text = el.text;
1919                        }
1920
1921                        var ela = Sys.Extended.UI.HTMLEditor.myClone(el, editor._doc, true);
1922
1923                        if (par.childNodes.length == 0 || !before) {
1924                            par.appendChild(ela);
1925                        } else {
1926                            par.insertBefore(ela, par.firstChild);
1927                        }
1928
1929                        if (text != null) {
1930                            ela.text = text;
1931                        }
1932                    }
1933                    el = before ? el.previousSibling : el.nextSibling
1934                }
1935
1936                if (par.childNodes.length == 0) {
1937                    delete par;
1938                    par = null;
1939                }
1940
1941                if (rpr == parent) {
1942                    return par;
1943                } else {
1944                    return diver(par, before ? rpr.previousSibling : rpr.nextSibling, rpr.parentNode, before);
1945                }
1946            };
1947
1948            var p1 = diver(null, el.previousSibling, el.parentNode, true);
1949            var p2 = diver(null, el.nextSibling, el.parentNode, false);
1950
1951            var par = parent.parentNode;
1952
1953            if (p1) {
1954                par.insertBefore(p1, parent);
1955                el.setAttribute("para", el.getAttribute("para") + " left");
1956            }
1957            par.insertBefore(el, parent);
1958            if (p2) {
1959                par.insertBefore(p2, parent);
1960                el.setAttribute("para", el.getAttribute("para") + " right");
1961            }
1962            par.removeChild(parent);
1963        }
1964        return el;
1965    },
1966
1967    noContextMenuAttributeName: function() {
1968        return Sys.Extended.UI.HTMLEditor.noContextMenuAttribute;
1969    },
1970
1971    _getTextNodeCollection: function(total) {
1972        var _result = [];
1973        if (this.isControl()) {
1974            return _result;
1975        }
1976
1977        var sel = this._getSelection();
1978        var range = this._createRange(sel);
1979
1980        var rn = Sys.Extended.UI.HTMLEditor.smartClassName + "_right";
1981        var ln = Sys.Extended.UI.HTMLEditor.smartClassName + "_left";
1982        var r_left = null;
1983        var r_right = null;
1984        var svs;
1985        if (typeof total == "undefined") {
1986            if (Sys.Extended.UI.HTMLEditor.isIE) {
1987                r_left = range.duplicate();
1988                r_right = range.duplicate();
1989                r_left.setEndPoint("EndToStart", range);
1990                r_right.setEndPoint("StartToEnd", range);
1991            } else {
1992                r_left = range.cloneRange();
1993                r_right = range.cloneRange();
1994                r_left.setEnd(r_left.startContainer, r_left.startOffset);
1995                r_right.setStart(r_right.endContainer, r_right.endOffset);
1996                svs = r_left.endOffset;
1997            }
1998
1999            if (!this.insertHTML("<span id='" + rn + "'/>", r_right)) {
2000                return _result;
2001            } else {
2002                if (Sys.Extended.UI.HTMLEditor.isOpera) {
2003                    r_left.setEnd(r_left.startContainer, svs);
2004                    r_left.setStart(r_left.startContainer, svs);
2005                }
2006                if (!this.insertHTML("<span id='" + ln + "'/>", r_left)) {
2007                    var rP = this._doc.getElementById(rn);
2008                    if (rP != null) {
2009                        temp = rP.parentNode;
2010                        temp.removeChild(rP);
2011                    }
2012                    var rL = this._doc.getElementById(rl);
2013                    if (rL != null) {
2014                        temp = rL.parentNode;
2015                        temp.removeChild(rL);
2016                    }
2017                    return _result;
2018                }
2019            }
2020        } else {
2021            var span;
2022
2023            span = this._doc.createElement("SPAN");
2024            span.id = rn;
2025            this._doc.body.appendChild(span);
2026
2027            span = this._doc.createElement("SPAN");
2028            span.id = ln;
2029            this._doc.body.insertBefore(span, this._doc.body.firstChild);
2030        }
2031
2032        var lPoint = this._doc.getElementById(ln);
2033        var rPoint = this._doc.getElementById(rn);
2034
2035        if (lPoint == null || rPoint == null) {
2036            var temp;
2037
2038            if (lPoint != null) {
2039                temp = lPoint.parentNode;
2040                temp.removeChild(lPoint);
2041            }
2042            if (rPoint != null) {
2043                temp = rPoint.parentNode;
2044                temp.removeChild(rPoint);
2045            }
2046            return [];
2047        }
2048
2049        while (lPoint.firstChild) {
2050            lPoint.removeChild(lPoint.firstChild);
2051        }
2052        while (rPoint.firstChild) {
2053            rPoint.removeChild(rPoint.firstChild);
2054        }
2055
2056        while (lPoint.previousSibling && lPoint.previousSibling.nodeType == 3 &&
2057              Sys.Extended.UI.HTMLEditor.Trim("" + lPoint.previousSibling.data + "").length == 0) {
2058            lPoint.parentNode.removeChild(lPoint.previousSibling);
2059        }
2060
2061        while (lPoint.nextSibling && lPoint.nextSibling.nodeType == 3 &&
2062              Sys.Extended.UI.HTMLEditor.Trim("" + lPoint.nextSibling.data + "").length == 0) {
2063            lPoint.parentNode.removeChild(lPoint.nextSibling);
2064        }
2065
2066        while (rPoint.previousSibling && rPoint.previousSibling.nodeType == 3 &&
2067              Sys.Extended.UI.HTMLEditor.Trim("" + rPoint.previousSibling.data + "").length == 0) {
2068            rPoint.parentNode.removeChild(rPoint.previousSibling);
2069        }
2070
2071        while (rPoint.nextSibling && rPoint.nextSibling.nodeType == 3 &&
2072              Sys.Extended.UI.HTMLEditor.Trim("" + rPoint.nextSibling.data + "").length == 0) {
2073            rPoint.parentNode.removeChild(rPoint.nextSibling);
2074        }
2075
2076        var _found = false;
2077        var editor = this;
2078
2079        function _diver(_point, prize) {
2080            while (_point) {
2081                if (_point.id && _point.id == rn) {
2082                    _found = true;
2083                    return;
2084                }
2085                if (_point.nodeType == 3) {
2086                    while (_point.nextSibling &&
2087                            (
2088                            _point.nextSibling.nodeType == 3 ||
2089                            (!Sys.Extended.UI.HTMLEditor.isIE && typeof editor.__saveBM__ != "undefined" && editor.__saveBM__ != null && editor.__saveBM__[0] == _point.nextSibling)
2090                            )) {
2091                        if (_point.nextSibling.nodeType == 3) {
2092                            _point.data = "" + _point.data + "" + _point.nextSibling.data + "";
2093                        } else {
2094                            editor.__saveBM__[0] = _point;
2095                            editor.__saveBM__[1] = ("" + _point.data + "").length;
2096                        }
2097
2098                        _point.parentNode.removeChild(_point.nextSibling);
2099                    }
2100                    if (Sys.Extended.UI.HTMLEditor.Trim("" + _point.data + "").length > 0) {
2101                        _result.push(_point);
2102                    }
2103                } else {
2104                    var tagName = _point.tagName;
2105                    if (_point.tagName) {
2106                        tagName = tagName.toUpperCase();
2107                        if (!(tagName == "MAP" || tagName == "AREA" || tagName == "SCRIPT" || tagName == "NOSCRIPT"))
2108                            if (!(_point.style && (Sys.Extended.UI.HTMLEditor.getStyle(_point, "dis
2108play") == "none" || Sys.Extended.UI.HTMLEditor.getStyle(_point, "visibility") == "hidden"))) {
2109                            _diver(_point.firstChild, false);
2110                        }
2111                    }
2112                }
2113
2114                if (_found) return;
2115
2116                var _save = _point.parentNode;
2117
2118                if (prize) {
2119                    while (_point.nextSibling == null) {
2120                        _point = _point.parentNode;
2121                    }
2122                }
2123
2124                _point = _point.nextSibling;
2125            }
2126        };
2127
2128        _diver(lPoint, true);
2129        var temp;
2130
2131        temp = lPoint.parentNode;
2132        temp.removeChild(lPoint);
2133        temp = rPoint.parentNode;
2134        temp.removeChild(rPoint);
2135
2136        if (typeof total == "undefined") {
2137            if (Sys.Extended.UI.HTMLEditor.isIE) {
2138                sel.empty();
2139                r_right.select();
2140            } else {
2141                if (_result.length > 0) {
2142                    this._removeAllRanges(sel);
2143                    var rrr = this._createRange();
2144                    rrr.setEnd(_result[_result.length - 1], _result[_result.length - 1].length);
2145                    rrr.setStart(_result[_result.length - 1], _result[_result.length - 1].length);
2146                    this._selectRange(sel, rrr);
2147                }
2148            }
2149        }
2150
2151        return _result;
2152    },
2153
2154    _getPlain: function() {
2155        var area = this._doc.createElement("textarea");
2156        area.width = "0";
2157        area.height = "0";
2158        this._doc.appendChild(area);
2159        var r = area.createTextRange();
2160        r.execCommand("paste");
2161        var res = area.value;
2162        res = res.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\r/g, "").replace(/\n/g, "<br/>");
2163        this._doc.removeChild(area);
2164        return res;
2165    },
2166
2167    _execCommand: function(cmdID, UI, param) {
2168        var editor = this;
2169        var sel;
2170        var range;
2171
2172        if (Sys.Extended.UI.HTMLEditor.isIE && !this.isControl()) {
2173            sel = this._getSelection();
2174            range = this._createRange(sel);
2175
2176            var prnt = range.parentElement();
2177            if (prnt.tagName.toUpperCase() == "TEXTAREA") {
2178                return;
2179            }
2180        }
2181
2182        if (cmdID.toLowerCase() != "createlink") {
2183            this._saveContent();
2184        }
2185
2186        switch (cmdID.toLowerCase()) {
2187            case "createlink":
2188                if (Sys.Extended.UI.HTMLEditor.isIE || !UI) {
2189                    this._doc.execCommand(cmdID, UI, param);
2190                } else {
2191                    var param;
2192                    if ((param = prompt("Enter URL"))) {
2193                        this._doc.execCommand(cmdID, false, param);
2194                    }
2195                }
2196                break;
2197
2198            case "backcolor":
2199            case "forecolor":
2200            case "fontname":
2201            case "fontsize":
2202                this.MSIE_applyCommand(cmdID.toLowerCase(), param);
2203                break;
2204
2205            case "indent":
2206                this.MSIE_indent(true);
2207                break;
2208
2209            case "outdent":
2210                this.MSIE_indent(false);
2211                break;
2212
2213            case "justifyleft":
2214                this.MSIE_justify("left");
2215                break;
2216
2217            case "justifyfull":
2218                this.MSIE_justify("justify");
2219                break;
2220
2221            case "justifycenter":
2222                this.MSIE_justify("center");
2223                break;
2224
2225            case "justifyright":
2226                this.MSIE_justify("right");
2227                break;
2228
2229            case "paragraph":
2230                this.MSIE_justify("remain", false, "P");
2231                break;
2232
2233            case "formatblock":
2234                if (param != null && typeof param == "string" && param.length == 2) {
2235                    if (param.substr(0, 1).toUpperCase() == "H" && parseInt(param.substr(1, 1)) > 0) {
2236                        this.MSIE_justify("remain", false, param);
2237                        break;
2238                    }
2239                }
2240                this._doc.execCommand(cmdID, UI, param);
2241                break;
2242
2243            case "insertunorderedlist":
2244                this.MSIE_list("UL");
2245                break;
2246
2247            case "insertorderedlist":
2248                this.MSIE_list("OL");
2249                break;
2250
2251            case "bold":
2252            case "italic":
2253            case "underline":
2254            case "strikethrough":
2255            case "superscript":
2256            case "subscript":
2257                this.MSIE_applyCommand(cmdID.toLowerCase());
2258                break;
2259
2260            default:
2261                this._doc.execCommand(cmdID, UI, param);
2262                break;
2263        }
2264
2265        this.onContentChanged();
2266
2267        if (!Sys.Extended.UI.HTMLEditor.isIE) {
2268            sel = this._getSelection();
2269            range = this._createRange(sel);
2270
2271            this._removeAllRanges(sel);
2272
2273            this._selectRange(sel, range);
2274            this.focusEditor();
2275        }
2276        var editor = this;
2277        setTimeout(function() { editor._editPanel.updateToolbar(); }, 0);
2278    },
2279
2280    MSIE_indent: function(increase) {
2281        return (Function.createDelegate(this, Sys.Extended.UI.HTMLEditor.MSIE_indent))(increase);
2282    },
2283
2284    MSIE_justify: function(textAlign, addParameter, addParameter1) {
2285        return (Function.createDelegate(this, Sys.Extended.UI.HTMLEditor.MSIE_justify))(textAlign, addParameter, addParameter1);
2286    },
2287
2288    MSIE_list: function(listTg) {
2289        return (Function.createDelegate(this, Sys.Extended.UI.HTMLEditor.MSIE_list))(listTg);
2290    },
2291
2292    getSelectionAfterOperation: function(paragraphs) {
2293        return (Function.createDelegate(this, Sys.Extended.UI.HTMLEditor.getSelectionAfterOperation))(paragraphs);
2294    },
2295
2296    setSelectionAfterOperation: function(pars, needJoiner) {
2297        return (Function.createDelegate(this, Sys.Extended.UI.HTMLEditor.setSelectionAfterOperation))(pars, needJoiner);
2298    },
2299
2300    get_paragraphs: function() {
2301        return (Function.createDelegate(this, Sys.Extended.UI.HTMLEditor.get_paragraphs))();
2302    },
2303
2304    getPseudoP: function() {
2305        return (Function.createDelegate(this, Sys.Extended.UI.HTMLEditor.getPseudoP))();
2306    },
2307
2308    getPseudoP_Recur: function(lPoint, rPoint, r_level) {
2309        return (Function.createDelegate(this, Sys.Extended.UI.HTMLEditor.getPseudoP_Recur))(lPoint, rPoint, r_level);
2310    },
2311
2312    unWrap: function(element, pars) {
2313        return (Function.createDelegate(this, Sys.Extended.UI.HTMLEditor.unWrap))(element, pars);
2314    },
2315
2316    tryUnWrap: function(element, pars, force) {
2317        return (Function.createDelegate(this, Sys.Extended.UI.HTMLEditor.tryUnWrap))(element, pars, force);
2318    },
2319
2320    MSIE_applyCommand: function(cmd, par) {
2321        var selectedHTML = (!Sys.Extended.UI.HTMLEditor.isIE) ? Sys.Extended.UI.HTMLEditor.Trim(this.getSelectedHTML()) : "";
2322
2323        if (this.isControl()) return;
2324
2325        var sel = this._getSelection();
2326        var range = this._createRange(sel);
2327        var savedRange = (Sys.Extended.UI.HTMLEditor.isIE) ? [range.boundingLeft, range.boundingTop] : [range.startContainer, range.startOffset];
2328        var notEmpty = (Sys.Extended.UI.HTMLEditor.isIE && range.text.length > 0) || (!Sys.Extended.UI.HTMLEditor.isIE && selectedHTML.length > 0);
2329
2330        var cssStyle = { name: "none", value: "none" };
2331        switch (cmd.toLowerCase()) {
2332            case "bold":
2333                cssStyle = { name: "font-weight", value: "bold", repl: false };
2334                break;
2335            case "italic":
2336                cssStyle = { name: "font-style", value: "italic", repl: false };
2337                break;
2338            case "underline":
2339                cssStyle = { name: "text-decoration", value: "underline", repl: false };
2340                break;
2341            case "strikethrough":
2342                cssStyle = { name: "text-decoration", value: "line-through", repl: false };
2343                break;
2344            case "superscript":
2345                cssStyle = { name: "vertical-align", value: "super", repl: false };
2346                break;
2347            case "subscript":
2348                cssStyle = { name: "vertical-align", value: "sub", repl: false };
2349                break;
2350            case "forecolor":
2351                cssStyle = { name: "color", value: par, repl: false };
2352                break;
2353            case "backcolor":
2354                cssStyle = { name: "background-color", value: par, repl: false };
2355                break;
2356            case "fontname":
2357                cssStyle = { name: "font-family", value: par, repl: false };
2358                break;
2359            case "fontsize":
2360                cssStyle = { name: "font-size", value: par, repl: false };
2361                break;
2362        }
2363
2364        if (notEmpty) {
2365            var rng = this._getTextNodeCollection();
2366            this.MSIE_applyCssStyle(cssStyle, rng, true);
2367        }
2368        else {
2369            if (this.isControl()) return;
2370
2371            var rng = this._tryExpand();
2372
2373            if (rng.length > 0) {
2374                this.MSIE_applyCssStyle(cssStyle, rng, false);
2375                if (Sys.Extended.UI.HTMLEditor.isIE && this.__saveBM__ != null) {
2376                    sel = this._getSelection();
2377                    range = this._createRange(sel);
2378                    range.moveToBookmark(this.__saveBM__);
2379                    range.select();
2380                    this.__saveBM__ = null;
2381                } else {
2382                    if (this.__saveBM__ != null) {
2383                        if (this.__saveBM__[0].nodeType == 3) {
2384                            sel = this._getSelection();
2385                            range = this._doc.createRange();
2386                            range.setStart(this.__saveBM__[0], this.__saveBM__[1]);
2387                            range.setEnd(this.__saveBM__[0], this.__saveBM__[1]);
2388                            this._removeAllRanges(sel);
2389                            this._selectRange(sel, range);
2390                        } else {
2391                            this._trySelect(this.__saveBM__[0], this.__saveBM__[0]);
2392                            this.__saveBM__[0].parentNode.removeChild(this.__saveBM__[0]);
2393                        }
2394                        this.__saveBM__ = null;
2395                    }
2396                }
2397            } else {
2398                this._setStyleForTyping(cssStyle);
2399            }
2400        }
2401    },
2402
2403    MSIE_applyCssStyle: function(cssStyle, rng, selectPrize) {
2404        var name = cssStyle.name.replace(/\-(\w)/g, function(strMatch, p1) { return p1.toUpperCase(); });
2405        var value = cssStyle.value;
2406        var repl = cssStyle.repl;
2407        var _detected = false;
2408        var _remove = false;
2409
2410        this._saveContent();
2411
2412        var rn = Sys.Extended.UI.HTMLEditor.smartClassName + "_right";
2413        var ln = Sys.Extended.UI.HTMLEditor.smartClassName + "_left";
2414
2415        var lPoint = this._doc.createElement("SPAN");
2416        lPoint.id = ln;
2417        var rPoint = this._doc.createElement("SPAN");
2418        rPoint.id = rn;
2419
2420        rng[0].parentNode.insertBefore(lPoint, rng[0]);
2421
2422        if (rng[rng.length - 1].nextSibling != null) {
2423            rng[rng.length - 1].parentNode.insertBefore(rPoint, rng[rng.length - 1].nextSibling);
2424        } else {
2425            rng[rng.length - 1].parentNode.appendChild(rPoint);
2426        }
2427
2428        Sys.Extended.UI.HTMLEditor.unStyle(lPoint);
2429        Sys.Extended.UI.HTMLEditor.unStyle(rPoint);
2430
2431
2432        var parentNodes = [];
2433        for (var i = 0; i < rng.length; i++) {
2434            var textNode = rng[i];
2435            var par = textNode.parentNode;
2436
2437            var j;
2438            for (j = 0; j < parentNodes.length; j++) {
2439                var parent = parentNodes[j];
2440                if (parent.parent == par) {
2441                    parent.textNodes.push(textNode);
2442                    break;
2443                }
2444            }
2445            if (j == parentNodes.length) {
2446                parentNodes.push({ parent: par, textNodes: [textNode] });
2447            }
2448        }
2449
2450        for (var i = 0; i < parentNodes.length; i++) {
2451            var parent = parentNodes[i];
2452
2453            if (parent.textNodes.length > 1) {
2454                var textNodes = parent.textNodes;
2455
2456                var lPointT = this._doc.createElement("SPAN");
2457                var rPointT = this._doc.createElement("SPAN");
2458
2459                textNodes[0].parentNode.insertBefore(lPointT, textNodes[0]);
2460
2461                if (textNodes[textNodes.length - 1].nextSibling != null) {
2462                    textNodes[textNodes.length - 1].parentNode.insertBefore(rPointT, textNodes[textNodes.length - 1].nextSibling);
2463                } else {
2464                    textNodes[textNodes.length - 1].parentNode.appendChild(rPointT);
2465                }
2466
2467                Sys.Extended.UI.HTMLEditor._moveTagsUp(lPointT, rPointT);
2468
2469                lPointT.parentNode.removeChild(lPointT);
2470                rPointT.parentNode.removeChild(rPointT);
2471            }
2472        }
2473
2474        for (var i = 0; i < rng.length; i++) {
2475            var textNode = rng[i];
2476            var par = textNode.parentNode;
2477            var _found = false;
2478
2479            while (par && par.tagName && par.childNodes.length == 1 && Sys.Extended.UI.HTMLEditor.isStyleTag(par.tagName)) {
2480                var parTag = par.tagName.toUpperCase();
2481                if (
2482                ((parTag == "I" || parTag == "EM") && cssStyle.name == "font-style") ||
2483                ((parTag == "B" || parTag == "STRONG") && cssStyle.name == "font-weight") ||
2484                ((parTag == "S" || parTag == "STRIKE") && cssStyle.name == "text-decoration") ||
2485                ((parTag == "U") && cssStyle.name == "text-decoration") ||
2486                ((parTag == "SUB" || parTag == "SUP") && cssStyle.name == "vertical-align")
2487                ) {
2488                    var parSaved = par;
2489                    par = par.parentNode;
2490
2491                    while (parSaved.firstChild) {
2492                        par.insertBefore(parSaved.firstChild, parSaved);
2493                    }
2494                    par.removeChild(parSaved);
2495
2496                    _found = true;
2497                    continue;
2498                }
2499                else if (par.style && par.style[name] && par.style[name].length > 0) {
2500                    var foundCss = par.style[name];
2501
2502                    if (name.toLowerCase().indexOf("color") >= 0 || name == "fontFamily" || name == "fontSize") {
2503                        par.style[name] = value;
2504                    } else {
2505                        if (repl) {
2506                            try {
2507                                par.style[name] = par.style[name] + " " + value;
2508
2509                                if (foundCss == par.style[name]) {
2510                                    par.style[name] = value;
2511                                }
2512                            } catch (e) {
2513                                par.style[name] = value;
2514                            }
2515                        } else {
2516                            if (!_detected) {
2517                                var sv = foundCss.replace(value, "");
2518                                if (name == "fontWeight" && foundCss.toString() == "700") {
2519                                    sv = "";
2520                                }
2521
2522                                if (sv == foundCss) {
2523                                    try {
2524                                        par.style[name] = par.style[name] + " " + value;
2525
2526                                        if (foundCss == par.style[name]) {
2527                                            par.style[name] = value;
2528                                        }
2529                                    } catch (e) {
2530                                        par.style[name] = value;
2531                                    }
2532                                } else {
2533                                    par.style[name] = sv.replace(/,/, "");
2534                                    _remove = true;
2535                                }
2536                                _detected = true;
2537                            } else {
2538                                if (_remove) {
2539                                    par.style[name] = foundCss.replace(value, "").replace(/,/, "");
2540                                } else {
2541                                    try {
2542                                        par.style[name] = par.style[name] + " " + value;
2543
2544                                        if (foundCss == par.style[name]) {
2545                                            par.style[name] = value;
2546                                        }
2547                                    } catch (e) {
2548                                        par.style[name] = value;
2549                                    }
2550                                }
2551                            }
2552                        }
2553                    }
2554
2555                    _found = true;
2556                }
2557                par = par.parentNode;
2558            }
2559
2560            if (!_found && !_remove) {
2561                var span;
2562
2563                span = this._doc.createElement("SPAN");
2564                span.style[name] = value;
2565
2566                var parN = textNode.parentNode;
2567                parN.insertBefore(span, textNode);
2568
2569                span.appendChild(textNode);
2570                _detected = true;
2571            }
2572        }
2573
2574        var commonParent = Sys.Extended.UI.HTMLEditor._commonTotalParent(lPoint, rPoint);
2575
2576        var pSibling = commonParent.parent.childNodes.item(commonParent.indexFirst).previousSibling;
2577        var nSibling = commonParent.parent.childNodes.item(commonParent.indexLast).nextSibling;
2578
2579        lPoint.parentNode.removeChild(lPoint);
2580        rPoint.parentNode.removeChild(rPoint);
2581
2582        var indexFirst = 0;
2583        var indexLast = commonParent.parent.childNodes.length;
2584
2585        if (pSibling != null) {
2586            indexFirst = Sys.Extended.UI.HTMLEditor.__getIndex(pSibling);
2587        }
2588
2589        if (nSibling != null) {
2590            indexLast = Sys.Extended.UI.HTMLEditor.__getIndex(nSibling) + 1;
2591            if (indexLast < commonParent.parent.childNodes.length) {
2592                if (nSibling.nodeType == 3) {
2593                    indexLast++;
2594                }
2595                else if (nSibling.nodeType == 1) {
2596                    var tag = nSibling.tagName.toUpperCase();
2597                    if (tag != "TR" && tag != "TD" && tag != "LI") {
2598                        indexLast++;
2599                    }
2600                }
2601            }
2602        }
2603
2604        Sys.Extended.UI.HTMLEditor.spanJoiner(commonParent.parent, this._doc, indexFirst, indexLast);
2605
2606        var editor = this;
2607
2608        if (selectPrize) {
2609            editor._selectRng(rng);
2610        }
2611
2612        setTimeout(function() {
2613            if (!Sys.Extended.UI.HTMLEditor.isIE) {
2614                editor.focusEditor();
2615            }
2616            editor._editPanel.updateToolbar();
2617        }, 0);
2618    },
2619
2620    _tryExpand: function(prize) {
2621        var result = [];
2622        var selectedHTML;
2623        var notEmpty;
2624
2625        var sel = this._getSelection();
2626        var range = this._createRange(sel);
2627        var sel1;
2628        var range1;
2629
2630        var rn = Sys.Extended.UI.HTMLEditor.smartClassName + "_right_add";
2631        var ln = Sys.Extended.UI.HTMLEditor.smartClassName + "_left_add";
2632        var mn = Sys.Extended.UI.HTMLEditor.smartClassName + "_middle_add";
2633
2634        if (Sys.Extended.UI.HTMLEditor.isIE && typeof prize == "undefined") {
2635            range.execCommand('bold');
2636            this.__saveBM__ = range.getBookmark();
2637            range.execCommand('bold');
2638        }
2639
2640        if (Sys.Extended.UI.HTMLEditor.isIE) {
2641            var mn_element = null;
2642            var mn_span_text = "<span id=" + mn + "></span>";
2643            var save_range = range.duplicate();
2644
2645            try { range.pasteHTML(mn_span_text); } catch (ex) { }
2646
2647            mn_element = this._doc.getElementById(mn);
2648
2649            if (mn_element == null) {
2650                return [];
2651            }
2652
2653            if (typeof prize != "undefined") {
2654                this.__saveBM__ = mn_element;
2655            }
2656
2657            if (mn_element.nextSibling != null && !Sys.Extended.UI.HTMLEditor.isInlineElement(mn_element.nextSibling)) {
2658                mn_element.parentNode.removeChild(mn_element);
2659                return [];
2660            }
2661
2662            range.expand('word');
2663            range.select();
2664
2665            if (range.text.length == 0) {
2666                mn_element.parentNode.removeChild(mn_element);
2667                save_range.select();
2668                return [];
2669            }
2670
2671            var re = new RegExp(mn_span_text, "ig");
2672            if (!re.test(range.htmlText.replace(/[\n\r]/g, ""))) {
2673                mn_element.parentNode.removeChild(mn_element);
2674                save_range.select();
2675                return [];
2676            }
2677
2678            re = new RegExp(mn_span_text + "(</span>|&nbsp;|[\\s])*$", "ig");
2679            if (re.test(range.htmlText.replace(/[\n\r]/g, ""))) {
2680                mn_element.parentNode.removeChild(mn_element);
2681                save_range.select();
2682                return [];
2683            }
2684
2685            while (range.text.length > 0 && range.text.substr(range.text.length - 1, 1) == " ") {
2686                range.moveEnd('character', -1);
2687                range.select();
2688                if (range.text.length == 0) {
2689                    mn_element.parentNode.removeChild(mn_element);
2690                    save_range.select();
2691                    return [];
2692                }
2693            }
2694
2695
2696            if (typeof prize == "undefined") {
2697                mn_element.parentNode.removeChild(mn_element);
2698            }
2699
2700            return this._getTextNodeCollection();
2701        }
2702
2703
2704        function wordBound(c) {
2705            var re = /[\d\w]/;
2706            if (re.test(c)) return false;
2707            re = /[\u0080-\u024F]/;
2708            if (re.test(c)) return false;
2709            re = /[\u0370-\u2000]/;
2710            if (re.test(c)) return false;
2711            return true;
2712        }
2713
2714        if (!this.insertHTML("<span id='" + ln + "'></span><span id='" + mn + "'></span><span id='" + rn + "'></span>")) return [];
2715
2716        var lPoint = this._doc.getElementById(ln);
2717        var rPoint = this._doc.getElementById(rn);
2718        var mPoint = this._doc.getElementById(mn);
2719
2720        Sys.Extended.UI.HTMLEditor.positionInParagraph(lPoint, lPoint.previousSibling, true, lPoint.parentNode, wordBound);
2721        try { this._trySelect(lPoint, rPoint); } catch (ex) { }
2722
2723        sel1 = this._getSelection();
2724        range1 = this._createRange(sel1);
2725        selectedHTML = (!Sys.Extended.UI.HTMLEditor.isIE) ? Sys.Extended.UI.HTMLEditor.Trim(this.getSelectedHTML()) : "";
2726        notEmpty = (Sys.Extended.UI.HTMLEditor.isIE && range1.text.length > 0) || (!Sys.Extended.UI.HTMLEditor.isIE && selectedHTML.length > 0);
2727
2728        if (!notEmpty || this._getTextNodeCollection().length == 0) {
2729            var text1 = this._doc.createTextNode("");
2730
2731            lPoint.parentNode.insertBefore(text1, lPoint);
2732            lPoint.parentNode.removeChild(lPoint);
2733            rPoint.parentNode.removeChild(rPoint);
2734            mPoint.parentNode.removeChild(mPoint);
2735
2736            var range = this._doc.createRange();
2737            range.setStart(text1, 0);
2738            range.setEnd(text1, 0);
2739            range.setStart(text1, 0);
2740            range.setEnd(text1, 0);
2741
2742            this._removeAllRanges(sel);
2743            this._selectRange(sel, range);
2744
2745            return [];
2746        }
2747
2748        rPoint.parentNode.insertBefore(lPoint, mPoint);
2749
2750        Sys.Extended.UI.HTMLEditor.positionInParagraph(rPoint, rPoint.nextSibling, false, rPoint.parentNode, wordBound);
2751        this._trySelect(lPoint, rPoint);
2752
2753        sel1 = this._getSelection();
2754        range1 = this._createRange(sel1);
2755        selectedHTML = (!Sys.Extended.UI.HTMLEditor.isIE) ? Sys.Extended.UI.HTMLEditor.Trim(this.getSelectedHTML()) : "";
2756        notEmpty = (Sys.Extended.UI.HTMLEditor.isIE && range1.text.length > 0) || (!Sys.Extended.UI.HTMLEditor.isIE && selectedHTML.length > 0);
2757
2758        if (!notEmpty || this._getTextNodeCollection().length == 0) {
2759            var text1 = this._doc.createTextNode("");
2760
2761            lPoint.parentNode.insertBefore(text1, lPoint);
2762            lPoint.parentNode.removeChild(lPoint);
2763            rPoint.parentNode.removeChild(rPoint);
2764            mPoint.parentNode.removeChild(mPoint);
2765
2766            var range = this._doc.createRange();
2767            range.setStart(text1, 0);
2768            range.setEnd(text1, 0);
2769            range.setStart(text1, 0);
2770            range.setEnd(text1, 0);
2771
2772            this._removeAllRanges(sel);
2773            this._selectRange(sel, range);
2774
2775            return [];
2776        }
2777
2778        Sys.Extended.UI.HTMLEditor.positionInParagraph(lPoint, lPoint.previousSibling, true, lPoint.parentNode, wordBound);
2779        this._trySelect(lPoint, rPoint);
2780        sel1 = this._getSelection();
2781        range1 = this._createRange(sel1);
2782        selectedHTML = (!Sys.Extended.UI.HTMLEditor.isIE) ? Sys.Extended.UI.HTMLEditor.Trim(this.getSelectedHTML()) : "";
2783        notEmpty = (Sys.Extended.UI.HTMLEditor.isIE && range1.text.length > 0) || (!Sys.Extended.UI.HTMLEditor.isIE && selectedHTML.length > 0);
2784
2785        if (Sys.Extended.UI.HTMLEditor.isIE) {
2786            if (typeof prize != "undefined") {
2787                this.__saveBM__ = mPoint;
2788            } else {
2789                mPoint.parentNode.removeChild(mPoint);
2790            }
2791        } else {
2792            this.__saveBM__ = [mPoint, 0];
2793        }
2794
2795        if (notEmpty) {
2796            result = this._getTextNodeCollection();
2797        }
2798
2799        lPoint.parentNode.removeChild(lPoint);
2800        rPoint.parentNode.removeChild(rPoint);
2801
2802        return result;
2803    },
2804
2805    _setStyleForTyping: function(cssStyle) {
2806        var name = cssStyle.name.replace(/\-(\w)/g, function(strMatch, p1) { return p1.toUpperCase(); });
2807        var value = cssStyle.value;
2808        var repl = cssStyle.repl;
2809
2810        if (this._StyleForTyping == null) {
2811            this._StyleForTyping = [];
2812        }
2813
2814        var n_arr = []
2815        var needApply = true;
2816        for (var i = 0; i < this._StyleForTyping.length; i++) {
2817            var i_name = this._StyleForTyping[i].name.replace(/\-(\w)/g, function(strMatch, p1) { return p1.toUpperCase(); });
2818            var i_value = this._StyleForTyping[i].value;
2819
2820            if (!(i_name == name && (i_value == value || repl))) {
2821                n_arr.push(this._StyleForTyping[i]);
2822            } else {
2823                needApply = false;
2824            }
2825        }
2826
2827        this._StyleForTyping = n_arr;
2828        if (needApply) {
2829            this._StyleForTyping.push(cssStyle);
2830        }
2831    },
2832
2833    _trySelect: function(lPoint, rPoint) {
2834        var sel = this._getSelection();
2835        var text1 = null;
2836        var text2 = null;
2837
2838        if (Sys.Extended.UI.HTMLEditor.isIE) {
2839            sel.empty();
2840            sel = this._getSelection();
2841            var range1 = this._createRange(sel);
2842            var range2 = this._createRange(sel);
2843
2844            try {
2845                if (lPoint != null) range1.moveToElementText(lPoint);
2846                if (rPoint != null) range2.moveToElementText(rPoint);
2847
2848                if (lPoint != null && rPoint != null) {
2849                    range1.setEndPoint("EndToEnd", range2);
2850                    range1.select();
2851                }
2852                else if (lPoint != null) range1.select();
2853                else if (rPoint != null) range2.select();
2854
2855            } catch (e) { }
2856        } else {
2857            try {
2858                text1 = this._doc.createTextNode("");
2859                text2 = this._doc.createTextNode("");
2860
2861                lPoint.parentNode.insertBefore(text1, lPoint);
2862                rPoint.parentNode.insertBefore(text2, rPoint);
2863
2864                var range = this._doc.createRange();
2865                range.setStart(text1, 0);
2866                range.setEnd(text2, 0);
2867
2868                this._removeAllRanges(sel);
2869                this._selectRange(sel, range);
2870            } catch (e) { }
2871        }
2872    },
2873
2874    getSelectedHTML: function() {
2875        var sel = this._getSelection();
2876        var ra
2876nge = this._createRange(sel);
2877        var existing = null;
2878        if (Sys.Extended.UI.HTMLEditor.isIE) {
2879            existing = range.htmlText;
2880        } else {
2881            if (Sys.Extended.UI.HTMLEditor.isSafari && (sel.type == "Caret" || sel.type == "None")) {
2882                existing = "";
2883            } else {
2884                if (Sys.Extended.UI.HTMLEditor.isSafari) {
2885                    if (range.cloneContents() == null) {
2886                        return "";
2887                    }
2888                }
2889                existing = Sys.Extended.UI.HTMLEditor.getHTML(range.cloneContents(), false);
2890            }
2891        }
2892        return existing;
2893    },
2894
2895    _queryCommandState: function(cmdID) {
2896        var obj = this._rangeStartEnd();
2897        if (obj == null) return false;
2898
2899        try {
2900            var cssStyle = { name: "none", value: "none" };
2901            switch (cmdID.toLowerCase()) {
2902                case "bold":
2903                    cssStyle = { name: "font-weight", value: "bold" };
2904                    break;
2905                case "italic":
2906                    cssStyle = { name: "font-style", value: "italic" };
2907                    break;
2908                case "underline":
2909                    cssStyle = { name: "text-decoration", value: "underline" };
2910                    break;
2911                case "strikethrough":
2912                    cssStyle = { name: "text-decoration", value: "line-through" };
2913                    break;
2914                case "superscript":
2915                    cssStyle = { name: "vertical-align", value: "super" };
2916                    break;
2917                case "subscript":
2918                    cssStyle = { name: "vertical-align", value: "sub" };
2919                    break;
2920            }
2921
2922            var el1 = obj.start;
2923            var el2 = obj.end;
2924            var cs1 = Sys.Extended.UI.HTMLEditor.getStyle(el1, cssStyle.name).toString().toLowerCase();
2925            var cs2 = Sys.Extended.UI.HTMLEditor.getStyle(el2, cssStyle.name).toString().toLowerCase();
2926
2927            if (cssStyle.name == "font-weight" && cs1 == "700") cs1 = "bold";
2928            if (cssStyle.name == "font-weight" && cs2 == "700") cs2 = "bold";
2929
2930            if (/MSIE (5|6)/.test(navigator.userAgent) && cmdID.toLowerCase() == "strikethrough" && (cs1 == "underline" || cs2 == "underline")) {
2931                while (el1 && Sys.Extended.UI.HTMLEditor.isStyleTag(el1.tagName)) {
2932                    if (el1.style.textDecoration.indexOf("line-through") >= 0) {
2933                        cs1 = el1.style.textDecoration;
2934                        break;
2935                    }
2936                    el1 = el1.parentNode;
2937                }
2938                while (el2 && Sys.Extended.UI.HTMLEditor.isStyleTag(el2.tagName)) {
2939                    if (el2.style.textDecoration.indexOf("line-through") >= 0) {
2940                        cs2 = el2.style.textDecoration;
2941                        break;
2942                    }
2943                    el2 = el2.parentNode;
2944                }
2945            }
2946
2947            if (Sys.Extended.UI.HTMLEditor.isSafari && (cmdID.toLowerCase() == "strikethrough" || cmdID.toLowerCase() == "underline")) {
2948                var cmdl = cmdID.toLowerCase();
2949                if (cmdl == "strikethrough") {
2950                    cmdl = "line-through";
2951                }
2952
2953                while (el1 && Sys.Extended.UI.HTMLEditor.isStyleTag(el1.tagName)) {
2954                    if (el1.style.textDecoration.indexOf(cmdl) >= 0) {
2955                        cs1 = el1.style.textDecoration;
2956                        break;
2957                    }
2958                    el1 = el1.parentNode;
2959                }
2960                while (el2 && Sys.Extended.UI.HTMLEditor.isStyleTag(el2.tagName)) {
2961                    if (el2.style.textDecoration.indexOf(cmdl) >= 0) {
2962                        cs2 = el2.style.textDecoration;
2963                        break;
2964                    }
2965                    el2 = el2.parentNode;
2966                }
2967            }
2968
2969            var ret = (cs1.indexOf(cssStyle.value) >= 0) && (cs2.indexOf(cssStyle.value) >= 0);
2970
2971            if (this._StyleForTyping != null && this._StyleForTyping.length > 0) {
2972                for (var i = 0; i < this._StyleForTyping.length; i++) {
2973                    var curCss = this._StyleForTyping[i];
2974
2975                    if (curCss.name == cssStyle.name && curCss.value == cssStyle.value) {
2976                        ret = !ret;
2977                        break;
2978                    }
2979                }
2980            }
2981
2982            return ret;
2983        } catch (ex) {
2984            return false;
2985        }
2986    },
2987
2988    _textAlignState: function(value) {
2989        var obj = this._rangeStartEnd();
2990        if (obj == null) return false;
2991
2992        try {
2993            var cs1 = this._textAlignStateSingle(obj.start);
2994            var cs2 = this._textAlignStateSingle(obj.end);
2995
2996            return (cs1 == value && cs2 == value);
2997        } catch (ex) {
2998            return false;
2999        }
3000    },
3001
3002    _textAlignStateSingle: function(el) {
3003        while (el && Sys.Extended.UI.HTMLEditor.isStyleTag(el.tagName)) {
3004            el = el.parentNode;
3005        }
3006        if (el != null) {
3007            var tagName = el.tagName.toUpperCase();
3008            if (tagName == "P" || tagName == "DIV") {
3009                return el.style.textAlign.toLowerCase();
3010            }
3011        }
3012        return null;
3013    },
3014
3015    _rangeStartEnd: function() {
3016        if (this.isControl()) return null;
3017
3018        try {
3019            var sel = this._getSelection();
3020            var range = this._createRange(sel);
3021            var el1 = null;
3022            var el2 = null;
3023
3024            if (!Sys.Extended.UI.HTMLEditor.isIE) {
3025                function __getText__(par, first) {
3026                    var ret = null;
3027
3028                    while (ret == null) {
3029                        if (par.nodeType == 3) {
3030                            if (first && range.startContainer != range.endContainer && range.startOffset == par.length && par.nextSibling) {
3031                                ret = __getText__(par.nextSibling, first);
3032                            } else if (!first && range.startContainer != range.endContainer && range.endOffset == 0 && par.previousSibling) {
3033                                ret = __getText__(par.previousSibling, first);
3034                            } else {
3035                                ret = par;
3036                            }
3037                        } else {
3038                            if ((first ? par.firstChild : par.lastChild) == null) {
3039                                ret = null;
3040                            } else {
3041                                ret = __getText__(first ? par.firstChild : par.lastChild, first);
3042                            }
3043                        }
3044
3045                        if (ret == null) {
3046                            par = first ? par.nextSibling : par.previousSibling;
3047                            if (par == null) return null;
3048                        } else {
3049                            return ret;
3050                        }
3051                    }
3052                }
3053
3054                var parent = this._getParent(range);
3055
3056                if (parent.nodeType != 3 && range.startContainer == range.endContainer &&
3057                range.startOffset == range.endOffset &&
3058                range.startContainer.childNodes.item(range.startOffset).tagName &&
3059                Sys.Extended.UI.HTMLEditor.isStyleTag(range.startContainer.childNodes.item(range.startOffset).tagName)
3060                ) {
3061                    return { start: range.startContainer.childNodes.item(range.startOffset), end: range.startContainer.childNodes.item(range.startOffset) };
3062                }
3063
3064                el1 = __getText__(range.startContainer, true);
3065                if (el1 != null && el1.parentNode != null) el1 = el1.parentNode;
3066                if (el1 == null) el1 = range.startContainer;
3067
3068                el2 = __getText__(range.endContainer, false);
3069                if (el2 != null && el2.parentNode != null) el2 = el2.parentNode;
3070                if (el2 == null) el2 = range.endContainer;
3071            } else {
3072                if (range.text.length == 0) {
3073                    el1 = el2 = this._getParent(range);
3074                } else {
3075                    var rn = Sys.Extended.UI.HTMLEditor.smartClassName + "_right_marker";
3076                    var ln = Sys.Extended.UI.HTMLEditor.smartClassName + "_left_marker";
3077
3078                    var r_left = range.duplicate();
3079                    var r_right = range.duplicate();
3080
3081                    r_left.setEndPoint("EndToStart", range);
3082                    r_right.setEndPoint("StartToEnd", range);
3083
3084                    r_right.pasteHTML("<span id='" + rn + "'/>");
3085                    r_left.pasteHTML("<span id='" + ln + "'/>");
3086
3087                    var lPoint = this._doc.getElementById(ln);
3088                    var rPoint = this._doc.getElementById(rn);
3089
3090                    el1 = lPoint.parentNode;
3091                    el2 = rPoint.parentNode;
3092
3093                    lPoint.parentNode.removeChild(lPoint);
3094                    rPoint.parentNode.removeChild(rPoint);
3095                }
3096            }
3097
3098            return { start: el1, end: el2 };
3099        } catch (ex) {
3100            return null;
3101        }
3102    },
3103
3104    rtlState: function() {
3105        if (this._doc.body.style.direction && this._doc.body.style.direction == "rtl") return true;
3106        return false;
3107    },
3108
3109    openWait: function() {
3110        this._editPanel.openWait();
3111    },
3112
3113    closeWait: function() {
3114        this._editPanel.closeWait();
3115    }
3116}
3117
3118Sys.Extended.UI.HTMLEditor.DesignPanel.ScriptRecover = function() {
3119    this.scriptsArray=[];
3120    this.scriptsArray_index=-1;
3121
3122    this.regReplScript1 = function(p0,p1) {
3123        this.scriptsArray.push(p1);
3124        return "";
3125    }
3126
3127    this.regReplFromScript = function(p0,p1,p2,p3) {
3128        return p1.replace(/&gt;/g ,">").replace(/&lt;/g ,"<").replace(/&amp;/g ,"&");
3129    }
3130
3131    this.regReplFromScript1 = function(p0,p1,p2,p3) {
3132        this.scriptsArray_index++;
3133        var mmm;
3134        if(!Sys.Extended.UI.HTMLEditor.isIE)
3135            mmm = this.scriptsArray[this.scriptsArray_index].replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,"\"");
3136        else
3137            mmm = this.scriptsArray[this.scriptsArray_index];
3138        return p1+mmm+p3;
3139    }
3140}
3141
3142Sys.Extended.UI.HTMLEditor.DesignPanel.registerClass("Sys.Extended.UI.HTMLEditor.DesignPanel",Sys.Extended.UI.HTMLEditor.ModePanel);
3143

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.