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

raeburn raeburn at source.lon-capa.org
Mon Jul 15 13:42:12 EDT 2013


raeburn		Mon Jul 15 17:42:12 2013 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm loncommon.pm lonhelp.pm 
  Log:
  - Scrolling in modal windows on mobile devices.
    - Wrapper (div using nicescroll) for contextual help shown in iframe.
    - div style width and height reset to 100% onload if not viewed in iframe
  - Bubblesheet format file contents display in modal window in domain 
    configuration screens
  - loncommon::modal_link() takes two additional args:
    $transparency and $style -- can be used to set allowtransparency and style
    for iframe (default is allowtransparency='true'). $style can be used to
    set background-color, to make contents of modal window more readable (e.g.
    if is a plain text file).
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.198 loncom/interface/domainprefs.pm:1.199
--- loncom/interface/domainprefs.pm:1.198	Tue Jul  9 00:17:22 2013
+++ loncom/interface/domainprefs.pm	Mon Jul 15 17:42:11 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.198 2013/07/09 00:17:22 raeburn Exp $
+# $Id: domainprefs.pm,v 1.199 2013/07/15 17:42:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3920,8 +3920,8 @@
         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                       '<span class="LC_nobreak">';
         if ($scantronurl) {
-            $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
-                          &mt('Default bubblesheet format file').'</a>';
+            $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
+                                                         undef,undef,undef,undef,'background-color:#ffffff');
         } else {
             $datatable = &mt('File unavailable for display');
         }
@@ -3946,11 +3946,12 @@
             } 
             $datatable .= '<td>'.$errorstr.'</td><td> ';
         } elsif ($scantronurl) {
+            my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
+                                                       undef,undef,undef,undef,'background-color:#ffffff');
             $datatable .= '<td><span class="LC_nobreak">'.
-                          '<a href="'.$scantronurl.'" target="_blank">'.
-                          &mt('Custom bubblesheet format file').'</a><label>'.
-                          '<input type="checkbox" name="scantronformat_del"'.
-                          '" value="1" />'.&mt('Delete?').'</label></span></td>'.
+                          $link.
+                          '<label><input type="checkbox" name="scantronformat_del"'.
+                          ' value="1" />'.&mt('Delete?').'</label></span></td>'.
                           '<td><span class="LC_nobreak"> '.
                           &mt('Replace:').'</span><br />';
         }
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1139 loncom/interface/loncommon.pm:1.1140
--- loncom/interface/loncommon.pm:1.1139	Fri Jul 12 00:15:40 2013
+++ loncom/interface/loncommon.pm	Mon Jul 15 17:42:11 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1139 2013/07/12 00:15:40 raeburn Exp $
+# $Id: loncommon.pm,v 1.1140 2013/07/15 17:42:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -7656,12 +7656,12 @@
 		$(".LCmodal-overlay").click(function(){modalWindow.close();});
 	}
 };
-	var openMyModal = function(source,width,height,scrolling)
+	var openMyModal = function(source,width,height,scrolling,transparency,style)
 	{
 		modalWindow.windowId = "myModal";
 		modalWindow.width = width;
 		modalWindow.height = height;
-		modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='true' src='" + source + "'>&lt/iframe>";
+		modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'>&lt/iframe>";
 		modalWindow.open();
 	};	
 // END LON-CAPA Internal -->
@@ -7671,16 +7671,18 @@
 }
 
 sub modal_link {
-    my ($link,$linktext,$width,$height,$target,$scrolling,$title)=@_;
+    my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
     unless ($width) { $width=480; }
     unless ($height) { $height=400; }
     unless ($scrolling) { $scrolling='yes'; }
+    unless ($transparency) { $transparency='true'; }
+
     my $target_attr;
     if (defined($target)) {
         $target_attr = 'target="'.$target.'"';
     }
     return <<"ENDLINK";
-<a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling'); return false;">
+<a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
            $linktext</a>
 ENDLINK
 }
@@ -7707,11 +7709,11 @@
     my ($funcname,$width,$height,$content)=@_;
     my $innerwidth=$width-20;
     $content=&js_ready(
-               &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
-                 &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','modal').
-                    $content.
+                 &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
+                 &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
+                 $content.
                  &end_scrollbox().
-               &end_page()
+                 &end_page()
              );
     return &modal_adhoc_script($funcname,$width,$height,$content);
 }
