4 * HtmlArea (tinyMCE) wrapper
6 * @author Gabor Berczi <gabor.berczi@devworx.hu>
11 Prado.WebUI.THtmlArea = Class.create(Prado.WebUI.Control,
13 initialize: function($super, options)
15 options.ID = options.EditorOptions.elements;
19 onInit : function(options)
21 this.options = options;
24 this.ajaxresponder = {
25 onComplete : function(request)
27 if(request && (request instanceof Prado.AjaxRequest))
31 this.registerAjaxHook();
33 this.registerInstance();
36 registerInstance: function()
38 if (typeof tinyMCE_GZ == 'undefined')
40 if (typeof tinyMCE == 'undefined')
42 if (typeof Prado.CallbackRequest != 'undefined')
43 if (typeof Prado.CallbackRequest.transport != 'undefined')
45 // we're in a callback
46 // try it again in some time, as tinyMCE is most likely still loading
47 this.setTimeout(this.registerInstance.bind(this), 50);
50 throw "TinyMCE libraries must be loaded first";
52 Prado.WebUI.THtmlArea.tinyMCELoadState = 255;
56 if (Prado.WebUI.THtmlArea.tinyMCELoadState==255)
60 Prado.WebUI.THtmlArea.pendingRegistrations.push(this.options.ID);
61 if (Prado.WebUI.THtmlArea.tinyMCELoadState==0)
63 Prado.WebUI.THtmlArea.tinyMCELoadState = 1;
65 this.options.CompressionOptions,
66 this.compressedScriptsLoaded.bind(this)
72 compressedScriptsLoaded: function()
74 Prado.WebUI.THtmlArea.tinyMCELoadState = 255;
76 while(Prado.WebUI.THtmlArea.pendingRegistrations.length>0)
77 if (wrapper = Prado.Registry.get(Prado.WebUI.THtmlArea.pendingRegistrations.pop()))
78 wrapper.initInstance();
81 initInstance: function()
83 tinyMCE.init(this.options.EditorOptions);
86 checkInstance: function()
88 if (!document.getElementById(this.ID))
92 removePreviousInstance: function()
94 for(var i=0;i<tinyMCE.editors.length;i++)
95 if (tinyMCE.editors[i].id==this.ID)
97 tinyMCE.editors.splice(i,1); // ugly hack, but works
98 this.deRegisterAjaxHook();
104 registerAjaxHook: function()
106 if (typeof(Ajax)!="undefined")
107 if (typeof(Ajax.Responders)!="undefined")
108 Ajax.Responders.register(this.ajaxresponder);
112 deRegisterAjaxHook: function()
114 if (typeof(Ajax)!="undefined")
115 if (typeof(Ajax.Responders)!="undefined")
116 Ajax.Responders.unregister(this.ajaxresponder);
121 // check for previous tinyMCE registration, and try to remove it gracefully first
122 var prev = tinyMCE.get(this.ID);
126 tinyMCE.execCommand('mceFocus', false, this.ID);
127 // when removed, tinyMCE restores its content to the textarea. If the textarea content has been
128 // updated in this same callback, it will be overwritten with the old content. Workaround this.
129 var curtext = $(this.ID).value;
130 tinyMCE.execCommand('mceRemoveControl', false, this.ID);
131 $(this.ID).value = curtext;
135 // suppress error here in case editor can't be properly removed
136 // (happens when <textarea> has been removed from DOM tree without deinitialzing the tinyMCE editor first)
139 // doublecheck editor instance here and remove manually from tinyMCE-registry if neccessary
140 this.removePreviousInstance();
142 this.deRegisterAjaxHook();
146 Object.extend(Prado.WebUI.THtmlArea,
148 pendingRegistrations : [],