[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
raeburn
raeburn at source.lon-capa.org
Wed Jun 15 13:20:45 EDT 2016
raeburn Wed Jun 15 17:20:45 2016 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
- Improvements in &linked_select_forms() routine.
- Support multiple calls to this routine when more than one pair of linked
select boxes is in use in a web page.
- Support special characters, e.g., - or white space in option names.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1244 loncom/interface/loncommon.pm:1.1245
--- loncom/interface/loncommon.pm:1.1244 Wed May 18 03:21:15 2016
+++ loncom/interface/loncommon.pm Wed Jun 15 17:20:44 2016
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1244 2016/05/18 03:21:15 raeburn Exp $
+# $Id: loncommon.pm,v 1.1245 2016/06/15 17:20:44 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1094,6 +1094,9 @@
=item * $onchangesecond, additional javascript call to execute for an onchange
event for the second <select> tag
+=item * $suffix, to differentiate separate uses of select2data javascript
+ objects in a page.
+
=back
Below is an example of such a hash. Only the 'text', 'default', and
@@ -1148,7 +1151,8 @@
$hashref,
$menuorder,
$onchangefirst,
- $onchangesecond
+ $onchangesecond,
+ $suffix
) = @_;
my $second = "document.$formname.$secondselectname";
my $first = "document.$formname.$firstselectname";
@@ -1156,20 +1160,20 @@
my $result = '';
$result.='<script type="text/javascript" language="JavaScript">'."\n";
$result.="// <![CDATA[\n";
- $result.="var select2data = new Object();\n";
+ $result.="var select2data${suffix} = new Object();\n";
$" = '","';
my $debug = '';
foreach my $s1 (sort(keys(%$hashref))) {
- $result.="select2data.d_$s1 = new Object();\n";
- $result.="select2data.d_$s1.def = new String('".
+ $result.="select2data${suffix}['d_$s1'] = new Object();\n";
+ $result.="select2data${suffix}['d_$s1'].def = new String('".
$hashref->{$s1}->{'default'}."');\n";
- $result.="select2data.d_$s1.values = new Array(";
+ $result.="select2data${suffix}['d_$s1'].values = new Array(";
my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
@s2values = @{$hashref->{$s1}->{'order'}};
}
$result.="\"@s2values\");\n";
- $result.="select2data.d_$s1.texts = new Array(";
+ $result.="select2data${suffix}['d_$s1'].texts = new Array(";
my @s2texts;
foreach my $value (@s2values) {
push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
@@ -1179,19 +1183,17 @@
$"=' ';
$result.= <<"END";
-function select1_changed() {
+function select1${suffix}_changed() {
// Determine new choice
- var newvalue = "d_" + $first.value;
+ var newvalue = "d_" + $first.options[$first.selectedIndex].value;
// update select2
- var values = select2data[newvalue].values;
- var texts = select2data[newvalue].texts;
- var select2def = select2data[newvalue].def;
+ var values = select2data${suffix}[newvalue].values;
+ var texts = select2data${suffix}[newvalue].texts;
+ var select2def = select2data${suffix}[newvalue].def;
var i;
// out with the old
- for (i = 0; i < $second.options.length; i++) {
- $second.options[i] = null;
- }
- // in with the nuclear
+ $second.options.length = 0;
+ // in with the new
for (i=0;i<values.length; i++) {
$second.options[i] = new Option(values[i]);
$second.options[i].value = values[i];
@@ -1205,7 +1207,7 @@
</script>
END
# output the initial values for the selection lists
- $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
+ $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
my @order = sort(keys(%{$hashref}));
if (ref($menuorder) eq 'ARRAY') {
@order = @{$menuorder};
@@ -5438,6 +5440,7 @@
.$lastitem
.'</span>';
}
+
$output .=
'<br />'
#FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
More information about the LON-CAPA-cvs
mailing list