(Partial) added /require command and debug module

This commit is contained in:
unkelpehr 2014-09-27 14:20:21 +02:00
parent b0d45d4b69
commit a72cd394ad
2 changed files with 44 additions and 10 deletions

View File

@ -8,7 +8,7 @@
mediator.on('console:server', server); mediator.on('console:server', server);
mediator.on('console:message', message); mediator.on('console:message', message);
mediator.on('console:lockinput', lockInput); mediator.on('console:lockinput', lockInput);
mediator.on('console:unlockinput', unlockInput); mediator.on('console:unlockInput', unlockInput);
mediator.on('console:param', param); mediator.on('console:param', param);
Emits: Emits:
@ -58,7 +58,7 @@ define(
showNotification(type, nick, text); showNotification(type, nick, text);
// Append the post to the chat DOM element // Append the post to the chat DOM element
components.chat['append'](post); components.chat.append(post);
}, },
@ -84,7 +84,7 @@ define(
}, },
motd = function (payload, done) { post('motd', payload); }, motd = function (payload) { post('motd', settings.motd); },
info = function (payload, done) { post('info', payload); }, info = function (payload, done) { post('info', payload); },
error = function (payload, done) { post('error', payload); }, error = function (payload, done) { post('error', payload); },
message = function (payload, done) { post('message', payload.message , payload.nick ); }, message = function (payload, done) { post('message', payload.message , payload.nick ); },
@ -98,7 +98,7 @@ define(
clear = function () { clear = function () {
fandango.subordinate(function () { fandango.subordinate(function () {
components.chat[0].innerHTML='' components.chat[0].innerHTML = '';
}); });
}, },
@ -113,6 +113,20 @@ define(
components.input.focus(); components.input.focus();
}, },
_require = function (filepath, done) {
lockInput();
post('info', 'Requiring ' + filepath + '...');
require([filepath], function () {
post('info', 'Successfully required ' + filepath + '.');
unlockInput();
done();
}, function (e) {
post('error', 'An error occurred while trying to load "' + filepath + '":\n' + e);
unlockInput();
done();
});
},
// Handler for the document`s keyDown-event. // Handler for the document`s keyDown-event.
onKeyDown = function (e) { onKeyDown = function (e) {
var buffer, var buffer,
@ -141,10 +155,10 @@ define(
// Shout this command to all modules // Shout this command to all modules
mediator.emit( mediator.emit(
'command:'+command, 'console:' + command,
payload, payload,
function(retvals, recipients) { function(retvals, recipients) {
if(recipients == 0) { if(!recipients) {
return post('error', $.template(templates.messages.unrecognized_command, { commandName: command })); return post('error', $.template(templates.messages.unrecognized_command, { commandName: command }));
} else { } else {
clearInput(); clearInput();
@ -180,7 +194,7 @@ define(
}; };
// Bind the necessary DOM events // Bind the necessary DOM events
$(document).on('keydown', onKeyDown);; $(document).on('keydown', onKeyDown);
// Put focus on the message input // Put focus on the message input
components.input.focus(); components.input.focus();
@ -195,5 +209,8 @@ define(
mediator.on('console:lockinput', lockInput); mediator.on('console:lockinput', lockInput);
mediator.on('console:unlockinput', unlockInput); mediator.on('console:unlockinput', unlockInput);
mediator.on('console:param', param); mediator.on('console:param', param);
mediator.on('console:require', _require);
mediator.on('console:post', function (data) {
post(data.type, data.data, data.nick);
});
}); });

View File

@ -0,0 +1,17 @@
define(['castrato'], function (castrato) {
var exports = {};
castrato.on('*', function (data, done, name) {
if (name !== 'console:post' && name !== 'notification:send') {
castrato.emit('console:post', {
type: 'server',
data: name + (data ? '(' + JSON.stringify(data) + ')' : ''),
debug: 1
});
}
done();
});
return exports;
});