message MDL-16706 Replaced inline JS with new PAGE methods and created message.js

This commit is contained in:
samhemelryk
2009-06-30 01:28:32 +00:00
parent ab3a235be4
commit c2a1db4576
4 changed files with 11 additions and 16 deletions
+1 -1
View File
@@ -25,7 +25,7 @@
/// Popup a window if required and quit (usually from external links).
if ($popup) {
print_header();
echo '<script type="text/javascript">'."\n//<![CDATA[\n openpopup('/message/index.php', 'message', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0);\n//]]>\n</script>";
echo $PAGE->requires->js_function_call('openpopup', Array('/message/index.php', 'message', 'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500', 0))->asap();
redirect("$CFG->wwwroot/", '', 0);
exit;
}
+2 -6
View File
@@ -19,7 +19,7 @@ if (!isset($CFG->message_offline_time)) {
function message_print_contacts() {
global $USER, $CFG, $DB;
global $USER, $CFG, $DB, $PAGE;
$timetoshowusers = 300; //Seconds default
if (isset($CFG->block_online_users_timetosee)) {
@@ -149,12 +149,8 @@ function message_print_contacts() {
$autorefresh = '<p align="center" class="note">'.get_string('pagerefreshes', 'message', $CFG->message_contacts_refresh).'</p>';
$autorefresh = addslashes_js($autorefresh); // js escaping
echo $PAGE->requires->js_function_call('document.write', Array($autorefresh))->asap();
// gracefully degrade JS autorefresh
echo '<script type="text/javascript">
//<![CDATA[
document.write("'.$autorefresh.'")
//]]>
</script>';
echo '<noscript><div class="button aligncenter">';
echo print_single_button('index.php', false, get_string('refresh'));
echo '</div></noscript>';
+3
View File
@@ -0,0 +1,3 @@
function set_focus(eid) {
document.getElementById(eid).focus();
}
+5 -9
View File
@@ -15,6 +15,8 @@ if (empty($CFG->messaging)) {
if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTEM))) {
$PAGE->requires->js('message/message.js');
/// (Don't use print_header, for more speed)
/// ehm - we have to use print_header() or else this breaks after any minor change in print_header()!
print_header();
@@ -65,10 +67,8 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE
$message = addslashes_js($message); // So Javascript can write it
/// Then write it to our own message screen immediately
echo "\n<script type=\"text/javascript\">\n<!--\n";
echo 'parent.messages.document.write(\''.$message."\\n');\n";
echo 'parent.messages.scroll(1,5000000);';
echo "\n-->\n</script>\n\n";
$PAGE->requires->js_function_call('parent.messages.document.write', Array($message));
$PAGE->requires->js_function_call('parent.messages.scroll', Array(1,5000000));
add_to_log(SITEID, 'message', 'write', 'history.php?user1='.$user->id.'&amp;user2='.$USER->id.'#m'.$messageid, $user->id);
}
@@ -97,11 +97,7 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE
}
echo '<div class="noframesjslink"><a target="_parent" href="discussion.php?id='.$userid.'&amp;noframesjs=1">'.get_string('noframesjs', 'message').'</a></div>';
echo "<script type=\"text/javascript\">".
"\n//<![CDATA[".
"\ndocument.getElementById(\"edit-message\").focus();".
"\n//]]>".
"\n</script>";
$PAGE->requires->js_function_call('set_focus', Array('edit-message'));
print_footer('empty');
}