[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonspeller.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 24 Mar 2006 21:40:12 -0000


albertel		Fri Mar 24 16:40:12 2006 EDT

  Modified files:              
    /loncom/interface	lonspeller.pm loncommon.pm 
  Log:
  - making the speller popup use a dynamically defined function rather than packing everything into the link URL (ie has a limit on href cvalues of 512 characters or something)
  - html_encode was supposeed to do <>& too
  - Firefox in standards compliance mode thinks that any instance of </script> means to end that last script so fooling it with making </script> in the script be '....</script'+'>....'
  
  
  
Index: loncom/interface/lonspeller.pm
diff -u loncom/interface/lonspeller.pm:1.15 loncom/interface/lonspeller.pm:1.16
--- loncom/interface/lonspeller.pm:1.15	Thu Mar 23 18:43:13 2006
+++ loncom/interface/lonspeller.pm	Fri Mar 24 16:40:11 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Interface routines for Aspell
 #
-# $Id: lonspeller.pm,v 1.15 2006/03/23 23:43:13 albertel Exp $
+# $Id: lonspeller.pm,v 1.16 2006/03/24 21:40:11 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -54,6 +54,13 @@
     $speller->set_option('lang',$lang);
 }
 
+{
+    my $uniq;
+    sub get_uniq {
+	return ++$uniq;
+    }
+}
+
 sub textsection {
     my $input=shift;
     my $output='';
@@ -64,22 +71,29 @@
 	    $output.=$word;
 	} else {
 	    my $suggestions=join(' ',$speller->suggest($word));
-	    $suggestions=~s/\'/\\\'/gs;
+	    $suggestions = "<script>alert('sug')</script>".$suggestions;
+	    $suggestions = &Apache::loncommon::js_ready($suggestions);
 	    if (($suggestions) && (!$insidelink)) {
 		my $start_page=
 		    &Apache::loncommon::start_page('Speller Suggestions',undef,
 						   {'only_body'   => 1,
 						    'js_ready'    => 1,
-						    'html_encode' => 1,
 						    'bgcolor'     => '#FFFFFF'});
 		my $end_page=
-		    &Apache::loncommon::end_page({'js_ready'    => 1,
-						  'html_encode' => 1,});
-		$output.='<a href="javascript:spellwin=window.open('.
-		    &Apache::lonhtmlcommon::javascript_nothing().
-		    ',\'spellwin\',\'height=140,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no\');'.
-                    'spellwin.'.&Apache::lonhtmlcommon::javascript_docopen().';spellwin.document.writeln(\''.$start_page.'<h3>'.$word.
-                    '</h3>'.$suggestions.$end_page.'\');spellwin.document.close();spellwin.focus()">';
+		    &Apache::loncommon::end_page({'js_ready'    => 1,});
+		my $num = &get_uniq();
+		my $info  ='<h3>'.$word.'</h3>'.$suggestions;
+		$output .= "<script type=\"text/javascript\">
+//<!--
+ function LONCAPA_lonspeller_$num() {
+    spellwin=open(".&Apache::lonhtmlcommon::javascript_nothing().",'spellwin','width=140,height=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
+    spellwin.".&Apache::lonhtmlcommon::javascript_docopen().";
+    spellwin.document.writeln('$start_page $info $end_page');
+    spellwin.document.close();
+    spellwin.focus();
+}
+//-->
+</script><a href=\"javascript:LONCAPA_lonspeller_$num();void(0);\">";
 	    }
 	    $output.='<font color="red">'.$word.'</font>';
 	    if (($suggestions) && (!$insidelink)) { $output.='</a>'; }
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.321 loncom/interface/loncommon.pm:1.322
--- loncom/interface/loncommon.pm:1.321	Fri Mar 24 13:09:27 2006
+++ loncom/interface/loncommon.pm	Fri Mar 24 16:40:11 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.321 2006/03/24 18:09:27 albertel Exp $
+# $Id: loncommon.pm,v 1.322 2006/03/24 21:40:11 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3150,7 +3150,7 @@
 sub html_encode {
     my ($result) = @_;
 
-    $result = &HTML::Entities::encode($result,'"');
+    $result = &HTML::Entities::encode($result,'<>&"');
     
     return $result;
 }
@@ -3158,7 +3158,8 @@
     my ($result) = @_;
 
     $result =~ s/[\n\r]/ /g;
-    $result =~ s/'/\\'/g;	
+    $result =~ s/'/\\'/g;
+    $result =~ s{</script>}{</scrip'+'t>}g;
     
     return $result;
 }