--- loncom/interface/lonhtmlcommon.pm 2019/07/27 00:38:33 1.358.2.15 +++ loncom/interface/lonhtmlcommon.pm 2024/07/02 02:29:13 1.358.2.21 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.358.2.15 2019/07/27 00:38:33 raeburn Exp $ +# $Id: lonhtmlcommon.pm,v 1.358.2.21 2024/07/02 02:29:13 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1268,9 +1268,9 @@ sub htmlareaheaders { ENDEDITOR } $s.=(<<ENDJQUERY); -<script type="text/javascript" src="/adm/jQuery/js/jquery-3.2.1.min.js"></script> -<script type="text/javascript" src="/adm/jQuery/js/jquery-ui-1.12.1.custom.min.js"></script> -<link rel="stylesheet" type="text/css" href="/adm/jQuery/css/smoothness/jquery-ui-1.12.1.custom.min.css" /> +<script type="text/javascript" src="/adm/jQuery/js/jquery-3.7.1.min.js"></script> +<script type="text/javascript" src="/adm/jQuery/js/jquery-ui-1.13.3.custom.min.js"></script> +<link rel="stylesheet" type="text/css" href="/adm/jQuery/css/smoothness/jquery-ui-1.13.3.custom.min.css" /> <script type="text/javascript" src="/adm/jpicker/js/jpicker-1.1.6.min.js" > </script> <link rel="stylesheet" type="text/css" href="/adm/jpicker/css/jPicker-1.1.6.min.css" /> @@ -1680,7 +1680,7 @@ sub show_return_link { $env{'request.uri'}=~m{^/priv/}) { return 1; } return if ($env{'request.noversionuri'} eq '/adm/supplemental'); - if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)}) + if (($env{'request.noversionuri'} =~ m{^/adm/viewclasslist($|\?)}) || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) { return if ($env{'form.register'}); @@ -1753,6 +1753,54 @@ clientTime = (new Date()).getTime(); 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) { + Array.from(numresp).forEach((el) => { + el.addEventListener("paste", (e) => { + e.preventDefault(); + e.stopPropagation(); + let p = (e.clipboardData || window.clipboardData).getData("text"); + p.toString(); + var regex; + try + { + regex = new RegExp ("\\p{Dash}", "gu"); + } + catch (e) { regex = new RegExp ("[\\u058A\\u05BE\\u1400\\u1806\\u2010-\\u2015\\u2E3A\\u2E3B\\u2E5D\\u301C\\uFE58\\uFE63\\uFF0D]","g"); } + p = p.replace(regex,'-'); + 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 +} + ############################################################ ############################################################ @@ -2539,9 +2587,9 @@ sub course_custom_roles { sub resource_info_box { - my ($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp)=@_; + my ($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp,$divforres)=@_; my $return=''; - if ($stuvcurrent ne '') { + if (($stuvcurrent ne '') || ($divforres)) { $return = '<div class="LC_left_float">'; } if ($symb) { @@ -2570,7 +2618,7 @@ sub resource_info_box { } else { $return='<p><span class="LC_error">'.&mt('No context provided.').'</span></p>'; } - if ($stuvcurrent ne '') { + if (($stuvcurrent ne '') || ($divforres)) { $return .= '</div>'; } return $return; @@ -3301,12 +3349,18 @@ PARAMSONE if (itemid != null) { itemh = itemid.offsetHeight; } - var primaryheight = document.getElementById('LC_nav_bar').offsetHeight; - var secondaryheight; + var primaryheight = 0; + if (document.getElementById('LC_nav_bar') != null) { + primaryheight = document.getElementById('LC_nav_bar').offsetHeight; + } + var secondaryheight = 0; if (document.getElementById('LC_secondary_menu') != null) { secondaryheight = document.getElementById('LC_secondary_menu').offsetHeight; } - var crumbsheight = document.getElementById('LC_breadcrumbs').offsetHeight; + var crumbsheight = 0; + if (document.getElementById('LC_breadcrumbs') != null) { + crumbsheight = document.getElementById('LC_breadcrumbs').offsetHeight; + } var dccidheight = 0; if (document.getElementById('dccid') != null) { dccidheight = document.getElementById('dccid').offsetHeight; @@ -3415,7 +3469,7 @@ ENDUTILITY sub jump_to_editres { my ($cfile,$home,$switchserver,$forceedit,$forcereg,$symb,$folderpath, - $title,$idx,$suppurl,$todocs,$suppanchor) = @_; + $title,$hostname,$idx,$suppurl,$todocs,$suppanchor) = @_; my ($jscall,$anchor,$usehttp,$usehttps,$is_ext); if ($switchserver) { if ($home) { @@ -3442,7 +3496,7 @@ sub jump_to_editres { $anchor = $3; $is_ext = 1; if (($extlink !~ /^https:/) && ($ENV{'SERVER_PORT'} == 443)) { - unless (&Apache::lonnet::uses_sts()) { + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) { $usehttp = 1; } } elsif ($env{'request.use_absolute'}) { @@ -3457,7 +3511,7 @@ sub jump_to_editres { ($env{'course.'.$env{'request.course.id'}.'.num'} eq $cnum) && ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $cdom)) { if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) { - unless (&Apache::lonnet::uses_sts()) { + unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) { $usehttp = 1; } } @@ -3528,15 +3582,18 @@ sub jump_to_editres { # javascript_valid_email # # Generates javascript to validate an e-mail address. -# Returns a javascript function which accetps a form field as argumnent, and +# Returns a javascript function which accepts a form field as argument, and # returns false if field.value does not satisfy two regular expression matches # for a valid e-mail address. Backwards compatible with old browsers without # support for javascript RegExp (just checks for @ in field.value in this case). sub javascript_valid_email { my $scripttag .= <<'END'; -function validmail(field) { +function validmail(field,suffix) { var str = field.value; + if (suffix != '' && suffix != undefined) { + str += suffix; + } if (window.RegExp) { var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)"; var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"