Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#434 closed defect (fixed)

FullPage plugin AND/OR fullpage=true (in the core) disables ContextMenu, TableOperations, DoubleClick and CharacterCount in IE. (will give price to whom fixes this bug)

Reported by: tigro@… Owned by: gogo
Priority: high Milestone: Version 1.0
Component: Xinha Core Version:
Severity: critical Keywords: fullpage
Cc:

Description

Hi!

I just found a REALLY annoying bug. It took me a quite a few hours to narrow it down till finally got what caused the trouble.

Problem:
Use FullPage? plugin among with oder plugins, like Tableoperation and Context menu (for testing load both).
Load the editor then change to TEXT mode. Now change back to WYSIWYG and voila. The context menu won't work anymore, nor will the tableoper. bar light up when you click inside a table.

This error exist in both xinha and in htmlarea - I guess it was around ever since the beginning :)

Can anyone fix this? I really need all of the mentioned plugins.

Thanks

Attachments (4)

htmlarea.js (164.0 KB) - added by anonymous 14 years ago.
With this version of htmlarea.js it is possible to switch to edit mode and bach with fullpage on. The events for updating the toolbar, and the context menu work with ie also. If have tried this with the example in the xinha distribution.
htmlarea.2.js (169.9 KB) - added by mharrisonline 14 years ago.
Patches applied to current version of htmlarea.js
htmlarea.3.js (169.9 KB) - added by mharrisonline 14 years ago.
This seems to work fine!
htmlarea.4.js (171.8 KB) - added by mharrisonline 14 years ago.
The newest htmlarea.js from 10/21 with patches applied

Download all attachments as: .zip

Change History (53)

comment:1 Changed 14 years ago by niko

i can confirm this bug on IE, firefox has no problems.

comment:2 Changed 14 years ago by Aron

If only Ie has it than its probably not a huge problem where core modification is needed. Can someone fix this, please?

comment:3 Changed 14 years ago by Aron

If only Ie has it than its probably not a huge problem where core modification is needed. Can someone fix this, please?

comment:4 Changed 14 years ago by gogo

  • Milestone set to Version 1.0
  • Priority changed from high to normal
  • Summary changed from FullPage plugin kills oder plugins (effects every user - Read this!!) to FullPage causes problem with ContextMenu, TableOperations in IE.

Aron & Submitter: Xinha is open source. Feel free to submit a patch, or patiently wait.

comment:5 Changed 14 years ago by mharrisonline

I've had that happen to me too, but I never realized what sequence was triggering it. I thought I was going mental or something. It also kills the doubleclick and character count plugins.

comment:6 Changed 14 years ago by Aron

  • Summary changed from FullPage causes problem with ContextMenu, TableOperations in IE. to FullPage plugin disables ContextMenu, TableOperations, DoubleClick and CharacterCount in IE. (will give price to whom fixex the bug))

I don't know about how you feel, but I think FullPage? plugin is quite essential for creating good webpages. I can not leave it out from my xinha setup. Also dont want to leve out the other plugins mentioned above. So...

I am willing to give a PRICE to the one person who fixes this bug. I think the price is quite fair for the job, it is:

A special collection of valuable ebooks where there are more than 25 ebooks with full resell rights (so you can make profit other than gaining good information from reading the books) + I cap this up with other 25 (not resellable) ebooks.

This is no bull, no hurting copyrights. I own a licence to for this package.

comment:7 Changed 14 years ago by mharrisonline

Maybe until it's fixed you could remove the view source button and use the Edit Tag plugin instead.

comment:8 Changed 14 years ago by Aron

  • Component changed from Plugin_FullPage to Xinha Core
  • Priority changed from normal to high
  • Summary changed from FullPage plugin disables ContextMenu, TableOperations, DoubleClick and CharacterCount in IE. (will give price to whom fixex the bug)) to FullPage plugin AND/OR fullpage=true (in the core) disables ContextMenu, TableOperations, DoubleClick and CharacterCount in IE. (will give price to whom fixes this bug)

!!!!IMPORTANT!!!!

I just found out that the problem even exist if there is no FullPage? plugin BUT you set the "this.fullpage = false" to TRUE in htmlarea.js !!!

Now we know that the error is not in the plugin but the core. As there is no problem in firefox this is another browser diffy. Please, someone who pacthed xinha/htmarea for IE take a look at this.

I still give the above mentioned PRICE for the one who fixes this!

comment:9 Changed 14 years ago by Aron

  • Severity changed from normal to critical

I narrowed the problem down even more:

having FullPage? plugin enabled or this.fullpage set to TRUE:
When changing the view from design mode to text mode then going back to design mode, any events attached previously to the iframe will be detached, including the font properties indicators (bold/italic/....) and ContextMenu? plugin, etc.

/Question from the cold, dark void: Gurus where are you? Why did you leave us?

comment:10 Changed 14 years ago by mharrisonline

Some more symptoms...

This only occurs in IE, not FireFox?

After toggling to source the status bar says (regardless of what you click on ever again:

body >> form#editors_here

When you click on form#editors_here you get an error (this is in the current example)

Line 3147
Char: 7
Error: Invalid arguement
Code 0:
URL:full_example-body.html

comment:11 Changed 14 years ago by mharrisonline

Well, one new symptom anyway. I see that it is IE specific was already mentioned twice.

comment:12 Changed 14 years ago by mharrisonline

I had this trouble in htmlarea3 also. I looked on the read-only htmlarea forum and didn't see any references to the issue. :(

comment:13 Changed 14 years ago by kizer@…

Here's a quick, dirty workaround (pretty newb at javascript, so..) :

Modify htmlarea.js:

add this line somewhere: var _events = [];

Modify the HTMLArea._addEvent function:

under "if (HTMLArea.is_ie) {" add:

var _event = {

_el : el,

_evname : evname,

_func : func

}

_events.push( _event );

modify the HTMLArea.prototype.setFullHTML function:

under the else (is_ie):

add this before the return statement:

_events.reverse();

for (var index=0; index < _events.length; index++) {

var _event = _events.pop();

if (_event != null) {

HTMLArea._addEvent(_event._el, _event._evname, _event._func);

}

}

this seemed to do the trick for me atleast...

should probably also modify the HTMLArea._removeEvent function to remove from the _events-array too....

comment:14 Changed 14 years ago by mharrisonline

I wasn't able to get this to make a difference... and when I right-clicked XINHA went all white... Could you attach your actual htmlarea.js file?

Just an aside, it looks like any plugin that uses editor.getHTML() will initiate this problem as well...

comment:15 Changed 14 years ago by mharrisonline

Xinha came back up, and when I right-clicked again it gave me the dreaded loop of endless "How did you get here? (Please report!") alerts...

comment:16 Changed 14 years ago by mharrisonline

I had these problems in IE6, where this completely kills XINHA, but the patch works perfectly in Firefox!

comment:17 Changed 14 years ago by mharrisonline

It looks like simply adding

var _events = [];

right before HTMLArea._addEvent fixes the problem in Firefox (we're halfway there!).

Leaving out either of the additions for IE in HTMLArea._addEvent or HTMLArea.prototype.setFullHTML prevents IE from locking up (while XINHA was whited out my other applications started blinking quickly if I maximized their windows over IE...) and leaves Firefox working.

comment:18 Changed 14 years ago by kizer@…

Sorry, was using an old version, and think it was just by chance that it worked. Today it didn't.. :o)

Ok, using the latest version of xinha, basic install (with just some changing of sizes, toolbar and fullpage set, and just contextmenu and fullscreen plugin), fullpage source view works fine in firefox, but in ie it breaks the contextmenu.

This is what I did to work around that, and it seems to work for me:

In htmlarea.js, at the very bottom of the HTMLArea.prototype.editorIsActivated function, add this:

if (!HTMLArea.is_gecko) {

is ie

if (HTMLArea._eventFlushers) {

for (var index=0; index < HTMLArea._eventFlushers.length; index++) {

var _event = HTMLArea._eventFlushers[index];

if (_event != null) {

if (_event[1] == "contextmenu") {

contextmenu-event

syntax: el.attachEvent("on" + evname,

func);

_event[0].attachEvent("on" + _event[1],

_event[2] );

}

}

}

}

}

Keep in mind that this is a work-around, not really a fix. Don't know if other events are screwed up, but they don't seem to be in my install atleast.
I don't really know very much about the inner workings of xinha, and this might break it in some unforseen way. It *should'nt* do anything to firefox, but you never know.. :o)

comment:19 Changed 14 years ago by mharrisonline

Do you mean like this? I have placed

var _events = [];


right before HTMLArea._addEvent which fixes XINHA in Firefox, and then I have modified HTMLArea.prototype.editorIsActivated as show below.

It doesn't seem to create a problem, but it doesn't seem to do anything the way I put it together...

  HTMLArea.prototype.editorIsActivated = function() {
    try {
      if (HTMLArea.is_gecko) return (this._doc.designMode == 'on');
      else return (this._doc.body.contentEditable);
    } catch (e)
    {
      return false;
    }
// inserted code from kizer@start.no begins here:

if (!HTMLArea.is_gecko) { 

	// is ie 

	if (HTMLArea._eventFlushers) { 

	for (var index=0; index < HTMLArea._eventFlushers.length; index++) { 

		var _event = HTMLArea._eventFlushers[index]; 

		if (_event != null) { 

		if (_event[1] == "contextmenu") { 

			// contextmenu-event 

			// syntax: el.attachEvent("on" + evname, func); _event[0].attachEvent("on" + _event[1], _event[2] ); 

		} 

		} 

	} 

	} 

}
// end of new code by kizer@start.no
	
  }

