Add 2 new hooks: geoSearch and nicknameClicked
For both of them returning false will interupt the default action 'geoSearch' is called when something is entered in the search box. The argument is the string entered in the search box 'nicknameClicked' is called when a nickname is cliked. The argument is an object with 2 properties: - 'event' contain the standard event object - 'nickname' contain the nick of the user
This commit is contained in:
13
code/chat.js
13
code/chat.js
@ -241,6 +241,14 @@ window.chat.renderFull = function(oldMsgsWereAdded) {
|
|||||||
// common
|
// common
|
||||||
//
|
//
|
||||||
|
|
||||||
|
window.chat.nicknameClicked = function(event, nickname) {
|
||||||
|
var hookData = { event: event, nickname: nickname.replace(/^@/, '') };
|
||||||
|
|
||||||
|
if (window.runHooks('nicknameClicked', hookData)) {
|
||||||
|
window.chat.addNickname(nickname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel) {
|
window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel) {
|
||||||
$.each(newData.result, function(ind, json) {
|
$.each(newData.result, function(ind, json) {
|
||||||
// avoid duplicates
|
// avoid duplicates
|
||||||
@ -283,9 +291,10 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel) {
|
|||||||
case 'AT_PLAYER':
|
case 'AT_PLAYER':
|
||||||
var thisToPlayer = (markup[1].plain == ('@'+window.PLAYER.nickname));
|
var thisToPlayer = (markup[1].plain == ('@'+window.PLAYER.nickname));
|
||||||
var spanClass = thisToPlayer ? "pl_nudge_me" : (markup[1].team + " pl_nudge_player");
|
var spanClass = thisToPlayer ? "pl_nudge_me" : (markup[1].team + " pl_nudge_player");
|
||||||
|
var atPlayerName = markup[1].plain.replace(/^@/, "");
|
||||||
msg += $('<div/>').html($('<span/>')
|
msg += $('<div/>').html($('<span/>')
|
||||||
.attr('class', spanClass)
|
.attr('class', spanClass)
|
||||||
.attr('onclick',"window.chat.addNickname('"+markup[1].plain+"')")
|
.attr('onclick',"window.chat.nicknameClicked(event, '"+atPlayerName+"')")
|
||||||
.text(markup[1].plain)).html();
|
.text(markup[1].plain)).html();
|
||||||
msgToPlayer = msgToPlayer || thisToPlayer;
|
msgToPlayer = msgToPlayer || thisToPlayer;
|
||||||
break;
|
break;
|
||||||
@ -401,7 +410,7 @@ window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarro
|
|||||||
var s = 'style="cursor:pointer; color:'+color+'"';
|
var s = 'style="cursor:pointer; color:'+color+'"';
|
||||||
var title = nick.length >= 8 ? 'title="'+nick+'" class="help"' : '';
|
var title = nick.length >= 8 ? 'title="'+nick+'" class="help"' : '';
|
||||||
var i = ['<span class="invisep"><</span>', '<span class="invisep">></span>'];
|
var i = ['<span class="invisep"><</span>', '<span class="invisep">></span>'];
|
||||||
return '<tr><td>'+t+'</td><td>'+i[0]+'<mark class="nickname" onclick="window.chat.addNickname(\'@' + nick + '\')" ' + s + '>'+ nick+'</mark>'+i[1]+'</td><td>'+msg+'</td></tr>';
|
return '<tr><td>'+t+'</td><td>'+i[0]+'<mark class="nickname" onclick="window.chat.nicknameClicked(event, \'@' + nick + '\')" ' + s + '>'+ nick+'</mark>'+i[1]+'</td><td>'+msg+'</td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
window.chat.addNickname= function(nick){
|
window.chat.addNickname= function(nick){
|
||||||
|
@ -4,7 +4,14 @@
|
|||||||
window.setupGeosearch = function() {
|
window.setupGeosearch = function() {
|
||||||
$('#geosearch').keypress(function(e) {
|
$('#geosearch').keypress(function(e) {
|
||||||
if((e.keyCode ? e.keyCode : e.which) != 13) return;
|
if((e.keyCode ? e.keyCode : e.which) != 13) return;
|
||||||
$.getJSON(NOMINATIM + encodeURIComponent($(this).val()), function(data) {
|
|
||||||
|
var search = $(this).val();
|
||||||
|
|
||||||
|
if (!runHooks('geoSearch', search)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.getJSON(NOMINATIM + encodeURIComponent(search), function(data) {
|
||||||
if(!data || !data[0]) return;
|
if(!data || !data[0]) return;
|
||||||
var b = data[0].boundingbox;
|
var b = data[0].boundingbox;
|
||||||
if(!b) return;
|
if(!b) return;
|
||||||
|
@ -59,15 +59,21 @@
|
|||||||
window._hooks = {}
|
window._hooks = {}
|
||||||
window.VALID_HOOKS = ['portalAdded', 'portalDetailsUpdated',
|
window.VALID_HOOKS = ['portalAdded', 'portalDetailsUpdated',
|
||||||
'publicChatDataAvailable', 'factionChatDataAvailable', 'portalDataLoaded',
|
'publicChatDataAvailable', 'factionChatDataAvailable', 'portalDataLoaded',
|
||||||
'beforePortalReRender', 'checkRenderLimit', 'requestFinished'];
|
'beforePortalReRender', 'checkRenderLimit', 'requestFinished', 'nicknameClicked',
|
||||||
|
'geoSearch'];
|
||||||
|
|
||||||
window.runHooks = function(event, data) {
|
window.runHooks = function(event, data) {
|
||||||
if(VALID_HOOKS.indexOf(event) === -1) throw('Unknown event type: ' + event);
|
if(VALID_HOOKS.indexOf(event) === -1) throw('Unknown event type: ' + event);
|
||||||
|
|
||||||
if(!_hooks[event]) return;
|
if(!_hooks[event]) return;
|
||||||
|
var interupted = false;
|
||||||
$.each(_hooks[event], function(ind, callback) {
|
$.each(_hooks[event], function(ind, callback) {
|
||||||
callback(data);
|
if (callback(data) === false) {
|
||||||
|
interupted = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
return !interupted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user