summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorctrlaltca@gmail.com <>2011-07-21 17:22:36 +0000
committerctrlaltca@gmail.com <>2011-07-21 17:22:36 +0000
commitee0a68eddb3c63d072a1e9844522d58ea8b31757 (patch)
treed5aeca6606699ae0837adacfca4351184f15b840
parent6e62809df9632e1bc16f6564b4d8c10d08053f42 (diff)
added Gabor's HtmlArea registration patch (fixes #351)
-rw-r--r--.gitattributes1
-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
4 files changed, 108 insertions, 1 deletions
diff --git a/.gitattributes b/.gitattributes
index 55e6ef02..64a342a8 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -2830,6 +2830,7 @@ framework/Web/Javascripts/source/prado/colorpicker/target_black.gif -text
framework/Web/Javascripts/source/prado/colorpicker/target_white.gif -text
framework/Web/Javascripts/source/prado/controls/accordion.js -text
framework/Web/Javascripts/source/prado/controls/controls.js -text
+framework/Web/Javascripts/source/prado/controls/htmlarea.js -text
framework/Web/Javascripts/source/prado/controls/keyboard.js -text
framework/Web/Javascripts/source/prado/controls/slider.js -text
framework/Web/Javascripts/source/prado/controls/tabpanel.js -text
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);
}