/* * NOTE: the /mod/chat/gui_header_js/ is not a real plugin, * ideally this code should be in /mod/chat/module.js */ /** * @namespace M.mod_chat_ajax */ M.mod_chat_ajax = M.mod_chat_ajax || {}; /** * Init ajax based Chat UI. * @namespace M.mod_chat_ajax * @function * @param {YUI} Y * @param {Object} cfg configuration data */ M.mod_chat_ajax.init = function(Y, cfg) { var gui_ajax = { // Properties api : M.cfg.wwwroot+'/mod/chat/chat_ajax.php?sesskey='+M.cfg.sesskey, // The path to the ajax callback script cfg : {}, // A configuration variable interval : null, // The interval object for refreshes layout : null, // A reference to the layout used in this module messages : [], // An array of messages scrollable : true, // True is scrolling should occur thememenu : null, // A reference to the menu for changing themes // Elements messageinput : null, sendbutton : null, messagebox : null, init : function(cfg) { this.cfg = cfg; this.cfg.req_count = this.cfg.req_count || 0; this.layout = new YAHOO.widget.Layout({ units : [ {position: 'right', width: 180, resize: true, gutter: '5px', scroll: true, body: 'chat-userlist', animate: false}, {position: 'bottom', height: 42, resize: false, body: 'chat-input-area', gutter: '5px', collapse: false, resize: false}, {position: 'center', body: 'chat-messages', gutter: '5px', scroll: true} ] }); this.layout.on('render', function() { var unit = this.getUnitByPosition('right'); if (unit) { unit.on('close', function() { closeLeft(); }); } }, this.layout); this.layout.render(); // Gather the general elements this.messageinput = Y.one('#input-message'); this.sendbutton = Y.one('#button-send'); this.messagebox = Y.one('#chat-messages'); // Attach the default events for this module this.sendbutton.on('click', this.send, this); this.messagebox.on('mouseenter', function() { this.scrollable = false; }, this); this.messagebox.on('mouseleave', function() { this.scrollable = true; }, this); // Send the message when the enter key is pressed Y.on('key', this.send, this.messageinput, 'press:13', this); document.title = this.cfg.chatroom_name; // Prepare and execute the first AJAX request of information Y.io(this.api,{ method : 'POST', data : build_querystring({ action : 'init', chat_init : 1, chat_sid : this.cfg.sid, theme : this.theme }), on : { success : function(tid, outcome) { this.messageinput.removeAttribute('disabled'); this.messageinput.set('value', ''); this.messageinput.focus(); try { var data = Y.JSON.parse(outcome.responseText); } catch (ex) { return; } this.update_users(data.users); } }, context : this }); var scope = this; this.interval = setInterval(function() { scope.update_messages(); }, this.cfg.timer, this); // Create and initalise theme changing menu /* this.thememenu = new Y.Overlay({ bodyContent : '
', visible : false, zIndex : 2, align : { node : '#choosetheme', points : [Y.WidgetPositionExt.BL, Y.WidgetPositionExt.BR] } }); this.thememenu.render(document.body); Y.one('#choosetheme').on('click', function(e){ this.show(); this.get('boundingBox').setStyle('visibility', 'visible'); }, this.thememenu); return; */ this.thememenu = new YAHOO.widget.Menu('basicmenu', {xy:[0,0]}); this.thememenu.addItems([ {text: "Bubble", url: this.cfg.chaturl+'&theme=bubble'}, {text: "Compact", url: this.cfg.chaturl+'&theme=compact'} ]); this.thememenu.render(document.body); Y.one('#choosetheme').on('click', function(e){ this.moveTo((e.pageX-20), (e.pageY-20)); this.show(); }, this.thememenu); }, append_message : function(key, message, row) { var item = Y.Node.create(''+users[i].picture+' |