Bughunt
This commit is contained in:
parent
65d8a1c122
commit
276220eaf4
|
@ -16,15 +16,12 @@
|
|||
mediator.emit('audio:play',...);
|
||||
ToDo
|
||||
*/
|
||||
define(
|
||||
{
|
||||
define({
|
||||
compiles: ['$'],
|
||||
requires: ['castrato', 'fandango', 'settings', 'templates', 'sounds', 'room', 'notifications', 'audio']
|
||||
}, function ($, requires, data) {
|
||||
|
||||
var
|
||||
|
||||
// Require shortcuts
|
||||
var // Require shortcuts
|
||||
fandango = requires.fandango,
|
||||
mediator = requires.castrato,
|
||||
settings = requires.settings,
|
||||
|
@ -42,8 +39,8 @@ define(
|
|||
parameters = {},
|
||||
|
||||
// Adds a new message to the DOM
|
||||
post = function (type, text, nick) {
|
||||
|
||||
commands = {
|
||||
post: function (type, text, nick) {
|
||||
var tpl = templates.post[type],
|
||||
post,
|
||||
data = fandango.merge({}, settings, {
|
||||
|
@ -55,76 +52,89 @@ define(
|
|||
post = $.template(tpl, data);
|
||||
|
||||
// Request a notification
|
||||
showNotification(type, nick, text);
|
||||
commands.showNotification(type, nick, text);
|
||||
|
||||
// Append the post to the chat DOM element
|
||||
components.chat.append(post);
|
||||
|
||||
},
|
||||
|
||||
param = function (p) {
|
||||
param: function (p) {
|
||||
parameters = fandango.merge({}, parameters, p);
|
||||
},
|
||||
|
||||
showNotification = function (type, nick, text) {
|
||||
|
||||
var title = (type!='message') ? 'Cryptalk' : nick,
|
||||
icon = (type == 'message') ? 'gfx/icon_128x128.png' : (type == 'error') ? 'gfx/icon_128x128_error.png' : 'gfx/icon_128x128_info.png';
|
||||
showNotification: function (type, nick, text) {
|
||||
var title = type !== 'message' ? 'Cryptalk' : nick,
|
||||
icon = type === 'message'? 'gfx/icon_128x128.png' : (type == 'error' ? 'gfx/icon_128x128_error.png' : 'gfx/icon_128x128_info.png');
|
||||
|
||||
// Emit notification
|
||||
mediator.emit('notification:send',
|
||||
{
|
||||
mediator.emit('notification:send', {
|
||||
title: title.substring(0, 20),
|
||||
body: text.substring(0, 80),
|
||||
icon: icon
|
||||
});
|
||||
|
||||
// Emit sound
|
||||
if ( type == 'message' ) mediator.emit('audio:play', sounds.message);
|
||||
|
||||
if (type === 'message') {
|
||||
mediator.emit('audio:play', sounds.message);
|
||||
}
|
||||
},
|
||||
|
||||
motd = function (payload) { post('motd', settings.motd); },
|
||||
info = function (payload, done) { post('info', payload); },
|
||||
error = function (payload, done) { post('error', payload); },
|
||||
message = function (payload, done) { post('message', payload.message , payload.nick ); },
|
||||
server = function (payload, done) { post('server', payload); },
|
||||
motd: function () {
|
||||
commands.post('motd', settings.motd);
|
||||
},
|
||||
|
||||
clearInput = function () {
|
||||
info: function (message) {
|
||||
commands.post('info', message);
|
||||
},
|
||||
|
||||
error: function (message) {
|
||||
commands.post('error', message);
|
||||
},
|
||||
|
||||
server: function (message) {
|
||||
commands.post('server', message);
|
||||
},
|
||||
|
||||
message: function (data) {
|
||||
commands.post('message', data.message, data.nick);
|
||||
},
|
||||
|
||||
clearInput: function () {
|
||||
fandango.subordinate(function () {
|
||||
components.input[0].value = '';
|
||||
});
|
||||
},
|
||||
|
||||
clear = function () {
|
||||
clear: function () {
|
||||
fandango.subordinate(function () {
|
||||
components.chat[0].innerHTML = '';
|
||||
});
|
||||
},
|
||||
|
||||
lockInput = function () {
|
||||
lockInput: function () {
|
||||
components.input[0].setAttribute('disabled', 'disabled');
|
||||
components.inputWrapper[0].className = 'loading';
|
||||
},
|
||||
|
||||
unlockInput = function () {
|
||||
unlockInput: function () {
|
||||
components.input[0].removeAttribute('disabled');
|
||||
components.inputWrapper[0].className = '';
|
||||
components.input.focus();
|
||||
},
|
||||
|
||||
_require = function (filepath, done) {
|
||||
lockInput();
|
||||
post('info', 'Requiring ' + filepath + '...');
|
||||
_require: function (filepath, done) {
|
||||
commands.lockInput();
|
||||
commands.post('info', 'Requiring ' + filepath + '...');
|
||||
require([filepath], function () {
|
||||
post('info', 'Successfully required ' + filepath + '.');
|
||||
unlockInput();
|
||||
commands.post('info', 'Successfully required ' + filepath + '.');
|
||||
commands.unlockInput();
|
||||
done();
|
||||
}, function (e) {
|
||||
post('error', 'An error occurred while trying to load "' + filepath + '":\n' + e);
|
||||
unlockInput();
|
||||
commands.post('error', 'An error occurred while trying to load "' + filepath + '":\n' + e);
|
||||
commands.unlockInput();
|
||||
done();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// Handler for the document`s keyDown-event.
|
||||
|
@ -159,9 +169,9 @@ define(
|
|||
payload,
|
||||
function(retvals, recipients) {
|
||||
if(!recipients) {
|
||||
return post('error', $.template(templates.messages.unrecognized_command, { commandName: command }));
|
||||
return commands.post('error', $.template(templates.messages.unrecognized_command, { commandName: command }));
|
||||
} else {
|
||||
clearInput();
|
||||
commands.clearInput();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -170,7 +180,7 @@ define(
|
|||
|
||||
if(!parameters.room || !parameters.key ) {
|
||||
// Make sure that the user has joined a room and the key is set
|
||||
return (!parameters.room) ? post('error', templates.messages.msg_no_room) : post('error', templates.messages.msg_no_key);
|
||||
return (!parameters.room) ? commands.post('error', templates.messages.msg_no_room) : commands.post('error', templates.messages.msg_no_key);
|
||||
}
|
||||
|
||||
// Before sending the message.
|
||||
|
@ -188,8 +198,7 @@ define(
|
|||
);
|
||||
|
||||
// And clear the the buffer
|
||||
clearInput();
|
||||
|
||||
commands.clearInput();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -200,17 +209,15 @@ define(
|
|||
components.input.focus();
|
||||
|
||||
// Connect events
|
||||
mediator.on('console:clear', clear);
|
||||
mediator.on('console:motd', motd);
|
||||
mediator.on('console:info', info);
|
||||
mediator.on('console:error', error);
|
||||
mediator.on('console:server', server);
|
||||
mediator.on('console:message', message);
|
||||
mediator.on('console:lockinput', lockInput);
|
||||
mediator.on('console:unlockinput', unlockInput);
|
||||
mediator.on('console:param', param);
|
||||
mediator.on('console:require', _require);
|
||||
for (var commandName in commands) {
|
||||
if (commandName === '_require' && commandName !== 'post') {
|
||||
mediator.on('console:' + commandName, commands[commandName]);
|
||||
}
|
||||
}
|
||||
|
||||
mediator.on('console:require', commands._require);
|
||||
|
||||
mediator.on('console:post', function (data) {
|
||||
post(data.type, data.data, data.nick);
|
||||
commands.post(data.type, data.data, data.nick);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue