7a2923d26a368cebe2324244b9b78609d18c26a3
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Resources / Public / JavaScript / HTMLArea / Editor / TextAreaContainer.js
1 /**
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13
14 /**
15 * The container of the textarea within the editor framework
16 */
17 define('TYPO3/CMS/Rtehtmlarea/HTMLArea/Editor/TextAreaContainer',
18 ['TYPO3/CMS/Rtehtmlarea/HTMLArea/Util/Util',
19 'TYPO3/CMS/Rtehtmlarea/HTMLArea/DOM/DOM',
20 'TYPO3/CMS/Rtehtmlarea/HTMLArea/Event/Event'],
21 function (Util, Dom, Event) {
22
23 /**
24 * Status bar constructor
25 */
26 var TextAreaContainer = function (config) {
27 Util.apply(this, config);
28 };
29
30 TextAreaContainer.prototype = {
31
32 /**
33 * Render the textarea container (called by framework rendering)
34 *
35 * @param object container: the container into which to insert the status bar (that is the framework)
36 * @return void
37 */
38 render: function (container) {
39 this.el = document.createElement('div');
40 if (this.id) {
41 this.el.setAttribute('id', this.id);
42 }
43 if (this.cls) {
44 this.el.setAttribute('class', this.cls);
45 }
46 this.el = container.appendChild(this.el);
47 this.swallow(this.textArea);
48 this.rendered = true;
49 this.initEventListeners();
50 },
51
52 /**
53 * Initialize listeners (after rendering)
54 */
55 initEventListeners: function () {
56 var self = this;
57 // Monitor editor being unloaded
58 Event.one(this.framework.iframe.getIframeWindow(), 'unload', function (event) { return self.onBeforeDestroy(); });
59 },
60
61 /**
62 * Get the element to which the textarea container is rendered
63 */
64 getEl: function () {
65 return this.el;
66 },
67
68 /**
69 * editorId should be set in config
70 */
71 editorId: null,
72
73 /**
74 * Get a reference to the editor
75 */
76 getEditor: function() {
77 return RTEarea[this.editorId].editor;
78 },
79
80 /**
81 * Let the textarea container swallow the textarea
82 */
83 swallow: function (textarea) {
84 this.originalParent = textarea.parentNode;
85 this.getEl().appendChild(textarea);
86 },
87
88 /**
89 * Show the texarea container
90 */
91 show: function () {
92 this.getEl().style.display = '';
93 Event.trigger(this, 'HTMLAreaEventTextAreaContainerShow');
94 },
95
96 /**
97 * Hide the texarea container
98 */
99 hide: function () {
100 this.getEl().style.display = 'none';
101 },
102
103 /**
104 * Throw back the texarea
105 */
106 onBeforeDestroy: function() {
107 this.originalParent.appendChild(this.textArea);
108 Event.off(this);
109 return true;
110 }
111 };
112
113 return TextAreaContainer;
114
115 });