From c2a1db457628588f2b12ea995d0fcf1025394d06 Mon Sep 17 00:00:00 2001 From: samhemelryk Date: Tue, 30 Jun 2009 01:28:32 +0000 Subject: [PATCH] message MDL-16706 Replaced inline JS with new PAGE methods and created message.js --- message/index.php | 2 +- message/lib.php | 8 ++------ message/message.js | 3 +++ message/send.php | 14 +++++--------- 4 files changed, 11 insertions(+), 16 deletions(-) create mode 100644 message/message.js diff --git a/message/index.php b/message/index.php index 2b6fa7c330..b207c6bf65 100644 --- a/message/index.php +++ b/message/index.php @@ -25,7 +25,7 @@ /// Popup a window if required and quit (usually from external links). if ($popup) { print_header(); - echo '"; + 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; } diff --git a/message/lib.php b/message/lib.php index 1f05da1bea..19ef75bf4c 100644 --- a/message/lib.php +++ b/message/lib.php @@ -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 = '

'.get_string('pagerefreshes', 'message', $CFG->message_contacts_refresh).'

'; $autorefresh = addslashes_js($autorefresh); // js escaping + echo $PAGE->requires->js_function_call('document.write', Array($autorefresh))->asap(); // gracefully degrade JS autorefresh - echo ''; echo ''; diff --git a/message/message.js b/message/message.js new file mode 100644 index 0000000000..6b7c6e32f7 --- /dev/null +++ b/message/message.js @@ -0,0 +1,3 @@ +function set_focus(eid) { + document.getElementById(eid).focus(); +} \ No newline at end of file diff --git a/message/send.php b/message/send.php index efc13d1609..4d74995003 100644 --- a/message/send.php +++ b/message/send.php @@ -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\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.'&user2='.$USER->id.'#m'.$messageid, $user->id); } @@ -97,11 +97,7 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE } echo ''; - echo ""; + $PAGE->requires->js_function_call('set_focus', Array('edit-message')); print_footer('empty'); } -- 2.39.5