// Preserve the Frog backend function. This plug-in is going to overwrite this function,
// but the original function will be called after a custom functio is called.
var origin_function = setTextAreaToolbar;
// This function replaces the Frog 'setTextAreaToolbar' if the editor is used.
// Cleans up the WYMeditor. Later the original Frog function is called.
wymeditor_setTextAreaToolbar = function(textarea, filter) {
jQuery.each(WYMeditor.INSTANCES, function() {
// Check if the editor is still active
if (this && this._doc && this._element.attr('id') == textarea && filter != "wymeditor") {
// Remove the editor
this.update();
$(this._box).remove();
delete this;
}
});
// call origin function, but keep this function maybe there is more than one instance
origin_function(textarea, filter);
};
// Forces all instances of the editor to update their content to the Frog text fields.
wymeditor_update_all = function() {
jQuery.each(WYMeditor.INSTANCES, function() {
// Only if editor is still there, store the content to the origin textarea
if (this._doc) {
this.update();
}
});
};
// Fix for wymeditor. Frog uses the <base href=""/>, but the wymeditor does not use this feature.
// TODO: raise a defect against the original wymeditor code base, then remove this workaround
// 1. get the base path from the current page
var wymeditor_frog_base = jQuery('base').attr('href') || "";
// 2. store the wymeditor fuctions
var wymeditor_origin_computeBasePath = WYMeditor.editor.prototype.computeBasePath;
var wymeditor_origin_computeWymPath = WYMeditor.editor.prototype.computeWymPath;
var wymeditor_origin_computeJqueryPath = WYMeditor.editor.prototype.computeJqueryPath;
var wymeditor_origin_computeCssPath = WYMeditor.editor.prototype.computeCssPath;
// 3. route the function to the new destination
WYMeditor.editor.prototype.computeBasePath = function() { return wymeditor_frog_base + wymeditor_origin_computeBasePath();};
WYMeditor.editor.prototype.computeWymPath = function() { return wymeditor_frog_base + wymeditor_origin_computeWymPath(); };
WYMeditor.editor.prototype.computeJqueryPath = function() { return wymeditor_frog_base + wymeditor_origin_computeJqueryPath(); };
WYMeditor.editor.prototype.computeCssPath = function() { return wymeditor_frog_base + wymeditor_origin_computeCssPath(); };
// Frog backend function to activate the WYMeditor. Used the Prototype JS library.
Control.TextArea.ToolBar.Wymeditor = Class.create();
Object.extend(Control.TextArea.ToolBar.Wymeditor.prototype,{
toolbar: false,
initialize: function(textarea, options) {
// We do not use the frog infrastructure
this.toolbar = { container: {} };
// Overwrite change function to hook in a 'destroy' function
setTextAreaToolbar = wymeditor_setTextAreaToolbar;
// Create the editor
jQuery('#'+textarea).wymeditor({
// The language is set from the backend
lang: frog_wymeditor_language,
skin: 'frog',
stylesheet: frog_wymeditor_stylesheet
});
// Register update event, could be added more than once (multiple page parts),
// but this should be no problem
jQuery('form:first').bind('submit', wymeditor_update_all);
}
});