// use ##emoticons_html## to replace the emoticons documentation
if(preg_match('~(##emoticons_html##)~', $output, $matches)) {
- $output = preg_replace('~(##emoticons_html##)~', get_emoticons_html(), $output);
+ $output = preg_replace('~(##emoticons_html##)~', get_emoticons_list_for_help_file(), $output);
}
// Do the main output.
$CFG->docroot = ''; // We don't want a doc link here
print_footer('none');
-// Utility function =================================================================
-
-function get_emoticons_html(){
- global $CFG;
- $output = '';
- $emoticonstring = $CFG->emoticons;
- $output .= '<ul>';
- if ($emoticonstring) {
- $items = explode('{;}', $CFG->emoticons);
- foreach ($items as $item) {
- $item = explode('{:}', $item);
- $emoticons[$item[0]] = $item[1];
- $output .= '<li><a href="javascript:inserttext(\''.$item[0].'\')"><img src="'.
- $CFG->pixpath.'/s/'.$item[1].'.gif" alt="'.$item[0].'" /></a>'.' <code>'.$item[0].
- '</code></li>';
- }
-
- }
- $output .= '</ul>';
- return $output;
-
-}
-
function file_exists_and_readable($filepath) {
return file_exists($filepath) and is_file($filepath) and is_readable($filepath);
}
<h1>Using Smilies (emoticons)</h1>
+<!-- Note, this file is no loger used in HEAD, it has been replaced by emoticons2.html
+which uses a dynamically buils list of smilies. The purpose of this note is to
+point out that it is not a problem that none fo the href="javascript:inserttext('...')"
+links work any more in HEAD. See MDL-16654. -->
+
<table align="center" border="1">
<tbody><tr valign="top">
<td>
}
function openpopup(url, name, options, fullscreen) {
- var fullurl = moodle_config.wwwroot + url;
+ var fullurl = moodle_cfg.wwwroot + url;
var windowobj = window.open(fullurl,name,options);
if (fullscreen) {
windowobj.moveTo(0,0);
windowobj.focus();
return false;
}
+
+/* This is only used on a few help pages. */
+emoticons_help = {
+ inputarea: null,
+
+ init: function(formname, fieldname, listid) {
+ if (!opener || !opener.document.forms[formname]) {
+ return;
+ }
+ emoticons_help.inputarea = opener.document.forms[formname][fieldname];
+ if (!emoticons_help.inputarea) {
+ return;
+ }
+ var emoticons = document.getElementById(listid).getElementsByTagName('li');
+ for (var i = 0; i < emoticons.length; i++) {
+ var text = emoticons[i].getElementsByTagName('img')[0].alt;
+ YAHOO.util.Event.addListener(emoticons[i], 'click', emoticons_help.inserttext, text);
+ }
+ },
+
+ inserttext: function(e, text) {
+ text = ' ' + text + ' ';
+ if (emoticons_help.inputarea.createTextRange && emoticons_help.inputarea.caretPos) {
+ var caretPos = emoticons_help.inputarea.caretPos;
+ caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
+ } else {
+ emoticons_help.inputarea.value += text;
+ }
+ emoticons_help.inputarea.focus();
+ }
+}
\ No newline at end of file
<?php /// $Id$
+/// Load up any required Javascript libraries
- /// Load up any required Javascript libraries
+if (!defined('MOODLE_INTERNAL')) {
+ die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
+}
- if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
+if (can_use_html_editor() && !empty($CFG->editorsrc)) {
+ foreach ( $CFG->editorsrc as $scriptsource ) {
+ echo '<script type="text/javascript" src="'. $scriptsource .'"></script>'."\n";
}
-
- if (can_use_html_editor() && !empty($CFG->editorsrc)) {
- foreach ( $CFG->editorsrc as $scriptsource ) {
- echo '<script type="text/javascript" src="'. $scriptsource .'"></script>'."\n";
- }
- }
-
+}
?>
<!--<style type="text/css">/*<![CDATA[*/ body{behavior:url(<?php echo $CFG->httpswwwroot ?>/lib/csshover.htc);} /*]]>*/</style>-->
</script>
<script type="text/javascript">
//<![CDATA[
+var id2suffix = {};
<?php
- echo "function inserttext(text) {\n";
- if (!empty($SESSION->inserttextform)) {
- $insertfield = "opener.document.forms['$SESSION->inserttextform'].$SESSION->inserttextfield";
- echo " if(!opener.document.forms['$SESSION->inserttextform']){";
+if (!empty($focus)) {
+ if(($pos = strpos($focus, '.')) !== false) {
+ //old style focus using form name - no allowed inXHTML Strict
+ $topelement = substr($focus, 0, $pos);
+ echo "addonload(function() { if(document.$topelement) document.$focus.focus(); });\n";
} else {
- $insertfield = "opener.document.forms['theform'].message";
- echo " if(!opener.document.forms['theform']){";
- }
- echo " return;";
- echo " }";
- echo " text = ' ' + text + ' ';\n";
- echo " if ( $insertfield.createTextRange && $insertfield.caretPos) {\n";
- echo " var caretPos = $insertfield.caretPos;\n";
- echo " caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;\n";
- echo " } else {\n";
- echo " $insertfield.value += text;\n";
- echo " }\n";
- echo " $insertfield.focus();\n";
- echo "}\n";
-
- if (!empty($focus)) {
- if(($pos = strpos($focus, '.')) !== false) {
- //old style focus using form name - no allowed inXHTML Strict
- $topelement = substr($focus, 0, $pos);
- echo "addonload(function() { if(document.$topelement) document.$focus.focus(); });\n";
- } else {
- //focus element with given id
- echo "addonload(function() { if(el = document.getElementById('$focus')) el.focus(); });\n";
- }
- $focus=false; // Prevent themes from adding it to body tag which breaks addonload(), MDL-10249
+ //focus element with given id
+ echo "addonload(function() { if(el = document.getElementById('$focus')) el.focus(); });\n";
}
-
- echo "var id2suffix = {};\n";
- echo "//]]>\n";
- echo "</script>\n";
+ $focus = false; // Prevent themes from adding it to body tag which breaks addonload(), MDL-10249
+}
?>
+//]]>
+</script>
}
}
+/**
+ * This code is called from help.php to inject a list of smilies into the
+ * emoticons help file.
+ *
+ * @return string HTML for a list of smilies.
+ */
+function get_emoticons_list_for_help_file(){
+ global $CFG, $SESSION;
+ if (empty($CFG->emoticons)) {
+ return '';
+ }
+
+ require_js(array('yui_yahoo', 'yui_event'));
+ $items = explode('{;}', $CFG->emoticons);
+ $output = '<ul id="emoticonlist">';
+ foreach ($items as $item) {
+ $item = explode('{:}', $item);
+ $output .= '<li><img src="' . $CFG->pixpath.'/s/' . $item[1] . '.gif" alt="' .
+ $item[0] . '" /><code>' . $item[0] . '</code></li>';
+ }
+ $output .= '</ul>';
+ if (!empty($SESSION->inserttextform)) {
+ $formname = $SESSION->inserttextform;
+ $fieldname = $SESSION->inserttextfield;
+ } else {
+ $formname = 'theform';
+ $fieldname = 'message';
+ }
+
+ $output .= print_js_call('emoticons_help.init', array($formname, $fieldname, 'emoticonlist'), true);
+ return $output;
+
+}
+
/**
* Given plain text, makes it into HTML as nicely as possible.
* May contain HTML tags already
// Have to treat the prefix and no prefix cases separately.
if ($prefix) {
// Recommended way, only one thing in global scope.
- $html .= 'var $name = ' . json_encode($settings) . "\n";
+ $html .= "var $prefix = " . json_encode($settings) . "\n";
} else {
// Old fashioned way.
foreach ($settings as $name => $value) {
- $html .= "var " . $name . " = '" . addslashes_js($value) . "'\n";
+ $html .= "var $name = '" . addslashes_js($value) . "'\n";
}
}
$urlparams[] = "module$i=".urlencode($item[2]);
}
$titles[] = trim($item[1], ". \t");
- }elseif (is_string($item)){
+ } else if (is_string($item)) {
$urlparams[] = "button$i=".urlencode($item);
- switch ($item){
+ switch ($item) {
case 'reading' :
$titles[] = get_string("helpreading");
break;
case 'questions' :
$titles[] = get_string("helpquestions");
break;
- case 'emoticons' :
+ case 'emoticons2' :
$titles[] = get_string("helpemoticons");
break;
- case 'richtext' :
+ case 'richtext2' :
$titles[] = get_string('helprichtext');
break;
- case 'text' :
+ case 'text2' :
$titles[] = get_string('helptext');
break;
default :