Diff for /loncom/interface/lonhtmlcommon.pm between versions 1.253.2.4 and 1.256

version 1.253.2.4, 2010/10/04 19:43:30 version 1.256, 2009/12/22 06:02:44
Line 1241  ENDLINK Line 1241  ENDLINK
 }  }
   
 sub htmlareaheaders {  sub htmlareaheaders {
     return if (&htmlareablocked());   my $s="";
     return if (!&htmlareabrowser());   if (!&htmlareablocked() && &htmlareabrowser()) {
     return (<<ENDHEADERS);   $s.=(<<ENDEDITOR);
 <script type="text/javascript" src="/fckeditor/fckeditor.js"></script>  <script type="text/javascript" src="/fckeditor/fckeditor.js"></script>
 ENDHEADERS  <script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
   ENDEDITOR
    }
       $s.=(<<ENDJQUERY);
   <script type="text/javascript" src="/adm/jQuery/js/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" src="/adm/jQuery/js/jquery-ui-1.7.2.custom.min.js"></script>
   ENDJQUERY
    return $s;
 }  }
   
 # ----------------------------------------------------------------- Preferences  # ----------------------------------------------------------------- Preferences
Line 1284  sub htmlareaselectactive { Line 1291  sub htmlareaselectactive {
     my $output='<script type="text/javascript" defer="1">'."\n"      my $output='<script type="text/javascript" defer="1">'."\n"
               .'// <![CDATA['."\n";                .'// <![CDATA['."\n";
     my $lang = &htmlarea_lang();      my $lang = &htmlarea_lang();
       $output.='
       
       function containsBlockHtml(id) {
    var re = $("#"+id).html().search(/(?:\&lt\;|\<)(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div)[\s]*((?:\/[\s]*(?:\&gt\;|\>)|(?:\&gt\;|\>)[\s\S]*(?:\&lt\;|\<)\/[\s]*\1[\s]*\(?:\&gt\;|\>))/im);
       return (re >= 0);
       }
       
       function startRichEditor(id) {
       CKEDITOR.replace(id, 
       {
       customConfig: "/ckeditor/loncapaconfig.js",
       }
       );
       }
       
       function destroyRichEditor(id) {
       CKEDITOR.instances[id].destroy();
       }
       
       function editorHandler(event) {
       var rawid = $(this).attr("id");
       var id = new RegExp("LC_rt_(.*)").exec(rawid)[1]
       event.preventDefault();
       if ($(this).hasClass("LC_enable_rt")) {
       startRichEditor(id);
    $("#LC_rt_"+id).html("<b>&laquo; Plain text</b>");
    $("#LC_rt_"+id).attr("title", "Disable rich text formatting and edit in plain text");
    $("#LC_rt_"+id).addClass("LC_disable_rt");
    $("#LC_rt_"+id).removeClass("LC_enable_rt");
       } else {
    destroyRichEditor(id);
    $("#LC_rt_"+id).html("<b>Rich formatting &raquo;</b>");
    $("#LC_rt_"+id).attr("title", "Enable rich text formatting (bold, italic, etc.)");
    $("#LC_rt_"+id).addClass("LC_enable_rt");
    $("#LC_rt_"+id).removeClass("LC_disable_rt");
    }
    }
       
       $(document).ready(function(){
    $(".LC_richAlwaysOn").each(function() {
    startRichEditor($(this).attr("id"));
    });
    $(".LC_richDetectHtml").each(function() {
    var id = $(this).attr("id");
    if(containsBlockHtml(id)) {
    $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Disable rich text formatting and edit in plain text\" class=\"LC_disable_rt\"><b>&laquo; Plain text</b></a></div>");
    startRichEditor(id);
    $("#LC_rt_"+id).click(editorHandler);
    }
    else {
    $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Enable rich text formatting (bold, italic, etc.)\" class=\"LC_enable_rt\"><b>Rich formatting &raquo;</b></a></div>");
    $("#LC_rt_"+id).click(editorHandler);
    }
    });
    $(".LC_richDefaultOn").each(function() {
    var id = $(this).attr("id");
    $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Disable rich text formatting and edit in plain text\" class=\"LC_disable_rt\"><b>&laquo; Plain text</b></a></div>");
    startRichEditor(id);
    $("#LC_rt_"+id).click(editorHandler);
    });
    $(".LC_richDefaultOff").each(function() {
    var id = $(this).attr("id");
    $(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Enable rich text formatting (bold, italic, etc.)\" class=\"LC_enable_rt\"><b>Rich formatting &raquo;</b></a></div>");
    $("#LC_rt_"+id).click(editorHandler);
    });
   
    });
   ';
       
     foreach my $field (@fields) {      foreach my $field (@fields) {
  $output.="   $output.='
   
 {  {
     var oFCKeditor = new FCKeditor('$field');   $(document).ready(function() {
     oFCKeditor.Config['CustomConfigurationsPath'] =    if (!($("#'.$field.'").hasClass("LC_richAlwaysOn"))) {
  '/fckeditor/loncapaconfig.js';       if (!($("#'.$field.'").hasClass("LC_richAlwaysOff"))) {
     oFCKeditor.ReplaceTextarea();   if (!($("#'.$field.'").hasClass("LC_richDetectHtml"))) {
     oFCKeditor.Config['AutoDetectLanguage'] = false;   if (!($("#'.$field.'").hasClass("LC_richDefaultOn"))) {
     oFCKeditor.Config['DefaultLanguage'] = '$lang';   if (!($("#'.$field.'").hasClass("LC_richDefaultOff"))) {
 }";   var oFCKeditor = new FCKeditor("'.$field.'");
    oFCKeditor.Config["CustomConfigurationsPath"] = 
    "/fckeditor/loncapaconfig.js";    
    oFCKeditor.ReplaceTextarea();
    oFCKeditor.Config["AutoDetectLanguage"] = false;
    oFCKeditor.Config["DefaultLanguage"] = "'.$lang.'";
    }
    }
    }
    }
    }
       });
   }';
     }      }
     $output.="\nwindow.status='Activated Editfields';\n"      $output.="\nwindow.status='Activated Editfields';\n"
             .'// ]]>'."\n"              .'// ]]>'."\n"
