Home: htmlArea 3 (beta): htmlArea 2 & 3 archive (read only): htmlArea v3.0 - Add-Ons:
DynamicCSS plugin problem with multiple instances



stanislas
Novice

Oct 20, 2004, 5:35 PM


Views: 6874
DynamicCSS plugin problem with multiple instances

Has anyone been able to make the DynamicCSS plugin work in multiple instances of htmlArea on the same page?

I made many changes to dynamiccss.js in an effort to make it work in multiple instances of the editor in a single page.

I think it now works correctly in IE6. But, in Mozilla 1.7.2, only one area behaves correctly. My knowledge of JavaScript in very limited. Could anyone help me find why this does not work in Mozilla? I am attaching the modified script.
Stanislas Rolland
Saint-Lambert, Qu�bec

(This post was edited by stanislas on Oct 24, 2004, 9:59 PM)
Attachments: dynamiccss-sr.js (8.06 KB)


stanislas
Novice

Nov 14, 2004, 9:24 AM


Views: 6561
Re: [stanislas] DynamicCSS plugin problem with multiple instances

Finally got this straight, tested with Mozilla 1.7.2 and IE6.
1. Use the attached version of dynamiccss.js
2. Specify editor.config.pageStyle as the url of a CSS file, not a CSS import rule.
3. Replace function initIframe (within function generate in htmlarea.js) with the following:

function initIframe() {
var doc = editor._iframe.contentWindow.document;
if (!doc) {
// Try again..
// FIXME: don't know what else to do here. Normally
// we'll never reach this point.
if (HTMLArea.is_gecko) {
setTimeout(initIframe, 100);
return false;
} else {
alert("ERROR: IFRAME can't be initialized.");
}
}
if (HTMLArea.is_gecko) {
// enable editable mode for Mozilla
doc.designMode = "on";
}
editor._doc = doc;
if (!editor.config.fullPage) {
// Begin change by Stanislas Rolland 2004-11-13
// Fix the initial loading in multiple frames when DynamicCSS is enabled
doc.open();
var html = "<html>\n";
html += "<head>\n";
html += "</head>\n";
html += "<body>\n </body>\n";
html += "</html>";
doc.write(html);
doc.close();
var head = doc.getElementsByTagName("head")[0];
if (editor.config.baseURL) {
var base = doc.createElement("base");
base.href = editor.config.baseURL;
head.appendChild(base);
}
if(editor.config.pageStyle) {
var link = doc.createElement("link");
link.rel = "stylesheet";
link.href = editor.config.pageStyle;
head.appendChild(link);
}
doc.body.innerHTML = editor._textArea.value;
doc.body.style.border = "0px";
} else {
var html = editor._textArea.value;
if (html.match(HTMLArea.RE_doctype)) {
editor.setDoctype(RegExp.$1);
html = html.replace(HTMLArea.RE_doctype, "");
}
doc.open();
doc.write(html);
doc.close();
}

if (HTMLArea.is_ie) {
// enable editable mode for IE. For some reason this
// doesn't work if done in the same place as for Gecko
// (above).
doc.body.contentEditable = true;
}

editor.focusEditor();
// check if any plugins have registered refresh handlers
for (var i in editor.plugins) {
var plugin = editor.plugins.instance;
if (typeof plugin.onGenerate == "function")
plugin.onGenerate();
if (typeof plugin.onGenerateOnce == "function") {
plugin.onGenerateOnce();
plugin.onGenerateOnce = null;
}
}

editor.focusEditor();
// 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);
});
// End change by Stanislas Rolland 2004-11-13

if (typeof editor.onGenerate == "function")
editor.onGenerate();

setTimeout(function() {
editor.updateToolbar();
}, 250);
};
Stanislas Rolland
Saint-Lambert, Qu�bec
Attachments: dynamiccss.js (8.80 KB)