--- loncom/interface/lonhtmlcommon.pm 2010/01/22 13:54:06 1.182.4.9 +++ loncom/interface/lonhtmlcommon.pm 2009/08/13 14:32:33 1.232 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.182.4.9 2010/01/22 13:54:06 raeburn Exp $ +# $Id: lonhtmlcommon.pm,v 1.232 2009/08/13 14:32:33 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -82,7 +82,7 @@ sub confirm_success { .''."\n"; } else { return ''."\n" - .''.&mt('OK').' '."\n" + .''.&mt('Ok').' '."\n" .$message."\n" .''."\n"; } @@ -160,10 +160,10 @@ sub authorbombs { $url=&Apache::lonnet::declutter($url); my ($udom,$uname)=($url=~m{^($LONCAPA::domain_re)/($LONCAPA::username_re)/}); my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom); - foreach (keys %bombs) { - if ($_=~/^$udom\/$uname\//) { + foreach my $bomb (keys(%bombs)) { + if ($bomb =~ /^$udom\/$uname\//) { return ''. + '">'.&mt('Bomb').''. &Apache::loncommon::help_open_topic('About_Bombs'); } } @@ -239,7 +239,7 @@ sub get_recent { # Begin filling return_hash with any 'always_include' option my %time_hash = (); my %return_hash = (); - foreach my $item (keys %recent) { + foreach my $item (keys(%recent)) { my ($thistime,$thisvalue)=(split(/\&/,$recent{$item})); if ($thistime eq 'always_include') { $return_hash{$item} = &unescape($thisvalue); @@ -496,7 +496,7 @@ document.$formname.$dname\_year.value, // ]]> ENDJS - $result .= ' '; + $result .= ' '; my $monthselector = qq{\n|; + '.$allcrs.'
'; + ($formname,'pickcourse','pickdomain','coursedesc','',1).''; + $output .= ''.&mt('All courses').'
'; if ($totcodes > 0) { my $numtitles = @$codetitles; if ($numtitles > 0) { @@ -1731,7 +1713,7 @@ sub course_selection { $output .= '
'; } } - $output .= ''.$pickspec.' '.$courseform.'  selected.
'."\n"; + $output .= ''.&mt('Pick specific course(s):').' '.$courseform.'  selected.
'."\n"; return $output; } @@ -1824,12 +1806,11 @@ sub course_custom_roles { # sub topic_bar { my ($imgnum,$title) = @_; - return ' -
- '.&mt('Step [_1]',$imgnum).
-              ' '.$title.' -
-'; + return '
' + .''.&mt('Step [_1]',$imgnum).'' + .' '.$title + .'
'; } ############################################## @@ -1964,7 +1945,7 @@ sub set_form_elements { $values{$name}[$i] =~ s/([\r\n\f]+)/\\n/g; $values{$name}[$i] =~ s/"/\\"/g; } - if (($$elements{$name} eq 'text') || ($$elements{$name} eq 'hidden')) { + if ($$elements{$name} eq 'text') { my $numvalues = @{$values{$name}}; if ($numvalues > 1) { my $valuestring = join('","',@{$values{$name}}); @@ -1999,8 +1980,6 @@ sub set_form_elements { $output .= qq| if (courseForm.elements['$name'].value == "$value") { courseForm.elements['$name'].checked = true; - } else { - courseForm.elements['$name'].checked = false; }|; } } @@ -2042,7 +2021,6 @@ sub set_form_elements { } } $output .= " - return; }\n"; return $output; } @@ -2085,6 +2063,273 @@ END } +# USAGE: htmltag(element, content, {attribute => value,...}); +# +# EXAMPLES: +# - htmltag('a', 'this is an anchor', {href => 'www.example.com', +# title => 'this is a title'}) +# +# - You might want to set up needed tags like: +# +# my $h3 = sub { return htmltag( "h3", @_ ) }; +# +# ... and use them: $h3->("This is a headline") +# +# - To set up a couple of tags, see sub inittags +# +# NOTES: +# - Empty elements, such as
are correctly terminated, +# i.e. htmltag('br') returns
+# - Empty attributes (title="") are filtered out. +# - The function will not check for deprecated attributes. +# +# OUTPUT: content enclosed in xhtml conform tags +sub htmltag{ + return + qq|<$_[0]| + . join( '', map { qq| $_="${$_[2]}{$_}"| if ${$_[2]}{$_} } keys %{ $_[2] } ) + . ($_[1] ? qq|>$_[1]| : qq|/>|). "\n"; +}; + + +# USAGE: inittags(@tags); +# +# EXAMPLES: +# - my ($h1, $h2, $h3) = initTags( qw( h1 h2 h3 ) ) +# $h1->("This is a headline") #Returns:

This is a headline

+# +# NOTES: See sub htmltag for further information. +# +# OUTPUT: List of subroutines. +sub inittags { + my @tags = @_; + return map { my $tag = $_; + sub { return htmltag( $tag, @_ ) } + } @tags; +} + + +# USAGE: scripttag(scriptcode, [start|end|both]); +# +# EXAMPLES: +# - scripttag("alert('Hello World!')", 'both') +# returns: +# +# +# NOTES: +# - works currently only for javascripts +# +# OUTPUT: +# Scriptcode properly enclosed in