--- loncom/homework/structuretags.pm 2011/12/10 17:53:45 1.498
+++ loncom/homework/structuretags.pm 2014/11/24 02:36:26 1.524
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.498 2011/12/10 17:53:45 raeburn Exp $
+# $Id: structuretags.pm,v 1.524 2014/11/24 02:36:26 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -61,6 +61,7 @@ use Apache::lonlocal;
use Apache::lonxml;
use Apache::londefdef;
use Apache::lonenc();
+use Apache::loncommon();
use Time::HiRes qw( gettimeofday tv_interval );
use lib '/home/httpd/lib/perl/';
use LONCAPA;
@@ -69,6 +70,105 @@ BEGIN {
&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'));
}
+
+#---------------------------------------------------------------------------------
+#
+# This section of code deals with hyphenation management.
+# We must do three things:
+# - keep track fo the desired languages to alter the header.
+# - provide hyphenation selection as needed by each language that appears in the
+# text.
+# - Provide the header text needed to make available the desired hyphenations.
+#
+#
+
+# Hash whose keys are the languages encountered in the document/resource.
+#
+
+my %languages_required;
+##
+# Given a language selection as input returns a chunk of LaTeX that
+# selects the required hyphenator.
+#
+# @param language - the language being selected.
+# @return string
+# @retval The LaTeX needed to select the hyphenation appropriate to the language.
+#
+sub select_hyphenation {
+ my $language = shift;
+
+ $language = &Apache::loncommon::latexlanguage($language); # Translate -> latex language.
+
+ # If there is no latex language there's not much we can do:
+
+ if ($language) {
+ &require_language($language);
+ my $babel_hyphenation = "\\selectlanguage{$language}";
+
+ return $babel_hyphenation;
+ } else {
+ return '';
+ }
+}
+##
+# Selects hyphenation based on the current problem metadata.
+# This requires that
+# - There is a language metadata item set for the problem.
+# - The language has a latex/babel hyphenation.
+#
+# @note: Uses &Apache::lonxml::request to locate the Uri associated with
+# this problem.
+# @return string (possibly empty).
+# @retval If not empty an appropriate \selectlanguage{} directive.
+#
+sub select_metadata_hyphenation {
+ my $uri = $Apache::lonxml::request->uri;
+ my $language = &Apache::lonnet::metadata($uri, 'language');
+ my $latex_language = &Apache::loncommon::latexhyphenation($language);
+ if ($latex_language) {
+ return '\selectlanguage{'.$latex_language."}\n";
+ }
+ return ''; # no latex hyphenation or no lang metadata.
+}
+
+
+##
+# Clears the set of languages required by the document being rendered.
+#
+sub clear_required_languages {
+ %languages_required = ();
+}
+##
+# Allows an external client of this module to register a need for a language:
+#
+# @param LaTeX language required:
+#
+sub require_language {
+ my $language = shift;
+ $languages_required{$language} = 1;
+}
+
+##
+# Provides the header for babel that indicates the languages
+# the document requires.
+# @return string
+# @retval \usepackage[lang1,lang2...]{babel}
+# @retval '' if there are no languages_required.
+sub languages_header {
+ my $header ='';
+ my @languages = (keys(%languages_required));
+
+ # Only generate the header if there are languages:
+
+ if (scalar @languages) {
+ my $language_list = join(',', (@languages));
+ $header = '\usepackage['.$language_list."]{babel}\n";
+ }
+ return $header;
+}
+
+#----------------------------------------------------------------------------------
+
sub start_web {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
if ($target ne 'edit' && $target ne 'modified') {
@@ -154,6 +254,55 @@ function image_response_click (which, e)
input_element.value = click;
img_element.src = '/adm/randomlabel.png?token='+token+'&clickdata='+click;
}
+
+var submithandled = 0;
+var keypresshandled = 0;
+
+$(document).ready(function(){
+
+ $(document).keypress(function(event){
+ var keycode = (event.keyCode ? event.keyCode : event.which);
+ if ((keycode == '13') && (keypresshandled == 0)) {
+ if ( $( document.activeElement ).hasClass("LC_textline") ) {
+ keypresshandled = 1;
+ var idsArray = $( document.activeElement ).attr("id").split(/HWVAL_/);
+ if (idsArray.length) {
+ event.preventDefault();
+ var itemsArray = idsArray[1].split(/_/);
+ var buttonId = idsArray[0]+'submit_'+itemsArray[0];
+ $("#"+buttonId).trigger("click");
+ }
+ }
+ }
+ });
+
+ $(document).delegate('form :submit', 'click', function( event ) {
+ if ( $( this ).hasClass( "LC_hwk_submit" ) ) {
+ var buttonId = this.id;
+ if (submithandled == 0) {
+ submithandled = 1;
+ $( "#msg_"+buttonId ).css({"display": "inline","background-color": "#87cefa",
+ "color": "black","padding": "2px"}) ;
+ if (( $(this.form).id == "LC_page" ) && ($('input[name="all_submit"]').length )) {
+ if (buttonId != "all_submit") {
+ $( ".LC_status_"+buttonId ).hide();
+ if (( "#"+buttonId+"_pressed" ).length) {
+ $( "#"+buttonId+"_pressed" ).val( "1" );
+ }
+ }
+ } else {
+ $( ".LC_status_"+buttonId ).hide();
+ }
+ $(this.form).submit();
+ $( ".LC_hwk_submit" ).prop( "disabled", true);
+ $( ".LC_textline" ).prop( "readonly", "readonly");
+ event.preventDefault();
+ return true;
+ }
+ }
+ });
+});
+
// ]]>
JS
@@ -279,10 +428,10 @@ sub page_start {
} elsif (!defined($found{'body'})
&& $env{'request.state'} eq 'construct') {
if ($target eq 'web' || $target eq 'edit') {
- # Breadcrumbs for Construction Space
+ # Breadcrumbs for Authoring Space
&Apache::lonhtmlcommon::clear_breadcrumbs();
&Apache::lonhtmlcommon::add_breadcrumb({
- 'text' => 'Construction Space',
+ 'text' => 'Authoring Space',
'href' => &Apache::loncommon::authorspace($env{'request.uri'}),
});
# breadcrumbs (and tools) will be created
@@ -314,6 +463,8 @@ sub page_start {
$body_args{'add_entries'} = \%add_entries;
if ( $env{'request.state'} eq 'construct') {
$body_args{'only_body'} = 1;
+ } elsif ($target eq 'web') {
+ $body_args{'print_suppress'} = 1;
}
}
$body_args{'no_auto_mt_title'} = 1;
@@ -353,7 +504,6 @@ sub page_start {
}
$form_tag_start.='>'."\n";
- my $symb=&Apache::lonnet::symbread();
if ($symb =~ /\S/) {
$symb=
&HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb));
@@ -538,7 +688,7 @@ sub problem_edit_header {
'.&Apache::lonxml::message_location().'
'.
- '
';
+ '
';
}
sub problem_edit_footer {
@@ -611,7 +761,7 @@ sub problem_web_to_edit_header {
".&mt("Problem Type:")."