[LON-CAPA-cvs] cvs: rat / lonpage.pm loncom/homework inputtags.pm structuretags.pm loncom/interface loncommon.pm lonhtmlcommon.pm
raeburn
raeburn at source.lon-capa.org
Sun Sep 10 14:12:55 EDT 2023
raeburn Sun Sep 10 18:12:55 2023 EDT
Modified files:
/loncom/homework inputtags.pm structuretags.pm
/loncom/interface lonhtmlcommon.pm loncommon.pm
/rat lonpage.pm
Log:
- Bug 5219
Dashes in text pasted into textbox(es) for numericalresponse item(s)
replaced with standard ascii minus, i.e., -
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.358 loncom/homework/inputtags.pm:1.359
--- loncom/homework/inputtags.pm:1.358 Sun Apr 2 03:16:28 2023
+++ loncom/homework/inputtags.pm Sun Sep 10 18:12:53 2023
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# input definitons
#
-# $Id: inputtags.pm,v 1.358 2023/04/02 03:16:28 raeburn Exp $
+# $Id: inputtags.pm,v 1.359 2023/09/10 18:12:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -450,6 +450,7 @@
if ($addchars) {
$result.=&addchars('HWVAL_'.$id,$addchars);
}
+ my $numrespclass;
my $readonly=&Apache::lonxml::get_param('readonly',$parstack,
$safeeval);
if (lc($readonly) eq 'yes'
@@ -457,6 +458,10 @@
$readonly=' readonly="readonly" ';
} else {
$readonly='';
+ if (($Apache::inputtags::status['-1'] eq 'CAN_ANSWER') &&
+ ($tagstack->[-2] eq 'numericalresponse')) {
+ $numrespclass = ' LC_numresponse_text';
+ }
}
my $name = 'HWVAL_'.$id;
my $itemid = 'HWVAL_'.$partid.'_'.$id;
@@ -470,7 +475,7 @@
. ' type="text" '.$readonly.' name="'. $name . '"'
. ' id="' . $input_tag_id . '"'
. ' value="'. $oldresponse.'"'
- . ' class="LC_textline spellchecked" size="'.$size.'"'.$maxlength.' />';
+ . ' class="LC_textline spellchecked'.$numrespclass.'" size="'.$size.'"'.$maxlength.' />';
$result .= &spellcheck_onblur($itemid, $spellcheck);
if (($Apache::inputtags::status['-1'] eq 'CAN_ANSWER') &&
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.577 loncom/homework/structuretags.pm:1.578
--- loncom/homework/structuretags.pm:1.577 Wed Jul 12 17:43:24 2023
+++ loncom/homework/structuretags.pm Sun Sep 10 18:12:53 2023
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.577 2023/07/12 17:43:24 raeburn Exp $
+# $Id: structuretags.pm,v 1.578 2023/09/10 18:12:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2373,7 +2373,8 @@
# computation:
#
if ($target eq 'web') {
- $result .= &Apache::lonhtmlcommon::set_compute_end_time();
+ $result .= &Apache::lonhtmlcommon::dash_to_minus_js().
+ &Apache::lonhtmlcommon::set_compute_end_time();
#
# Closing tags delayed so any <script></script> tags
# not in head can appear inside body, for valid xhtml.
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.408 loncom/interface/lonhtmlcommon.pm:1.409
--- loncom/interface/lonhtmlcommon.pm:1.408 Thu Oct 27 20:08:16 2022
+++ loncom/interface/lonhtmlcommon.pm Sun Sep 10 18:12:54 2023
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.408 2022/10/27 20:08:16 raeburn Exp $
+# $Id: lonhtmlcommon.pm,v 1.409 2023/09/10 18:12:54 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1813,6 +1813,48 @@
END
}
+##
+# Client-side javascript to convert any dashes in text pasted
+# into textbox(es) for numericalresponse item(s) to a standard
+# minus, i.e., - . Calls to dash_to_minus_js() in end_problem()
+# and in loncommon::endbodytag() for a .page (arg: dashjs => 1)
+#
+# Will apply to any input tag with class: LC_numresponse_text.
+# Currently set in start_textline for numericalresponse items.
+#
+
+sub dash_to_minus_js {
+ return <<'ENDJS';
+
+<script type="text/javascript">
+//<![CDATA[
+//<!-- BEGIN LON-CAPA Internal
+document.addEventListener("DOMContentLoaded", (event) => {
+ const numresp = document.querySelectorAll("input.LC_numresponse_text");
+ if (numresp.length > 0) {
+ numresp.forEach((el) => {
+ el.addEventListener("paste", (e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ let p = (e.clipboardData || window.clipboardData).getData("text");
+ p.toString();
+ p = p.replace(/\p{Dash}/gu, '-');
+ putInText(p);
+ });
+ });
+ }
+ const putInText = (newText, el = document.activeElement) => {
+ const [start, end] = [el.selectionStart, el.selectionEnd];
+ el.setRangeText(newText, start, end, 'end');
+ }
+});
+// END LON-CAPA Internal -->
+//]]>
+</script>
+
+ENDJS
+}
+
############################################################
############################################################
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1410 loncom/interface/loncommon.pm:1.1411
--- loncom/interface/loncommon.pm:1.1410 Thu Jul 6 17:16:35 2023
+++ loncom/interface/loncommon.pm Sun Sep 10 18:12:54 2023
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1410 2023/07/06 17:16:35 raeburn Exp $
+# $Id: loncommon.pm,v 1.1411 2023/09/10 18:12:54 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -6849,6 +6849,9 @@
$endbodytag;
}
}
+ if ((ref($args) eq 'HASH') && ($args->{'dashjs'})) {
+ $endbodytag = &Apache::lonhtmlcommon::dash_to_minus_js().$endbodytag;
+ }
return $endbodytag;
}
Index: rat/lonpage.pm
diff -u rat/lonpage.pm:1.142 rat/lonpage.pm:1.143
--- rat/lonpage.pm:1.142 Tue Oct 4 20:39:57 2022
+++ rat/lonpage.pm Sun Sep 10 18:12:55 2023
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Page Handler
#
-# $Id: lonpage.pm,v 1.142 2022/10/04 20:39:57 raeburn Exp $
+# $Id: lonpage.pm,v 1.143 2023/09/10 18:12:55 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -268,6 +268,7 @@
my $nforms=0;
my $nuploads=0;
my $ntimers=0;
+ my $hasnumresp;
my %turninpaths;
my %multiresps;
my $turninparent;
@@ -512,6 +513,11 @@
$ntimers++;
$hastimer = 1;
}
+ unless ($hasnumresp) {
+ if ($output=~/\<input[^\>]+class\s*=\s*[\'\"]*([^\'\"\>]+|)LC_numresponse_text/) {
+ $hasnumresp = 1;
+ }
+ }
$output=~
s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
$output=~
@@ -953,8 +959,11 @@
&mt('Processing your submission ...').'</div></form>');
}
unless (($target eq 'tex') || ($target eq 'tex_answer')) {
- $r->print(&Apache::loncommon::end_page({'discussion'
- => 1,}));
+ my $args = {'discussion' => 1};
+ if ($hasnumresp) {
+ $args->{'dashjs'} = 1;
+ }
+ $r->print(&Apache::loncommon::end_page($args));
} else {
$r->print('\end{document}'.$number_of_columns);
}
More information about the LON-CAPA-cvs
mailing list