@@ -7928,13 +7930,13 @@
 
 
 sub start_scrollbox {
-    my ($outerwidth,$width,$height,$id,$bgcolor,$cursor) = @_;
+    my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
     unless ($outerwidth) { $outerwidth='520px'; }
     unless ($width) { $width='500px'; }
     unless ($height) { $height='200px'; }
     my ($table_id,$div_id,$tdcol);
     if ($id ne '') {
-        $table_id = " id='table_$id'";
+        $table_id = ' id="table_'.$id.'"';
         $div_id = ' id="div_'.$id.'"';
     }
     if ($bgcolor ne '') {
@@ -7942,57 +7944,8 @@
     }
     my $nicescroll_js;
     if ($env{'browser.mobile'}) {
-        my %options;
-        if (ref($cursor) eq 'HASH') {
-            %options = %{$cursor};
-        }
-        unless ($options{'railalign'} =~ /^left|right$/) {
-            $options{'railalign'} = 'left';
-        }
-        unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
-            my $function  = &get_users_function();
-            $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
-            unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
-                $options{'cursorcolor'} = '#00F';
-            }
-        }
-        if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
-            unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
-                $options{'cursoropacity'}='1.0';
-            }
-        } else {
-            $options{'cursoropacity'}='1.0';
-        }
-        if ($options{'cursorfixedheight'} eq 'none') {
-            delete($options{'cursorfixedheight'});
-        } else {
-            unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
-        }
-        unless ($options{'railoffset'} =~ /^{[\w\:\d]+}$/) {
-            delete($options{'railoffset'});
-        } 
-        my @niceoptions;
-        while (my($key,$value) = each(%options)) {
-            if ($value =~ /^\{.+\}$/) {
-                push(@niceoptions,$key.':'.$value);
-            } else {
-                push(@niceoptions,$key.':"'.$value.'"');
-            }
-        }
-        $nicescroll_js = '
-<script type="text/javascript">
-// <![CDATA[ 
-$(document).ready(
-  function() {  
-      $("#div_'.$id.'").niceScroll({'.join(',', at niceoptions).'});
-  }
-);
-
-// ]]>
-</script>
-';
+        $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
     }
-
     return <<"END";
 $nicescroll_js
 
@@ -8005,6 +7958,87 @@
     return '</div></td></tr></table>';
 }
 