Am I doing something wrong or skipping something?

comment:20 Changed 14 years ago by kizer@…

I don't know if it's just here, or if you have it like that in your code, but it looks
like this line is on the same as the syntax-comment, which means it also is commented out:

_event[0].attachEvent("on" + _event[1], _event[2] );

And did you include the entire code for the HTMLArea.prototype.editorIsActivated function? My version (taken from the latest xinha build) is much longer...

comment:21 Changed 14 years ago by mharrisonline

Ah, it is pretty long. Does this look right? It still doesn't work for me in ie...

  HTMLArea.prototype.editorIsActivated = function() {
    try {
      if (HTMLArea.is_gecko) return (this._doc.designMode == 'on');
      else return (this._doc.body.contentEditable);
    } catch (e)
    {
      return false;
    }
  }

  HTMLArea._someEditorHasBeenActivated = false;
  HTMLArea._currentlyActiveEditor      = false;
  HTMLArea.prototype.activateEditor = function()
  {
    // We only want ONE editor at a time to be active
    if(HTMLArea._currentlyActiveEditor)
    {
      if(HTMLArea._currentlyActiveEditor == this) return true;
      HTMLArea._currentlyActiveEditor.deactivateEditor();
    }

    if (HTMLArea.is_gecko && this._doc.designMode != 'on')
    {
      try
      {
        // cannot set design mode if no display
        if (this._iframe.style.display == 'none')
        {
          this._iframe.style.display = '';
          this._doc.designMode = 'on';
          this._iframe.style.display = 'none';
        }
        else
        {
          this._doc.designMode = 'on';
        }
      } catch (e) {}
    }
    else if(!HTMLArea.is_gecko && this._doc.body.contentEditable != true)
    {
      this._doc.body.contentEditable = true;
    }

    // We need to know that at least one editor on the page has been activated
    // this is because we will not focus any editor until an editor has been activated
    HTMLArea._someEditorHasBeenActivated = true;
    HTMLArea._currentlyActiveEditor      = this;

    var editor = this;
    this.enableToolbar();
	if (!HTMLArea.is_gecko) { 

// is ie 

if (HTMLArea._eventFlushers) { 

for (var index=0; index < HTMLArea._eventFlushers.length; index++) { 

var _event = HTMLArea._eventFlushers[index]; 

if (_event != null) { 

if (_event[1] == "contextmenu") { 

// contextmenu-event 

// syntax: el.attachEvent("on" + evname, func); _event[0].attachEvent("on" + _event[1], _event[2] ); 

} 

} 

} 

} 

} 


  }

comment:22 Changed 14 years ago by mharrisonline

Oops, you're right,

_event[0].attachEvent("on" + _event[1], _event[2] );


had become part of the comment. Now, I get an error that says on line 1828 character 1 there is a type mismatch. Line 1828 is the empty line directly below the line shown that had previously been commented out.

comment:23 Changed 14 years ago by kizer@…

Hmm... that sounds strange... maybe you should try to write the whole thing in manually, instead of copy-pasting it in? Have experienced strange stuff when just copy-pasting from a website before... But really, I have no idea... :o)

comment:24 Changed 14 years ago by mharrisonline

Well, I tried that, but it still doesn't work for me. Interestingly, I get the error above when I use the current example page, but when I use the old demo.html page to launch XINHA the bug is still there but the error message doesn't happen.

