--- loncom/interface/lonhtmlcommon.pm 2015/05/11 17:18:36 1.358.2.1
+++ loncom/interface/lonhtmlcommon.pm 2015/03/31 13:46:01 1.359
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.358.2.1 2015/05/11 17:18:36 raeburn Exp $
+# $Id: lonhtmlcommon.pm,v 1.359 2015/03/31 13:46:01 damieng Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -482,36 +482,7 @@ the date/time fields are left empty.
=item $state
Specifies the initial state of the form elements. Either 'disabled' or empty.
-Defaults to empty, which indicates the form elements are not disabled.
-
-=item $no_hh_mm_ss
-
-If true, text boxes for hours, minutes and seconds are omitted.
-
-=item $defhour
-
-Default value for hours (a default of 0 is used otherwise).
-
-=item $defmin
-
-Default value for minutes (a default of 0 is used otherwise).
-
-=item defsec
-
-Default value for seconds (a default of 0 is used otherwise).
-
-=item $nolink
-
-If true, a "Select calendar" link (to pop-up a calendar) is not displayed
-to the right of the items.
-
-=item $no_mm_ss
-
-If true, text boxes for minutes and seconds are omitted.
-
-=item $no_ss
-
-If true, text boxes for seconds are omitted.
+Defaults to empty, which indiciates the form elements are not disabled.
=back
@@ -525,7 +496,7 @@ The method used to restrict user input w
##############################################
sub date_setter {
my ($formname,$dname,$currentvalue,$special,$includeempty,$state,
- $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink,$no_mm_ss,$no_ss) = @_;
+ $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink) = @_;
my $now = time;
my $tzname;
@@ -678,24 +649,17 @@ ENDJS
$result .= &mt('[_1] [_2] [_3] ',
$monthselector,$dayselector,$yearselector).
$tzone;
- } elsif ($no_mm_ss) {
- $result .= &mt('[_1] [_2] [_3] [_4]',
- $monthselector,$dayselector,$yearselector,
- $hourselector).
- $tzone;
- } elsif ($no_ss) {
- $result .= &mt('[_1] [_2] [_3] [_4] [_5]m',
- $monthselector,$dayselector,$yearselector,
- $hourselector,$minuteselector).
- $tzone;
+ if (!$nolink) {
+ $result .= &mt('[_1]Select Date[_2]',$cal_link,'');
+ }
} else {
$result .= &mt('[_1] [_2] [_3] [_4] [_5]m [_6]s ',
$monthselector,$dayselector,$yearselector,
$hourselector,$minuteselector,$secondselector).
$tzone;
- }
- if (!$nolink) {
- $result .= &mt('[_1]Select Date[_2]',$cal_link,'');
+ if (!$nolink) {
+ $result .= &mt('[_1]Select Date[_2]',$cal_link,'');
+ }
}
$result .= "\n\n";
return $result;
@@ -1342,6 +1306,40 @@ sub htmlareaselectactive {
}
function startRichEditor(id) {
+ // fix character entities inside
+ // NOTE: this is not fixing characters inside
+ var ta = document.getElementById(id);
+ var value = ta.value;
+ var in_m = false; // in the m element
+ var in_text = false; // in the text inside the m element
+ var im = -1; // position of
+ var it = -1; // position of the text inside
+ for (var i=0; i if found twice
+ in_m = true;
+ in_text = false;
+ im = i;
+ it = -1;
+ } else if (in_m) {
+ if (!in_text) {
+ if (value.charAt(i) == ">") {
+ in_text = true;
+ it = i+1;
+ }
+ } else if (value.substr(i, 4) == "") {
+ in_m = false;
+ var text = value.substr(it, i-it);
+ var l1 = text.length;
+ text = text.replace(//g, ">");
+ var l2 = text.length;
+ value = value.substr(0, it) + text + "" + value.substr(i+4);
+ i = i + (l2-l1);
+ }
+ }
+ }
+ ta.value = value;
CKEDITOR.replace(id,
{
customConfig: "/ckeditor/loncapaconfig.js",
@@ -1353,6 +1351,63 @@ sub htmlareaselectactive {
function destroyRichEditor(id) {
CKEDITOR.instances[id].destroy();
+ // replace character entities < and > in
+ // and "&fctname(" by "&fctname("
+ // and the quotes inside functions: "&fct(1, "a")" -> "&fct(1, "a")"
+ var ta = document.getElementById(id);
+ var value = ta.value;
+ var in_m = false; // in the m element
+ var in_text = false; // in the text inside the m element
+ var im = -1; // position of
+ var it = -1; // position of the text inside
+ for (var i=0; i if found twice
+ in_m = true;
+ in_text = false;
+ im = i;
+ it = -1;
+ } else if (in_m) {
+ if (!in_text) {
+ if (value.charAt(i) == ">") {
+ in_text = true;
+ it = i+1;
+ }
+ } else if (value.substr(i, 4) == "") {
+ in_m = false;
+ var text = value.substr(it, i-it);
+ var l1 = text.length;
+ text = text.replace(/</g, "<");
+ text = text.replace(/>/g, ">");
+ var l2 = text.length;
+ value = value.substr(0, it) + text + "" + value.substr(i+4);
+ i = i + (l2-l1);
+ }
+ }
+ }
+ // fix function names
+ value = value.replace(/&([a-zA-Z_]+)\(/g, "&$1(");
+ // fix quotes in functions
+ var pos_next_fct = value.search(/&[a-zA-Z_]+\(/);
+ var depth = 0;
+ for (var i=0; i 0) {
+ if (value.charAt(i) == ")")
+ depth--;
+ else if (value.substr(i, 6) == """)
+ value = value.substr(0, i) + "\"" + value.substr(i+6);
+ }
+ }
+ // replace the text value
+ ta.value = value;
}
function editorHandler(event) {
@@ -3647,7 +3702,6 @@ add_item_funclist
Inputs: ./.
Returns: HTML code with function list end
-
=cut
sub end_funclist {
@@ -3691,8 +3745,6 @@ sub funclist_from_array {
=pod
-=over
-
=item &actionbox( \@array )
Constructs a XHTML list from \@array with the first item being visually
@@ -3710,7 +3762,7 @@ A reference to the array containing text
=back
-Returns: XHTML div as string.
+Returns: XHTML div as string.
=back