summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/Javascripts/source/packages.php5
-rw-r--r--framework/Web/Javascripts/source/prado/controls/htmlarea.js100
-rw-r--r--framework/Web/UI/WebControls/THtmlArea.php3
3 files changed, 107 insertions, 1 deletions
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 <gabor.berczi@devworx.hu>
+ *
+*/
+
+
+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<tinyMCE.editors.length;i++)
+ if (tinyMCE.editors[i].id==this.id)
+ {
+ tinyMCE.editors = tinyMCE.editors.slice(0,i-1).concat(tinyMCE.editors.slice(i+1)); // ugly hack, but works
+ this.deRegisterAjaxHook();
+ Prado.Registry.unset(this.id);
+ i--;
+ }
+ },
+
+ registerAjaxHook: function()
+ {
+ if (typeof(Ajax)!="undefined")
+ if (typeof(Ajax.Responders)!="undefined")
+ Ajax.Responders.register(this.ajaxresponder);
+ },
+
+
+ deRegisterAjaxHook: function()
+ {
+ if (typeof(Ajax)!="undefined")
+ if (typeof(Ajax.Responders)!="undefined")
+ Ajax.Responders.unregister(this.ajaxresponder);
+ },
+
+ deinitialize: function()
+ {
+ // check for previous tinyMCE registration, and try to remove it gracefully first
+ var prev = tinyMCE.get(this.id);
+ if (prev)
+ try
+ {
+ tinyMCE.execCommand('mceFocus', false, this.id);
+ tinyMCE.execCommand('mceRemoveControl', false, this.id);
+ }
+ catch (e)
+ {
+ // suppress error here in case editor can't be properly removed
+ // (happens when <textarea> 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);
}