[imp] HTML composition in IE fix

Michael Dick mikedick at vagabond.net.nz
Fri Jan 9 03:00:03 PST 2004


HTMLArea composition in internet explorer has been broken for some time.
I've been doing some investigating and found the cause(s).
I'll attach a couple of patches for consideration, which will work for the
current cvs version of horde and imp.

The problem is that internet explorer doesn't return the correct element when
calling getElementById("message")
You'd think that this would return the element with the id of "message", but
instead it returns the first element with a name of "message" (there are two
fields named "message" in the page, the first is a hidden field in the
spelling form, and it's the second field that has the ID of "message".)
This patch really relates to HTMLArea rather than imp, but I include the patch
so people can use HTML composition in IE before the final release of HTMLArea
3. (htmlarea.diff, apply to
horde/templates/javascript/htmlarea/htmlarea.js)

Secondly, setting the value wrap="hard" for a textarea seems to corrupt the
HTMLArea form data in that field, so there's a patch to omit this value if we
are using HTML composition. (composeinc.diff apply to
horde/imp/templates/compose/compose.inc)

This obviously doesn't solve all the problems with HTML composition, but
it's a start.

Mike Dick
-------------- next part --------------
--- imp/templates/compose/compose.inc	Fri Jan  9 23:07:33 2004
+++ compose.inc	Fri Jan  9 23:15:47 2004
@@ -426,7 +426,7 @@ $locked_charset = $prefs->isLocked('send
   <tr>
     <td class="light" align="right" valign="top"><b><?php echo Horde::label('message', _("Text")) ?>&nbsp;</b></td>
     <td class="item">
-      <textarea class="composebody" tabindex="<?php echo $tabindex++ ?>" name="message" id="message" rows="20" cols="<?php echo $prefs->getValue('wrap_width') ?>"<?php if ($GLOBALS['browser']->isBrowser('msie')) { echo ' wrap="hard"'; } ?>><?php echo htmlspecialchars($msg) ?></textarea>
+      <textarea class="composebody" tabindex="<?php echo $tabindex++ ?>" name="message" id="message" rows="20" cols="<?php echo $prefs->getValue('wrap_width') ?>"<?php if ($GLOBALS['browser']->isBrowser('msie')&&(!isset($_POST['rtemode'])||($_POST['rtemode']!=2))) { echo ' wrap="hard"'; } ?>><?php echo htmlspecialchars($msg) ?></textarea>
     </td>
   </tr>
 
-------------- next part --------------
--- templates/javascript/htmlarea/htmlarea.js	Fri Jan  9 22:54:12 2004
+++ htmlarea.js	Fri Jan  9 22:42:40 2004
@@ -8,7 +8,7 @@
 // Version 3.0 developed by Mihai Bazon for InteractiveTools.
 //	     http://students.infoiasi.ro/~mishoo
 //
-// $Id: htmlarea.js,v 1.2 2004/01/05 05:16:43 mdjukic Exp $
+// $Id: htmlarea.js,v 1.19 2003/08/10 15:56:34 mishoo Exp $
 
 // Creates a new HTMLArea object.  Tries to replace the textarea with the given
 // ID with it.
@@ -146,7 +146,7 @@ HTMLArea.Config = function () {
 	this.btnList = {
 		bold: [ "<?php echo _("Bold"); ?>", "ed_format_bold.gif", false, function(e) {e.execCommand("bold");} ],
 		italic: [ "<?php echo _("Italic"); ?>", "ed_format_italic.gif", false, function(e) {e.execCommand("italic");} ],
-		underline: [ "<?php echo _("Underline"); ?>, "ed_format_underline.gif", false, function(e) {e.execCommand("underline");} ],
+		underline: [ "<?php echo _("Underline"); ?>", "ed_format_underline.gif", false, function(e) {e.execCommand("underline");} ],
 		strikethrough: [ "<?php echo _("Strikethrough"); ?>", "ed_format_strike.gif", false, function(e) {e.execCommand("strikethrough");} ],
 		subscript: [ "<?php echo _("Subscript"); ?>", "ed_format_sub.gif", false, function(e) {e.execCommand("subscript");} ],
 		superscript: [ "<?php echo _("Superscript"); ?>", "ed_format_sup.gif", false, function(e) {e.execCommand("superscript");} ],
@@ -271,7 +271,7 @@ HTMLArea.replaceAll = function(config) {
 
 /** Helper function: replaces the TEXTAREA with the given ID with HTMLArea. */
 HTMLArea.replace = function(id, config) {
-	var ta = document.getElementById(id);
+	var ta = ie_getElement_fix("textarea", id);
 	return ta ? (new HTMLArea(ta, config)).generate() : null;
 };
 
@@ -548,7 +548,7 @@ HTMLArea.prototype.generate = function (
 	var textarea = this._textArea;
 	if (typeof textarea == "string") {
 		// it's not element but ID
-		this._textArea = textarea = document.getElementById(textarea);
+		this._textArea = textarea = ie_getElement_fix("textarea", textarea);
 	}
 	this._ta_size = {
 		w: textarea.offsetWidth,
@@ -1620,6 +1620,21 @@ HTMLArea.prototype.imgURL = function(fil
 
 HTMLArea.prototype.popupURL = function(file) {
 	return this.config.editorURL + this.config.popupURL + file;
+};
+
+ie_getElement_fix = function(tag, id) {
+ if(document.getElementsByTagName)
+ {
+  var objs = document.getElementsByTagName(tag);
+  var counter;
+  var chosen_element;
+  for(counter=0; counter < (objs.length+1); counter ++)
+  {
+      if(objs[counter].id==id)
+      { chosen_element=objs[counter]; break;}
+  }
+  return chosen_element;
+ }
 };
 
 // EOF


More information about the imp mailing list