summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorctrlaltca <>2012-05-28 06:56:42 +0000
committerctrlaltca <>2012-05-28 06:56:42 +0000
commitaec092c914fb4a78fbc46361839822928694aca4 (patch)
treef887b447119b9783e19cb2f157612536d1743bd1 /framework/Web
parentac8908ea795f22e4bcf8726971919d6413a0b9e6 (diff)
Patch for #404
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/Javascripts/source/prado/controls/htmlarea.js69
-rw-r--r--framework/Web/UI/WebControls/THtmlArea.php39
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);
}