Line 1378  returns: nothing Line 1467  returns: nothing
         # The first one should be the course or a menu link          # The first one should be the course or a menu link
         if (!defined($menulink)) { $menulink=1; }          if (!defined($menulink)) { $menulink=1; }
         if ($menulink) {          if ($menulink) {
             if ($menulink eq '_nomenu') {              my $description = 'Menu';
                 return unless($last);              my $no_mt_descr = 0;
               if (exists($env{'request.course.id'}) && 
                   $env{'request.course.id'} ne '') {
                   $description = 
                       $env{'course.'.$env{'request.course.id'}.'.description'};
                   $no_mt_descr = 1;
               }
               $menulink =  {  href   =>'/adm/menu',
                               title  =>'Go to main menu',
                               target =>'_top',
                               text   =>$description,
                               no_mt  =>$no_mt_descr, };
               if($last) {
                   #$last set, so we have some crumbs
                   unshift(@Crumbs,$menulink);
             } else {              } else {
                 my $description = 'Menu';                  #only menulink crumb present
                 my $href = '/adm/menu';                  $last = $menulink;
                 my $tooltip = 'Go to main menu';  
                 my $no_mt_descr = 0;  
                 if ((exists($env{'request.course.id'})) &&  
                     ($env{'request.course.id'} ne '')) {  
   
                     if ((&Apache::loncommon::needs_gci_custom()) || ($env{'user.domain'} eq 'gcitest')) {  
                         $href = '/adm/navmaps';  
                         $tooltip = 'Contents';  
                     }  
                     if ($env{'course.'.$env{'request.course.id'}.'.description'} ne '') {  
                         $description =  
                             $env{'course.'.$env{'request.course.id'}.'.description'};  
                         $no_mt_descr = 1;  
                     }  
                 }  
                 $menulink =  {  href   => $href,  
                                 title  => $tooltip,  
                                 target => '_top',  
                                 text   => $description,  
                                 no_mt  => $no_mt_descr, };  
                 if ($last) {  
                     #$last set, so we have some crumbs  
                     unshift(@Crumbs,$menulink);  
                 } else {  
                     #only menulink crumb present  
                     $last = $menulink;  
                 }  
             }              }
         }          }
         my $links = join "",           my $links = join "", 
