--- loncom/interface/lonhtmlcommon.pm 2004/04/23 17:49:25 1.67 +++ loncom/interface/lonhtmlcommon.pm 2004/06/04 16:05:47 1.74 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.67 2004/04/23 17:49:25 matthew Exp $ +# $Id: lonhtmlcommon.pm,v 1.74 2004/06/04 16:05:47 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -163,9 +163,15 @@ sub textbox { ############################################## ############################################## sub checkbox { - my ($name,$value) = @_; - my $Str = '<input type="checkbox" name="'.$name.'"'. - ($value?' checked="1"':'').' />'; + my ($name,$checked,$value) = @_; + my $Str = '<input type="checkbox" name="'.$name.'" '; + if (defined($value)) { + $Str .= 'value="'.$value.'"'; + } + if ($checked) { + $Str .= ' checked="1"'; + } + $Str .= ' />'; return $Str; } @@ -862,37 +868,73 @@ sub crumbs { # ------------------------------------------------- Output headers for HTMLArea sub htmlareaheaders { - unless (&htmlareablocked()) { return ''; } + if (&htmlareablocked()) { return ''; } my $lang='en'; + if (&mt('htmlarea_lang') ne 'htmlarea_lang') { + $lang=&mt('htmlarea_lang'); + } return (<<ENDHEADERS); <script type="text/javascript"> - _editor_url="/htmlarea/"; +_editor_url='/htmlarea/'; +_editor_lang='$lang'; </script> <script type="text/javascript" src="/htmlarea/htmlarea.js"></script> -<script type="text/javascript" src="/htmlarea/lang/$lang.js"></script> -<script type="text/javascript" src="/htmlarea/dialog.js"></script> -<style type="text/css"> -\@import url(/htmlarea/htmlarea.css); -</style> ENDHEADERS } +# ------------------------------------------------- Activate additional buttons + +sub htmlareaaddbuttons { + if (&htmlareablocked()) { return ''; } + return (<<ENDADDBUTTON); + var config=new HTMLArea.Config(); + config.registerButton('ed_math','LaTeX Inline', + '/htmlarea/images/ed_math.gif',false, + function(editor,id) { + editor.surroundHTML('<m>\$','\$</m>'); + } + ); + config.registerButton('ed_math_eqn','LaTeX Equation', + '/htmlarea/images/ed_math_eqn.gif',false, + function(editor,id) { + editor.surroundHTML('<br /><m>\\\\[','\\\\]</m><br />'); + } + ); + config.toolbar.push(['ed_math','ed_math_eqn']); +ENDADDBUTTON +} # ---------------------------------------------------------- Script to activate sub htmlareaactive { - unless (&htmlareablocked()) { return ''; } + if (&htmlareablocked()) { return ''; } + my $addbuttons=&htmlareaaddbuttons(); return (<<ENDSCRIPT); <script type="text/javascript" defer="1"> - HTMLArea.replaceAll(); + $addbuttons + HTMLArea.replaceAll(config); </script> ENDSCRIPT } +# ----------------------------------------- Script to activate only some fields + +sub htmlareaselectactive { + my @fields=@_; + if (&htmlareablocked()) { return ''; } + my $output='<script type="text/javascript" defer="1">'. + &htmlareaaddbuttons(); + foreach(@fields) { + $output.="\nHTMLArea.replace('$_',config);"; + } + $output.="\nwindow.status='Activated Editfields';\n</script>"; + return $output; +} + # --------------------------------------------------------------------- Blocked sub htmlareablocked { - unless (&htmlareabrowser()) { return ''; } - return 1; + unless (&htmlareabrowser()) { return 1; } + return 0; } # ---------------------------------------- Browser capable of running HTMLArea? @@ -969,23 +1011,34 @@ returns: nothing # The last breadcrumb does not have a link, so handle it separately. my $last = pop(@Crumbs); # - # The first one should be the course, I guess. + # The first one should be the course or a menu link if (!defined($menulink)) { $menulink=1; } - if ($menulink && exists($ENV{'request.course.id'}) && $ENV{'request.course.id'} ne '') { - my $cid = $ENV{'request.course.id'}; + if ($menulink) { + my $description = 'Menu'; + if (exists($ENV{'request.course.id'}) && + $ENV{'request.course.id'} ne '') { + $description = + $ENV{'course.'.$ENV{'request.course.id'}.'.description'}; + } unshift(@Crumbs,{ - href=>'/adm/menu', - title=>'Go to main menu', - text=>$ENV{'course.'.$cid.'.description'}, - }); + href =>'/adm/menu', + title =>'Go to main menu', + target =>'_top', + text =>$description, + }); } my $links .= join('->', map { $faq = $_->{'faq'} if (exists($_->{'faq'})); $bug = $_->{'bug'} if (exists($_->{'bug'})); - '<a href="'.$_->{'href'}.'" title="'.&mt($_->{'title'}).'">'. - &mt($_->{'text'}).'</a>' + my $result = '<a href="'.$_->{'href'}.'" '; + if (defined($_->{'target'}) && $_->{'target'} ne '') { + $result .= 'target="'.$_->{'target'}.'" '; + } + $result .='title="'.&mt($_->{'title'}).'">'. + &mt($_->{'text'}).'</a>'; + $result; } @Crumbs ); $links .= '->' if ($links ne '');