add hook for chat data

This commit is contained in:
Stefan Breunig 2013-02-18 11:12:26 +01:00
parent 4eb90976e3
commit 044b5f2147
2 changed files with 9 additions and 1 deletions

View File

@ -200,6 +200,8 @@ window.chat.handlePublic = function(data, textStatus, jqXHR) {
chat.writeDataToHash(data, chat._publicData, true); chat.writeDataToHash(data, chat._publicData, true);
var oldMsgsWereAdded = old !== chat.getOldestTimestamp(false); var oldMsgsWereAdded = old !== chat.getOldestTimestamp(false);
runHooks('publicChatDataAvailable', {raw: data, processed: chat._publicData});
switch(chat.getActive()) { switch(chat.getActive()) {
case 'public': window.chat.renderPublic(oldMsgsWereAdded); break; case 'public': window.chat.renderPublic(oldMsgsWereAdded); break;
case 'compact': window.chat.renderCompact(oldMsgsWereAdded); break; case 'compact': window.chat.renderCompact(oldMsgsWereAdded); break;

View File

@ -24,9 +24,15 @@
// the Leaflet CircleMarker for the portal in "portal" var. // the Leaflet CircleMarker for the portal in "portal" var.
// portalDetailsUpdated: fired after the details in the sidebar have // portalDetailsUpdated: fired after the details in the sidebar have
// been (re-)rendered // been (re-)rendered
// publicChatDataAvailable: this hook runs after data for any of the
// public chats has been received and processed, but not
// yet been displayed. The data hash contains both the un-
// processed raw ajax response as well as the processed
// chat data that is going to be used for display.
window._hooks = {} window._hooks = {}
window.VALID_HOOKS = ['portalAdded', 'portalDetailsUpdated']; window.VALID_HOOKS = ['portalAdded', 'portalDetailsUpdated',
'publicChatDataAvailable'];
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);