File:  [LON-CAPA] / loncom / homework / daxepage.pm
Revision 1.8: download - view: text, annotated - select for diffs
Sun Nov 26 02:15:29 2023 UTC (5 months, 2 weeks ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Remove declaration of unused var in javascript.

    1: # The LearningOnline Network
    2: # Page with Daxe on the left side and the preview on the right side
    3: #
    4: # $Id: daxepage.pm,v 1.8 2023/11/26 02:15:29 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: package Apache::daxepage;
   31: use strict;
   32: 
   33: use Apache::loncommon();
   34: use Apache::lonhtmlcommon();
   35: use Apache::lonmenu();
   36: use Apache::lonlocal;
   37: use Apache::Constants qw(:common);
   38: use HTML::Entities();
   39: 
   40: sub handler {
   41:     my $request = shift;
   42:     my $uri = $request->uri;
   43:     $uri =~ s{^/daxepage}{};
   44:     &Apache::loncommon::content_type($request,'text/html');
   45:     if ($uri !~ /\.(task|problem|exam|quiz|assess|survey|library|xml|html|htm|xhtml|xhtm)$/) {
   46:         $request->status(406);
   47:         return OK;
   48:     }
   49:     my %editors = &Apache::loncommon::permitted_editors();
   50:     unless ($editors{'daxe'}) {
   51:         my $msg = '<p class="LC_warning">'.
   52:                   &mt('Daxe editor is not enabled for this Authoring Space.').'</p>';
   53:         &do_redirect($request,$uri,$msg);
   54:         return OK;
   55:     }
   56:     my %lt = &Apache::lonlocal::texthash(
   57:                                           'noif' => 'No iframe support.',
   58:                                           'show' => 'Show content in pop-up window',
   59:                                         );
   60:     my $name = $uri;
   61:     $name =~ s/^.*\/([^\/]+)$/$1/;
   62:     my $daxeurl = '/adm/daxe/daxe.html?config=config/loncapa_config.xml&save=/daxesave'.
   63:                   '&file=/daxeopen'.$uri;
   64:     my $headjs = &Apache::loncommon::iframe_wrapper_headjs().
   65:                  &toggle_LCmenus_js();
   66:     my $args = {
   67:                 'collapsible_header' => 1,
   68:                };
   69:     my $startpage = &Apache::loncommon::start_page('Daxe: '.$name,$headjs,$args).
   70:                     &Apache::lonmenu::constspaceform();
   71:     my $endpage = &Apache::loncommon::end_page();
   72: 
   73:     # javascript will position the iframe if window was resized (or zoomed)
   74:     my $script = &Apache::loncommon::iframe_wrapper_resizejs();
   75:     my $dest = &HTML::Entities::encode($daxeurl,'&<>"');
   76:     my $noiframe = &Apache::loncommon::modal_link($dest,$lt{'show'},500,400);
   77: 
   78:     $request->print(<<"ENDFRAME");
   79: $startpage
   80: $script
   81: <div class="LC_iframecontainer" style="padding-right: 5px">
   82: <iframe src="$dest">$lt{'noif'} $noiframe</iframe>
   83: </div>
   84: $endpage
   85: ENDFRAME
   86:     return OK;
   87: }
   88: 
   89: sub toggle_LCmenus_js {
   90:     my %lt = &Apache::lonlocal::texthash(
   91:                                          altc => 'menu state: collapsed',
   92:                                          alte => 'menu state: explanded',
   93:                                          ttlc => 'display standard menus',
   94:                                          ttle => 'hide standard menus',
   95:     );
   96:     return <<"ENDJS";
   97: <script type="text/javascript">
   98: //<![CDATA[
   99: \$(document).ready (function () {
  100:     \$(".LC_collapse_trigger").on("click", function (e) {
  101:         var id = this.id;
  102:         var \$content = \$(this).next (".LC_menus_content");
  103:         var expanded = \$content.hasClass ("shown");
  104:         if (expanded) {
  105:             \$content.removeClass ("shown");
  106:             \$content.addClass ("hidden");
  107:         } else {
  108:             \$content.removeClass ("hidden");
  109:             \$content.addClass ("shown");
  110:         }
  111: 
  112:         \$(this).find ("[aria-expanded]")
  113:         .attr ("aria-expanded", !expanded);
  114: 
  115:         \$(this).find ("[aria-pressed]")
  116:         .attr ("aria-pressed", !expanded);
  117: 
  118:         \$(this).find (".LC_collapsible_indicator").attr ({
  119:         "src":
  120:         (expanded)? "/res/adm/pages/collapsed.png" : "/res/adm/pages/expanded.png",
  121:         "alt":
  122:         (expanded)? "$lt{altc}" : "$lt{alte}",
  123:         "title":
  124:         (expanded)? "$lt{ttlc}" : "$lt{ttle}"
  125:         });
  126: 
  127:         \$(window).trigger('resize');
  128:         \$(this).focus ();
  129:     });
  130: 
  131:     \$("#LC_expandingContainer").attr ("aria-live", "off");
  132: });
  133: //]]>
  134: </script>
  135: ENDJS
  136: 
  137: }
  138: 
  139: sub do_redirect {
  140:     my ($request,$uri,$msg) = @_;
  141:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  142:     $request->print(
  143:         &Apache::loncommon::start_page('Authoring Space',undef,
  144:                                        {'redirect'       => [2,$uri]}).
  145: 
  146:         '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
  147:         "$msg\n".
  148:         &Apache::loncommon::end_page());
  149:     return;
  150: }
  151: 
  152: 1;
  153: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>