Line 1418  returns: nothing Line 1494  returns: nothing
                      $bug  = $_->{'bug'}  if (exists($_->{'bug'}));                       $bug  = $_->{'bug'}  if (exists($_->{'bug'}));
                      $help = $_->{'help'} if (exists($_->{'help'}));                       $help = $_->{'help'} if (exists($_->{'help'}));
   
                      my $result = $_->{no_mt} ? $_->{text} : mt($_->{text});                       my $result = htmltag( 'a', 
                                              $_->{no_mt} ? 
                      if ($_->{href}){                                              $_->{text} : mt($_->{text}), 
                          $result = htmltag( 'a', $result,   
                                            {                                              { 
                                                href   => $_->{href},                                                 href   => $_->{href},
                                                title  => $_->{no_mt} ?                                                  title  => $_->{no_mt} ? 
                                                 $_->{title} : mt($_->{title}),                                                  $_->{title} : mt($_->{title}),
                                                target => $_->{target},                                                 target => $_->{target},
                                            });                                             });
                      }  
   
                      $result = htmltag( 'li', "$result $crumbsymbol");                       $result = htmltag( 'li', "$result $crumbsymbol");
                  } @Crumbs;                       } @Crumbs;
   
         #should the last Element be translated?          #should the last Element be translated?
           $links  .= htmltag( 'li', 
         my $lasttext = $last->{'no_mt'} ? $last->{'text'}                          htmltag( 'b', 
                      : mt( $last->{'text'} );                                   $last->{'no_mt'} ? 
                                    $last->{'text'} : mt($last->{'text'}) ));
         # last breadcrumb is the first order heading of a page  
         # for course breadcrumbs it's just bold  
         $links .= htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1',  
                            $lasttext), {title => $lasttext});  
   
         my $icons = '';          my $icons = '';
         $faq  = $last->{'faq'}  if (exists($last->{'faq'}));          $faq  = $last->{'faq'}  if (exists($last->{'faq'}));
Line 1476  returns: nothing Line 1545  returns: nothing
                              .$links;                               .$links;
         }          }
                   
         render_tools(\$links);          #SD START (work in progress!)
           add_tools(\$links);
           #SD END
         $links = htmltag('div', $links,           $links = htmltag('div', $links, 
                         { id => "LC_breadcrumbs" }) unless ($CourseBreadcrumbs) ;                          { id => "LC_breadcrumbs" }) unless ($CourseBreadcrumbs) ;
         render_advtools(\$links);          add_advtools(\$links);
   
         # Return the @Crumbs stack to what we started with          # Return the @Crumbs stack to what we started with
         push(@Crumbs,$last);          push(@Crumbs,$last);
