/* * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com * * http://extjs.com/license */ Ext.form.HtmlEditor = Ext.extend(Ext.form.Field, { enableFormat : true, enableFontSize : true, enableColors : true, enableAlignments : true, enableLists : true, enableSourceEdit : true, enableLinks : true, enableFont : true, createLinkText : "Please enter the URL for the link:", defaultLinkValue : "http:/" + "/", fontFamilies : ["Arial", "Courier New", "Tahoma", "Times New Roman", "Verdana"], defaultFont : "tahoma", validationEvent : false, deferHeight : true, initialized : false, activated : false, sourceEditMode : false, onFocus : Ext.emptyFn, iframePad : 3, hideMode : "offsets", defaultAutoCreate : { tag : "textarea", style : "width:500px;height:300px;", autocomplete : "off" }, initComponent : function() { this.addEvents("initialize", "activate", "beforesync", "beforepush", "sync", "push", "editmodechange") }, createFontOptions : function() { var D = [], B = this.fontFamilies, C, F; for (var E = 0, A = B.length; E < A; E++) { C = B[E]; F = C.toLowerCase(); D.push("") } return D.join("") }, createToolbar : function(C) { function B(F, D, E) { return { itemId : F, cls : "x-btn-icon x-edit-" + F, enableToggle : D !== false, scope : C, handler : E || C.relayBtnCmd, clickEvent : "mousedown", tooltip : C.buttonTips[F] || undefined, tabIndex : -1 } } var A = new Ext.Toolbar({ renderTo : this.wrap.dom.firstChild }); A.el.on("click", function(D) { D.preventDefault() }); if (this.enableFont && !Ext.isSafari) { this.fontSelect = A.el.createChild({ tag : "select", cls : "x-font-select", html : this.createFontOptions() }); this.fontSelect.on("change", function() { var D = this.fontSelect.dom.value; this.relayCmd("fontname", D); this.deferFocus() }, this); A.add(this.fontSelect.dom, "-") } if (this.enableFormat) { A.add(B("bold"), B("italic"), B("underline")) } if (this.enableFontSize) { A.add("-", B("increasefontsize", false, this.adjustFont), B( "decreasefontsize", false, this.adjustFont)) } if (this.enableColors) { A.add("-", { itemId : "forecolor", cls : "x-btn-icon x-edit-forecolor", clickEvent : "mousedown", tooltip : C.buttonTips["forecolor"] || undefined, tabIndex : -1, menu : new Ext.menu.ColorMenu({ allowReselect : true, focus : Ext.emptyFn, value : "000000", plain : true, selectHandler : function(E, D) { this.execCmd("forecolor", Ext.isSafari || Ext.isIE ? "#" + D : D); this.deferFocus() }, scope : this, clickEvent : "mousedown" }) }, { itemId : "backcolor", cls : "x-btn-icon x-edit-backcolor", clickEvent : "mousedown", tooltip : C.buttonTips["backcolor"] || undefined, tabIndex : -1, menu : new Ext.menu.ColorMenu({ focus : Ext.emptyFn, value : "FFFFFF", plain : true, allowReselect : true, selectHandler : function(E, D) { if (Ext.isGecko) { this.execCmd("useCSS", false); this.execCmd("hilitecolor", D); this.execCmd("useCSS", true); this.deferFocus() } else { this.execCmd(Ext.isOpera ? "hilitecolor" : "backcolor", Ext.isSafari || Ext.isIE ? "#" + D : D); this.deferFocus() } }, scope : this, clickEvent : "mousedown" }) }) } if (this.enableAlignments) { A.add("-", B("justifyleft"), B("justifycenter"), B("justifyright")) } if (!Ext.isSafari) { if (this.enableLinks) { A.add("-", B("createlink", false, this.createLink)) } if (this.enableLists) { A.add("-", B("insertorderedlist"), B("insertunorderedlist")) } if (this.enableSourceEdit) { A.add("-", B("sourceedit", true, function(D) { this.toggleSourceEdit(D.pressed) })) } } this.tb = A }, getDocMarkup : function() { return "
" }, getEditorBody : function() { return this.doc.body || this.doc.documentElement }, onRender : function(C, A) { Ext.form.HtmlEditor.superclass.onRender.call(this, C, A); this.el.dom.style.border = "0 none"; this.el.dom.setAttribute("tabIndex", -1); this.el.addClass("x-hidden"); if (Ext.isIE) { this.el.applyStyles("margin-top:-1px;margin-bottom:-1px;") } this.wrap = this.el.wrap({ cls : "x-html-editor-wrap", cn : { cls : "x-html-editor-tb" } }); this.createToolbar(this); this.tb.items.each(function(E) { if (E.itemId != "sourceedit") { E.disable() } }); var D = document.createElement("iframe"); D.name = Ext.id(); D.frameBorder = "no"; D.src = (Ext.SSL_SECURE_URL || "javascript:false"); this.wrap.dom.appendChild(D); this.iframe = D; if (Ext.isIE) { D.contentWindow.document.designMode = "on"; this.doc = D.contentWindow.document; this.win = D.contentWindow } else { this.doc = (D.contentDocument || window.frames[D.name].document); this.win = window.frames[D.name]; this.doc.designMode = "on" } this.doc.open(); this.doc.write(this.getDocMarkup()); this.doc.close(); var B = { run : function() { if (this.doc.body || this.doc.readyState == "complete") { Ext.TaskMgr.stop(B); this.doc.designMode = "on"; this.initEditor.defer(10, this) } }, interval : 10, duration : 10000, scope : this }; Ext.TaskMgr.start(B); if (!this.width) { this.setSize(this.el.getSize()) } }, onResize : function(B, C) { Ext.form.HtmlEditor.superclass.onResize.apply(this, arguments); if (this.el && this.iframe) { if (typeof B == "number") { var D = B - this.wrap.getFrameWidth("lr"); this.el.setWidth(this.adjustWidth("textarea", D)); this.iframe.style.width = D + "px" } if (typeof C == "number") { var A = C - this.wrap.getFrameWidth("tb") - this.tb.el.getHeight(); this.el.setHeight(this.adjustWidth("textarea", A)); this.iframe.style.height = A + "px"; if (this.doc) { this.getEditorBody().style.height = (A - (this.iframePad * 2)) + "px" } } } }, toggleSourceEdit : function(A) { if (A === undefined) { A = !this.sourceEditMode } this.sourceEditMode = A === true; var C = this.tb.items.get("sourceedit"); if (C.pressed !== this.sourceEditMode) { C.toggle(this.sourceEditMode); return } if (this.sourceEditMode) { this.tb.items.each(function(D) { if (D.itemId != "sourceedit") { D.disable() } }); this.syncValue(); this.iframe.className = "x-hidden"; this.el.removeClass("x-hidden"); this.el.dom.removeAttribute("tabIndex"); this.el.focus() } else { if (this.initialized) { this.tb.items.each(function(D) { D.enable() }) } this.pushValue(); this.iframe.className = ""; this.el.addClass("x-hidden"); this.el.dom.setAttribute("tabIndex", -1); this.deferFocus() } var B = this.lastSize; if (B) { delete this.lastSize; this.setSize(B) } this.fireEvent("editmodechange", this, this.sourceEditMode) }, createLink : function() { var A = prompt(this.createLinkText, this.defaultLinkValue); if (A && A != "http:/" + "/") { this.relayCmd("createlink", A) } }, adjustSize : Ext.BoxComponent.prototype.adjustSize, getResizeEl : function() { return this.wrap }, getPositionEl : function() { return this.wrap }, initEvents : function() { this.originalValue = this.getValue() }, markInvalid : Ext.emptyFn, clearInvalid : Ext.emptyFn, setValue : function(A) { Ext.form.HtmlEditor.superclass.setValue.call(this, A); this.pushValue() }, cleanHtml : function(A) { A = String(A); if (A.length > 5) { if (Ext.isSafari) { A = A .replace( /\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, "") } } if (A == " ") { A = "" } return A }, syncValue : function() { if (this.initialized) { var D = this.getEditorBody(); var C = D.innerHTML; if (Ext.isSafari) { var B = D.getAttribute("style"); var A = B.match(/text-align:(.*?);/i); if (A && A[1]) { C = "