]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/Javascripts/source/prado/controls/htmlarea4.js
64a78176f2f5b78dedd2e9bf3df677503c2221e8
[bacula/bacula] / gui / baculum / framework / Web / Javascripts / source / prado / controls / htmlarea4.js
1
2 /*
3  *
4  * HtmlArea (tinyMCE 4) wrapper
5  *
6  * @author Gabor Berczi <gabor.berczi@devworx.hu>
7  *
8 */
9
10
11 Prado.WebUI.THtmlArea4 = jQuery.klass(Prado.WebUI.Control,
12 {
13         initialize: function($super, options)
14         {
15                 options.ID = options.EditorOptions.elements;
16                 $super(options);
17         },
18
19     onInit : function(options)
20         {
21                 this.options = options;
22                 tinyMCE.init(this.options.EditorOptions);
23         },
24
25         removePreviousInstance: function()
26         {
27                 for(var i=0;i<tinyMCE.editors.length;i++)
28                         if (tinyMCE.editors[i].id==this.ID)
29                         {
30                                 tinyMCE.editors.splice(i,1); // ugly hack, but works
31                                 i--;
32                         }
33         },
34
35         onDone: function()
36         {
37                 // check for previous tinyMCE registration, and try to remove it gracefully first
38                 var prev = tinyMCE.get(this.ID);
39                 if (prev)
40                 try
41                 {
42                         tinyMCE.execCommand('mceFocus', false, this.ID);
43                         // when removed, tinyMCE restores its content to the textarea. If the textarea content has been
44                         // updated in this same callback, it will be overwritten with the old content. Workaround this.
45                 //      var curtext = jQuery(this.ID).html();
46                         tinyMCE.execCommand('mceRemoveControl', false, this.ID);
47                 //      jQuery(this.ID).html(curtext);
48                 }
49                 catch (e)
50                 {
51                         // suppress error here in case editor can't be properly removed
52                         // (happens when <textarea> has been removed from DOM tree without deinitialzing the tinyMCE editor first)
53                 }
54
55                 // doublecheck editor instance here and remove manually from tinyMCE-registry if neccessary
56                 this.removePreviousInstance();
57         }
58 });