Line 1497  returns: nothing Line 1568  returns: nothing
         push(@Crumbs,@_);          push(@Crumbs,@_);
     }      }
           
 =item add_breadcrumb_tool($category, $html)  
   
 Adds $html to $category of the breadcrumb toolbar container.  
   
 $html is usually a link to a page that invokes a function on the currently  
 displayed data (e.g. print when viewing a problem)  
   
 Currently there are 3 possible values for $category:  
   
 =over  
   
 =item navigation  
 left of breadcrumbs line  
   
 =item tools  
 right of breadcrumbs line  
   
 =item advtools  
 advanced tools shown in a separate box below breadcrumbs line  
   
 =back  
   
 returns: nothing  
   
 =cut  
   
       #SD START (work in progress!)
     sub add_breadcrumb_tool {      sub add_breadcrumb_tool {
         my ($category, @html) = @_;          my ($category, $html) = @_;
         return unless @html;          return unless $html;
         if (!defined(%tools)) {          if (!defined(%tools)) { 
             %tools = ( navigation => [], tools => [], advtools => []);              my %tools = ( A => [], B => [], C => []);
         }  
   
         #this cleans data received from lonmenu::innerregister  
         @html = grep {defined $_ && $_ ne ''} @html;  
         for (@html) {  
             s/align="(right|left)"//;  
             s/<span.*?\/span>// if $category ne 'advtools';  
         }          }
           push @{$tools{$category}}, $html;
         push @{$tools{$category}}, @html;  
     }      }
   
 =item clear_breadcrumb_tools()  
   
 Clears the breadcrumb toolbar container.  
   
 returns: nothing  
   
 =cut  
   
     sub clear_breadcrumb_tools {      sub clear_breadcrumb_tools {
         undef(%tools);          undef(%tools);
     }      }
   
 =item render_tools(\$breadcrumbs)      sub add_tools {
           my ($links) = @_;
 Creates html for breadcrumb tools (categories navigation and tools) and inserts  
 \$breadcrumbs at the correct position.  
   
 input: \$breadcrumbs - a reference to the string containing prepared  
 breadcrumbs.  
   
 returns: nothing  
 =cut  
   
 #TODO might split this in separate functions for each category  
     sub render_tools {  
         my ($breadcrumbs) = @_;  
         return unless defined %tools;          return unless defined %tools;
           my $html = '<ul class="LC_bct">';
         my $navigation = list_from_array($tools{navigation},          for my $category ('A','B') {
                    { listattr => { class=>"LC_breadcrumb_tools_navigation" } });              $html .= '<li class="LC_breadcrumb_tools">'
         my $tools = list_from_array($tools{tools},                     . '<ul class="LC_breadcrumb_tools'
                    { listattr => { class=>"LC_breadcrumb_tools_tools" } });                     . " LC_breadcrumb_tools_$category\">";
         $$breadcrumbs = list_from_array([$navigation, $tools, $$breadcrumbs],              for my $item (@{$tools{$category}}){
                    { listattr => { class=>'LC_breadcrumb_tools_outerlist' } });                  #SD ugly! I'll fix that later on
                   $item =~ s/align="(right|left)"//;
                   $item =~ s/<span(.*?)\/span>//;
                   $html .= "<li>$item</li>";
               }
               $html .= '</ul></li>';
               if ($category eq 'A') { $html .= "<li>$$links</li>"; }
           }
           $$links = $html.'</ul>';
     }      }
   
 =item render_advtools(\$breadcrumbs,$legend)      sub add_advtools {
           my ($links) = @_;
 Creates html for advanced tools (category advtools) and inserts \$breadcrumbs          return unless (defined $tools{'C'}) and (scalar (@{$tools{'C'}}) > 0);
 at the correct position.          my $html = start_funclist();
           for my $item (@{$tools{'C'}}){
 input: \$breadcrumbs - a reference to the string containing prepared                  next unless $item;
 breadcrumbs (after render_tools call).                  $item =~ s/align="(right|left)"//;
                   $html .= add_item_funclist($item);
 returns: nothing          }
 =cut          $html   .= end_funclist();
           $html    = Apache::loncommon::head_subbox($html);
     sub render_advtools {          $$links .= $html;
         my ($breadcrumbs,$legend) = @_;  
         return unless     (defined $tools{'advtools'})  
                       and (scalar(@{$tools{'advtools'}}) > 0);  
         my $args;  
         if ($legend) {  
             $args = {legend => $legend};  
         }  
         $$breadcrumbs .= Apache::loncommon::head_subbox(  
                             funclist_from_array($tools{'advtools'},$args));  
     }      }
       #SD END
   
 } # End of scope for @Crumbs  } # End of scope for @Crumbs
   
