From aec092c914fb4a78fbc46361839822928694aca4 Mon Sep 17 00:00:00 2001 From: ctrlaltca <> Date: Mon, 28 May 2012 06:56:42 +0000 Subject: Patch for #404 --- .../Javascripts/source/prado/controls/htmlarea.js | 69 +++++++++++++++++++--- framework/Web/UI/WebControls/THtmlArea.php | 39 ++++++------ 2 files changed, 79 insertions(+), 29 deletions(-) diff --git a/framework/Web/Javascripts/source/prado/controls/htmlarea.js b/framework/Web/Javascripts/source/prado/controls/htmlarea.js index 595b7928..4cb37c6f 100644 --- a/framework/Web/Javascripts/source/prado/controls/htmlarea.js +++ b/framework/Web/Javascripts/source/prado/controls/htmlarea.js @@ -12,19 +12,14 @@ Prado.WebUI.THtmlArea = Class.create(Prado.WebUI.Control, { initialize: function($super, options) { - options.ID = options.elements; + options.ID = options.EditorOptions.elements; $super(options); }, - onInit : function(options) + onInit : function(options) { - if (typeof(tinyMCE)=='undefined') - throw "TinyMCE libraries must be loaded first"; - this.options = options; - tinyMCE.init(options); - var obj = this; this.ajaxresponder = { onComplete : function(request) @@ -34,6 +29,59 @@ Prado.WebUI.THtmlArea = Class.create(Prado.WebUI.Control, } }; this.registerAjaxHook(); + + this.registerInstance(); + }, + + registerInstance: function() + { + if (typeof tinyMCE_GZ == 'undefined') + { + if (typeof tinyMCE == 'undefined') + { + if (typeof Prado.CallbackRequest != 'undefined') + if (typeof Prado.CallbackRequest.transport != 'undefined') + { + // we're in a callback + // try it again in some time, as tinyMCE is most likely still loading + this.setTimeout(this.registerInstance.bind(this), 50); + return; + } + throw "TinyMCE libraries must be loaded first"; + } + Prado.WebUI.THtmlArea.tinyMCELoadState = 255; + this.initInstance(); + } + else + if (Prado.WebUI.THtmlArea.tinyMCELoadState==255) + this.initInstance(); + else + { + Prado.WebUI.THtmlArea.pendingRegistrations.push(this.options.ID); + if (Prado.WebUI.THtmlArea.tinyMCELoadState==0) + { + Prado.WebUI.THtmlArea.tinyMCELoadState = 1; + tinyMCE_GZ.init( + this.options.CompressionOptions, + this.compressedScriptsLoaded.bind(this) + ); + } + } + }, + + compressedScriptsLoaded: function() + { + Prado.WebUI.THtmlArea.tinyMCELoadState = 255; + tinymce.dom.Event._pageInit(); + var wrapper; + while(Prado.WebUI.THtmlArea.pendingRegistrations.length>0) + if (wrapper = Prado.Registry.get(Prado.WebUI.THtmlArea.pendingRegistrations.pop())) + wrapper.initInstance(); + }, + + initInstance: function() + { + tinyMCE.init(this.options.EditorOptions); }, checkInstance: function() @@ -92,3 +140,10 @@ Prado.WebUI.THtmlArea = Class.create(Prado.WebUI.Control, } }); +Object.extend(Prado.WebUI.THtmlArea, +{ + pendingRegistrations : [], + tinyMCELoadState : 0 +}); + + diff --git a/framework/Web/UI/WebControls/THtmlArea.php b/framework/Web/UI/WebControls/THtmlArea.php index 22f8e5f5..b73e03d7 100644 --- a/framework/Web/UI/WebControls/THtmlArea.php +++ b/framework/Web/UI/WebControls/THtmlArea.php @@ -349,9 +349,6 @@ class THtmlArea extends TTextBox public function onPreRender($param) { parent::onPreRender($param); - $this->loadJavascriptLibrary(); - if($this->getEnableCompression()) - $this->preLoadCompressedScript(); } /** @@ -389,31 +386,22 @@ class THtmlArea extends TTextBox return self::$_themes; } - protected function preLoadCompressedScript() + protected function getCompressionOptions() { - $scripts = $this->getPage()->getClientScript(); - $key = 'prado:THtmlArea:compressed'; - if(!$scripts->isBeginScriptRegistered($key)) - { - $options['plugins'] = implode(',', $this->getAvailablePlugins()); - $options['themes'] = implode(',', $this->getAvailableThemes()); - $options['languages'] = $this->getLanguageSuffix($this->getCulture()); - $options['disk_cache'] = true; - $options['debug'] = false; - $js = TJavaScript::encode($options,true,true); - $script = "if(typeof(tinyMCE_GZ)!='undefined'){ tinyMCE_GZ.init({$js}); }"; - if ($this->getPage()->getIsCallback()) - $script.= 'tinymce.dom.Event._pageInit();'; - $scripts->registerEndScript($key, $script); - } + return array( + 'plugins' => implode(',', $this->getAvailablePlugins()), + 'themes' => implode(',', $this->getAvailableThemes()), + 'languages' => $this->getLanguageSuffix($this->getCulture()), + 'disk_cache' => true, + 'debug' => false + ); } protected function loadJavascriptLibrary() { $scripts = $this->getPage()->getClientScript(); - if(!$scripts->isScriptFileRegistered('prado:THtmlArea')) - $scripts->registerScriptFile('prado:THtmlArea', $this->getScriptUrl()); $scripts->registerPradoScript('htmlarea'); + $scripts->registerScriptFile('prado:THtmlArea', $this->getScriptUrl()); } /** @@ -421,8 +409,15 @@ class THtmlArea extends TTextBox */ protected function registerEditorClientScript($writer) { + $this->loadJavascriptLibrary(); $scripts = $this->getPage()->getClientScript(); - $options = TJavaScript::encode($this->getEditorOptions(),true,true); // Force encoding of empty strings + $options = array( + 'EditorOptions' => $this->getEditorOptions() + ); + if($this->getEnableCompression()) + $options['CompressionOptions'] = $this->getCompressionOptions(); + + $options = TJavaScript::encode($options,true,true); $script = "new Prado.WebUI.THtmlArea($options)"; $scripts->registerEndScript('prado:THtmlArea'.$this->ClientID,$script); } -- cgit v1.2.3