Is there anyway you could attach a htmlarea.js file where this works?

 HTMLArea.prototype.editorIsActivated = function() {
    try {
      if (HTMLArea.is_gecko) return (this._doc.designMode == 'on');
      else return (this._doc.body.contentEditable);
    } catch (e)
    {
      return false;
    }
  }

  HTMLArea._someEditorHasBeenActivated = false;
  HTMLArea._currentlyActiveEditor      = false;
  HTMLArea.prototype.activateEditor = function()
  {
    // We only want ONE editor at a time to be active
    if(HTMLArea._currentlyActiveEditor)
    {
      if(HTMLArea._currentlyActiveEditor == this) return true;
      HTMLArea._currentlyActiveEditor.deactivateEditor();
    }

    if (HTMLArea.is_gecko && this._doc.designMode != 'on')
    {
      try
      {
        // cannot set design mode if no display
        if (this._iframe.style.display == 'none')
        {
          this._iframe.style.display = '';
          this._doc.designMode = 'on';
          this._iframe.style.display = 'none';
        }
        else
        {
          this._doc.designMode = 'on';
        }
      } catch (e) {}
    }
    else if(!HTMLArea.is_gecko && this._doc.body.contentEditable != true)
    {
      this._doc.body.contentEditable = true;
    }

    // We need to know that at least one editor on the page has been activated
    // this is because we will not focus any editor until an editor has been activated
    HTMLArea._someEditorHasBeenActivated = true;
    HTMLArea._currentlyActiveEditor      = this;

    var editor = this;
    this.enableToolbar();
if (!HTMLArea.is_gecko) { 

	// is ie 

	if (HTMLArea._eventFlushers) { 

	for (var index=0; index < HTMLArea._eventFlushers.length; index++) { 

		var _event = HTMLArea._eventFlushers[index]; 

		if (_event != null) { 

		if (_event[1] == "contextmenu") { 

			// contextmenu-event 

			// syntax: el.attachEvent("on" + evname, func); 
			_event[0].attachEvent("on" + _event[1], _event[2] ); 

		} 

		} 

	} 

	} 

} 

	
  }

comment:25 Changed 14 years ago by anonymous

  • Resolution set to fixed
  • Status changed from new to closed

comment:26 Changed 14 years ago by Aaron

  • Resolution fixed deleted
  • Status changed from closed to reopened

Dear anonymous! Please DONT close a ticket when it is NOT solved yet!
As you should have read it thru the discussion there is NO FIX for the problem yet even the workaround has some questions open!! Dear mharrisonline: Thanks for your work in this issue. Could you sumarise what to modify. The patching of the patches over a patch is a little hard to get thru. THANKS!

comment:27 Changed 14 years ago by mharrisonline

As I understand it from kizer@…, what I last posted (replacement for HTMLArea.prototype.editorIsActivated) is the patch that is described and the only change that needs to be made, but it doesn't work for me.

comment:28 Changed 14 years ago by mharrisonline

Unfortunately, it is extremely noticeable when XINHA chokes and loses all context sensitive functionality. Even if you avoid using most of the plugins, the toolbar breaks and locks into highlighting the last button pushed. The status bar freezes. If you click on the status bar after it freezes, you get a JavaScript? error.

comment:29 Changed 14 years ago by mharrisonline

I just saw this bug happen over and over to someone today that would never view source. She kept trying to use context meenu, and it wasn't there, so each time she had to save, closr Xinha, and reopen the editor again.

Some plugins trigger it when you are in Full Page mode. What if new code keeps getting built on top of the bad code that creates this bug? Oops, that's what's probably happening...

comment:30 Changed 14 years ago by jschipf@…

I am not quit sure if it solves all problems, but for my cases the solution below works.

I changed the function initIframe() to end with the following lines.

doc.write(html);
doc.close();

this.setEditorEvents();

}

The part with setting the events is put into the new function

HTMLArea.prototype.setEditorEvents = function() {

var editor=this;
var doc=this._doc;
if we have multiple editors some bug in Mozilla makes some lose editing ability
HTMLArea._addEvents
(

doc,
mousedown?,
function() { editor.activateEditor(); return true; }

);

intercept some events; for updating the toolbar & keyboard handlers
HTMLArea._addEvents
(doc, ["keydown", "keypress", "mousedown", "mouseup", "drag"],

function (event) {
return editor._editorEvent(HTMLArea.is_ie ? editor._iframe.contentWindow.event : event);

});

check if any plugins have registered refresh handlers
for (var i in editor.plugins) {

var plugin = editor.plugins[i].instance;
HTMLArea.refreshPlugin(plugin);

}

specific editor initialization
if(typeof editor._onGenerate == "function") {

editor._onGenerate();

}

}

and in the function setFullHTML() I added the following line in the IE if part.

if(reac) this.activateEditor();
this.setEditorEvents();
return true;

}

I am sure, that using the plugins onGenerate function is not the correct way to solve the problem. Maby there should be some plugin callback function setEditorEvents. But at least the context menu plugin does the necessary code in its onGenerate function.
As far as I can see only events for the editor element itself (this._doc) are lost when using setFullHTML, and I found no other plugins that set events on that element.

comment:31 Changed 14 years ago by mharrisonline

Undo triggers this error too...

I tried to follow your instructions and changed the current htmlarea.js as shown below, but I get a javascript error. Did I do it right?

I made the function HTMLArea.prototype.initIframe look like this:

HTMLArea.prototype.initIframe = function()
  {
    this.disableToolbar();
  doc.write(html); doc.close(); 

this.setEditorEvents(); 

}

