[LON-CAPA-cvs] cvs: loncom /xml scripttag.pm

raeburn raeburn at source.lon-capa.org
Sun Feb 5 18:00:06 EST 2012


raeburn		Sun Feb  5 23:00:06 2012 EDT

  Modified files:              
    /loncom/xml	scripttag.pm 
  Log:
  - Support use of .js files as dependencies in web pages uploaded directly 
    to a course (e.g., for Camtasia).
  
  
Index: loncom/xml/scripttag.pm
diff -u loncom/xml/scripttag.pm:1.164 loncom/xml/scripttag.pm:1.165
--- loncom/xml/scripttag.pm:1.164	Fri Dec 23 19:38:01 2011
+++ loncom/xml/scripttag.pm	Sun Feb  5 23:00:06 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # <script> definiton
 #
-# $Id: scripttag.pm,v 1.164 2011/12/23 19:38:01 www Exp $
+# $Id: scripttag.pm,v 1.165 2012/02/05 23:00:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -126,6 +126,38 @@
       if ($target ne "meta" && $target ne 'tex' && $target ne 'answer') {
 	  $result = $token->[4];
 	  $result.=$bodytext;
+          if ($type eq "text/javascript") {
+              my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
+              if (($src =~ /\.js$/) && ($src !~ m{^(/|https?://)})) {
+                  my ($path,$scriptname) = ($src =~ m{^(.+)/([^/]*)$});
+                  my $docuri =
+                      $Apache::lonnet::env{'request.noversionuri'};
+                  my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+                  my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+                  if ($docuri =~ m{^(\Q/uploaded/$cdom/$cnum\E)/(docs/.*/)[^/]+$}) {
+                      my $prefix = $1;
+                      my $relpath = $2;
+                      my $cleanrelpath;
+                      foreach my $dir (split(/\//,$relpath.$path)) {
+                          next if ($dir eq '.');
+                          if ($dir eq '..') {
+                              $cleanrelpath =~ s{([^/]+/)$}{};
+                          } else {
+                              $cleanrelpath .= $dir.'/';
+                          }
+                      }
+                      $cleanrelpath =~ s{/$}{};
+                      if ($cleanrelpath ne '') {
+                          $src = $prefix.'/'.$cleanrelpath.'/'.$scriptname;
+                      } else {
+                          $src = $prefix.'/'.$scriptname;
+                      }
+                      if ($src ne '') {
+                          &Apache::lonxml::extlink($src);
+                      }
+                  }
+              }
+          }
       }
   }
   return $result;




More information about the LON-CAPA-cvs mailing list