--- loncom/interface/lonhtmlcommon.pm 2009/08/23 12:59:18 1.182.4.8 +++ loncom/interface/lonhtmlcommon.pm 2009/11/14 18:54:17 1.243 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.182.4.8 2009/08/23 12:59:18 raeburn Exp $ +# $Id: lonhtmlcommon.pm,v 1.243 2009/11/14 18:54:17 amueller Exp $ # # Copyright Michigan State University Board of Trustees # @@ -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|; + '.&mt('All courses').'
'; + ($formname,'pickcourse','pickdomain','coursedesc','',1,$crstype).''; + $output .= ''.$allcrs.'
'; if ($totcodes > 0) { my $numtitles = @$codetitles; if ($numtitles > 0) { @@ -1717,7 +1779,7 @@ sub course_selection { $output .= '
'; } } - $output .= ''.&mt('Pick specific course(s):').' '.$courseform.'  selected.
'."\n"; + $output .= ''.$pickspec.' '.$courseform.'  selected.
'."\n"; return $output; } @@ -1805,17 +1867,22 @@ sub course_custom_roles { # topic_bar # -# Generates a div containing a numbered (static image) followed by a title -# with a background color defined in the corresponding CSS: LC_topic_bar -# +# Generates a div containing an (optional) numbered (static) image followed by a +# title with a background color defined in the corresponding CSS: LC_topic_bar +# Inputs: +# 1. number to display (corresponding static image should exist). +# img tag will be included if arg is an integer in the range 1 to 9. +# 2. title text to display. +# Outputs - a scalar containing html mark-up for the div. + sub topic_bar { my ($imgnum,$title) = @_; - return ' -
- '.&mt('Step [_1]',$imgnum).
-              ' '.$title.' -
-'; + my $imgtag; + if ($imgnum =~ /^[1-9]$/) { + $imgtag = ''.&mt('Step [_1]',$imgnum).' '; + } + return '
'.$imgtag.$title.'
'; } ############################################## @@ -2028,6 +2095,7 @@ sub set_form_elements { } } $output .= " + return; }\n"; return $output; } @@ -2070,6 +2138,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