--- loncom/interface/lonhtmlcommon.pm 2018/09/09 21:16:34 1.358.2.14
+++ loncom/interface/lonhtmlcommon.pm 2023/09/11 14:13:31 1.358.2.20
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.358.2.14 2018/09/09 21:16:34 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 @@ 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';
+
+
+
+ENDJS
+}
+
############################################################
############################################################
@@ -2110,11 +2152,11 @@ sub docs_breadcrumbs {
my $foldername=shift(@folders);
if ($folderpath) {$folderpath.='&';}
$folderpath.=$folder.'&'.$foldername;
- my $url;
+ my $url = $env{'request.use_absolute'};
if ($allowed) {
- $url = '/adm/coursedocs?folderpath=';
+ $url .= '/adm/coursedocs?folderpath=';
} else {
- $url = '/adm/supplemental?folderpath=';
+ $url .= '/adm/supplemental?folderpath=';
}
$url .= &escape($folderpath);
my $name=&unescape($foldername);
@@ -2539,9 +2581,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 = '
';
}
if ($symb) {
@@ -2570,7 +2612,7 @@ sub resource_info_box {
} else {
$return='
'.&mt('No context provided.').'
';
}
- if ($stuvcurrent ne '') {
+ if (($stuvcurrent ne '') || ($divforres)) {
$return .= '
';
}
return $return;
@@ -3301,12 +3343,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;
@@ -3386,7 +3434,17 @@ function go(url) {
if (url!='' && url!= null) {
currentURL = null;
currentSymb= null;
- window.location.href=url;
+ var lcHostname = setLCHost();
+ if (lcHostname!='' && lcHostname!= null) {
+ var RegExp = /^https?\:/;
+ if (RegExp.test(url)) {
+ window.location.href=url;
+ } else {
+ window.location.href=lcHostname+url;
+ }
+ } else {
+ window.location.href=url;
+ }
}
}
@@ -3405,8 +3463,8 @@ ENDUTILITY
sub jump_to_editres {
my ($cfile,$home,$switchserver,$forceedit,$forcereg,$symb,$folderpath,
- $title,$idx,$suppurl,$todocs,$suppanchor) = @_;
- my ($jscall,$anchor);
+ $title,$hostname,$idx,$suppurl,$todocs,$suppanchor) = @_;
+ my ($jscall,$anchor,$usehttp,$usehttps,$is_ext);
if ($switchserver) {
if ($home) {
$cfile = '/adm/switchserver?otherserver='.$home.'&role='.
@@ -3426,9 +3484,37 @@ sub jump_to_editres {
}
} else {
unless ($cfile =~ m{^/priv/}) {
- if ($cfile =~ m{^(/adm/wrapper/ext/[^#]+)#([^#]+)$}) {
+ if ($cfile =~ m{^(/adm/wrapper/ext/([^#]+))(?:|#([^#]+))$}) {
$cfile = $1;
- $anchor = $2;
+ my $extlink = $2;
+ $anchor = $3;
+ $is_ext = 1;
+ if (($extlink !~ /^https:/) && ($ENV{'SERVER_PORT'} == 443)) {
+ unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
+ $usehttp = 1;
+ }
+ } elsif ($env{'request.use_absolute'}) {
+ if ($env{'request.use_absolute'} =~ m{^https://}) {
+ $usehttps = 1;
+ }
+ }
+ } elsif ($cfile =~ m{^/?public/($match_domain)/($match_courseid)/syllabus}) {
+ if ($ENV{'SERVER_PORT'} == 443) {
+ my ($cdom,$cnum) = ($1,$2);
+ if (($env{'request.course.id'}) &&
+ ($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()) || (&Apache::lonnet::waf_allssl($hostname))) {
+ $usehttp = 1;
+ }
+ }
+ }
+ } elsif ($env{'request.use_absolute'}) {
+ if ($env{'request.use_absolute'} =~ m{^https://}) {
+ $usehttps = 1;
+ }
+ }
}
if ($symb) {
if ($anchor ne '') {
@@ -3454,6 +3540,16 @@ sub jump_to_editres {
}
if ($forceedit) {
$cfile .= (($cfile=~/\?/)?'&':'?').'forceedit=1';
+ if ($usehttps) {
+ $cfile = $env{'request.use_absolute'}.(($cfile =~ /^\//)? '':'/').$cfile;
+ }
+ } elsif ($usehttp) {
+ if ($hostname ne '') {
+ $cfile = 'http://'.$hostname.(($cfile =~ /^\//)? '':'/').$cfile;
+ }
+ $cfile .= (($cfile=~/\?/)?'&':'?').'usehttp=1';
+ } elsif ($usehttps) {
+ $cfile = $env{'request.use_absolute'}.(($cfile =~ /^\//)? '':'/').$cfile;
}
if ($forcereg) {
$cfile .= (($cfile=~/\?/)?'&':'?').'register=1';
@@ -3480,15 +3576,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})(\\]?)$"; //"