From ee0a68eddb3c63d072a1e9844522d58ea8b31757 Mon Sep 17 00:00:00 2001 From: "ctrlaltca@gmail.com" <> Date: Thu, 21 Jul 2011 17:22:36 +0000 Subject: added Gabor's HtmlArea registration patch (fixes #351) --- framework/Web/Javascripts/source/packages.php | 5 ++ .../Javascripts/source/prado/controls/htmlarea.js | 100 +++++++++++++++++++++ framework/Web/UI/WebControls/THtmlArea.php | 3 +- 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 framework/Web/Javascripts/source/prado/controls/htmlarea.js (limited to 'framework/Web') diff --git a/framework/Web/Javascripts/source/packages.php b/framework/Web/Javascripts/source/packages.php index a8484820..cff913f8 100644 --- a/framework/Web/Javascripts/source/packages.php +++ b/framework/Web/Javascripts/source/packages.php @@ -78,6 +78,10 @@ $packages = array( 'prado/controls/accordion.js' ), + 'htmlarea'=>array( + 'prado/controls/htmlarea.js' + ), + ); @@ -98,6 +102,7 @@ $dependencies = array( 'activefileupload' => array('prado', 'effects', 'ajax', 'activefileupload'), 'dragdropextra' => array('prado', 'effects', 'ajax', 'dragdrop','dragdropextra'), 'accordion' => array('prado', 'effects', 'accordion'), + 'htmlarea' => array('prado', 'htmlarea'), ); return array($packages, $dependencies); diff --git a/framework/Web/Javascripts/source/prado/controls/htmlarea.js b/framework/Web/Javascripts/source/prado/controls/htmlarea.js new file mode 100644 index 00000000..5ee01c05 --- /dev/null +++ b/framework/Web/Javascripts/source/prado/controls/htmlarea.js @@ -0,0 +1,100 @@ + +/* + * + * HtmlArea (tinyMCE) wrapper + * + * @author Gabor Berczi + * +*/ + + +Prado.WebUI.THtmlArea = Class.create(); +Prado.WebUI.THtmlArea.prototype = +{ + initialize : function(options) + { + this.onInit(options); + }, + + onInit : function(options) + { + if (typeof(tinyMCE)=='undefined') + throw "TinyMCE libraries must be loaded first"; + + this.options = options; + this.id = options.elements; + + var p = Prado.Registry.get(this.id); + if (p) p.deinitialize(); + + tinyMCE.init(options); + + Prado.Registry.set(this.id, this); + + var obj = this; + this.ajaxresponder = { + onComplete : function(request) + { + if(request && request instanceof Prado.AjaxRequest) + obj.checkInstance(); + } + }; + this.registerAjaxHook(); + }, + + checkInstance: function() + { + if (!document.getElementById(this.id)) + this.deinitialize(); + }, + + removePreviousInstance: function() + { + for(var i=0;i has been removed from DOM tree without deinitialzing the tinyMCE editor first) + } + + // doublecheck editor instance here and remove manually from tinyMCE-registry if neccessary + this.removePreviousInstance(); + + this.deRegisterAjaxHook(); + } +} + diff --git a/framework/Web/UI/WebControls/THtmlArea.php b/framework/Web/UI/WebControls/THtmlArea.php index 383411c5..e5d62c58 100644 --- a/framework/Web/UI/WebControls/THtmlArea.php +++ b/framework/Web/UI/WebControls/THtmlArea.php @@ -413,6 +413,7 @@ class THtmlArea extends TTextBox $scripts = $this->getPage()->getClientScript(); if(!$scripts->isScriptFileRegistered('prado:THtmlArea')) $scripts->registerScriptFile('prado:THtmlArea', $this->getScriptUrl()); + $scripts->registerPradoScript('htmlarea'); } /** @@ -422,7 +423,7 @@ class THtmlArea extends TTextBox { $scripts = $this->getPage()->getClientScript(); $options = TJavaScript::encode($this->getEditorOptions(),true,true); // Force encoding of empty strings - $script = "if(typeof(tinyMCE)!='undefined')\r\n{ tinyMCE.init($options); }"; + $script = "new Prado.WebUI.THtmlArea($options)"; $scripts->registerEndScript('prado:THtmlArea'.$this->ClientID,$script); } -- cgit v1.2.3