[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface lonhtmlcommon.pm

raeburn raeburn at source.lon-capa.org
Mon Sep 11 10:13:31 EDT 2023


raeburn		Mon Sep 11 14:13:31 2023 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	lonhtmlcommon.pm 
  Log:
  - For 2.11
    Backport 1.409
  
  
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.358.2.19 loncom/interface/lonhtmlcommon.pm:1.358.2.20
--- loncom/interface/lonhtmlcommon.pm:1.358.2.19	Mon Dec 13 22:03:32 2021
+++ loncom/interface/lonhtmlcommon.pm	Mon Sep 11 14:13:31 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.358.2.19 2021/12/13 22:03:32 raeburn Exp $
+# $Id: lonhtmlcommon.pm,v 1.358.2.20 2023/09/11 14:13:31 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1753,6 +1753,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
+}
+
 ############################################################
 ############################################################
 




More information about the LON-CAPA-cvs mailing list