and then added the new function:

HTMLArea.prototype.setEditorEvents = function() { 

var editor=this; var doc=this._doc; // if we have multiple editors some bug in Mozilla makes some lose editing ability HTMLArea._addEvents ( 

doc, ["mousedown"], function() { editor.activateEditor(); return true; } 

); 

// intercept some events; for updating the toolbar & keyboard handlers HTMLArea._addEvents (doc, ["keydown", "keypress", "mousedown", "mouseup", "drag"], 

function (event) { return editor._editorEvent(HTMLArea.is_ie ? editor._iframe.contentWindow.event : event); 

}); 

// check if any plugins have registered refresh handlers for (var i in editor.plugins) { 

var plugin = editor.plugins[i].instance; HTMLArea.refreshPlugin(plugin); 

} 

// specific editor initialization if(typeof editor._onGenerate == "function") { 

editor._onGenerate(); 

} 

}

and then changed the function HTMLArea.prototype.setFullHTML to:

HTMLArea.prototype.setFullHTML = function(html) {
  var save_multiline = RegExp.multiline;
  RegExp.multiline = true;
  if (html.match(HTMLArea.RE_doctype)) {
    this.setDoctype(RegExp.$1);
    html = html.replace(HTMLArea.RE_doctype, "");
  }
  RegExp.multiline = save_multiline;
  if (!HTMLArea.is_ie) {
    if (html.match(HTMLArea.RE_head))
      this._doc.getElementsByTagName("head")[0].innerHTML = RegExp.$1;
    if (html.match(HTMLArea.RE_body))
      this._doc.getElementsByTagName("body")[0].innerHTML = RegExp.$1;
	  if(reac) this.activateEditor(); this.setEditorEvents(); return true; 


  } else {
    var reac = this.editorIsActivated();
    if(reac) this.deactivateEditor();
    var html_re = /<html>((.|\n)*?)<\/html>/i;
    html = html.replace(html_re, "$1");
    this._doc.open();
    this._doc.write(html);
    this._doc.close();
    if(reac) this.activateEditor();
    return true;
  }
};


Did I make a mistake?


comment:32 Changed 14 years ago by anonymous

Hi,

the full code

  HTMLArea.prototype.initIframe = function()
  {
    this.disableToolbar();
    var doc = null;
    var editor = this;
    try
    {
      if (editor._iframe.contentDocument)
      {
        this._doc = editor._iframe.contentDocument;        
      }
      else
      {
        this._doc = editor._iframe.contentWindow.document;
      }
      doc = this._doc;      
      if (!doc) { // try later
        if (HTMLArea.is_gecko) {
          setTimeout(function() { editor.initIframe()}, 50);
          return false;
        } else {
          alert("ERROR: IFRAME can't be initialized.");
        }
      }
    }
    catch(e)
    { // try later
      setTimeout(function() { editor.initIframe()}, 50);
    }
    
    HTMLArea.freeLater(this, '_doc');
    
    doc.open();
    if (!editor.config.fullPage) {
      var html = "<html>\n";
      html += "<head>\n";
      html += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + editor.config.charSet + "\">\n";
      if(typeof editor.config.baseHref != 'undefined' && editor.config.baseHref != null)
      {
        html += "<base href=\"" + editor.config.baseHref + "\"/>\n";
      }
      html += "<style title=\"table borders\">"
           + ".htmtableborders, .htmtableborders td, .htmtableborders th {border : 1px dashed lightgrey ! important;} \n"
           + "</style>\n";
      html += "<style type=\"text/css\">"
           + "html, body { border: 0px; } \n"
           + "span.macro, span.macro ul, span.macro div, span.macro p {background : #CCCCCC;}\n"
           + "</style>\n";

      if(editor.config.pageStyle)
      {
        html += "<style type=\"text/css\">\n" + editor.config.pageStyle + "\n</style>";
      }

      if(typeof editor.config.pageStyleSheets !== 'undefined')
      {
        for(style_i = 0; style_i < editor.config.pageStyleSheets.length; style_i++)
        {
          if(editor.config.pageStyleSheets[style_i].length > 0)
              html += "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + editor.config.pageStyleSheets[style_i] + "\">";
            //html += "<style> @import url('" + editor.config.pageStyleSheets[style_i] + "'); </style>\n";
        }
      }
      html += "</head>\n";
      html += "<body>\n";
      html +=   editor.inwardHtml(editor._textArea.value);
      html += "</body>\n";
      html += "</html>";
    } else {
      var html = editor.inwardHtml(editor._textArea.value);
      if (html.match(HTMLArea.RE_doctype)) {
        editor.setDoctype(RegExp.$1);
        html = html.replace(HTMLArea.RE_doctype, "");
      }
    }
    doc.write(html);
    doc.close();
    this.setEditorEvents();
  }

