--- loncom/interface/lonhtmlcommon.pm 2013/07/02 19:04:37 1.348 +++ loncom/interface/lonhtmlcommon.pm 2018/04/29 16:28:25 1.358.2.12 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.348 2013/07/02 19:04:37 raeburn Exp $ +# $Id: lonhtmlcommon.pm,v 1.358.2.12 2018/04/29 16:28:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -64,9 +64,15 @@ use HTML::Entities(); use LONCAPA qw(:DEFAULT :match); sub java_not_enabled { - return "\n".''. - &mt('The required Java applet could not be started. Please make sure to have Java installed and active in your browser.'). - "\n"; + if (($env{'browser.mobile'}) && ($env{'browser.mobile'} =~ /^ipad|ipod|iphone$/i)) { + return "\n".''. + &mt('The required Java applet could not be started, because Java is not supported by your mobile device.'). + "\n"; + } else { + return "\n".''. + &mt('The required Java applet could not be started. Please make sure to have Java installed and active in your browser.'). + "\n"; + } } sub coursepreflink { @@ -86,7 +92,7 @@ sub raw_href_to_link { sub entity_encode { my ($text)=@_; - return &HTML::Entities::encode($text, '<>&"'); + return &HTML::Entities::encode($text, '\'<>&"'); } sub direct_parm_link { @@ -170,7 +176,7 @@ sub dragmath_js { function mathedit(textarea, doc) { targetEntry = textarea; targetDoc = doc; - newwin = window.open("/adm/dragmath/applet/$popup.html","","width=565,height=500,resizable"); + newwin = window.open("/adm/dragmath/$popup.html","","width=565,height=500,resizable"); } // ]]> @@ -401,7 +407,7 @@ sub textbox { ############################################## ############################################## sub checkbox { - my ($name,$checked,$value) = @_; + my ($name,$checked,$value,$special) = @_; my $Str = ''; return $Str; } @@ -476,7 +482,36 @@ 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 indiciates the form elements are not disabled. +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. =back @@ -490,7 +525,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_hh_mm_ss,$defhour,$defmin,$defsec,$nolink,$no_mm_ss,$no_ss) = @_; my $now = time; my $tzname; @@ -499,6 +534,8 @@ sub date_setter { if (! defined($state) || $state ne 'disabled') { $state = ''; + } else { + $state = 'disabled="disabled"'; } if (! defined($no_hh_mm_ss)) { $no_hh_mm_ss = 0; @@ -643,17 +680,24 @@ ENDJS $result .= &mt('[_1] [_2] [_3] ', $monthselector,$dayselector,$yearselector). $tzone; - if (!$nolink) { - $result .= &mt('[_1]Select Date[_2]',$cal_link,''); - } + } 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; } 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; @@ -1116,9 +1160,9 @@ sub Close_PrgWin { # ------------------------------------------------------- Puts directory header sub crumbs { - my ($uri,$target,$prefix,$form,$skiplast)=@_; + my ($uri,$target,$prefix,$form,$skiplast,$onclick)=@_; # You cannot crumbnify uploaded or adm resources - if ($uri=~/^\/*(uploaded|adm)\//) { return &mt('(Internal Course/Group Content)'); } + if ($uri=~/^\/*(uploaded|adm)\//) { return &mt('(Internal Course/Community Content)'); } if ($target) { $target = ' target="'. &Apache::loncommon::escape_single($target).'"'; @@ -1138,13 +1182,19 @@ sub crumbs { } else { $path.='/'; } + if ($path eq '/res/') { + unless (&Apache::lonnet::allowed('bre',$path)) { + $output.="$dir/"; + next; + } + } my $href_path = &HTML::Entities::encode($path,'<>&"'); &Apache::loncommon::inhibit_menu_check(\$href_path); if ($form) { my $href = 'javascript:'.$form.".action='".$href_path."';".$form.'.submit();'; - $output.=qq{$dir/}; + $output.=qq{$dir/}; } else { - $output.=qq{$dir/}; + $output.=qq{$dir/}; } } } else { @@ -1215,17 +1265,18 @@ sub htmlareaheaders { ENDEDITOR } $s.=(< - - + + + - + + ENDJQUERY return $s; @@ -1299,6 +1350,41 @@ sub htmlareaselectactive { } function startRichEditor(id) { + // fix character entities inside + // NOTE: this is not fixing characters inside + // NOTE: < and > inside should fix automatically because there should not be a letter after <. + 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", @@ -1310,6 +1396,68 @@ sub htmlareaselectactive { function destroyRichEditor(id) { CKEDITOR.instances[id].destroy(); + // replace character entities < and > in and + // 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_element = false; // in the m or chem element + var tagname = ""; // m or chem + var in_text = false; // in the text inside the element + var im = -1; // position of start tag + var it = -1; // position of the text inside + for (var i=0; i") { + in_text = true; + it = i+1; + } + } else if (value.substr(i, 3+tagname.length) == "") { + in_element = 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); + 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) { @@ -1617,12 +1765,19 @@ A link to help for the component will be All inputs can be undef without problems. Inputs: $component (the text on the right side of the breadcrumbs trail), - $component_help + $component_help (the help item filename (without .tex extension). $menulink (boolean, controls whether to include a link to /adm/menu) $helplink (if 'nohelp' don't include the orange help link) $css_class (optional name for the class to apply to the table for CSS) $no_mt (optional flag, 1 if &mt() is _not_ to be applied to $component when including the text on the right. + $CourseBreadcrumbs (optional flag, 1 if &breadcrumbs called from &docs_breadcrumbs, + because breadcrumbs are being) + $topic_help (optional help item to be displayed on right side of the breadcrumbs + row, using loncommon::help_open_topic() to generate the link. + $topic_help_text (text to include in the link in the optional help item + on the right side of the breadcrumbs row. + Returns a string containing breadcrumbs for the current page. =item &clear_breadcrumbs() @@ -1650,7 +1805,7 @@ returns: nothing sub breadcrumbs { my ($component,$component_help,$menulink,$helplink,$css_class,$no_mt, - $CourseBreadcrumbs) = @_; + $CourseBreadcrumbs,$topic_help,$topic_help_text) = @_; # $css_class ||= 'LC_breadcrumbs'; @@ -1675,7 +1830,7 @@ returns: nothing $env{'course.'.$env{'request.course.id'}.'.description'}; $no_mt_descr = 1; if ($env{'request.noversionuri'} =~ - m{^/public/($match_domain)/($match_courseid)/syllabus$}) { + m{^/?public/($match_domain)/($match_courseid)/syllabus$}) { unless (($env{'course.'.$env{'request.course.id'}.'.domain'} eq $1) && ($env{'course.'.$env{'request.course.id'}.'.num'} eq $2)) { $description = 'Menu'; @@ -1699,11 +1854,15 @@ returns: nothing my $links; if ((&show_return_link) && (!$CourseBreadcrumbs) && (ref($last) eq 'HASH')) { my $alttext = &mt('Go Back'); + my $hashref = { href => '/adm/flip?postdata=return:', + title => &mt('Back to most recent content resource'), + class => 'LC_menubuttons_link', + }; + if ($env{'request.noversionuri'} eq '/adm/searchcat') { + $hashref->{'target'} = '_top'; + } $links=&htmltag( 'a',''.$alttext.'', - { href => '/adm/flip?postdata=return:', - title => &mt('Back to most recent content resource'), - class => 'LC_menubuttons_link', - }); + $hashref); $links=&htmltag('li',$links); } $links.= join "", @@ -1753,6 +1912,10 @@ returns: nothing $component_help, $faq,$bug); } + if ($topic_help && $topic_help_text) { + $icons .= ' '.&Apache::loncommon::help_open_topic($topic_help,&mt($topic_help_text),'', + undef,600); + } # @@ -1765,7 +1928,7 @@ returns: nothing } - if ($component) { + if (($component) || ($topic_help && $topic_help_text)) { $links = &htmltag('span', ( $no_mt ? $component : mt($component) ). ( $icons ? $icons : '' ), @@ -1868,6 +2031,16 @@ returns: nothing undef(%tools); } +=item ¤t_breadcrumb_tools() + +returns: a hash containing the current breadcrumb tools. + +=cut + + sub current_breadcrumb_tools { + return %tools; + } + =item &render_tools(\$breadcrumbs) Creates html for breadcrumb tools (categories navigation and tools) and inserts @@ -2230,10 +2403,10 @@ sub course_selection { if ($totcodes > 0) { my $numtitles = @$codetitles; if ($numtitles > 0) { - $output .= '
'; + $output .= '
'; $output .= ''; @@ -2409,9 +2582,9 @@ sub resource_info_box { # sub display_usage { - my ($current_disk_usage,$disk_quota) = @_; - my $usage = $current_disk_usage/1000; - my $quota = $disk_quota/1000; + my ($current_disk_usage,$disk_quota,$context) = @_; + my $usage = $current_disk_usage/1024; + my $quota = $disk_quota/1024; my $percent; if ($disk_quota == 0) { $percent = 100.0; @@ -2435,9 +2608,13 @@ sub display_usage { if ($prog_width > 100) { $prog_width = 100; } + my $display = 'block'; + if ($context eq 'authoring') { + $display = 'inline'; + } return ' -
'.&mt('Currently using [_1] of the [_2] available.',$usage.' MB ('.$percent.'%)',$quota.' MB')."\n". -'
'."\n". +
'.&mt('Currently using [_1] of the [_2] available.',$usage.' MB ('.$percent.'%)',$quota.' MB')."\n". +'
'."\n". '
'."\n". '
'."\n". '
'; @@ -2687,10 +2864,12 @@ sub set_form_elements { sub file_submissionchk_js { my ($turninpaths,$multiples) = @_; - my $overwritewarn = &mt('File(s) you uploaded for your submission will overwrite existing file(s) submitted for this item').'\\n'. + my $overwritewarn = &mt('File(s) you uploaded for your submission will overwrite existing file(s) submitted for this item')."\n". &mt('Continue submission and overwrite the file(s)?'); - my $delfilewarn = &mt('You have indicated you wish to remove some files previously included in your submission.').'\\n'. + &js_escape(\$overwritewarn); + my $delfilewarn = &mt('You have indicated you wish to remove some files previously included in your submission.')."\n". &mt('Continue submission with these files removed?'); + &js_escape(\$delfilewarn); my ($turninpathtext,$multtext,$arrayindexofjs); if (ref($turninpaths) eq 'HASH') { foreach my $key (sort(keys(%{$turninpaths}))) { @@ -2931,7 +3110,7 @@ ENDSCRIPT ############################################## sub resize_scrollbox_js { - my ($context,$tabidstr) = @_; + my ($context,$tabidstr,$tid) = @_; my (%names,$paddingwfrac,$offsetwfrac,$offsetv,$minw,$minv); if ($context eq 'docs') { %names = ( @@ -2941,7 +3120,7 @@ sub resize_scrollbox_js { scroll => 'contentscroll', boxh => 'contenteditor', ); - $paddingwfrac = 0.09; + $paddingwfrac = 0.09; $offsetwfrac = 0.015; $offsetv = 20; $minw = 250; @@ -2967,9 +3146,11 @@ window.onresize=callResize; '; if ($context eq 'docs') { - $output .= ' -var activeTab; -'; + if ($env{'form.active'}) { + $output .= "\nvar activeTab = '$env{'form.active'}$tid';\n"; + } else { + $output .= "\nvar activeTab = '';\n"; + } } $output .= <<"FIRST"; @@ -2980,6 +3161,7 @@ function resize_scrollbox(scrollboxname, var scrolltableid = 'table_'+scrollboxname; var scrollbox; var scrolltable; + var ismobile = '$env{'browser.mobile'}'; if (document.getElementById("$names{'boxw'}") == null) { return; @@ -3016,6 +3198,7 @@ FIRST } $output .= <<"SECOND"; var listwchange; + var scrollchange; if (chkw == 1) { var boxw = document.getElementById("$names{'boxw'}").offsetWidth; var itemw; @@ -3027,6 +3210,7 @@ FIRST var scrollboxw = scrollbox.offsetWidth; var scrollboxscrollw = scrollbox.scrollWidth; + var scrollstart = scrollboxw; var offsetw = parseInt(vpw * $offsetwfrac); var paddingw = parseInt(vpw * $paddingwfrac); @@ -3101,11 +3285,19 @@ PARAMSONE } } + if (newscrollboxw != scrollboxw) { + scrollchange = 1; + } + if (itemid.offsetWidth != itemwstart) { listwchange = 1; } } if ((chkh == 1) || (listwchange)) { + var itemid = document.getElementById("$names{'item'}"); + if (itemid != null) { + itemh = itemid.offsetHeight; + } var primaryheight = document.getElementById('LC_nav_bar').offsetHeight; var secondaryheight; if (document.getElementById('LC_secondary_menu') != null) { @@ -3126,6 +3318,7 @@ PARAMSONE var scrollboxheight = scrollbox.offsetHeight; var scrollboxscrollheight = scrollbox.scrollHeight; + var scrollboxh = scrollboxheight; var minvscrollbox = $minv; var offsetv = $offsetv; @@ -3156,6 +3349,13 @@ PARAMSONE scrollbox.style.height = newscrollheight+"px"; } } + var newscrollboxh = scrollbox.offsetHeight; + if (scrollboxh != newscrollboxh) { + scrollchange = 1; + } + } + if (ismobile && scrollchange) { + \$("#div_$names{'scroll'}").getNiceScroll().onResize(); } return; } @@ -3174,8 +3374,9 @@ THIRD ############################################## sub javascript_jumpto_resource { - my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'. + my $confirm_switch = &mt("Editing requires switching to the resource's home server.")."\n". &mt('Switch server?'); + &js_escape(\$confirm_switch); return (<&'); } } - $jscall = "go('$cfile')"; + if ($anchor ne '') { + $cfile .= '#'.$anchor; + } + $jscall = "go('".&Apache::loncommon::escape_single($cfile)."')"; } return $jscall; } @@ -3316,7 +3533,7 @@ END sub htmltag{ return qq|<$_[0]| - . join( '', map { qq| $_="${$_[2]}{$_}"| if ${$_[2]}{$_} } keys %{ $_[2] } ) + . join( '', map { qq| $_="${$_[2]}{$_}"| if ${$_[2]}{$_} } keys(%{ $_[2] }) ) . ($_[1] ? qq|>$_[1]| : qq|/>|). "\n"; }; @@ -3579,6 +3796,7 @@ add_item_funclist Inputs: ./. Returns: HTML code with function list end + =cut sub end_funclist { @@ -3622,6 +3840,8 @@ sub funclist_from_array { =pod +=over + =item &actionbox( \@array ) Constructs a XHTML list from \@array with the first item being visually @@ -3639,7 +3859,7 @@ A reference to the array containing text =back -Returns: XHTML div as string. +Returns: XHTML div as string. =back
'.$$codetitles[0].'
'."\n". '
'.$$codetitles[$i].'
'."\n". ''."\n". '