[TASK] RTE: Cleanup iframe initialization 98/36098/4
authorStanislas Rolland <typo3@sjbr.ca>
Sun, 18 Jan 2015 16:55:07 +0000 (11:55 -0500)
committerStanislas Rolland <typo3@sjbr.ca>
Sun, 18 Jan 2015 17:01:15 +0000 (18:01 +0100)
Releases: master
Resolves: #64343
Change-Id: I3be65963074d2c95f7617ac8a61ddc8b71adec8a
Reviewed-on: http://review.typo3.org/36098
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/Editor/Iframe.js

index 7fa46ae..4be0f38 100644 (file)
@@ -42,16 +42,16 @@ define('TYPO3/CMS/Rtehtmlarea/HTMLArea/Editor/Iframe',
                render: function (container) {
                        this.config = this.getEditor().config;
                        this.createIframe(container);
-                       this.htmlRenderer = new Walker({
-                               keepComments: !this.config.htmlRemoveComments,
-                               removeTags: this.config.htmlRemoveTags,
-                               removeTagsAndContents: this.config.htmlRemoveTagsAndContents,
-                               baseUrl: this.config.baseURL
-                       });
                        if (!this.config.showStatusBar) {
                                Dom.addClass(this.getEl(), 'noStatusBar');
                        }
-                       this.initEventListeners();
+                       this.initStyleChangeEventListener();
+                       if (UserAgent.isOpera) {
+                               var self = this;
+                               Event.one(this.getEl(), 'load', function (event) { self.initializeIframe(); return true; })
+                       } else {
+                               this.initializeIframe();
+                       }
                },
 
                /**
@@ -62,19 +62,6 @@ define('TYPO3/CMS/Rtehtmlarea/HTMLArea/Editor/Iframe',
                },
 
                /**
-                * Initialize event listeners and the document after the iframe has rendered
-                */
-               initEventListeners: function () {
-                       this.initStyleChangeEventListener();
-                       if (UserAgent.isOpera) {
-                               var self = this;
-                               Event.one(iframe, 'load', function (event) { self.initializeIframe(event); return true; })
-                       } else {
-                               this.initializeIframe();
-                       }
-               },
-
-               /**
                 * The editor iframe may become hidden with style.display = "none" on some parent div
                 * This breaks the editor in Firefox: the designMode attribute needs to be reset after the style.display of the container div is reset to "block"
                 * In all browsers, it breaks the evaluation of the framework dimensions
@@ -408,13 +395,28 @@ define('TYPO3/CMS/Rtehtmlarea/HTMLArea/Editor/Iframe',
                /**
                 * Instance of DOM walker
                 */
-               htmlRenderer: {},
+               htmlRenderer: null,
+
+               /**
+                * Getter for the instance of DOM walker
+                */
+               getHtmlRenderer: function () {
+                       if (!this.htmlRenderer) {
+                               this.htmlRenderer = new Walker({
+                                       keepComments: !this.config.htmlRemoveComments,
+                                       removeTags: this.config.htmlRemoveTags,
+                                       removeTagsAndContents: this.config.htmlRemoveTagsAndContents,
+                                       baseUrl: this.config.baseURL
+                               });
+                       }
+                       return this.htmlRenderer;
+               },
 
                /**
                 * Get the HTML content of the iframe
                 */
                getHTML: function () {
-                       return this.htmlRenderer.render(this.document.body, false);
+                       return this.getHtmlRenderer().render(this.document.body, false);
                },
 
                /**
@@ -586,7 +588,7 @@ define('TYPO3/CMS/Rtehtmlarea/HTMLArea/Editor/Iframe',
                        if (UserAgent.isGecko) {
                                var self = this;
                                window.setTimeout(function () {
-                                       Dom.makeUrlsAbsolute(self.getEditor().document.body, self.config.baseURL, self.htmlRenderer);   
+                                       Dom.makeUrlsAbsolute(self.getEditor().document.body, self.config.baseURL, self.getHtmlRenderer());
                                }, 50);
                        }
                        return true;
@@ -606,7 +608,7 @@ define('TYPO3/CMS/Rtehtmlarea/HTMLArea/Editor/Iframe',
                        // Make src url absolute in Firefox
                        if (UserAgent.isGecko) {
                                window.setTimeout(function () {
-                                       Dom.makeUrlsAbsolute(event.target, self.config.baseURL, self.htmlRenderer);
+                                       Dom.makeUrlsAbsolute(event.target, self.config.baseURL, self.getHtmlRenderer());
                                }, 50);
                        }
                        this.getToolbar().updateLater(100);