From 3afc728f5cf59bc3a1980d642c0610aa803d64a8 Mon Sep 17 00:00:00 2001 From: vyshane Date: Tue, 14 Mar 2006 05:26:03 +0000 Subject: [PATCH] Changed use_html_editor and print_editor_config functions so that we have an editor javascript object that we can use when we create the HTMLArea editor. This object allows us to call e.g. editor.insertHtml(). --- lib/weblib.php | 170 +++++++++++++++++++++++++------------------------ 1 file changed, 87 insertions(+), 83 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index e73920fffd..f31597c07d 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -3215,15 +3215,74 @@ function print_richedit_javascript($form, $name, $source='no') { */ function use_html_editor($name='', $editorhidebuttons='') { echo ''."\n"; } +function print_editor_config($editorhidebuttons='', $return=false) { + global $CFG; + + $str = "var config = editor.config;\n"; + $str .= "config.pageStyle = \"body {"; + + if (!(empty($CFG->editorbackgroundcolor))) { + $str .= " background-color: $CFG->editorbackgroundcolor;"; + } + + if (!(empty($CFG->editorfontfamily))) { + $str .= " font-family: $CFG->editorfontfamily;"; + } + + if (!(empty($CFG->editorfontsize))) { + $str .= " font-size: $CFG->editorfontsize;"; + } + + $str .= " }\";\n"; + $str .= "config.killWordOnPaste = "; + $str .= (empty($CFG->editorkillword)) ? "false":"true"; + $str .= ';'."\n"; + $str .= 'config.fontname = {'."\n"; + + $fontlist = isset($CFG->editorfontlist) ? explode(';', $CFG->editorfontlist) : array(); + $i = 1; // Counter is used to get rid of the last comma. + + foreach ($fontlist as $fontline) { + if (!empty($fontline)) { + if ($i > 1) { + $str .= ','."\n"; + } + list($fontkey, $fontvalue) = split(':', $fontline); + $str .= '"'. $fontkey ."\":\t'". $fontvalue ."'"; + + $i++; + } + } + $str .= '};'; + + if (!empty($editorhidebuttons)) { + $str .= "\nconfig.hideSomeButtons(\" ". $editorhidebuttons ." \");\n"; + } else if (!empty($CFG->editorhidebuttons)) { + $str .= "\nconfig.hideSomeButtons(\" ". $CFG->editorhidebuttons ." \");\n"; + } + + if (!empty($CFG->editorspelling) && !empty($CFG->aspellpath)) { + $str .= print_speller_code($usehtmleditor=true, true); + } + + if ($return) { + return $str; + } + echo $str; +} + /** * Returns a turn edit on/off button for course in a self contained form. * Used to be an icon, but it's now a simple form button @@ -3631,7 +3690,6 @@ function navmenu($course, $cm=NULL, $targetwindow='self') { ''. $nextmod .''; } - /** * Given a course * This function returns a small popup menu with all the @@ -3724,8 +3782,6 @@ function navmenulist($course, $sections, $modinfo, $isteacher, $strsection, $str return implode("\n", $menu); } - - /** * Prints form items with the names $day, $month and $year * @@ -4423,63 +4479,6 @@ function print_side_block_end($attributes = array()) { } -/** - * Prints out the HTML editor config. - * - * @uses $CFG - */ - function print_editor_config($editorhidebuttons='') { - - global $CFG; - - // print new config - echo 'var config = new HTMLArea.Config();'."\n"; - echo "config.pageStyle = \"body {"; - if(!(empty($CFG->editorbackgroundcolor))) { - echo " background-color: $CFG->editorbackgroundcolor;"; - } - - if(!(empty($CFG->editorfontfamily))) { - echo " font-family: $CFG->editorfontfamily;"; - } - - if(!(empty($CFG->editorfontsize))) { - echo " font-size: $CFG->editorfontsize;"; - } - - echo " }\";\n"; - echo "config.killWordOnPaste = "; - echo(empty($CFG->editorkillword)) ? "false":"true"; - echo ';'."\n"; - echo 'config.fontname = {'."\n"; - - $fontlist = isset($CFG->editorfontlist) ? explode(';', $CFG->editorfontlist) : array(); - $i = 1; // Counter is used to get rid of the last comma. - - foreach($fontlist as $fontline) { - if(!empty($fontline)) { - if ($i > 1) { - echo ','."\n"; - } - list($fontkey, $fontvalue) = split(':', $fontline); - echo '"'. $fontkey ."\":\t'". $fontvalue ."'"; - - $i++; - } - } - echo '};'; - - if (!empty($editorhidebuttons)) { - echo "\nconfig.hideSomeButtons(\" ". $editorhidebuttons ." \");\n"; - } else if (!empty($CFG->editorhidebuttons)) { - echo "\nconfig.hideSomeButtons(\" ". $CFG->editorhidebuttons ." \");\n"; - } - - if(!empty($CFG->editorspelling) && !empty($CFG->aspellpath)) { - print_speller_code($usehtmleditor=true); - } -} - /** * Prints out code needed for spellchecking. * Original idea by Ludo (Marc Alier). @@ -4488,29 +4487,34 @@ function print_side_block_end($attributes = array()) { * @param boolean $usehtmleditor ? * @todo Finish documenting this function */ -function print_speller_code ($usehtmleditor=false) { +function print_speller_code ($usehtmleditor=false, $return=false) { global $CFG; - + $str = ''; + if(!$usehtmleditor) { - echo "\n".''."\n"; + $str .= "\n".''."\n"; } else { - echo "\nfunction spellClickHandler(editor, buttonId) {\n"; - echo "\teditor._textArea.value = editor.getHTML();\n"; - echo "\tvar speller = new spellChecker( editor._textArea );\n"; - echo "\tspeller.popUpUrl = \"" . $CFG->wwwroot ."/lib/speller/spellchecker.html\";\n"; - echo "\tspeller.spellCheckScript = \"". $CFG->wwwroot ."/lib/speller/server-scripts/spellchecker.php\";\n"; - echo "\tspeller._moogle_edit=1;\n"; - echo "\tspeller._editor=editor;\n"; - echo "\tspeller.openChecker();\n"; - echo '}'."\n"; + $str .= "\nfunction spellClickHandler(editor, buttonId) {\n"; + $str .= "\teditor._textArea.value = editor.getHTML();\n"; + $str .= "\tvar speller = new spellChecker( editor._textArea );\n"; + $str .= "\tspeller.popUpUrl = \"" . $CFG->wwwroot ."/lib/speller/spellchecker.html\";\n"; + $str .= "\tspeller.spellCheckScript = \"". $CFG->wwwroot ."/lib/speller/server-scripts/spellchecker.php\";\n"; + $str .= "\tspeller._moogle_edit=1;\n"; + $str .= "\tspeller._editor=editor;\n"; + $str .= "\tspeller.openChecker();\n"; + $str .= '}'."\n"; } + if ($return) { + return $str; + } + echo $str; } /** @@ -4775,4 +4779,4 @@ function page_doc_link($text='', $iconpath='') { // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140: -?> +?> \ No newline at end of file -- 2.39.5