--- loncom/interface/lonhtmlcommon.pm 2022/05/30 14:03:14 1.358.2.19.2.2
+++ loncom/interface/lonhtmlcommon.pm 2021/06/07 06:15:55 1.399
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.358.2.19.2.2 2022/05/30 14:03:14 raeburn Exp $
+# $Id: lonhtmlcommon.pm,v 1.399 2021/06/07 06:15:55 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -78,11 +78,11 @@ sub java_not_enabled {
sub coursepreflink {
my ($text,$category)=@_;
if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
- my $target =' target="_top"';
- if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
- $target = '';
- }
- return '&"').'">'.$text.'';
+ my $target =' target="_top"';
+ if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
+ $target ='';
+ }
+ return '&"').'">'.$text.'';
} else {
return '';
}
@@ -106,12 +106,12 @@ sub direct_parm_link {
$part=&entity_encode($part);
if (($symb) && (&Apache::lonnet::allowed('opa')) && ($target ne 'tex')) {
my $target=' target="_top"';
- if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
- $target = '';
+ if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
+ $target='';
}
- return "$linktext";
+ return "$linktext";
} else {
- return $linktext;
+ return $linktext;
}
}
##############################################
@@ -459,10 +459,12 @@ sub radio {
&date_setter returns html and javascript for a compact date-setting form.
To retrieve values from it, use &get_date_from_form.
-Inputs
-
=over 4
+=item Inputs
+
+=over
+
=item $dname
The name to prepend to the form elements.
@@ -523,10 +525,12 @@ If true, text boxes for seconds are omit
=back
-Bugs
+=item Bugs
The method used to restrict user input will fail in the year 2400.
+=back
+
=cut
##############################################
@@ -693,11 +697,13 @@ ENDJS
$monthselector,$dayselector,$yearselector,
$hourselector).
$tzone;
+
} elsif ($no_ss) {
$result .= &mt('[_1] [_2] [_3] [_4] [_5]m',
$monthselector,$dayselector,$yearselector,
$hourselector,$minuteselector).
$tzone;
+
} else {
$result .= &mt('[_1] [_2] [_3] [_4] [_5]m [_6]s ',
$monthselector,$dayselector,$yearselector,
@@ -749,7 +755,9 @@ sub build_url {
get_date_from_form retrieves the date specified in an &date_setter form.
-Inputs:
+=over
+
+=item Inputs:
=over 4
@@ -763,6 +771,8 @@ The unix time to use as the default in c
=back
+=back
+
Returns: Unix time represented in the form.
=cut
@@ -935,7 +945,9 @@ sub javascript_docopen {
Returns html for a selection box which allows the user to choose the
enrollment status of students. The selection box name is 'Status'.
-Inputs:
+=over
+
+=item Inputs:
$status: the currently selected status. If undefined the value of
$env{'form.Status'} is taken. If that is undefined, a value of 'Active'
@@ -949,6 +961,8 @@ $size: the size (number of lines) of the
$onchange: javascript to use when the value is changed. Enclosed in
double quotes, ""s, not single quotes.
+=back
+
Returns: a perl string as described.
=cut
@@ -996,7 +1010,7 @@ sub StatusOptions {
=pod
-=item Progess Window Handling Routines
+=item Progress Window Handling Routines
These routines handle the creation, update, increment, and closure of
progress windows. The progress window reports to the user the number
@@ -1010,9 +1024,11 @@ of items completed and an estimate of th
Writes javascript to the client to open a progress window and returns a
data structure used for bookkeeping.
-Inputs
+=over
-=over 4
+=item Inputs
+
+=over
=item $r Apache request
@@ -1022,6 +1038,8 @@ Inputs
=back
+=back
+
Returns a hash containing the progress state data structure.
If $number_to_do is zero or null, an indeterminate progress bar will
be used.
@@ -1031,7 +1049,9 @@ be used.
Updates the text in the progress indicator. Does not increment the count.
See &Increment_PrgWin.
-Inputs:
+=over
+
+=item Inputs:
=over 4
@@ -1043,25 +1063,38 @@ Inputs:
=back
+=back
+
Returns: none
-=item Increment_PrgWin()
+=item &Increment_PrgWin()
Increment the count of items completed for the progress window by $step or 1 if no step is provided.
-Inputs:
+=over
+
+=item Inputs:
=over 4
-=item $r Apache request
+=item $r
-=item $prog_state Pointer to the data structure returned by Create_PrgWin
+Apache request
+
+=item $prog_state
+
+Pointer to the data structure returned by Create_PrgWin
+
+=item $extraInfo
+
+A description of the items being iterated over. Typically 'student'.
-=item $extraInfo A description of the items being iterated over. Typically
-'student'.
+=item $step
-=item $step (optional) counter step. Will be set to default 1 if ommited. step must be greater than 0 or empty.
+(optional) counter step. Will be set to default 1 if ommited. step must be greater than 0 or empty.
+
+=back
=back
@@ -1072,7 +1105,9 @@ Returns: none
Closes the progress window.
-Inputs:
+=over
+
+=item Inputs:
=over 4
@@ -1082,6 +1117,8 @@ Inputs:
=back
+=back
+
Returns: none
=back
@@ -1316,6 +1353,68 @@ $(document).ready(function(){
});';
}
+sub countdown {
+
+ # Code to put a due date countdown in 'duedatecountdown' span.
+ # This is currently located in the breadcrumb headers.
+ # note that the dueDateLayout is internatinoalized below.
+ # Here document is used to support the substitution into the javascript below.
+ # ..which unforunately necessitates escaping the $'s in the javascript.
+ # There are several times of importance
+ #
+ # serverDueDate - The absolute time at which the problem expires.
+ # serverTime - The server's time when the problem finished computing.
+ # clientTime - The client's time...as close to serverTime as possible.
+ # The clientTime will be slightly later due to
+ # 1. The latency between problem computation and
+ # the first network action.
+ # 2. The time required between the page load-start and the actual
+ # initial javascript execution that got clientTime.
+ # These are used as follows:
+ # The difference between clientTime and serverTime are used to
+ # correct for differences in clock settings between the browser's system and the
+ # server's.
+ #
+ # The difference between clientTime and the time at which the ready() method
+ # starts executing is used to estimate latencies for page load and submission.
+ # Since this is an estimate, it is doubled. The latency estimate + one minute
+ # is used to determine when the countdown timer turns red to warn the user
+ # to think about submitting.
+
+
+ my $dueDateLayout = &mt('Due in: {dn} {dl} {hnn}{sep}{mnn}{sep}{snn} [_1]',
+ "");
+ my $early = '- '.&mt('Submit Early').'';
+ my $pastdue = '- '.&mt('Past Due').'';
+ return <<"JAVASCRIPT";
+
+ var documentReadyTime;
+
+\$(document).ready(function() {
+ if (typeof(dueDate) != "undefined") {
+ documentReadyTime = (new Date()).getTime();
+ \$("#duedatecountdown").countdown({until: dueDate, compact: true,
+ layout: "$dueDateLayout",
+ onTick: function (periods) {
+ var latencyEstimate = (documentReadyTime - clientTime) * 2;
+ if(\$.countdown.periodsToSeconds(periods) < (300 + latencyEstimate)) {
+ \$("#submitearly").html("$early");
+ if (\$.countdown.periodsToSeconds(periods) < 1) {
+ \$("#submitearly").html("$pastdue");
+ }
+ }
+ if(\$.countdown.periodsToSeconds(periods) < (60 + latencyEstimate)) {
+ \$(this).css("color", "red"); //Highlight last minute.
+ }
+ }
+ });
+ }
+});
+
+JAVASCRIPT
+
+}
+
# ----------------------------------------- Script to activate only some fields
sub htmlareaselectactive {
@@ -1539,62 +1638,11 @@ sub htmlareaselectactive {
});
';
- $output .= &color_picker;
-
- # Code to put a due date countdown in 'duedatecountdown' span.
- # This is currently located in the breadcrumb headers.
- # note that the dueDateLayout is internatinoalized below.
- # Here document is used to support the substitution into the javascript below.
- # ..which unforunately necessitates escaping the $'s in the javascript.
- # There are several times of importance
- #
- # serverDueDate - The absolute time at which the problem expires.
- # serverTime - The server's time when the problem finished computing.
- # clientTime - The client's time...as close to serverTime as possible.
- # The clientTime will be slightly later due to
- # 1. The latency between problem computation and
- # the first network action.
- # 2. The time required between the page load-start and the actual
- # initial javascript execution that got clientTime.
- # These are used as follows:
- # The difference between clientTime and serverTime are used to
- # correct for differences in clock settings between the browser's system and the
- # server's.
- #
- # The difference between clientTime and the time at which the ready() method
- # starts executing is used to estimate latencies for page load and submission.
- # Since this is an estimate, it is doubled. The latency estimate + one minute
- # is used to determine when the countdown timer turns red to warn the user
- # to think about submitting.
+ $output .= &color_picker();
- my $dueDateLayout = &mt('Due in: {dn} {dl} {hnn}{sep}{mnn}{sep}{snn} [_1]',
- "");
- my $early = '- '.&mt('Submit Early').'';
- my $pastdue = '- '.&mt('Past Due').'';
- $output .= <'/adm/menu',
title =>'Go to main menu',
@@ -1887,8 +1968,11 @@ returns: nothing
title => &mt('Back to most recent content resource'),
class => 'LC_menubuttons_link',
};
- if ($links_target) {
- $hashref->{'target'} = $links_target;
+ if ($env{'request.noversionuri'} eq '/adm/searchcat') {
+ $hashref->{'target'} = '_top';
+ if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
+ $hashref->{'target'} = '';
+ }
}
$links=&htmltag( 'a','',
$hashref);
@@ -1939,12 +2023,11 @@ returns: nothing
if ($faq ne '' || $component_help ne '' || $bug ne '') {
$icons .= &Apache::loncommon::help_open_menu($component,
$component_help,
- $faq,$bug,'','','','',
- $links_target);
+ $faq,$bug);
}
if ($topic_help && $topic_help_text) {
$icons .= ' '.&Apache::loncommon::help_open_topic($topic_help,&mt($topic_help_text),'',
- undef,600,'',$links_target);
+ undef,600);
}
#
@@ -2013,7 +2096,9 @@ Adds $html to $category of the breadcrum
$html is usually a link to a page that invokes a function on the currently
displayed data (e.g. print when viewing a problem)
-Currently there are 3 possible values for $category:
+=over
+
+=item Currently there are 3 possible values for $category:
=over
@@ -2027,7 +2112,9 @@ remaining items in right of breadcrumbs
advanced tools shown in a separate box below breadcrumbs line
=back
-
+
+=back
+
returns: nothing
=cut
@@ -2076,8 +2163,17 @@ returns: a hash containing the current b
Creates html for breadcrumb tools (categories navigation and tools) and inserts
\$breadcrumbs at the correct position.
-input: \$breadcrumbs - a reference to the string containing prepared
-breadcrumbs.
+=over
+
+=item input:
+
+=over
+
+=item \$breadcrumbs - a reference to the string containing prepared breadcrumbs.
+
+=back
+
+=back
returns: nothing
@@ -2103,8 +2199,17 @@ returns: nothing
Creates html for advanced tools (category advtools) and inserts \$breadcrumbs
at the correct position.
-input: \$breadcrumbs - a reference to the string containing prepared
-breadcrumbs (after render_tools call).
+=over
+
+=item input:
+
+=over
+
+=item \$breadcrumbs - a reference to the string containing prepared breadcrumbs (after render_tools call).
+
+=back
+
+=back
returns: nothing
@@ -3328,18 +3433,12 @@ PARAMSONE
if (itemid != null) {
itemh = itemid.offsetHeight;
}
- var primaryheight = 0;
- if (document.getElementById('LC_nav_bar') != null) {
- primaryheight = document.getElementById('LC_nav_bar').offsetHeight;
- }
- var secondaryheight = 0;
+ var primaryheight = document.getElementById('LC_nav_bar').offsetHeight;
+ var secondaryheight;
if (document.getElementById('LC_secondary_menu') != null) {
secondaryheight = document.getElementById('LC_secondary_menu').offsetHeight;
}
- var crumbsheight = 0;
- if (document.getElementById('LC_breadcrumbs') != null) {
- crumbsheight = document.getElementById('LC_breadcrumbs').offsetHeight;
- }
+ var crumbsheight = document.getElementById('LC_breadcrumbs').offsetHeight;
var dccidheight = 0;
if (document.getElementById('dccid') != null) {
dccidheight = document.getElementById('dccid').offsetHeight;
@@ -3482,7 +3581,7 @@ sub jump_to_editres {
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);
@@ -3682,7 +3781,9 @@ sub scripttag {
Constructs a XHTML list from \@array.
-input:
+=over
+
+=item input:
=over
@@ -3696,7 +3797,9 @@ Attributes for and - passed in a
See htmltag() for more details.
=back
-
+
+=back
+
returns: XHTML list as String.
=cut
@@ -3815,13 +3918,19 @@ should be included in this list.
If the optional headline text is not provided, a default text will be used.
+=over
+
+=item Related routines:
-Related routines:
=over 4
-add_item_funclist
-end_funclist
+
+=item add_item_funclist
+
+=item end_funclist
+
=back
+=back
Inputs: (optional) headline text
@@ -3848,10 +3957,18 @@ sub start_funclist {
Adds an item to the list of available functions
-Related routines:
+=over
+
+=item Related routines:
+
=over 4
-start_funclist
-end_funclist
+
+=item start_funclist
+
+=item end_funclist
+
+=back
+
=back
Inputs: content item with text and link to function
@@ -3874,10 +3991,13 @@ sub add_item_funclist {
End list of available functions
-Related routines:
-=over 4
-start_funclist
-add_item_funclist
+=over
+
+=item Related routines:
+
+ start_funclist
+ add_item_funclist
+
=back
Inputs: ./.
@@ -3910,7 +4030,7 @@ A string that's used as visually highlig
it's value evaluates to false.
=back
-
+
returns: XHTML list as string.
=back
@@ -3923,7 +4043,7 @@ sub funclist_from_array {
$args->{legend} ||= mt('Functions');
return list_from_array( [$args->{legend}, @$items],
{ listattr => {class => 'LC_funclist'} });
-}
+}
=pod
@@ -3945,8 +4065,8 @@ e.g. a file operation in Authoring Space
A reference to the array containing text. Details: sub funclist_from_array
=back
-
-Returns: XHTML div as string.
+
+Returns: XHTML div as string.
=back