summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts
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 /framework/Web/Javascripts
parent6e62809df9632e1bc16f6564b4d8c10d08053f42 (diff)
added Gabor's HtmlArea registration patch (fixes #351)
Diffstat (limited to 'framework/Web/Javascripts')
-rw-r--r--framework/Web/Javascripts/source/packages.php5
-rw-r--r--framework/Web/Javascripts/source/prado/controls/htmlarea.js100
2 files changed, 105 insertions, 0 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();
+ }
+}
+