From: samhemelryk <samhemelryk>
Date: Tue, 30 Jun 2009 01:28:32 +0000 (+0000)
Subject: message MDL-16706 Replaced inline JS with new PAGE methods and created message.js
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c2a1db457628588f2b12ea995d0fcf1025394d06;p=moodle.git

message MDL-16706 Replaced inline JS with new PAGE methods and created 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 '<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;
     }
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 = '<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>';
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<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');
 }