Refactor the RichEditor/HTMLArea so that JS and CSS scripts can be placed in the header block.

This commit is contained in:
Colin Kuskie 2010-09-16 16:07:51 -07:00
parent dadb7cae00
commit b04aa0a1f3
2 changed files with 36 additions and 14 deletions

View file

@ -493,14 +493,11 @@ sub getRichEditor {
$config{height} = $self->editorHeight || "100%";
$config{plugins} = join(",",@plugins);
$self->session->style->setScript($self->session->url->extras('yui/build/yahoo/yahoo-min.js'));
$self->session->style->setScript($self->session->url->extras('yui/build/event/event-min.js'));
$self->session->style->setScript($self->session->url->extras('tinymce/jscripts/tiny_mce/tiny_mce_src.js'));
$self->session->style->setScript($self->session->url->extras("tinymce-webgui/callbacks.js"));
my $out = '';
if ($ask) {
$out = q|<a style="display: block;" href="javascript:toggleEditor('|.$nameId.q|')">|.$i18n->get('Toggle editor').q|</a>|;
}
$self->richedit_headTags;
$out .= qq|<script type="text/javascript">\n|;
if ($ask) {
$out .= <<"EOHTML1";
@ -526,6 +523,25 @@ EOHTML1
}
#-------------------------------------------------------------------
=head2 richedit_headTags ( )
Similar to the headTags method for Form plugins, this sets all Javascript and CSS links for the
richeditor to work.
=cut
sub richedit_headTags {
my $self = shift;
my $style = $self->session->style;
my $url = $self->session->url;
$style->setScript($url->extras('yui/build/yahoo/yahoo-min.js'));
$style->setScript($url->extras('yui/build/event/event-min.js'));
$style->setScript($url->extras('tinymce/jscripts/tiny_mce/tiny_mce_src.js'));
$style->setScript($url->extras("tinymce-webgui/callbacks.js"));
}
#-------------------------------------------------------------------
=head2 indexContent ( )

View file

@ -156,7 +156,12 @@ Set the head tags for this form plugin
sub headTags {
my $self = shift;
$self->session->style->setScript($self->session->url->extras('textFix.js'),{ type=>'text/javascript' });
if (! $self->{_richEdit}) {
$self->{_richEdit} = eval { WebGUI::Asset->newById($self->session,$self->get("richEditId")) };
return if Exception::Class->caught();
}
$self->session->style->setScript($self->session->url->extras('textFix.js'));
$self->{_richEdit}->richedit_headTags;
}
#-------------------------------------------------------------------
@ -182,15 +187,16 @@ Renders an HTML area field.
sub toHtml {
my $self = shift;
my $i18n = WebGUI::International->new($self->session);
my $richEdit = eval { WebGUI::Asset::RichEdit->newById($self->session, $self->get("richEditId")); };
if (! Exception::Class->caught() ) {
$self->set("extras", $self->get('extras') . q{ onblur="fixChars(this.form['}.$self->get("name").q{'])" mce_editable="true" });
$self->set("resizable", 0);
return $self->SUPER::toHtml.$richEdit->getRichEditor($self->get('id'));
} else {
$self->session->errorHandler->warn($i18n->get('rich editor load error','Form_HTMLArea'));
return $self->SUPER::toHtml;
}
if (! $self->{_richEdit}) {
my $richEdit = eval { WebGUI::Asset::RichEdit->newById($self->session, $self->get("richEditId")); };
if (Exception::Class->caught() ) {
$self->session->errorHandler->warn($i18n->get('rich editor load error','Form_HTMLArea'));
return $self->SUPER::toHtml;
}
}
$self->set("extras", $self->get('extras') . q{ onblur="fixChars(this.form['}.$self->get("name").q{'])" mce_editable="true" });
$self->set("resizable", 0);
return $self->SUPER::toHtml.$self->{_richEdit}->getRichEditor($self->get('id'));
}