[LON-CAPA-cvs] cvs: rat / lonwrapper.pm

raeburn raeburn at source.lon-capa.org
Tue May 20 07:47:06 EDT 2014


raeburn		Tue May 20 11:47:06 2014 EDT

  Modified files:              
    /rat	lonwrapper.pm 
  Log:
  - Circumvent lack of scrolling for multi-page PDFs in iFrames on iOS 
    by substituting inline display in iframe with a link when viewing on 
    mobile device (Main Content area).
  
  
Index: rat/lonwrapper.pm
diff -u rat/lonwrapper.pm:1.46 rat/lonwrapper.pm:1.47
--- rat/lonwrapper.pm:1.46	Tue Oct 22 23:13:54 2013
+++ rat/lonwrapper.pm	Tue May 20 11:47:06 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Wrapper for external and binary files as standalone resources
 #
-# $Id: lonwrapper.pm,v 1.46 2013/10/22 23:13:54 raeburn Exp $
+# $Id: lonwrapper.pm,v 1.47 2014/05/20 11:47:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -40,7 +40,7 @@
 
 # ================================================================ Main Handler
 sub wrapper {
-    my ($url,$brcrum,$absolute,$is_ext) = @_;
+    my ($url,$brcrum,$absolute,$is_ext,$is_pdf) = @_;
 
     my $forcereg;
     unless ($env{'form.folderpath'}) {
@@ -68,15 +68,31 @@
     my $endpage = &Apache::loncommon::end_page();
 
     if ($env{'browser.mobile'}) {
-        return <<ENDFRAME;
-        $startpage
-        <div style="overflow:scroll; -webkit-overflow-scrolling:touch;">
-        <iframe src="$url" height="100%" width="100%" frameborder="0">
-            $lt{'noif'} $noiframe
-        </iframe>
-        </div>
-        $endpage
-ENDFRAME
+        my $output = $startpage;
+        if ($is_pdf) {
+            my $title = $env{'form.title'};
+            if ($title eq '') {
+                unless ($env{'request.enc'}) {
+                    ($title) = ($url =~ m{/([^/]+)$});
+                    $title =~ s/(\?[^\?]+)$//;
+                }
+            }
+            unless ($title eq '') {
+                $output .= $title.'<br />';
+            }
+            $output .= '<a href="'.$url.'">'.&mt('Link to PDF (for mobile devices)').'</a>';
+        } else {
+            $output .= '<div style="overflow:scroll; -webkit-overflow-scrolling:touch;">'."\n".
+                       '<iframe src="$url" height="100%" width="100%" frameborder="0">'."\n".
+                       "$lt{'noif'} $noiframe\n".
+                       "</iframe>\n".
+                       "</div>\n";
+            $output .= '<iframe src="$url" height="100%" width="100%" frameborder="0">'."\n".
+                       "$lt{'noif'} $noiframe\n".
+                       '</iframe>';
+        }
+        $output .= $endpage;
+        return $output;
     } else {
         my $script = &Apache::lonhtmlcommon::scripttag(<<SCRIPT);
         \$(document).ready( function() {
@@ -123,7 +139,7 @@
     return OK if $r->header_only;
 
     my $url = $r->uri;
-    my ($is_ext,$brcrum,$absolute);
+    my ($is_ext,$brcrum,$absolute,$is_pdf);
 
     for ($url){
         s|^/adm/wrapper||;
@@ -132,6 +148,10 @@
         s|:|:|g;              
     }
 
+    if ($url =~ /\.pdf$/i) {
+        $is_pdf = 1;
+    }
+ 
     if ($is_ext) {
         my $hostname = $r->hostname();
         my $lonhost = &Apache::lonnet::host_from_dns($hostname);
@@ -189,7 +209,7 @@
         # encrypt url if not external
         &Apache::lonenc::check_encrypt(\$url) if $url !~ /^https?\:/ ;
 
-        $r->print( wrapper($url,$brcrum,$absolute,$is_ext) );
+        $r->print( wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf) );
 
     } # not just the menu
     
@@ -216,7 +236,7 @@
 
 =over
 
-=item wrapper($url,$brcrum,$absolute,$is_ext)
+=item wrapper($url,$brcrum,$absolute,$is_ext,$is_pdf))
 
 =over
 
@@ -252,6 +272,10 @@
 
 true if URL is for an external resource.
 
+=item $is_pdf
+
+true if URL is for a PDF (based on file extension).
+
 =back
 
 Returns markup for the entire page.




More information about the LON-CAPA-cvs mailing list