From c5f1fdb451610810be87237101b212a903df670f Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Mon, 15 Feb 2010 06:08:41 +0000 Subject: [PATCH] mod-chat MDL-21534 Added documentation, revised namespace, fixed non-namespaced function call. --- mod/chat/gui_header_js/chatinput.php | 2 +- mod/chat/gui_header_js/insert.php | 9 +++- mod/chat/gui_header_js/module.js | 70 ++++++++++++++++++++++------ mod/chat/gui_header_js/users.php | 3 +- 4 files changed, 64 insertions(+), 20 deletions(-) diff --git a/mod/chat/gui_header_js/chatinput.php b/mod/chat/gui_header_js/chatinput.php index 0ee709073a9..b6b700cdbb3 100644 --- a/mod/chat/gui_header_js/chatinput.php +++ b/mod/chat/gui_header_js/chatinput.php @@ -36,7 +36,7 @@ $module = array( 'fullpath' => '/mod/chat/gui_header_js/module.js', 'requires' => array('base', 'node') ); -$PAGE->requires->js_init_call('M.mod_chat_js.init', array(false), false, $module); +$PAGE->requires->js_init_call('M.mod_chat.js.init', array(false), false, $module); //Setup course, lang and theme $PAGE->set_course($course); diff --git a/mod/chat/gui_header_js/insert.php b/mod/chat/gui_header_js/insert.php index 209a64fd5cc..be314eed9d8 100644 --- a/mod/chat/gui_header_js/insert.php +++ b/mod/chat/gui_header_js/insert.php @@ -63,10 +63,15 @@ if (!empty($chat_message)) { } if ($chatuser->version == 'header_js') { + /// force msg referesh ASAP - $PAGE->requires->js('/mod/chat/gui_header_js/chat_gui_header.js'); if ($CFG->chat_normal_updatemode != 'jsupdated') { // See bug MDL-6791 - $PAGE->requires->js_function_call('insert_redirect'); + $module = array( + 'name' => 'mod_chat_js', + 'fullpath' => '/mod/chat/gui_header_js/module.js', + 'requires' => array('base', 'node') + ); + $PAGE->requires->js_init_call('M.mod_chat.js.insert_redirect', array(false), false, $module); } $PAGE->requires->js_function_call('parent.input.enableForm'); } diff --git a/mod/chat/gui_header_js/module.js b/mod/chat/gui_header_js/module.js index d834bc095d4..e410ff6c565 100644 --- a/mod/chat/gui_header_js/module.js +++ b/mod/chat/gui_header_js/module.js @@ -1,12 +1,31 @@ +/** + * Module for the general JavaScript chat module + */ YUI.add('mod_chat_js', function(Y){ + /** + * @namespace M.mod_chat + */ + M.mod_chat = M.mod_chat || {}; + /** + * @namespace M.mod_chat.js + */ + M.mod_chat.js = { - M.mod_chat_js = { - - waitflag : false, - timer : null, - timeout : 1, - users : [], + waitflag : false, // True when a submission is in progress + timer : null, // Stores the timer object + timeout : 1, // The seconds between updates + users : [], // An array of users + /** + * Function that kicks everything off depending on what is available + * within the page, this means we can call it from within each frame and it + * will set up correctly + * + * @function + * @this {M.mod_chat.js} + * @param {YUI} Y + * @param {Array|null} users + */ init : function(Y, users) { if (users) { this.users = users; @@ -18,17 +37,30 @@ YUI.add('mod_chat_js', function(Y){ inputform.on('submit', this.submit, this); } }, - + /** + * Starts the update timeout + * + * @function + * @this {M.mod_chat.js} + */ start : function() { this.timer = setTimeout(function(self){ self.update(); }, this.timeout*1000, this); }, - + /** + * Stops the update timeout + * @function + * @this {M.mod_chat.js} + */ stop : function() { clearTimeout(this.timer); }, - + /** + * Updates the user information + * @function + * @this {M.mod_chat.js} + */ update : function() { for (var i in this.users) { var el = Y.one('#uidle'+this.users[i]); @@ -42,17 +74,26 @@ YUI.add('mod_chat_js', function(Y){ } this.start(); }, - + /** + * Redirects the frames parent + */ insert_redirect : function() { parent.jsupdate.location.href = parent.jsupdate.document.anchors[0].href; }, - - enable_form : function(el) { + /** + * Enables the input form + * @this {M.mod_chat.js} + */ + enable_form : function() { + var el = Y.one('#input_chat_message'); this.waitflag = false; el.set('className',''); el.focus(); }, - + /** + * Submits the entered message + * @param {Event} e + */ submit : function(e) { e.halt(); if(this.waitflag) { @@ -64,10 +105,9 @@ YUI.add('mod_chat_js', function(Y){ inputchatmessage.set('value', ''); inputchatmessage.addClass('wait'); Y.one('#sendForm').submit(); - this.enable_form(inputchatmessage); + this.enable_form(); return false; } } - }, '2.0.0', {requires:['base','node']}); \ No newline at end of file diff --git a/mod/chat/gui_header_js/users.php b/mod/chat/gui_header_js/users.php index 35af4d35629..abb9427e275 100644 --- a/mod/chat/gui_header_js/users.php +++ b/mod/chat/gui_header_js/users.php @@ -72,7 +72,7 @@ $module = array( 'fullpath' => '/mod/chat/gui_header_js/module.js', 'requires' => array('base', 'node') ); -$PAGE->requires->js_init_call('M.mod_chat_js.init', array($uidles), false, $module); +$PAGE->requires->js_init_call('M.mod_chat.js.init', array($uidles), false, $module); /// Print user panel body $timenow = time(); @@ -92,7 +92,6 @@ foreach ($chatusers as $chatuser) { $row = array(); - //$popupid = $OUTPUT->add_action_handler(new component_action('click', 'openpopup', array('url'=>'/user/view.php?id=$chatuser->id&course=$courseid', 'name'=>'user'.$chatuser->id, 'options'=>''))); $row[0] = $OUTPUT->user_picture($chatuser, array('courseid'=>$courseid, 'popup'=>true)); $row[1] = html_writer::start_tag('p'); $row[1] .= html_writer::start_tag('font', array('size'=>'1'));