--- loncom/homework/inputtags.pm 2012/09/14 11:23:58 1.309 +++ loncom/homework/inputtags.pm 2012/09/24 10:34:19 1.310 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # input definitons # -# $Id: inputtags.pm,v 1.309 2012/09/14 11:23:58 goltermann Exp $ +# $Id: inputtags.pm,v 1.310 2012/09/24 10:34:19 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -125,6 +125,37 @@ sub initialize_inputtags { %Apache::inputtags::submission_display=(); } +# +# provides the onblur binding for spellchecking. This could be an +# empty string if spellchecking was not enabled. +# Jquery selector binding is done rather than setting an onblur +# attribute because we'll need to set the element's spellcheck language +# option dynamically so we need $(this) to be defined. +# +# @param id - The element id to bind. +# @param lang - Language in which spellchecking is desired. +# if undef, nothing is generated. +# @return string - onblur specification to do the requested spellchecking. +# +sub spellcheck_onblur { + my ($id, $lang) = @_; + my $result = ''; + if ($lang) { + + $result = < +\$('\#$id').blur(function() { + doSpellcheck('\#$id', '$lang'); + }); + + +JAVASCRIPT + + + } + return $result; +} + sub check_for_duplicate_ids { my %check; foreach my $id (@Apache::inputtags::partlist, @@ -194,13 +225,13 @@ sub start_textfield { if ( $rows eq '') { $rows = 16; } my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval); $result=''; + my $tagident = 'HWVAL_' . $resid; if ($addchars) { - $result.=&addchars('HWVAL_'.$resid,$addchars); + $result.=&addchars($tagident, $addchars); } my $textareaclass = 'class="LC_richDetectHtml spellchecked"'; - $result.= '"; + my $resid = $Apache::inputtags::response[-1]; + my $tagident = 'HWVAL_' . $resid; + my $result = ""; + $result .= &spellcheck_onblur($tagident, $spellcheck); + return $result; } } elsif ($target eq 'edit') { $result=&Apache::edit::end_table(); @@ -334,6 +370,12 @@ sub start_textline { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result = ""; my $input_id = &start_input($parstack,$safeeval); + + # The spellcheck attribute + # 1. enables spellchecking. + # 2. Provides the language code in which the spellchecking will be performed. + + my $spellcheck = &Apache::lonxml::get_param('spellcheck', $parstack, $safeeval); if ($target eq 'web') { $Apache::lonxml::evaluate--; my $partid=$Apache::inputtags::part; @@ -384,9 +426,15 @@ sub start_textline { if ($Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') { $name = "none"; } - $result.= ''; + $result.= ''; + + $result .= &spellcheck_onblur($name, $spellcheck); } if ($Apache::lonhomework::type eq 'exam' && &needs_exam_box($tagstack)) {