--- loncom/homework/structuretags.pm 2007/04/07 00:12:43 1.376 +++ loncom/homework/structuretags.pm 2011/01/07 05:14:57 1.465.2.12 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.376 2007/04/07 00:12:43 albertel Exp $ +# $Id: structuretags.pm,v 1.465.2.12 2011/01/07 05:14:57 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,6 +27,29 @@ # ### +=pod + +=head1 NAME + +Apache::structuretags + +=head1 SYNOPSIS + + +This is part of the LearningOnline Network with CAPA project +described at http://www.lon-capa.org. + + +=head1 NOTABLE SUBROUTINES + +=over + +=item + +=back + +=cut + package Apache::structuretags; @@ -36,20 +59,31 @@ use Apache::File(); use Apache::lonmenu; use Apache::lonlocal; use Apache::lonxml; +use Apache::londefdef; use Apache::lonenc(); use Time::HiRes qw( gettimeofday tv_interval ); use lib '/home/httpd/lib/perl/'; use LONCAPA; BEGIN { - &Apache::lonxml::register('Apache::structuretags',('block','languageblock','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startouttext','endouttext','simpleeditbutton','definetag')); + &Apache::lonxml::register('Apache::structuretags',('block','languageblock','translated','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startpartmarker','startouttext','endpartmarker','endouttext','simpleeditbutton','definetag')); } sub start_web { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; - my $bodytext=&Apache::lonxml::get_all_text("/web",$parser,$style); - if ($target eq 'web' || $target eq 'webgrade') { - return $bodytext; + if ($target ne 'edit' && $target ne 'modified') { + my $bodytext=&Apache::lonxml::get_all_text("/web",$parser,$style); + if ($target eq 'web' || $target eq 'webgrade') { + return $bodytext; + } + } elsif ($target eq "edit" ) { + my $bodytext = + &Apache::lonxml::get_all_text_unbalanced("/web",$parser); + my $result = &Apache::edit::tag_start($target,$token); + $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1); + return $result; + } elsif ( $target eq "modified" ) { + return $token->[4].&Apache::edit::modifiedfield("/web",$parser); } return ''; } @@ -61,9 +95,26 @@ sub end_web { sub start_tex { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result=''; - my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser,$style); - if ($target eq 'tex') { - return $bodytext.' '; + if ($target ne 'edit' && $target ne 'modified') { + my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser,$style); + if ($target eq 'tex') { + + # If inside a table, occurrences of \\ must be removed; + # else the table blows up. + + if (&Apache::londefdef::is_inside_of($tagstack, "table")) { + $bodytext =~ s/\\\\//g; + } + return $bodytext.'{}'; + } + } elsif ($target eq "edit" ) { + my $bodytext = + &Apache::lonxml::get_all_text_unbalanced("/tex",$parser); + my $result = &Apache::edit::tag_start($target,$token); + $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1); + return $result; + } elsif ( $target eq "modified" ) { + return $token->[4].&Apache::edit::modifiedfield("/tex",$parser); } return $result;; } @@ -72,6 +123,88 @@ sub end_tex { return ''; } +sub homework_js { + return &Apache::loncommon::resize_textarea_js(). + &setmode_javascript(). + <<'JS'; + +JS +} + +sub setmode_javascript { + return <<"ENDSCRIPT"; + +ENDSCRIPT +} + +sub file_delchk_js { + my $delfilewarn = &mt('You have indicated you wish to remove some files previously included in your submission.').'\\n'. + &mt('Continue submission with these files removed?'); + return <<"ENDSCRIPT"; + +ENDSCRIPT +} + sub page_start { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name, $extra_head)=@_; @@ -88,13 +221,18 @@ sub page_start { $parstack,$parser,$safeeval); } - $extra_head.= ' - -'; + $extra_head .= &homework_js(). + &Apache::lonhtmlcommon::dragmath_js("EditMathPopup"); + if (&Apache::lonhtmlcommon::htmlareabrowser()) { + my %textarea_args = ( + dragmath => 'math', + ); + $extra_head .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args); + } + my $is_task = ($env{'request.uri'} =~ /\.task$/); + if ($is_task) { + $extra_head .= &file_delchk_js(); + } my %body_args; if (defined($found{'html'})) { @@ -103,13 +241,9 @@ function setSubmittedPart (part) { $extra_head .= &Apache::lonhtmlcommon::spellheader(); - my $css_href = &Apache::lonnet::EXT('resource.0.cssfile'); - if ($css_href =~ /\S/) { - &Apache::lonxml::extlink($css_href); - $extra_head .= - ''; - } - if ($target eq 'edit') { + $extra_head .= &Apache::londefdef::generate_css_links(); + + if ($env{'request.state'} eq 'construct') { $extra_head.=&Apache::edit::js_change_detection(). "