1 // This file is part of Moodle - http://moodle.org/
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 * This module instantiates the functionality of the messaging area.
19 * @module core_message/message_area
20 * @package core_message
21 * @copyright 2016 Mark Nelson <markn@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 define(['jquery', 'core_message/message_area_contacts', 'core_message/message_area_messages',
25 'core_message/message_area_profile', 'core_message/message_area_tabs', 'core_message/message_area_search'],
26 function($, Contacts, Messages, Profile, Tabs, Search) {
31 * @param {String} selector The selector for the page region containing the message area.
33 function Messagearea(selector) {
34 this.node = $(selector);
38 /** @type {jQuery} The jQuery node for the page region containing the message area. */
39 Messagearea.prototype.node = null;
42 * Initialise the other objects we require.
44 Messagearea.prototype._init = function() {
53 * Handles adding a delegate event to the messaging area node.
55 * @param {String} action The action we are listening for
56 * @param {String} selector The selector for the page we are assigning the action to
57 * @param {Function} callable The function to call when the event happens
59 Messagearea.prototype.onDelegateEvent = function(action, selector, callable) {
60 this.node.on(action, selector, callable);
64 * Handles adding a custom event to the messaging area node.
66 * @param {String} action The action we are listening for
67 * @param {Function} callable The function to call when the event happens
69 Messagearea.prototype.onCustomEvent = function(action, callable) {
70 this.node.on(action, callable);
74 * Handles triggering an event on the messaging area node.
76 * @param {String} event The selector for the page region containing the message area
77 * @param {Object=} data The data to pass when we trigger the event
79 Messagearea.prototype.trigger = function(event, data) {
80 if (typeof data == 'undefined') {
83 this.node.trigger(event, data);
87 * Handles finding a node in the messaging area.
89 * @param {String} selector The selector for the node we are looking for
90 * @return {jQuery} The node
92 Messagearea.prototype.find = function(selector) {
93 return this.node.find(selector);
97 * Returns the ID of the user whose message area we are viewing.
99 * @return {int} The user id
101 Messagearea.prototype.getCurrentUserId = function() {
102 return this.node.data('userid');