diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js index 0ed0c33230..d952d6abbc 100644 --- a/public/src/modules/chat.js +++ b/public/src/modules/chat.js @@ -258,6 +258,12 @@ define('chat', [ } }; + // TODO: see taskbar.js:44 + module.closeByUUID = function (uuid) { + var chatModal = $('.chat-modal[data-uuid="' + uuid + '"]'); + module.close(chatModal); + }; + module.center = function (chatModal) { var hideAfter = false; if (chatModal.hasClass('hide')) { diff --git a/public/src/modules/taskbar.js b/public/src/modules/taskbar.js index 5a1c0d886f..d285756391 100644 --- a/public/src/modules/taskbar.js +++ b/public/src/modules/taskbar.js @@ -34,6 +34,42 @@ define('taskbar', ['benchpress', 'translator'], function (Benchpress, translator return false; }); }); + + $(window).on('action:app.loggedOut', function () { + taskbar.closeAll(); + }); + }; + + taskbar.close = function (module, uuid) { + // Sends signal to the appropriate module's .close() fn (if present) + var btnEl = taskbar.tasklist.find('[data-module="' + module + '"][data-uuid="' + uuid + '"]'); + var fnName = 'close'; + + // TODO: Refactor chat module to not take uuid in close instead of by jQuery element + if (module === 'chat') { + fnName = 'closeByUUID'; + } + + if (btnEl.length) { + require([module], function (module) { + if (typeof module[fnName] === 'function') { + module[fnName](uuid); + } + }); + } + }; + + taskbar.closeAll = function (module) { + // module is optional + var selector = '[data-uuid]'; + + if (module) { + selector = '[data-module="' + module + '"]' + selector; + } + + taskbar.tasklist.find(selector).each(function (idx, el) { + taskbar.close(module || el.getAttribute('data-module'), el.getAttribute('data-uuid')); + }); }; taskbar.discard = function (module, uuid) {