Ticket #547 (closed defect: fixed)
this._doc.body has no properties in onGenerate() when using stylistLoadStylesheet (Firefox)
| Reported by: | anonymous | Owned by: | gogo |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Xinha Core | Version: | |
| Severity: | normal | Keywords: | ongenerate stylistLoadStyleSheet body pagestylesheets |
| Cc: |
Description
I was trying to use the Stylist plugin with loading external stylesheet AND to set the id of the body of editor content using _onGenerate() function:
HTMLArea.prototype._onGenerate = function() {
this._doc.body.id = 'content';
};
In IE everything was working fine, but Firefox could not set the ID because of error: this._doc.body has no properties. After a bit of debugging I traced down the problem - it appears only when using Stylist plugin, which fills up HTMLArea.pageStyleSheets array.
When this array is not empty Xinha writes the stylesheet definition HTML block in line 1897 of htmlarea.js. (by the way - the block is XHTML invalid - it should end with "/>") with appropriate link tag.
What happens is that on writing the html to the document object, this object is not "finalized" at once, at least not in Firefox, it probably fetches and parses the stylesheet. So when the _onGenenerate() method is called a few lines later, this._doc object has no body nor any other properties yet! (in fact, it does only have execute() method). Don't know if there is a way to wait for this object to "filnalize" - I solved this problem myself by using this modification:
HTMLArea.prototype._onGenerate = function() {
var editor = this;
if (!this._doc.body)
setTimeout(function() { editor._onGenerate()}, 50);
else {
this._doc.body.id = 'content';
}
};
but i suggest moving this to core (some sort of waiting for this._doc to initialize) as it may lead to undesired behaviour in future.