Line 1730  ENDTWO Line 1749  ENDTWO
   
 } # End: row_count block for pick_box  } # End: row_count block for pick_box
   
   
 sub role_select_row {  sub role_select_row {
     my ($roles,$title,$css_class,$show_separate_custom,$cdom,$cnum) = @_;      my ($roles,$title,$css_class,$show_separate_custom,$cdom,$cnum) = @_;
     my $crstype = 'Course';      my $crstype = 'Course';
Line 1976  sub topic_bar { Line 1996  sub topic_bar {
   
 ##############################################  ##############################################
 ##############################################  ##############################################
                                                                                
 # echo_form_input  # echo_form_input
 #  #
 # Generates html markup to add form elements from the referrer page  # Generates html markup to add form elements from the referrer page
Line 2040  sub echo_form_input { Line 2061  sub echo_form_input {
   
 ##############################################  ##############################################
 ##############################################  ##############################################
                                                                                
 # set_form_elements  # set_form_elements
 #  #
 # Generates javascript to set form elements to values based on  # Generates javascript to set form elements to values based on
Line 2257  sub htmltag{ Line 2279  sub htmltag{
 # USAGE: inittags(@tags);  # USAGE: inittags(@tags);
 #  #
 # EXAMPLES:  # EXAMPLES:
 #  - my ($h1, $h2, $h3) = inittags( qw( h1 h2 h3 ) )  #  - my ($h1, $h2, $h3) = initTags( qw( h1 h2 h3 ) )
 #    $h1->("This is a headline") #Returns: <h1>This is a headline</h1>  #    $h1->("This is a headline") #Returns: <h1>This is a headline</h1>
 #  #
 # NOTES: See sub htmltag for further information.  # NOTES: See sub htmltag for further information.
Line 2306  sub scripttag { Line 2328  sub scripttag {
 };  };
   
   
 =item list_from_array( \@array, { listattr =>{}, itemattr =>{} } )  
   
 Constructs a XHTML list from \@array.  
   
 input:  
   
 =over  
   
 =item \@array  
   
 A reference to the array containing text that will be wrapped in <li></li> tags.  
   
 =item { listattr => {}, itemattr =>{} }  
   
 Attributes for <ul> and <li> passed in as hash references.  
 See htmltag() for more details.  
   
 =back  
   
 returns: XHTML list as String.  
   
 =cut  
   
 # \@items, {listattr => { class => 'abc', id => 'xyx' }, itemattr => {class => 'abc', id => 'xyx'}}  
 sub list_from_array {  
     my ($items, $args) = @_;  
     return unless scalar @$items;  
     my ($ul, $li) = inittags( qw(ul li) );  
     my $listitems = join '', map { $li->($_, $args->{itemattr}) } @$items;  
     return $ul->( $listitems, $args->{listattr} );  
 }  
   
   
 ##############################################  ##############################################
 ##############################################  ##############################################
   
Line 2368  sub list_from_array { Line 2357  sub list_from_array {
 #  #
 # Outputs: A scalar containing the html markup for the menu.  # Outputs: A scalar containing the html markup for the menu.
   
   # ---- Remove when done ----
   # This routine is part of the redesign of LON-CAPA and it's 
   # subject to change during this project.
   # Don't rely on its current functionality as it might be 
   # changed or removed.
   # --------------------------
 sub generate_menu {  sub generate_menu {
     my @menu = @_;      my @menu = @_;
     # subs for specific html elements      # subs for specific html elements
Line 2383  sub generate_menu { Line 2378  sub generate_menu {
             # create the markup for the current $link and push it into @links.              # create the markup for the current $link and push it into @links.
             # each entry consists of an image and a text optionally followed               # each entry consists of an image and a text optionally followed 
             # by a help link.              # by a help link.
             my $src;  
             if ($$link{icon} ne '') {  
                 $src = '/res/adm/pages/'.$$link{icon};  
             }  
             push(@links,$li->(              push(@links,$li->(
                         $a->(                          $a->(
                             $img->("", {                              $img->("", {
                                 class => "LC_noBorder LC_middle",                                  class => "LC_noBorder LC_middle",
                                 src   => $src,                                  src   => "/res/adm/pages/$$link{icon}",
                                 alt   => mt(defined($$link{alttext}) ?                                  alt   => mt(defined($$link{alttext}) ?
                                 $$link{alttext} : $$link{linktext})                                  $$link{alttext} : $$link{linktext})
                             }), {                              }), {
Line 2494  sub add_item_funclist { Line 2485  sub add_item_funclist {
     return '<li>'.$content.'</li>'."\n";      return '<li>'.$content.'</li>'."\n";
 }  }
   
   ##############################################
   ##############################################
   
 =pod  =pod
   
 =item &end_funclist  =item &end_funclist
Line 2509  add_item_funclist Line 2503  add_item_funclist
 Inputs: ./.  Inputs: ./.
   
 Returns: HTML code with function list end  Returns: HTML code with function list end
   
 =cut  =cut
   
   ##############################################
   ##############################################
   
 sub end_funclist {  sub end_funclist {
     return "</ul>\n";      return "</ul>\n";
 }  }
   
 =pod  
   
 =item funclist_from_array( \@array, {legend => 'text for legend'} )  
   
 Constructs a XHTML list from \@array with the first item being visually  
 highlighted and set to the value of legend or 'Functions' if legend is  
 empty.  
   
 =over  
   
 =item \@array  
   
 A reference to the array containing text that will be wrapped in <li></li> tags.  
   
 =item { legend => 'text' }  
   
 A string that's used as visually highlighted first item. 'Functions' is used if  
 it's value evaluates to false.  
   
 =back  
   
 returns: XHTML list as string.  
   
 =back  
   
 =cut  
   
 sub funclist_from_array {  
     my ($items, $args) = @_;  
     $args->{legend} ||= mt('Functions');  
     return list_from_array( [$args->{legend}, @$items],  
                { listattr => {class => 'LC_funclist'} });  
 }  
   
 1;  1;
   
 __END__  __END__

Removed from v.1.253.2.4  
changed lines
  Added in v.1.256


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