the function setFullHTML

  HTMLArea.prototype.setFullHTML = function(html) {
    var save_multiline = RegExp.multiline;
    RegExp.multiline = true;
    if (html.match(HTMLArea.RE_doctype)) {
      this.setDoctype(RegExp.$1);
      html = html.replace(HTMLArea.RE_doctype, "");
    }
    RegExp.multiline = save_multiline;
    if (!HTMLArea.is_ie) {
      if (html.match(HTMLArea.RE_head))
        this._doc.getElementsByTagName("head")[0].innerHTML = RegExp.$1;
      if (html.match(HTMLArea.RE_body))
        this._doc.getElementsByTagName("body")[0].innerHTML = RegExp.$1;
    } else {
      var reac = this.editorIsActivated();
      if(reac) this.deactivateEditor();
      var html_re = /<html>((.|\n)*?)<\/html>/i;
      html = html.replace(html_re, "$1");
      this._doc.open();
      this._doc.write(html);
      this._doc.close();
      if(reac) this.activateEditor();
      this.setEditorEvents();
      return true;
    }
  };

comment:33 Changed 14 years ago by mharrisonline

Could you attach a copy of htmlarea.js where this works?

Changed 14 years ago by anonymous

With this version of htmlarea.js it is possible to switch to edit mode and bach with fullpage on. The events for updating the toolbar, and the context menu work with ie also. If have tried this with the example in the xinha distribution.

comment:34 Changed 14 years ago by jschipf@…

I have attached the file that works with my installation.

comment:35 Changed 14 years ago by mharrisonline

Wow! It really works! Thanks! It fixes everything

I noticed that your htmlarea.js is dated 2005-08-05, and the code around the functions is different than the code in today's htmlarea.js. That probably explains why I was getting an error when I tried to use your changes with the current download.

I'll go back and try to figure out which changeset makes the patch not work and post what I find out. I just updated my implementation of Xinha to the 10/5 download, I'd happily roll it back if that's what I would have to do to use this.

Thank you, thank you, thank you.

One odd thing I noticed is that when I use this htmlarea.js in today's download with the character counter plugin, every time I view source the status bar gets longer and new character count text appears, which updates. The older character counts stay frozen as they do without this patch. Interesting.

comment:36 Changed 14 years ago by mharrisonline

The error occurs when the code tries to call the function setEditorEvents() which is not in recent versions of XINHA...

Changed 14 years ago by mharrisonline

Patches applied to current version of htmlarea.js

comment:37 Changed 14 years ago by mharrisonline

The missing code that needed to be added in addition what you pasted above on October6 was:

  HTMLArea.prototype.setEditorEvents = function() {
    var editor=this;
    var doc=this._doc;
    // if we have multiple editors some bug in Mozilla makes some lose editing ability
    HTMLArea._addEvents
    (
      doc,
      ["mousedown"],
      function() { editor.activateEditor(); return true; }
    );


    // intercept some events; for updating the toolbar & keyboard handlers
    HTMLArea._addEvents
    (doc, ["keydown", "keypress", "mousedown", "mouseup", "drag"],
      function (event) {
      return editor._editorEvent(HTMLArea.is_ie ? editor._iframe.contentWindow.event : event);
    });

    // check if any plugins have registered refresh handlers
    for (var i in editor.plugins) {
      var plugin = editor.plugins[i].instance;
      HTMLArea.refreshPlugin(plugin);
    }

    // specific editor initialization
    if(typeof editor._onGenerate == "function") {
      editor._onGenerate();
    }
  }

This has to be pasted after HTMLArea.prototype.setFullHTML. Most of this code is currently in the HTMLArea.prototype.initIframe function that is replaced.

The bug is fixed, context sensitivity is restored,and I can click on the nodes in the status bar without errors!

I wonder why it makes character counter go crazy though...

comment:38 Changed 14 years ago by mharrisonline

I found one problem... although clicking on undo works fine, if I use ctrl-Z I get an error at ev.cancelBubble = true; in the function

HTMLArea._stopEvent = function(ev) {
  if (HTMLArea.is_ie) {
    ev.cancelBubble = true;
    ev.returnValue = false;
  } else {
    ev.preventDefault();
    ev.stopPropagation();
  }
};

comment:39 Changed 14 years ago by mharrisonline

Commenting out these two lines seems to fix the problem,

ev.cancelBubble = true;
ev.returnValue = false;

