mirror of
https://github.com/webmin/webmin.git
synced 2026-06-23 04:20:32 +01:00
Fix to abstract HTML editor setup
This commit is contained in:
@@ -133,15 +133,13 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
sub html_editor_parts
|
||||
sub html_editor_toolbar
|
||||
{
|
||||
my ($part, $type) = @_;
|
||||
my ($opts) = @_;
|
||||
|
||||
# Editor toolbars
|
||||
if ($part eq 'toolbar') {
|
||||
# Toolbar for mail editor
|
||||
if ($type eq 'mail') {
|
||||
return
|
||||
# Toolbar for mail editor
|
||||
if ($opts->{'type'} eq 'simple') {
|
||||
return
|
||||
<<EOF;
|
||||
[
|
||||
[{'font': [false, 'monospace']},
|
||||
@@ -160,8 +158,8 @@ if ($part eq 'toolbar') {
|
||||
]
|
||||
EOF
|
||||
}
|
||||
if ($type eq 'full') {
|
||||
return
|
||||
if ($opts->{'type'} eq 'advanced') {
|
||||
return
|
||||
<<EOF;
|
||||
[
|
||||
[{'font': [false, 'monospace']},
|
||||
@@ -183,17 +181,16 @@ EOF
|
||||
]
|
||||
EOF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub html_editor_init_script
|
||||
{
|
||||
my ($type, $opts) = @_;
|
||||
$opts ||= {};
|
||||
my ($opts) = @_;
|
||||
my $html_editor_init_script =
|
||||
<<EOF;
|
||||
<script type="text/javascript">
|
||||
const mail_init_editor = function() {
|
||||
const targ = document.querySelector('[name="body"]'),
|
||||
const targ = document.querySelector('[name="@{[$opts->{'textarea'}]}"]'),
|
||||
qs = Quill.import('attributors/style/size'),
|
||||
qf = Quill.import('attributors/style/font'),
|
||||
escapeHTML_ = function(htmlStr) {
|
||||
@@ -234,7 +231,7 @@ my $html_editor_init_script =
|
||||
'Resize',
|
||||
],
|
||||
},
|
||||
toolbar: @{[&html_editor_parts('toolbar', $type)]},
|
||||
toolbar: @{[&html_editor_toolbar($opts)]},
|
||||
},
|
||||
bounds: '.ql-compose-container',
|
||||
theme: 'snow'
|
||||
@@ -287,4 +284,34 @@ EOF
|
||||
return $html_editor_init_script;
|
||||
}
|
||||
|
||||
sub html_editor
|
||||
{
|
||||
my ($opts) = @_;
|
||||
# Get template
|
||||
my $html_editor_template =
|
||||
&html_editor_template($opts);
|
||||
# Get toolbar styling
|
||||
my $html_editor_styles_toolbar =
|
||||
&html_editor_styles('toolbar');
|
||||
# Load bundles
|
||||
my ($html_editor_load_scripts);
|
||||
my %tinfo = &get_theme_info($current_theme);
|
||||
if (!$tinfo{'spa'}) {
|
||||
# Load HTML editor files and dependencies
|
||||
$html_editor_load_scripts =
|
||||
&html_editor_load_bundle($opts);
|
||||
}
|
||||
|
||||
# HTML editor init
|
||||
$opts->{'load'} = !$tinfo{'spa'};
|
||||
my $html_editor_init_scripts =
|
||||
&html_editor_init_script($opts);
|
||||
|
||||
# Return complete HTML editor
|
||||
return $html_editor_template .
|
||||
$html_editor_styles_toolbar .
|
||||
$html_editor_load_scripts .
|
||||
$html_editor_init_scripts;
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -443,26 +443,23 @@ if ($in{'new'}) {
|
||||
# Output message body input
|
||||
print &ui_table_start($text{'reply_body'}, "width=100%", 2, undef,
|
||||
&ui_links_row(\@bodylinks));
|
||||
my $html_editor_quote = &iframe_quote($quote);
|
||||
my $html_editor_template;
|
||||
my $html_editor_styles;
|
||||
my $html_editor_scripts;
|
||||
my $html_editor_load_scripts;
|
||||
|
||||
# Process email quote
|
||||
$quote = &iframe_quote($quote);
|
||||
|
||||
# Get HTML editor and replies
|
||||
my $html_editor = &html_editor(
|
||||
{ textarea => 'body',
|
||||
type => 'simple',
|
||||
extra =>
|
||||
{ js => ['highlight/highlight'],
|
||||
css => ['highlight/highlight'] },
|
||||
quote => length($quote),
|
||||
after =>
|
||||
{ editor => $quote }
|
||||
});
|
||||
|
||||
if ($html_edit) {
|
||||
$html_editor_template = &html_editor_template({after => {editor => $html_editor_quote}});
|
||||
$html_editor_styles = &html_editor_styles('toolbar');
|
||||
my %tinfo = &get_theme_info($current_theme);
|
||||
if (!$tinfo{'spa'}) {
|
||||
# Load HTML editor files
|
||||
$html_editor_load_scripts =
|
||||
&html_editor_load_bundle(
|
||||
{extra =>
|
||||
{js => ['highlight/highlight'],
|
||||
css => ['highlight/highlight']}});
|
||||
}
|
||||
# HTML editor init
|
||||
$html_editor_scripts =
|
||||
&html_editor_init_script('mail', {load => !$tinfo{'spa'}});
|
||||
$sig =~ s/\n/<br>/g,
|
||||
$sig =~ s/^\s+//g,
|
||||
$sig = "<br><br>$sig<br><br>"
|
||||
@@ -470,10 +467,7 @@ if ($html_edit) {
|
||||
print &ui_table_row(undef,
|
||||
&ui_textarea("body", $sig, 16, 80, undef, 0,
|
||||
"style='display: none' id=body").
|
||||
$html_editor_template.
|
||||
$html_editor_styles.
|
||||
$html_editor_load_scripts.
|
||||
$html_editor_scripts, 2);
|
||||
$html_editor, 2);
|
||||
}
|
||||
else {
|
||||
# Show text editing area
|
||||
|
||||
Reference in New Issue
Block a user