+sub nicescroll_javascript {
+    my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
+    my %options;
+    if (ref($cursor) eq 'HASH') {
+        %options = %{$cursor};
+    }
+    unless ($options{'railalign'} =~ /^left|right$/) {
+        $options{'railalign'} = 'left';
+    }
+    unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
+        my $function  = &get_users_function();
+        $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
+        unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
+            $options{'cursorcolor'} = '#00F';
+        }
+    }
+    if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
+        unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
+            $options{'cursoropacity'}='1.0';
+        }
+    } else {
+        $options{'cursoropacity'}='1.0';
+    }
+    if ($options{'cursorfixedheight'} eq 'none') {
+        delete($options{'cursorfixedheight'});
+    } else {
+        unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
+    }
+    unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
+        delete($options{'railoffset'});
+    }
+    my @niceoptions;
+    while (my($key,$value) = each(%options)) {
+        if ($value =~ /^\{.+\}$/) {
+            push(@niceoptions,$key.':'.$value);
+        } else {
+            push(@niceoptions,$key.':"'.$value.'"');
+        }
+    }
+    my $nicescroll_js = '
+$(document).ready(
+      function() {
+          $("#'.$id.'").niceScroll({'.join(',', at niceoptions).'});
+      }
+);
+';
+    if ($framecheck) {
+        $nicescroll_js .= '
+function expand_div(caller) {
+    if (top === self) {
+        document.getElementById("'.$id.'").style.width = "auto";
+        document.getElementById("'.$id.'").style.height = "auto";
+    } else {
+        try {
+            if (parent.frames) {
+                if (parent.frames.length > 1) {
+                    var framesrc = parent.frames[1].location.href;
+                    var currsrc = framesrc.replace(/\#.*$/,"");
+                    if ((caller == "search") || (currsrc == "'.$location.'")) {
+                        document.getElementById("'.$id.'").style.width = "auto";
+                        document.getElementById("'.$id.'").style.height = "auto";
+                    }
+                }
+            }
+        } catch (e) {
+            return;
+        }
+    }
+    return;
+}
+';
+    }
+    if ($needjsready) {
+        $nicescroll_js = '
+<script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
+    } else {
+        $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
+    }
+    return $nicescroll_js;
+}
+
 sub simple_error_page {
     my ($r,$title,$msg) = @_;
     my $page =
Index: loncom/interface/lonhelp.pm
diff -u loncom/interface/lonhelp.pm:1.40 loncom/interface/lonhelp.pm:1.41
--- loncom/interface/lonhelp.pm:1.40	Tue Jan  4 21:53:23 2011
+++ loncom/interface/lonhelp.pm	Mon Jul 15 17:42:11 2013
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonhelp.pm,v 1.40 2011/01/04 21:53:23 raeburn Exp $
+# $Id: lonhelp.pm,v 1.41 2013/07/15 17:42:11 raeburn Exp $
 #
 # .tex help system web server handler
 #
@@ -57,7 +57,7 @@
 
 # Serve out the text
 sub servetext {
-    my ($r,$text) = @_;
+    my ($r,$text,$is_mobile,$firstfile) = @_;
     my $bugs=&Apache::loncommon::help_open_bug('Documentation',&mt('Report a documentation bug'));
     my $morehelp;#=&Apache::loncommon::help_open_menu(undef,undef,1,undef,undef,undef,undef,'Help and Assistance Menu');
     my $header=&mt('LON-CAPA Help');
@@ -66,8 +66,21 @@
     src="/adm/help/gif/lonhelpheader.gif"/>$header</h3><hr />
     <!-- BEGIN -->
 HEADER
-
-    $r->print($text);
+    if ($is_mobile) {
+        my $width = 500;
+        my $height = 400;
+        my $machine = &Apache::lonnet::absolute_url();
+        $r->print(&Apache::loncommon::nicescroll_javascript('helpwrapper',
+                                                            {cursorcolor => '#00F',
+                                                             railalign => 'right',
+                                                             railoffset => '{top:5,left:40}'},
+                                                             undef,1,$machine.$firstfile));
+        $r->print('<div id="helpwrapper" style="height:'.$height.'px; width:'.$width.'px; overflow: auto;">'.
+                  $text.
+                  '</div>');
+    } else {
+        $r->print($text);
+    }
 
     if (&Apache::lonnavmaps::advancedUser()) {
 	my $search=&mt('Search LON-CAPA help');
@@ -199,9 +212,20 @@
 
      &Apache::lonlocal::get_language_handle($r);
      &Apache::loncommon::content_type($r,"text/html");
+     my $caller;
+     if ($env{'form.searchterm'}=~/\w/) {
+        $caller = 'search';
+     }
+     my $starthash = {
+           only_body   => 1,
+           add_entries => {
+                            'onload' => "javascript:expand_div('$caller');",
+                          },
+     };
+
+     my $firstfile;
      my $start_page=
-	 &Apache::loncommon::start_page('LON-CAPA Help',undef,
-					{'only_body' => 1,});
+	 &Apache::loncommon::start_page('LON-CAPA Help',undef,$starthash);
      my $text='';
      if ($env{'form.searchterm'}=~/\w/) {
 	 ($text,my $matches)=&listmatches($docroot,$env{'form.searchterm'},&Apache::lonlocal::current_language().'/');
@@ -231,7 +255,8 @@
 	 # so replace : with ,
 	 $filenames =~ s/:/,/g;
 	 my @files = split(/,/, $filenames);
-	 
+         $firstfile = '/adm/help/'.$files[0].'.hlp';
+
 	 for my $filename (@files) {
 	     if (-e $docroot.'/adm/help/tex/'.
 		 &Apache::lonlocal::current_language().'/'.
@@ -249,7 +274,7 @@
 
      $r->send_http_header;
      $r->print($start_page);
-     &servetext($r,$text);
+     &servetext($r,$text,$env{'browser.mobile'},$firstfile);
      $r->print(&Apache::loncommon::end_page());
 
      return OK;


More information about the LON-CAPA-cvs mailing list