HTMLArea._stopEvent = function(ev) {
  if (HTMLArea.is_ie) {
//    ev.cancelBubble = true;
//    ev.returnValue = false;
  } else {
    ev.preventDefault();
    ev.stopPropagation();
  }
};

The stopevent function is used A LOT in htmlarea.js, and this kills it for IE. Does anyone know what this function is doing, and is it really important?

comment:40 Changed 14 years ago by mharrisonline

This seems to work also...

HTMLArea._stopEvent = function(ev) {
  if (HTMLArea.is_ie) {
try{    ev.cancelBubble = true;
    ev.returnValue = false;
} catch(e){}
  } else {
    ev.preventDefault();
    ev.stopPropagation();
  }
};

Changed 14 years ago by mharrisonline

This seems to work fine!

comment:41 Changed 14 years ago by mharrisonline

I just attached htmlarea.3.js above which seems to have no problems at all. It uses the catch to stop the Ctrl-Z Ctrl-Y error, leaving the StopEvent? functional when it actually works.

Could anyone else test this in IE fullpage mode, and other combinations to look for problems? Aron?

Because this fix reinitializes plugins every time Xinha would normally break, the character counter plugin writes itself onto the status bar again. That's one unusable plugin instead of half a dozen or so...

comment:42 Changed 14 years ago by gocher

I fixed the problem with the CharCounter? plugin in changest 387!

comment:43 Changed 14 years ago by mharrisonline

You rock, Gocher! (As always)

comment:44 Changed 14 years ago by mharrisonline

I just discovered that the error with Ctrl-Z and Ctrl-Y is in core Xinha, not the patch submitted by jschipf@….

comment:45 Changed 14 years ago by mharrisonline

There were several changesets on 10/21 that altered the functions affected by this patch. I applied the changesets to the new code, and the patch still works! You also need to apply the stopevent patch shown above, but for the rest, here are the patches applied to the new code:

   HTMLArea.prototype.initIframe = function()
  {
    this.disableToolbar();
    var doc = null;
    var editor = this;
    try
    {
      if (editor._iframe.contentDocument)
      {
        this._doc = editor._iframe.contentDocument;        
      }
      else
      {
        this._doc = editor._iframe.contentWindow.document;
      }
      doc = this._doc;      
      if (!doc) { // try later
        if (HTMLArea.is_gecko) {
          setTimeout(function() { editor.initIframe()}, 50);
          return false;
        } else {
          alert("ERROR: IFRAME can't be initialized.");
        }
      }
    }
    catch(e)
    { // try later
      setTimeout(function() { editor.initIframe()}, 50);
    }
    
    HTMLArea.freeLater(this, '_doc');
    
    doc.open();
    if (!editor.config.fullPage) {
      var html = "<html>\n";
      html += "<head>\n";
      html += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + editor.config.charSet + "\">\n";
      if(typeof editor.config.baseHref != 'undefined' && editor.config.baseHref != null)
      {
        html += "<base href=\"" + editor.config.baseHref + "\"/>\n";
      }
      html += "<style title=\"table borders\">"
           + ".htmtableborders, .htmtableborders td, .htmtableborders th {border : 1px dashed lightgrey ! important;} \n"
           + "</style>\n";
      html += "<style type=\"text/css\">"
           + "html, body { border: 0px;  background-color: #ffffff; } \n"
           + "span.macro, span.macro ul, span.macro div, span.macro p {background : #CCCCCC;}\n"
           + "</style>\n";

      if(editor.config.pageStyle)
      {
        html += "<style type=\"text/css\">\n" + editor.config.pageStyle + "\n</style>";
      }

      if(typeof editor.config.pageStyleSheets !== 'undefined')
      {
        for(style_i = 0; style_i < editor.config.pageStyleSheets.length; style_i++)
        {
          if(editor.config.pageStyleSheets[style_i].length > 0)
              html += "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + editor.config.pageStyleSheets[style_i] + "\">";
            //html += "<style> @import url('" + editor.config.pageStyleSheets[style_i] + "'); </style>\n";
        }
      }
      html += "</head>\n";
      html += "<body>\n";
      html +=   editor.inwardHtml(editor._textArea.value);
      html += "</body>\n";
      html += "</html>";
    } else {
      var html = editor.inwardHtml(editor._textArea.value);
      if (html.match(HTMLArea.RE_doctype)) {
        editor.setDoctype(RegExp.$1);
        html = html.replace(HTMLArea.RE_doctype, "");
      }
    }
    doc.write(html);
    doc.close();

    this.setEditorEvents();
  };

