--- loncom/interface/lonhtmlcommon.pm 2009/12/11 17:25:01 1.254 +++ loncom/interface/lonhtmlcommon.pm 2010/01/05 00:42:49 1.258 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.254 2009/12/11 17:25:01 bisitz Exp $ +# $Id: lonhtmlcommon.pm,v 1.258 2010/01/05 00:42:49 faziophi Exp $ # # Copyright Michigan State University Board of Trustees # @@ -384,7 +384,7 @@ dname_hour, dname_min, and dname_sec. The current setting for this time parameter. A unix format time (time in seconds since the beginning of Jan 1st, 1970, GMT. An undefined value is taken to indicate the value is the current time -unless it is requested to leave it empty. See $includeempty. +unless it is requested to leave it empty. See $includeempty. Also, to be explicit, a value of 'now' also indicates the current time. =item $special @@ -418,8 +418,8 @@ sub date_setter { my $now = time; my $tzname; - my ($sec,$min,$hour,$mday,$month,$year) = ('','',undef,'','',''); - # other potentially useful values: wkday,yrday,is_daylight_savings + my ($sec,$min,$hour,$mday,$month,$year) = ('', '', undef,''.''.''); + #other potentially useful values: wkday,yrday,is_daylight_savings if (! defined($state) || $state ne 'disabled') { $state = ''; @@ -427,29 +427,26 @@ sub date_setter { if (! defined($no_hh_mm_ss)) { $no_hh_mm_ss = 0; } - if ($currentvalue eq 'now') { $currentvalue = $now; } - + # Default value: Set empty date field to current time # unless empty inclusion is requested if ((!$includeempty) && (!$currentvalue)) { - $currentvalue = $now; + $currentvalue = $now; } # Do we have a date? Split it! if ($currentvalue) { - ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue); + ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue); - # No values provided for hour, min, sec? Use default 0 + #No values provided for hour, min, sec? Use default 0 if (($defhour) || ($defmin) || ($defsec)) { $sec = ($defsec ? $defsec : 0); $min = ($defmin ? $defmin : 0); $hour = ($defhour ? $defhour : 0); } } - - # Create Output my $result = "\n<!-- $dname date setting form -->\n"; $result .= <<ENDJS; <script type="text/javascript"> @@ -1243,11 +1240,18 @@ ENDLINK } sub htmlareaheaders { - return if (&htmlareablocked()); - return if (!&htmlareabrowser()); - return (<<ENDHEADERS); + my $s=""; + if (!&htmlareablocked() && &htmlareabrowser()) { + $s.=(<<ENDEDITOR); <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 @@ -1286,16 +1290,98 @@ sub htmlareaselectactive { my $output='<script type="text/javascript" defer="1">'."\n" .'// <![CDATA['."\n"; my $lang = &htmlarea_lang(); + $output.=' + + function containsBlockHtml(id) { + var re = $("#"+id).html().search(/(?:\<\;|\<)(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div)[\s]*((?:\/[\s]*(?:\>\;|\>)|(?:\>\;|\>)[\s\S]*(?:\<\;|\<)\/[\s]*\1[\s]*\(?:\>\;|\>))/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>« 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 »</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>« 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 »</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>« 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 »</b></a></div>"); + $("#LC_rt_"+id).click(editorHandler); + }); + + }); +'; + foreach my $field (@fields) { - $output.=" + $output.=' + { - var oFCKeditor = new FCKeditor('$field'); - oFCKeditor.Config['CustomConfigurationsPath'] = - '/fckeditor/loncapaconfig.js'; - oFCKeditor.ReplaceTextarea(); - oFCKeditor.Config['AutoDetectLanguage'] = false; - oFCKeditor.Config['DefaultLanguage'] = '$lang'; -}"; + $(document).ready(function() { + if (!($("#'.$field.'").hasClass("LC_richAlwaysOn"))) { + if (!($("#'.$field.'").hasClass("LC_richAlwaysOff"))) { + if (!($("#'.$field.'").hasClass("LC_richDetectHtml"))) { + if (!($("#'.$field.'").hasClass("LC_richDefaultOn"))) { + 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" .'// ]]>'."\n"