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

raeburn raeburn at source.lon-capa.org
Sat Nov 18 16:50:06 EST 2023


raeburn		Sat Nov 18 21:50:06 2023 EDT

  Modified files:              
    /rat	lonwrapper.pm 
    /loncom/interface	loncommon.pm 
  Log:
  - Move javascript used for handling resize of page containing iframe from 
    lonwrapper.pm to two new subroutines in loncommon.pm to facilitate reuse.
  
  
Index: rat/lonwrapper.pm
diff -u rat/lonwrapper.pm:1.84 rat/lonwrapper.pm:1.85
--- rat/lonwrapper.pm:1.84	Sat Nov 18 21:45:11 2023
+++ rat/lonwrapper.pm	Sat Nov 18 21:50:06 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Wrapper for external and binary files as standalone resources
 #
-# $Id: lonwrapper.pm,v 1.84 2023/11/18 21:45:11 raeburn Exp $
+# $Id: lonwrapper.pm,v 1.85 2023/11/18 21:50:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -153,13 +153,7 @@
 #
 
     unless ($clientmobile || ($exttool eq 'window') || ($exttool eq 'tab') || $uselink) {
-        $headjs = '
-<script type="text/javascript">
-// <![CDATA[
-var LCnotready = 0;
-var LCresizedef = 0;
-// ]]>
-</script>'."\n";
+        $headjs = &Apache::loncommon::iframe_wrapper_headjs();
     }
 
     my $startpage = &Apache::loncommon::start_page('Menu',$headjs,$args).$countdown.$donemsg;
@@ -302,49 +296,8 @@
         $linktext = &mt('Link to resource');
         return $startpage.&create_link($url,$anchor,$title,$linktext).$endpage;
     } else {
-        my $offset = 5;
-        &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
-        if (($env{'form.inhibitmenu'} eq 'yes') || ($env{'form.only_body'})) {
-            $offset = 0;
-        }
-        my $script = &Apache::lonhtmlcommon::scripttag(<<SCRIPT);
-        \$(document).ready( function() {
-            \$(window).unbind('resize').resize(function(){
-                var header = null;
-                var offset = $offset;
-                var height = 0;
-                var hdrtop = 0;
-                if (\$('div.LC_head_subbox:first').length) {
-                    header = \$('div.LC_head_subbox:first');
-                    offset = 9;
-                } else {
-                    if (\$('#LC_breadcrumbs').length) {
-                        header = \$('#LC_breadcrumbs');
-                    }
-                }
-                if (header != null && header.length) {
-                    height = header.height();
-                    hdrtop = header.position().top;
-                }
-                var pos = height + hdrtop + offset;
-                \$('.LC_iframecontainer').css('top', pos);
-            });
-            LCresizedef = 1;
-            if (LCnotready == 1) {
-                LCnotready = 0;
-                \$(window).trigger('resize');
-            }
-        });
-        window.onload = function(){
-             if (LCresizedef) {
-                 LCnotready = 0;
-                 \$(window).trigger('resize');
-             } else {
-                 LCnotready = 1;
-             }
-        };
-SCRIPT
         # javascript will position the iframe if window was resized (or zoomed)
+        my $script = &Apache::loncommon::iframe_wrapper_resizejs();
         my $dest = &HTML::Entities::encode($url.$anchor,'&<>"');
         return <<ENDFRAME;
         $startpage
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1419 loncom/interface/loncommon.pm:1.1420
--- loncom/interface/loncommon.pm:1.1419	Sat Nov 18 21:12:45 2023
+++ loncom/interface/loncommon.pm	Sat Nov 18 21:50:06 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1419 2023/11/18 21:12:45 raeburn Exp $
+# $Id: loncommon.pm,v 1.1420 2023/11/18 21:50:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2441,6 +2441,98 @@
 
 =pod
 
+=item * &iframe_wrapper_headjs()
+
+#
+# Where iframe is in use, if window.onload() executes before the custom resize function
+# has been defined (jQuery), two global javascript vars (LCnotready and LCresizedef)
+# are used to ensure document.ready() triggers a call to resize, so the iframe contents
+# do not obscure the Functions menu.
+#
+
+=back
+
+=cut
+
+
+sub iframe_wrapper_headjs {
+    return <<"ENDJS";
+<script type="text/javascript">
+// <![CDATA[
+var LCnotready = 0;
+var LCresizedef = 0;
+// ]]>
+</script>
+
+ENDJS
+
+}
+
+=pod
+
+=item * &iframe_wrapper_resizejs()
+
+#
+# jQuery to use when iframe is in use and a page resize occurs.
+# This script will ensure that the iframe does not obscure any
+# standard LON-CAPA inline menus (primary, secondary, and/or
+# breadcrumbs and Functions menus. Expects javascript from
+# &iframe_wrapper_headjs() to be in head portion of the web page,
+# e.g., by inclusion in second arg passed to &start_page().
+#
+
+=back
+
+=cut
+
+sub iframe_wrapper_resizejs {
+    my $offset = 5;
+    &get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
+    if (($env{'form.inhibitmenu'} eq 'yes') || ($env{'form.only_body'})) {
+        $offset = 0;
+    }
+    return &Apache::lonhtmlcommon::scripttag(<<SCRIPT);
+    \$(document).ready( function() {
+        \$(window).unbind('resize').resize(function(){
+            var header = null;
+            var offset = $offset;
+            var height = 0;
+            var hdrtop = 0;
+            if (\$('div.LC_head_subbox:first').length) {
+                header = \$('div.LC_head_subbox:first');
+                offset = 9;
+            } else {
+                if (\$('#LC_breadcrumbs').length) {
+                    header = \$('#LC_breadcrumbs');
+                }
+            }
+            if (header != null && header.length) {
+                height = header.height();
+                hdrtop = header.position().top;
+            }
+            var pos = height + hdrtop + offset;
+            \$('.LC_iframecontainer').css('top', pos);
+        });
+        LCresizedef = 1;
+        if (LCnotready == 1) {
+            LCnotready = 0;
+            \$(window).trigger('resize');
+        }
+    });
+    window.onload = function(){
+         if (LCresizedef) {
+             LCnotready = 0;
+             \$(window).trigger('resize');
+         } else {
+             LCnotready = 1;
+         }
+    };
+SCRIPT
+
+}
+
+=pod
+
 =head1 Excel and CSV file utility routines
 
 =cut




More information about the LON-CAPA-cvs mailing list