// Switches editor mode; parameter can be "textmode" or "wysiwyg".  If no
// parameter was passed this function toggles between modes.
HTMLArea.prototype.setMode = function(mode) {
  if (typeof mode == "undefined") {
    mode = ((this._editMode == "textmode") ? "wysiwyg" : "textmode");
  }
  switch (mode) {
    case "textmode":
    {
      var html = this.outwardHtml(this.getHTML());
      this.setHTML(html);

      // Hide the iframe
      this.deactivateEditor();
      this._iframe.style.display   = 'none';
      this._textArea.style.display = '';

      if (this.config.statusBar)
      {
        this._statusBarTree.style.display = "none";
        this._statusBarTextMode.style.display = "";
      }

      this.notifyOf('modechange', {'mode':'text'});
      break;
    }

    case "wysiwyg":
    {
      var html = this.inwardHtml(this.getHTML());
      this.deactivateEditor();
      this.setHTML(html);
      this._iframe.style.display   = '';
      this._textArea.style.display = "none";
      this.activateEditor();
      if (this.config.statusBar)
      {
        this._statusBarTree.style.display = "";
        this._statusBarTextMode.style.display = "none";
      }

      this.notifyOf('modechange', {'mode':'wysiwyg'});
      break;
    }

    default:
    {
      alert("Mode <" + mode + "> not defined!");
      return false;
    }
  }
  this._editMode = mode;

  for (var i in this.plugins) {
    var plugin = this.plugins[i].instance;
    if (plugin && typeof plugin.onMode == "function") plugin.onMode(mode);
  }
};

HTMLArea.prototype.setFullHTML = function(html) {
  var save_multiline = RegExp.multiline;
  RegExp.multiline = true;
  if (html.match(HTMLArea.RE_doctype)) {
    this.setDoctype(RegExp.$1);
    html = html.replace(HTMLArea.RE_doctype, "");
  }
  RegExp.multiline = save_multiline;
  if (!HTMLArea.is_ie) {
    if (html.match(HTMLArea.RE_head))
      this._doc.getElementsByTagName("head")[0].innerHTML = RegExp.$1;
    if (html.match(HTMLArea.RE_body))
      this._doc.getElementsByTagName("body")[0].innerHTML = RegExp.$1;
  } else {
    var reac = this.editorIsActivated();
    if(reac) this.deactivateEditor();
    var html_re = /<html>((.|\n)*?)<\/html>/i;
    html = html.replace(html_re, "$1");
    this._doc.open();
    this._doc.write(html);
    this._doc.close();
    if(reac) this.activateEditor();
    this.setEditorEvents();
    return true;
  }
};
  HTMLArea.prototype.setEditorEvents = function() {
    var editor=this;
    var doc=this._doc;
editor.whenDocReady(
      function() {
        // if we have multiple editors some bug in Mozilla makes some lose editing ability
        HTMLArea._addEvents
        (
          doc,
          ["mousedown"],
          function() { editor.activateEditor(); return true; }
        );
    
    
        // intercept some events; for updating the toolbar & keyboard handlers
        HTMLArea._addEvents
          (doc, ["keydown", "keypress", "mousedown", "mouseup", "drag"],
           function (event) {
             return editor._editorEvent(HTMLArea.is_ie ? editor._iframe.contentWindow.event : event);
           });
    
        // check if any plugins have registered refresh handlers
        for (var i in editor.plugins) {
          var plugin = editor.plugins[i].instance;
          HTMLArea.refreshPlugin(plugin);
        }
    
        // specific editor initialization
        if(typeof editor._onGenerate == "function") {
          editor._onGenerate();
        }
      }
    );
  
  };
  
/** Delay a function until the document is ready for operations.  See ticket:547 */
HTMLArea.prototype.whenDocReady = function(doFunction)
{
  var editor = this;  
  
  if(!this._doc.body)
  {
    setTimeout(function() {editor.whenDocReady(doFunction)}, 50); 
  }
  else
  {
    doFunction();
  }
}

/***************************************************
 *  Category: PLUGINS
 ***************************************************/

Changed 14 years ago by mharrisonline

The newest htmlarea.js from 10/21 with patches applied

comment:46 Changed 14 years ago by mharrisonline

I just attached the 10/21/05 htmlarea.js with these patches applied. It seems to work great, is there any reason why this code should not be added to XINHA and this ticket closed? It would be great to finally be rid of this HTMLArea3 bug once and for all! :D

comment:47 Changed 14 years ago by gocher

Is it fixed in Changeset 391, by gogo?

comment:48 Changed 14 years ago by gocher

  • Resolution set to fixed
  • Status changed from reopened to closed

No it isn't, but now it is!
fixed in Changeset 401

comment:49 Changed 14 years ago by mharrisonline

It really is fixed! Thank you!

Note: See TracTickets for help on using tickets.